File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
compiler/rustc_middle/src/mir
tests/ui/consts/const-eval Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -520,11 +520,13 @@ impl<'tcx> Const<'tcx> {
520520 // types are fine though.
521521 ty:: ConstKind :: Value ( _) => c. ty ( ) . is_primitive ( ) ,
522522 ty:: ConstKind :: Unevaluated ( ..) | ty:: ConstKind :: Expr ( ..) => false ,
523+ // This can happen if evaluation of a constant failed. The result does not matter
524+ // much since compilation is doomed.
525+ ty:: ConstKind :: Error ( ..) => false ,
523526 // Should not appear in runtime MIR.
524527 ty:: ConstKind :: Infer ( ..)
525528 | ty:: ConstKind :: Bound ( ..)
526- | ty:: ConstKind :: Placeholder ( ..)
527- | ty:: ConstKind :: Error ( ..) => bug ! ( ) ,
529+ | ty:: ConstKind :: Placeholder ( ..) => bug ! ( ) ,
528530 } ,
529531 Const :: Unevaluated ( ..) => false ,
530532 // If the same slice appears twice in the MIR, we cannot guarantee that we will
Original file line number Diff line number Diff line change 1+ error[E0080]: evaluation of `<A<()> as Foo<()>>::BAR` failed
2+ --> $DIR/issue-50814-2.rs:16:24
3+ |
4+ LL | const BAR: usize = [5, 6, 7][T::BOO];
5+ | ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
6+
7+ note: erroneous constant encountered
8+ --> $DIR/issue-50814-2.rs:20:6
9+ |
10+ LL | &<A<T> as Foo<T>>::BAR
11+ | ^^^^^^^^^^^^^^^^^^^^^
12+
13+ note: erroneous constant encountered
14+ --> $DIR/issue-50814-2.rs:20:5
15+ |
16+ LL | &<A<T> as Foo<T>>::BAR
17+ | ^^^^^^^^^^^^^^^^^^^^^^
18+
19+ error: aborting due to previous error
20+
21+ For more information about this error, try `rustc --explain E0080`.
Original file line number Diff line number Diff line change 11error[E0080]: evaluation of `<A<()> as Foo<()>>::BAR` failed
2- --> $DIR/issue-50814-2.rs:14 :24
2+ --> $DIR/issue-50814-2.rs:16 :24
33 |
44LL | const BAR: usize = [5, 6, 7][T::BOO];
55 | ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
66
77note: erroneous constant encountered
8- --> $DIR/issue-50814-2.rs:18 :6
8+ --> $DIR/issue-50814-2.rs:20 :6
99 |
1010LL | &<A<T> as Foo<T>>::BAR
1111 | ^^^^^^^^^^^^^^^^^^^^^
1212
1313note: the above error was encountered while instantiating `fn foo::<()>`
14- --> $DIR/issue-50814-2.rs:30 :22
14+ --> $DIR/issue-50814-2.rs:32 :22
1515 |
1616LL | println!("{:x}", foo::<()>() as *const usize as usize);
1717 | ^^^^^^^^^^^
Original file line number Diff line number Diff line change 11// build-fail
2+ // revisions: normal mir-opt
3+ // [mir-opt]compile-flags: -Zmir-opt-level=4
24
35trait C {
46 const BOO : usize ;
You can’t perform that action at this time.
0 commit comments