Skip to content

Commit 9772c85

Browse files
committed
another test for too big type
1 parent 346f8f2 commit 9772c85

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

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

0 commit comments

Comments
 (0)