From 9772c85ebc9620050eec48a322d96d7474ab97f5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 26 Mar 2022 10:44:30 -0400 Subject: [PATCH] another test for too big type --- .../{slice-too-big.rs => too-big-slice.rs} | 0 tests/compile-fail/too-big-unsized.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) rename tests/compile-fail/{slice-too-big.rs => too-big-slice.rs} (100%) create mode 100644 tests/compile-fail/too-big-unsized.rs diff --git a/tests/compile-fail/slice-too-big.rs b/tests/compile-fail/too-big-slice.rs similarity index 100% rename from tests/compile-fail/slice-too-big.rs rename to tests/compile-fail/too-big-slice.rs diff --git a/tests/compile-fail/too-big-unsized.rs b/tests/compile-fail/too-big-unsized.rs new file mode 100644 index 00000000000..ad7bc6e938a --- /dev/null +++ b/tests/compile-fail/too-big-unsized.rs @@ -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 +} }