about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Wock <ajwock@gmail.com>2024-06-01 14:59:13 -0400
committerAndrew Wock <ajwock@gmail.com>2024-06-03 07:18:24 -0400
commit66a13861aee8f3754dbec65af21c2ef6ca9756f9 (patch)
tree8c9a6e3a0d7d4b75934c63f5c72a6176894260dd
parentada5e2c7b5427a591e30baeeee2698a5eb6db0bd (diff)
downloadrust-66a13861aee8f3754dbec65af21c2ef6ca9756f9.tar.gz
rust-66a13861aee8f3754dbec65af21c2ef6ca9756f9.zip
Fix ICE caused by ignoring EffectVars in type inference
Signed-off-by: Andrew Wock <ajwock@gmail.com>
-rw-r--r--compiler/rustc_infer/src/infer/mod.rs2
-rw-r--r--compiler/rustc_infer/src/infer/resolve.rs3
-rw-r--r--tests/crashes/119830.rs11
-rw-r--r--tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.rs24
-rw-r--r--tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.stderr69
5 files changed, 98 insertions, 11 deletions
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs
index c8bb6cf5f9b..cb93ef7fdb0 100644
--- a/compiler/rustc_infer/src/infer/mod.rs
+++ b/compiler/rustc_infer/src/infer/mod.rs
@@ -587,6 +587,7 @@ pub enum FixupError {
     UnresolvedFloatTy(FloatVid),
     UnresolvedTy(TyVid),
     UnresolvedConst(ConstVid),
+    UnresolvedEffect(EffectVid),
 }
 
 /// See the `region_obligations` field for more information.
@@ -614,6 +615,7 @@ impl fmt::Display for FixupError {
             ),
             UnresolvedTy(_) => write!(f, "unconstrained type"),
             UnresolvedConst(_) => write!(f, "unconstrained const value"),
+            UnresolvedEffect(_) => write!(f, "unconstrained effect value"),
         }
     }
 }
diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs
index 21ef2e89523..830d79f52b9 100644
--- a/compiler/rustc_infer/src/infer/resolve.rs
+++ b/compiler/rustc_infer/src/infer/resolve.rs
@@ -167,6 +167,9 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
                 ty::ConstKind::Infer(InferConst::Fresh(_)) => {
                     bug!("Unexpected const in full const resolver: {:?}", c);
                 }
+                ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
+                    return Err(FixupError::UnresolvedEffect(evid));
+                }
                 _ => {}
             }
             c.try_super_fold_with(self)
diff --git a/tests/crashes/119830.rs b/tests/crashes/119830.rs
deleted file mode 100644
index 71becc04e16..00000000000
--- a/tests/crashes/119830.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-//@ known-bug: #119830
-#![feature(effects)]
-#![feature(min_specialization)]
-
-trait Specialize {}
-
-trait Foo {}
-
-impl<T> const Foo for T {}
-
-impl<T> const Foo for T where T: const Specialize {}
diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.rs
new file mode 100644
index 00000000000..9778217d462
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.rs
@@ -0,0 +1,24 @@
+//@ check-fail
+// Fixes #119830
+
+#![feature(effects)]
+#![feature(min_specialization)]
+#![feature(const_trait_impl)]
+
+trait Specialize {}
+
+trait Foo {}
+
+impl<T> const Foo for T {}
+//~^ error: const `impl` for trait `Foo` which is not marked with `#[const_trait]`
+//~| error: the const parameter `host` is not constrained by the impl trait, self type, or predicates [E0207]
+
+impl<T> const Foo for T where T: const Specialize {}
+//~^ error: const `impl` for trait `Foo` which is not marked with `#[const_trait]`
+//~| error: `const` can only be applied to `#[const_trait]` traits
+//~| error: the const parameter `host` is not constrained by the impl trait, self type, or predicates [E0207]
+//~| error: specialization impl does not specialize any associated items
+//~| error: could not resolve generic parameters on overridden impl
+
+fn main() {
+}
diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.stderr
new file mode 100644
index 00000000000..d18063f8d3d
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/spec-effectvar-ice.stderr
@@ -0,0 +1,69 @@
+error: const `impl` for trait `Foo` which is not marked with `#[const_trait]`
+  --> $DIR/spec-effectvar-ice.rs:12:15
+   |
+LL | trait Foo {}
+   | - help: mark `Foo` as const: `#[const_trait]`
+LL |
+LL | impl<T> const Foo for T {}
+   |               ^^^
+   |
+   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
+   = note: adding a non-const method body in the future would be a breaking change
+
+error: const `impl` for trait `Foo` which is not marked with `#[const_trait]`
+  --> $DIR/spec-effectvar-ice.rs:16:15
+   |
+LL | trait Foo {}
+   | - help: mark `Foo` as const: `#[const_trait]`
+...
+LL | impl<T> const Foo for T where T: const Specialize {}
+   |               ^^^
+   |
+   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
+   = note: adding a non-const method body in the future would be a breaking change
+
+error: `const` can only be applied to `#[const_trait]` traits
+  --> $DIR/spec-effectvar-ice.rs:16:40
+   |
+LL | impl<T> const Foo for T where T: const Specialize {}
+   |                                        ^^^^^^^^^^
+
+error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/spec-effectvar-ice.rs:12:9
+   |
+LL | impl<T> const Foo for T {}
+   |         ^^^^^ unconstrained const parameter
+   |
+   = note: expressions using a const parameter must map each value to a distinct output value
+   = note: proving the result of expressions other than the parameter are unique is not supported
+
+error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/spec-effectvar-ice.rs:16:9
+   |
+LL | impl<T> const Foo for T where T: const Specialize {}
+   |         ^^^^^ unconstrained const parameter
+   |
+   = note: expressions using a const parameter must map each value to a distinct output value
+   = note: proving the result of expressions other than the parameter are unique is not supported
+
+error: specialization impl does not specialize any associated items
+  --> $DIR/spec-effectvar-ice.rs:16:1
+   |
+LL | impl<T> const Foo for T where T: const Specialize {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: impl is a specialization of this impl
+  --> $DIR/spec-effectvar-ice.rs:12:1
+   |
+LL | impl<T> const Foo for T {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: could not resolve generic parameters on overridden impl
+  --> $DIR/spec-effectvar-ice.rs:16:1
+   |
+LL | impl<T> const Foo for T where T: const Specialize {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0207`.