about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-02-17 21:15:18 +0000
committerMichael Goulet <michael@errs.io>2023-02-18 19:49:40 +0000
commitec40b1a3938ea0f7ae27b4bffe62bd41dc8015af (patch)
tree4ee758fe4f70c8e384c575ecb035c2752d3703f0
parentf4a4a3147955ceb359204d85a74e15ee9d98046b (diff)
downloadrust-ec40b1a3938ea0f7ae27b4bffe62bd41dc8015af.tar.gz
rust-ec40b1a3938ea0f7ae27b4bffe62bd41dc8015af.zip
Collapse placeholders to root universe in canonicalizer if not preserving universes
-rw-r--r--compiler/rustc_infer/src/infer/canonical/canonicalizer.rs13
-rw-r--r--tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs8
-rw-r--r--tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr38
3 files changed, 53 insertions, 6 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
index 2b33d31994f..b736a416e4a 100644
--- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
+++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
@@ -418,10 +418,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
                 bug!("encountered a fresh type during canonicalization")
             }
 
-            ty::Placeholder(placeholder) => self.canonicalize_ty_var(
-                CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
-                t,
-            ),
+            ty::Placeholder(mut placeholder) => {
+                if !self.canonicalize_mode.preserve_universes() {
+                    placeholder.universe = ty::UniverseIndex::ROOT;
+                }
+                self.canonicalize_ty_var(
+                    CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
+                    t,
+                )
+            }
 
             ty::Bound(debruijn, _) => {
                 if debruijn >= self.binder_index {
diff --git a/tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs b/tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs
index 1612de7fc45..3128e0f3138 100644
--- a/tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs
+++ b/tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs
@@ -7,7 +7,15 @@ where
 {
 }
 
+pub fn bar()
+where
+    for<V> V: IntoIterator,
+{
+}
+
 fn main() {
     foo();
     //~^ ERROR the size for values of type `V` cannot be known at compilation time
+
+    bar();
 }
diff --git a/tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr b/tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr
index eeb3baf010f..3af115d897d 100644
--- a/tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr
+++ b/tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr
@@ -8,7 +8,7 @@ LL | #![feature(non_lifetime_binders)]
    = note: `#[warn(incomplete_features)]` on by default
 
 error[E0277]: the size for values of type `V` cannot be known at compilation time
-  --> $DIR/bad-sized-cond.rs:11:5
+  --> $DIR/bad-sized-cond.rs:17:5
    |
 LL |     foo();
    |     ^^^ doesn't have a size known at compile-time
@@ -23,6 +23,40 @@ LL | where
 LL |     for<V> V: Sized,
    |               ^^^^^ required by this bound in `foo`
 
-error: aborting due to previous error; 1 warning emitted
+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
+  --> $DIR/bad-sized-cond.rs:20:5
+   |
+LL |     bar();
+   |     ^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })`
+   = note: required for `V` to implement `IntoIterator`
+note: required by a bound in `bar`
+  --> $DIR/bad-sized-cond.rs:12:15
+   |
+LL | pub fn bar()
+   |        --- required by a bound in this
+LL | where
+LL |     for<V> V: IntoIterator,
+   |               ^^^^^^^^^^^^ required by this bound in `bar`
+
+error[E0277]: `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })` is not an iterator
+  --> $DIR/bad-sized-cond.rs:20:5
+   |
+LL |     bar();
+   |     ^^^ `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })` is not an iterator
+   |
+   = help: the trait `Iterator` is not implemented for `Placeholder(Placeholder { universe: U3, name: Param(DefId(0:6 ~ bad_sized_cond[9450]::bar::V), "V") })`
+   = note: required for `V` to implement `IntoIterator`
+note: required by a bound in `bar`
+  --> $DIR/bad-sized-cond.rs:12:15
+   |
+LL | pub fn bar()
+   |        --- required by a bound in this
+LL | where
+LL |     for<V> V: IntoIterator,
+   |               ^^^^^^^^^^^^ required by this bound in `bar`
+
+error: aborting due to 3 previous errors; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0277`.