Skip to content

Commit

Permalink
Rollup merge of #117438 - cjgillot:deterministic-error, r=oli-obk
Browse files Browse the repository at this point in the history
Do not ICE on constant evaluation failure in GVN.

Fixes #117362
  • Loading branch information
matthiaskrgr authored Oct 31, 2023
2 parents 793776f + 5b7cc9d commit f623530
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,13 @@ impl<'tcx> Const<'tcx> {
// 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
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/consts/const-eval/issue-50814-2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// build-fail
// revisions: normal mir-opt
// [mir-opt]compile-flags: -Zmir-opt-level=4

trait C {
const BOO: usize;
Expand Down

0 comments on commit f623530

Please sign in to comment.