Skip to content

Commit b549ba1

Browse files
committed
Fix one layer of closures not being able to constrain opaque types
1 parent ef52dc7 commit b549ba1

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
322322
| DefKind::GlobalAsm
323323
| DefKind::Impl { .. } => {}
324324
DefKind::Closure | DefKind::Generator => {
325-
return tcx.opaque_types_defined_by(tcx.local_parent(item));
325+
// All items in the signature of the parent are ok
326+
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
327+
// And items in the body of the closure itself
328+
collector.collect_taits_declared_in_body();
326329
}
327330
}
328331
tcx.arena.alloc_from_iter(collector.opaques)

tests/ui/type-alias-impl-trait/nested_in_closure.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ fn main() {
55
type Tait = impl Sized;
66
let y: Tait = ();
77
//~^ ERROR: item constrains opaque type that is not in its signature
8-
//~| ERROR: item constrains opaque type that is not in its signature
98
};
109
}

tests/ui/type-alias-impl-trait/nested_in_closure.stderr

+1-14
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,5 @@ note: this item must have the opaque type in its signature in order to be able t
1111
LL | fn main() {
1212
| ^^^^
1313

14-
error: item constrains opaque type that is not in its signature
15-
--> $DIR/nested_in_closure.rs:6:23
16-
|
17-
LL | let y: Tait = ();
18-
| ^^
19-
|
20-
= note: this item must have the opaque type in its signature in order to be able to register hidden types
21-
note: this item must have the opaque type in its signature in order to be able to register hidden types
22-
--> $DIR/nested_in_closure.rs:4:13
23-
|
24-
LL | let x = || {
25-
| ^^
26-
27-
error: aborting due to 2 previous errors
14+
error: aborting due to previous error
2815

0 commit comments

Comments
 (0)