Skip to content

Commit 83b5eb9

Browse files
committed
Always error on SizeOverflow during mir evaluation
1 parent 1df512f commit 83b5eb9

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

src/librustc/mir/interpret/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ impl<'tcx> ConstEvalErr<'tcx> {
141141
err_inval!(Layout(LayoutError::Unknown(_))) |
142142
err_inval!(TooGeneric) =>
143143
return Err(ErrorHandled::TooGeneric),
144-
err_inval!(Layout(LayoutError::SizeOverflow(_))) |
145144
err_inval!(TypeckError) =>
146145
return Err(ErrorHandled::Reported),
147146
_ => {},

src/test/ui/consts/issue-55878.rs

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

src/test/ui/consts/issue-55878.stderr

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

src/test/ui/issues/issue-56762.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ impl TooBigArray {
1717
}
1818

1919
static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
20+
//~^ ERROR could not evaluate static initializer
2021
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
22+
//~^ ERROR could not evaluate static initializer
2123

2224
fn main() { }

src/test/ui/issues/issue-56762.stderr

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
error: the type `[u8; 2305843009213693951]` is too big for the current architecture
1+
error[E0080]: could not evaluate static initializer
2+
--> $DIR/issue-56762.rs:19:1
3+
|
4+
LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951])
26

3-
error: aborting due to previous error
7+
error[E0080]: could not evaluate static initializer
8+
--> $DIR/issue-56762.rs:21:1
9+
|
10+
LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951])
412

13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)