1
Fork 0

Don't allow accidental runtime-checks

This commit is contained in:
Oli Scherer 2022-07-11 14:16:14 +00:00
parent 8440208eb1
commit d935c70afa

View file

@ -4,6 +4,7 @@
// size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes).
// check-pass
// compile-flags: --crate-type=lib
#![feature(repr_simd)]
@ -23,14 +24,13 @@ struct Size<const S: usize>;
// Overwriting the runtime assertion and making it a compile-time assertion
macro_rules! assert_size {
($a:ty, $b:expr) => {{
($a:ty, $b:expr) => {
const _: Size::<{$b}> = Size::<{size_of::<$a>()}>;
}};
};
}
const PTR_SIZE: usize = std::mem::size_of::<*const ()>();
fn main() {
assert_size!(Option<Wrapper<u32>>, 8);
assert_size!(Option<Wrapper<N32>>, 4); // (✓ niche opt)
assert_size!(Option<Transparent<u32>>, 8);
@ -78,4 +78,3 @@ fn main() {
assert_size!( UnsafeCell<Vec4<N32>> , 16);
assert_size!(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
}