Skip to content

Commit be153f0

Browse files
committed
Only prevent TAITs from defining each other, RPIT and async are fine, they only ever have one defining site, and it is ordered correctly around expected and actual type in type comparisons
1 parent 7f608eb commit be153f0

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8282
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
8383
ty::Opaque(def_id, substs) => {
8484
if let ty::Opaque(did2, _) = *b.kind() {
85-
if self.opaque_type_origin(did2, cause.span).is_some() {
85+
// We could accept this, but there are various ways to handle this situation, and we don't
86+
// want to make a decision on it right now. Likely this case is so super rare anyway, that
87+
// no one encounters it in practice.
88+
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
89+
// where it is of no concern, so we only check for TAITs.
90+
if let Some(OpaqueTyOrigin::TyAlias) =
91+
self.opaque_type_origin(did2, cause.span)
92+
{
8693
self.tcx
8794
.sess
8895
.struct_span_err(

src/test/ui/impl-trait/example-calendar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-pass
12
// ignore-compare-mode-chalk
23

34
#![feature(fn_traits,
@@ -589,7 +590,7 @@ fn test_format_month() {
589590
fn format_months(it: impl Iterator<Item = impl DateIterator>)
590591
-> impl Iterator<Item=impl Iterator<Item=String>>
591592
{
592-
it.map(format_month) //~ ERROR opaque type's hidden type cannot be another opaque type
593+
it.map(format_month)
593594
}
594595

595596
/// Takes an iterator of iterators of strings; the sub-iterators are consumed

src/test/ui/impl-trait/example-calendar.stderr

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)