@@ -19,46 +19,46 @@ struct Transparent<T>(T);
19
19
struct NoNiche<T>(UnsafeCell<T>);
20
20
21
21
// Overwriting the runtime assertion and making it a compile-time assertion
22
- macro_rules! assert_eq {
22
+ macro_rules! assert_size {
23
23
($a:ty, $b:literal) => {{
24
24
const _: () = assert!(std::mem::size_of::<$a>() == $b);
25
25
}};
26
26
}
27
27
28
28
fn main() {
29
- assert_eq !(Option<Wrapper<u32>>, 8);
30
- assert_eq !(Option<Wrapper<N32>>, 4); // (✓ niche opt)
31
- assert_eq !(Option<Transparent<u32>>, 8);
32
- assert_eq !(Option<Transparent<N32>>, 4); // (✓ niche opt)
33
- assert_eq !(Option<NoNiche<u32>>, 8);
34
- assert_eq !(Option<NoNiche<N32>>, 8); // (✗ niche opt)
29
+ assert_size !(Option<Wrapper<u32>>, 8);
30
+ assert_size !(Option<Wrapper<N32>>, 4); // (✓ niche opt)
31
+ assert_size !(Option<Transparent<u32>>, 8);
32
+ assert_size !(Option<Transparent<N32>>, 4); // (✓ niche opt)
33
+ assert_size !(Option<NoNiche<u32>>, 8);
34
+ assert_size !(Option<NoNiche<N32>>, 8); // (✗ niche opt)
35
35
36
- assert_eq !(Option<UnsafeCell<u32>>, 8);
37
- assert_eq !(Option<UnsafeCell<N32>>, 8); // (✗ niche opt)
36
+ assert_size !(Option<UnsafeCell<u32>>, 8);
37
+ assert_size !(Option<UnsafeCell<N32>>, 8); // (✗ niche opt)
38
38
39
- assert_eq !( UnsafeCell<&()> , 8);
40
- assert_eq !(Option<UnsafeCell<&()>>, 16); // (✗ niche opt)
41
- assert_eq !( Cell<&()> , 8);
42
- assert_eq !(Option< Cell<&()>>, 16); // (✗ niche opt)
43
- assert_eq !( RefCell<&()> , 16);
44
- assert_eq !(Option< RefCell<&()>>, 24); // (✗ niche opt)
45
- assert_eq !( RwLock<&()> , 24);
46
- assert_eq !(Option< RwLock<&()>>, 32); // (✗ niche opt)
47
- assert_eq !( Mutex<&()> , 16);
48
- assert_eq !(Option< Mutex<&()>>, 24); // (✗ niche opt)
39
+ assert_size !( UnsafeCell<&()> , 8);
40
+ assert_size !(Option<UnsafeCell<&()>>, 16); // (✗ niche opt)
41
+ assert_size !( Cell<&()> , 8);
42
+ assert_size !(Option< Cell<&()>>, 16); // (✗ niche opt)
43
+ assert_size !( RefCell<&()> , 16);
44
+ assert_size !(Option< RefCell<&()>>, 24); // (✗ niche opt)
45
+ assert_size !( RwLock<&()> , 24);
46
+ assert_size !(Option< RwLock<&()>>, 32); // (✗ niche opt)
47
+ assert_size !( Mutex<&()> , 16);
48
+ assert_size !(Option< Mutex<&()>>, 24); // (✗ niche opt)
49
49
50
- assert_eq !( UnsafeCell<&[i32]> , 16);
51
- assert_eq !(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt)
52
- assert_eq !( UnsafeCell<(&(), &())> , 16);
53
- assert_eq !(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt)
50
+ assert_size !( UnsafeCell<&[i32]> , 16);
51
+ assert_size !(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt)
52
+ assert_size !( UnsafeCell<(&(), &())> , 16);
53
+ assert_size !(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt)
54
54
55
55
trait Trait {}
56
- assert_eq !( UnsafeCell<&dyn Trait> , 16);
57
- assert_eq !(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt)
56
+ assert_size !( UnsafeCell<&dyn Trait> , 16);
57
+ assert_size !(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt)
58
58
59
59
#[repr(simd)]
60
60
pub struct Vec4<T>([T; 4]);
61
61
62
- assert_eq !( UnsafeCell<Vec4<N32>> , 16);
63
- assert_eq !(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
62
+ assert_size !( UnsafeCell<Vec4<N32>> , 16);
63
+ assert_size !(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
64
64
}
0 commit comments