Skip to content

Commit a99e6cc

Browse files
committed
test post-monomorphization const errors
1 parent 52c7b8e commit a99e6cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ pub fn report_error<'tcx, 'mir>(
8888
"Undefined Behavior",
8989
ResourceExhaustion(_) =>
9090
"resource exhaustion",
91+
InvalidProgram(InvalidProgramInfo::ReferencedConstant) =>
92+
"post-monomorphization error",
9193
_ =>
9294
bug!("This error should be impossible in Miri: {}", e),
9395
};

tests/compile-fail/erroneous_const.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Zmir-opt-level=3
2+
//! Make sure we detect erroneous constants post-monomorphization even when they are optimized away.
3+
//! (https://github.com/rust-lang/miri/issues/1382)
4+
#![feature(const_panic)]
5+
#![feature(never_type)]
6+
#![warn(const_err)]
7+
8+
struct PrintName<T>(T);
9+
impl<T> PrintName<T> {
10+
const VOID: ! = panic!(); //~WARN any use of this value will cause an error
11+
}
12+
13+
fn no_codegen<T>() {
14+
let _ = PrintName::<T>::VOID; //~ERROR referenced constant has errors
15+
}
16+
fn main() {
17+
no_codegen::<i32>();
18+
}

0 commit comments

Comments
 (0)