diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-06-29 07:52:45 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-07 13:17:00 +0000 |
| commit | b549ba1bd4313990d164bc7152e61aefd68eeacd (patch) | |
| tree | 8083bddb20bead7792218e9c79871d7206e7a4c1 | |
| parent | ef52dc7bb8c14c5663773f70e1353fd53131261c (diff) | |
| download | rust-b549ba1bd4313990d164bc7152e61aefd68eeacd.tar.gz rust-b549ba1bd4313990d164bc7152e61aefd68eeacd.zip | |
Fix one layer of closures not being able to constrain opaque types
| -rw-r--r-- | compiler/rustc_ty_utils/src/opaque_types.rs | 5 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/nested_in_closure.rs | 1 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/nested_in_closure.stderr | 15 |
3 files changed, 5 insertions, 16 deletions
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 |
