Rollup merge of #117438 - cjgillot:deterministic-error, r=oli-obk
Do not ICE on constant evaluation failure in GVN. Fixes https://github.com/rust-lang/rust/issues/117362
This commit is contained in:
commit
f623530742
@ -520,11 +520,13 @@ pub fn is_deterministic(&self) -> bool {
|
||||
// types are fine though.
|
||||
ty::ConstKind::Value(_) => c.ty().is_primitive(),
|
||||
ty::ConstKind::Unevaluated(..) | ty::ConstKind::Expr(..) => false,
|
||||
// This can happen if evaluation of a constant failed. The result does not matter
|
||||
// much since compilation is doomed.
|
||||
ty::ConstKind::Error(..) => false,
|
||||
// Should not appear in runtime MIR.
|
||||
ty::ConstKind::Infer(..)
|
||||
| ty::ConstKind::Bound(..)
|
||||
| ty::ConstKind::Placeholder(..)
|
||||
| ty::ConstKind::Error(..) => bug!(),
|
||||
| ty::ConstKind::Placeholder(..) => bug!(),
|
||||
},
|
||||
Const::Unevaluated(..) => false,
|
||||
// If the same slice appears twice in the MIR, we cannot guarantee that we will
|
||||
|
21
tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr
Normal file
21
tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
error[E0080]: evaluation of `<A<()> as Foo<()>>::BAR` failed
|
||||
--> $DIR/issue-50814-2.rs:16:24
|
||||
|
|
||||
LL | const BAR: usize = [5, 6, 7][T::BOO];
|
||||
| ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
|
||||
|
||||
note: erroneous constant encountered
|
||||
--> $DIR/issue-50814-2.rs:20:6
|
||||
|
|
||||
LL | &<A<T> as Foo<T>>::BAR
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: erroneous constant encountered
|
||||
--> $DIR/issue-50814-2.rs:20:5
|
||||
|
|
||||
LL | &<A<T> as Foo<T>>::BAR
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
@ -1,17 +1,17 @@
|
||||
error[E0080]: evaluation of `<A<()> as Foo<()>>::BAR` failed
|
||||
--> $DIR/issue-50814-2.rs:14:24
|
||||
--> $DIR/issue-50814-2.rs:16:24
|
||||
|
|
||||
LL | const BAR: usize = [5, 6, 7][T::BOO];
|
||||
| ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
|
||||
|
||||
note: erroneous constant encountered
|
||||
--> $DIR/issue-50814-2.rs:18:6
|
||||
--> $DIR/issue-50814-2.rs:20:6
|
||||
|
|
||||
LL | &<A<T> as Foo<T>>::BAR
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: the above error was encountered while instantiating `fn foo::<()>`
|
||||
--> $DIR/issue-50814-2.rs:30:22
|
||||
--> $DIR/issue-50814-2.rs:32:22
|
||||
|
|
||||
LL | println!("{:x}", foo::<()>() as *const usize as usize);
|
||||
| ^^^^^^^^^^^
|
@ -1,4 +1,6 @@
|
||||
// build-fail
|
||||
// revisions: normal mir-opt
|
||||
// [mir-opt]compile-flags: -Zmir-opt-level=4
|
||||
|
||||
trait C {
|
||||
const BOO: usize;
|
||||
|
Loading…
Reference in New Issue
Block a user