Move checks to compile-time

This commit is contained in:
Oli Scherer 2022-07-11 10:29:02 +00:00
parent 984db78d77
commit 3f4cf59323

View file

@ -3,7 +3,7 @@
// test checks that an `Option<UnsafeCell<NonZeroU32>>` has the same
// size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes).
// run-pass
// check-pass
#![feature(repr_simd)]
@ -19,6 +19,13 @@ struct Transparent<T>(T);
struct NoNiche<T>(UnsafeCell<T>);
// Overwriting the runtime assertion and making it a compile-time assertion
macro_rules! assert_eq {
($a:expr, $b:literal) => {{
const _: () = assert!($a == $b);
}};
}
fn main() {
assert_eq!(size_of::<Option<Wrapper<u32>>>(), 8);
assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4); // (✓ niche opt)