Skip to content

Commit 017b0fb

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 + 9772c85 commit 017b0fb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
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)