test for "erroneous constant used" post-monomorphization error

This commit is contained in:
Ralf Jung 2022-05-08 17:56:09 +02:00
parent 3b8b6aa8b6
commit d585b92fe3
2 changed files with 17 additions and 1 deletions

View File

@ -182,7 +182,11 @@ pub fn report_error<'tcx, 'mir>(
"Undefined Behavior",
ResourceExhaustion(_) =>
"resource exhaustion",
InvalidProgram(InvalidProgramInfo::AlreadyReported(_) | InvalidProgramInfo::Layout(..)) =>
InvalidProgram(
InvalidProgramInfo::AlreadyReported(_) |
InvalidProgramInfo::Layout(..) |
InvalidProgramInfo::ReferencedConstant
) =>
"post-monomorphization error",
kind =>
bug!("This error should be impossible in Miri: {:?}", kind),

View File

@ -0,0 +1,12 @@
const X: u32 = 5;
const Y: u32 = 6;
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
//~^ERROR any use of this value
//~|WARN previously accepted
fn main() {
println!("{}", FOO); //~ERROR post-monomorphization error
//~|ERROR evaluation of constant value failed
//~|ERROR erroneous constant used
//~|WARN previously accepted
}