Always error on SizeOverflow during mir evaluation

This commit is contained in:
Esteban Küber 2019-07-30 17:46:46 -07:00
parent 1df512fcae
commit 83b5eb9615
5 changed files with 34 additions and 3 deletions

View File

@ -141,7 +141,6 @@ impl<'tcx> ConstEvalErr<'tcx> {
err_inval!(Layout(LayoutError::Unknown(_))) |
err_inval!(TooGeneric) =>
return Err(ErrorHandled::TooGeneric),
err_inval!(Layout(LayoutError::SizeOverflow(_))) |
err_inval!(TypeckError) =>
return Err(ErrorHandled::Reported),
_ => {},

View File

@ -0,0 +1,4 @@
// error-pattern: reaching this expression at runtime will panic or abort
fn main() {
println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());
}

View File

@ -0,0 +1,15 @@
error: reaching this expression at runtime will panic or abort
--> $SRC_DIR/libcore/mem/mod.rs:LL:COL
|
LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 18446744073709551615])
|
::: $DIR/issue-55878.rs:3:26
|
LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());
| ---------------------------------------------------
|
= note: `#[deny(const_err)]` on by default
error: aborting due to previous error

View File

@ -17,6 +17,8 @@ impl TooBigArray {
}
static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
//~^ ERROR could not evaluate static initializer
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
//~^ ERROR could not evaluate static initializer
fn main() { }

View File

@ -1,4 +1,15 @@
error: the type `[u8; 2305843009213693951]` is too big for the current architecture
error[E0080]: could not evaluate static initializer
--> $DIR/issue-56762.rs:19:1
|
LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951])
error: aborting due to previous error
error[E0080]: could not evaluate static initializer
--> $DIR/issue-56762.rs:21:1
|
LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951])
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.