Skip to content

Commit 3f8c3b7

Browse files
committed
another test for too big type
1 parent 346f8f2 commit 3f8c3b7

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)