diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 2a706d72843..40d61f47adb 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -322,7 +322,10 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ | DefKind::GlobalAsm | DefKind::Impl { .. } => {} DefKind::Closure | DefKind::Generator => { - return tcx.opaque_types_defined_by(tcx.local_parent(item)); + // All items in the signature of the parent are ok + collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); + // And items in the body of the closure itself + collector.collect_taits_declared_in_body(); } } tcx.arena.alloc_from_iter(collector.opaques) diff --git a/tests/ui/type-alias-impl-trait/nested_in_closure.rs b/tests/ui/type-alias-impl-trait/nested_in_closure.rs index 3e9453559d5..3c15b0708a3 100644 --- a/tests/ui/type-alias-impl-trait/nested_in_closure.rs +++ b/tests/ui/type-alias-impl-trait/nested_in_closure.rs @@ -5,6 +5,5 @@ fn main() { type Tait = impl Sized; let y: Tait = (); //~^ ERROR: item constrains opaque type that is not in its signature - //~| ERROR: item constrains opaque type that is not in its signature }; } diff --git a/tests/ui/type-alias-impl-trait/nested_in_closure.stderr b/tests/ui/type-alias-impl-trait/nested_in_closure.stderr index c2e584793ad..beb670db171 100644 --- a/tests/ui/type-alias-impl-trait/nested_in_closure.stderr +++ b/tests/ui/type-alias-impl-trait/nested_in_closure.stderr @@ -11,18 +11,5 @@ note: this item must have the opaque type in its signature in order to be able t LL | fn main() { | ^^^^ -error: item constrains opaque type that is not in its signature - --> $DIR/nested_in_closure.rs:6:23 - | -LL | let y: Tait = (); - | ^^ - | - = note: this item must have the opaque type in its signature in order to be able to register hidden types -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/nested_in_closure.rs:4:13 - | -LL | let x = || { - | ^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error