about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-08 16:08:07 +0100
committerGitHub <noreply@github.com>2021-12-08 16:08:07 +0100
commit317f750ff76ae680d6891de0a5087e1aa903bc6c (patch)
tree7a565f4c946b00116f01e2723b768ea13e621bc9 /src
parent7970fab252f1bde4bba96142d0843747c6e9b4ad (diff)
parent3f831c64ccd210754d16d6ab9c287b02e3d3eabe (diff)
downloadrust-317f750ff76ae680d6891de0a5087e1aa903bc6c.tar.gz
rust-317f750ff76ae680d6891de0a5087e1aa903bc6c.zip
Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obk
Allow for failure of subst_normalize_erasing_regions in const_eval

Fixes https://github.com/rust-lang/rust/issues/72845

Using associated types that cannot be normalized previously resulted in an ICE. We now allow for normalization failure and return a "TooGeneric" error in that case.

r? ```@RalfJung``` maybe?
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/const-generics/issues/issue-72845.rs49
-rw-r--r--src/test/ui/const-generics/issues/issue-72845.stderr12
-rw-r--r--src/test/ui/consts/const-eval/const-eval-query-stack.stderr2
3 files changed, 62 insertions, 1 deletions
diff --git a/src/test/ui/const-generics/issues/issue-72845.rs b/src/test/ui/const-generics/issues/issue-72845.rs
new file mode 100644
index 00000000000..bea5dc8ba21
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-72845.rs
@@ -0,0 +1,49 @@
+#![feature(generic_const_exprs)]
+#![feature(specialization)]
+#![allow(incomplete_features)]
+
+//--------------------------------------------------
+
+trait Depth {
+    const C: usize;
+}
+
+trait Type {
+    type AT: Depth;
+}
+
+//--------------------------------------------------
+
+enum Predicate<const B: bool> {}
+
+trait Satisfied {}
+
+impl Satisfied for Predicate<true> {}
+
+//--------------------------------------------------
+
+trait Spec1 {}
+
+impl<T: Type> Spec1 for T where Predicate<{T::AT::C > 0}>: Satisfied {}
+
+trait Spec2 {}
+
+//impl<T: Type > Spec2 for T where Predicate<{T::AT::C > 1}>: Satisfied {}
+impl<T: Type > Spec2 for T where Predicate<true>: Satisfied {}
+
+//--------------------------------------------------
+
+trait Foo {
+    fn Bar();
+}
+
+impl<T: Spec1> Foo for T {
+    default fn Bar() {}
+}
+
+impl<T: Spec2> Foo for T {
+//~^ ERROR conflicting implementations of trait
+    fn Bar() {}
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-72845.stderr b/src/test/ui/const-generics/issues/issue-72845.stderr
new file mode 100644
index 00000000000..631c8605fb4
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-72845.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `Foo`
+  --> $DIR/issue-72845.rs:44:1
+   |
+LL | impl<T: Spec1> Foo for T {
+   | ------------------------ first implementation here
+...
+LL | impl<T: Spec2> Foo for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/consts/const-eval/const-eval-query-stack.stderr b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
index e6fecef9fb3..45a3d901c98 100644
--- a/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
@@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
 LL |     let x: &'static i32 = &X;
    |                            ^ referenced constant has errors
 query stack during panic:
-#0 [normalize_mir_const_after_erasing_regions] normalizing `main::promoted[1]`
+#0 [try_normalize_mir_const_after_erasing_regions] normalizing `main::promoted[1]`
 #1 [optimized_mir] optimizing MIR for `main`
 #2 [collect_and_partition_mono_items] collect_and_partition_mono_items
 end of query stack