1 // For rust-lang/rust#68303: the contents of `UnsafeCell<T>` cannot
2 // participate in the niche-optimization for enum discriminants. This
3 // test checks that an `Option<UnsafeCell<NonZeroU32>>` has the same
4 // size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes).
10 use std::cell::UnsafeCell;
11 use std::mem::size_of;
12 use std::num::NonZeroU32 as N32;
17 struct Transparent<T>(T);
23 assert_eq!(size_of::<Option<Wrapper<u32>>>(), 8);
24 assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4);
25 assert_eq!(size_of::<Option<Transparent<u32>>>(), 8);
26 assert_eq!(size_of::<Option<Transparent<N32>>>(), 4);
27 assert_eq!(size_of::<Option<NoNiche<u32>>>(), 8);
28 assert_eq!(size_of::<Option<NoNiche<N32>>>(), 8);
30 assert_eq!(size_of::<Option<UnsafeCell<u32>>>(), 8);
31 assert_eq!(size_of::<Option<UnsafeCell<N32>>>(), 8);