another test for too big type
This commit is contained in:
parent
346f8f2219
commit
9772c85ebc
18
tests/compile-fail/too-big-unsized.rs
Normal file
18
tests/compile-fail/too-big-unsized.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use std::mem;
|
||||
|
||||
#[allow(unused)]
|
||||
struct MySlice {
|
||||
prefix: u64,
|
||||
tail: [u8],
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const TOO_BIG: usize = 1usize << 47;
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const TOO_BIG: usize = 1usize << 31;
|
||||
|
||||
fn main() { unsafe {
|
||||
let ptr = Box::into_raw(Box::new(0u8));
|
||||
// The slice part is actually not "too big", but together with the `prefix` field it is.
|
||||
let _x: &MySlice = mem::transmute((ptr, TOO_BIG-1)); //~ ERROR: invalid reference metadata: total size is bigger than largest supported object
|
||||
} }
|
Loading…
Reference in New Issue
Block a user