Skip to content

Commit ec40b1a

Browse files
Collapse placeholders to root universe in canonicalizer if not preserving universes
1 parent f4a4a31 commit ec40b1a

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
418418
bug!("encountered a fresh type during canonicalization")
419419
}
420420

421-
ty::Placeholder(placeholder) => self.canonicalize_ty_var(
422-
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
423-
t,
424-
),
421+
ty::Placeholder(mut placeholder) => {
422+
if !self.canonicalize_mode.preserve_universes() {
423+
placeholder.universe = ty::UniverseIndex::ROOT;
424+
}
425+
self.canonicalize_ty_var(
426+
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
427+
t,
428+
)
429+
}
425430

426431
ty::Bound(debruijn, _) => {
427432
if debruijn >= self.binder_index {

tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ where
77
{
88
}
99

10+
pub fn bar()
11+
where
12+
for<V> V: IntoIterator,
13+
{
14+
}
15+
1016
fn main() {
1117
foo();
1218
//~^ ERROR the size for values of type `V` cannot be known at compilation time
19+
20+
bar();
1321
}

tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr

+36-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | #![feature(non_lifetime_binders)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error[E0277]: the size for values of type `V` cannot be known at compilation time
11-
--> $DIR/bad-sized-cond.rs:11:5
11+
--> $DIR/bad-sized-cond.rs:17:5
1212
|
1313
LL | foo();
1414
| ^^^ doesn't have a size known at compile-time
@@ -23,6 +23,40 @@ LL | where
2323
LL | for<V> V: Sized,
2424
| ^^^^^ required by this bound in `foo`
2525

26-
error: aborting due to previous error; 1 warning emitted
26+
error[E0277]: the size for values of type `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })` cannot be known at compilation time
27+
--> $DIR/bad-sized-cond.rs:20:5
28+
|
29+
LL | bar();
30+
| ^^^ doesn't have a size known at compile-time
31+
|
32+
= help: the trait `Sized` is not implemented for `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })`
33+
= note: required for `V` to implement `IntoIterator`
34+
note: required by a bound in `bar`
35+
--> $DIR/bad-sized-cond.rs:12:15
36+
|
37+
LL | pub fn bar()
38+
| --- required by a bound in this
39+
LL | where
40+
LL | for<V> V: IntoIterator,
41+
| ^^^^^^^^^^^^ required by this bound in `bar`
42+
43+
error[E0277]: `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })` is not an iterator
44+
--> $DIR/bad-sized-cond.rs:20:5
45+
|
46+
LL | bar();
47+
| ^^^ `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })` is not an iterator
48+
|
49+
= help: the trait `Iterator` is not implemented for `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })`
50+
= note: required for `V` to implement `IntoIterator`
51+
note: required by a bound in `bar`
52+
--> $DIR/bad-sized-cond.rs:12:15
53+
|
54+
LL | pub fn bar()
55+
| --- required by a bound in this
56+
LL | where
57+
LL | for<V> V: IntoIterator,
58+
| ^^^^^^^^^^^^ required by this bound in `bar`
59+
60+
error: aborting due to 3 previous errors; 1 warning emitted
2761

2862
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)