Move checks to compile-time
This commit is contained in:
parent
984db78d77
commit
3f4cf59323
1 changed files with 8 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue