Skip to content

Commit b22707b

Browse files
committed
Auto merge of #2039 - RalfJung:too-big, r=RalfJung
another test for too big type The existing test covers "slice is bigger than largest supported object" but we had no test covering "total size is bigger than largest supported object", which happens when the unsized tail itself is okay in terms of size, but together with the sized prefix it becomes too big. Cc rust-lang/rust#95334
2 parents 346f8f2 + 3f8c3b7 commit b22707b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/compile-fail/too-big-unsized.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::mem;
2+
3+
#[allow(unused)]
4+
struct MySlice {
5+
prefix: u64,
6+
tail: [u8],
7+
}
8+
9+
fn main() { unsafe {
10+
let ptr = Box::into_raw(Box::new(0u8));
11+
let too_big = if cfg!(target_pointer_width = "64") { 1usize << 47 } else { 1usize << 31 };
12+
// The slice part is actually not "too big", but together with the `prefix` field it is.
13+
let _x: &MySlice = mem::transmute((ptr, too_big-1)); //~ ERROR: invalid reference metadata: total size is bigger than largest supported object
14+
} }

0 commit comments

Comments
 (0)