From a0ac13d8a16af1fa24f43d7f6cb39a9f78ba91fe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 30 Apr 2022 17:06:50 +0200 Subject: [PATCH] gracefully handle type-too-large layout errors --- src/diagnostics.rs | 4 +--- tests/compile-fail/erroneous_const.rs | 2 +- tests/compile-fail/type-too-large.rs | 6 ++++++ 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 tests/compile-fail/type-too-large.rs diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 1a39a1ff33..5d20cc6ff6 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -182,10 +182,8 @@ pub fn report_error<'tcx, 'mir>( "Undefined Behavior", ResourceExhaustion(_) => "resource exhaustion", - InvalidProgram(InvalidProgramInfo::ReferencedConstant) => + InvalidProgram(InvalidProgramInfo::AlreadyReported(_) | InvalidProgramInfo::Layout(..)) => "post-monomorphization error", - InvalidProgram(InvalidProgramInfo::AlreadyReported(_)) => - "error occurred", kind => bug!("This error should be impossible in Miri: {:?}", kind), }; diff --git a/tests/compile-fail/erroneous_const.rs b/tests/compile-fail/erroneous_const.rs index 2592483fe6..8975694f51 100644 --- a/tests/compile-fail/erroneous_const.rs +++ b/tests/compile-fail/erroneous_const.rs @@ -12,7 +12,7 @@ impl PrintName { fn no_codegen() { if false { - let _ = PrintName::::VOID; //~ERROR error occurred: encountered constant + let _ = PrintName::::VOID; //~ERROR post-monomorphization error } } fn main() { diff --git a/tests/compile-fail/type-too-large.rs b/tests/compile-fail/type-too-large.rs new file mode 100644 index 0000000000..2c4ff7013a --- /dev/null +++ b/tests/compile-fail/type-too-large.rs @@ -0,0 +1,6 @@ +// ignore-32bit + +fn main() { + let _fat: [u8; (1<<61)+(1<<31)] = + [0; (1u64<<61) as usize +(1u64<<31) as usize]; //~ ERROR post-monomorphization error +}