diff --git a/src/test/ui/layout/unsafe-cell-hides-niche.rs b/src/test/ui/layout/unsafe-cell-hides-niche.rs index 1d0e1fce178..865fc2ae297 100644 --- a/src/test/ui/layout/unsafe-cell-hides-niche.rs +++ b/src/test/ui/layout/unsafe-cell-hides-niche.rs @@ -4,6 +4,7 @@ // size in memory as an `Option>` (namely, 8 bytes). // check-pass +// compile-flags: --crate-type=lib #![feature(repr_simd)] @@ -23,59 +24,57 @@ // 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>, 8); - assert_size!(Option>, 4); // (✓ niche opt) - assert_size!(Option>, 8); - assert_size!(Option>, 4); // (✓ niche opt) - assert_size!(Option>, 8); - assert_size!(Option>, 8); // (✗ niche opt) +assert_size!(Option>, 8); +assert_size!(Option>, 4); // (✓ niche opt) +assert_size!(Option>, 8); +assert_size!(Option>, 4); // (✓ niche opt) +assert_size!(Option>, 8); +assert_size!(Option>, 8); // (✗ niche opt) - assert_size!(Option>, 8); - assert_size!(Option>, 8); // (✗ niche opt) +assert_size!(Option>, 8); +assert_size!(Option>, 8); // (✗ niche opt) - assert_size!( UnsafeCell<&()> , PTR_SIZE); - assert_size!(Option>, PTR_SIZE * 2); // (✗ niche opt) - assert_size!( Cell<&()> , PTR_SIZE); - assert_size!(Option< Cell<&()>>, PTR_SIZE * 2); // (✗ niche opt) - assert_size!( RefCell<&()> , PTR_SIZE * 2); - assert_size!(Option< RefCell<&()>>, PTR_SIZE * 3); // (✗ niche opt) - assert_size!( - RwLock<&()>, - if cfg!(target_pointer_width = "32") { 16 } else { 24 } - ); - assert_size!( - Option>, - if cfg!(target_pointer_width = "32") { 20 } else { 32 } - ); // (✗ niche opt) - assert_size!( - Mutex<&()> , - if cfg!(target_pointer_width = "32") { 12 } else { 16 } - ); - assert_size!( - Option>, - if cfg!(target_pointer_width = "32") { 16 } else { 24 } - ); // (✗ niche opt) +assert_size!( UnsafeCell<&()> , PTR_SIZE); +assert_size!(Option>, PTR_SIZE * 2); // (✗ niche opt) +assert_size!( Cell<&()> , PTR_SIZE); +assert_size!(Option< Cell<&()>>, PTR_SIZE * 2); // (✗ niche opt) +assert_size!( RefCell<&()> , PTR_SIZE * 2); +assert_size!(Option< RefCell<&()>>, PTR_SIZE * 3); // (✗ niche opt) +assert_size!( + RwLock<&()>, + if cfg!(target_pointer_width = "32") { 16 } else { 24 } +); +assert_size!( + Option>, + if cfg!(target_pointer_width = "32") { 20 } else { 32 } +); // (✗ niche opt) +assert_size!( + Mutex<&()> , + if cfg!(target_pointer_width = "32") { 12 } else { 16 } +); +assert_size!( + Option>, + if cfg!(target_pointer_width = "32") { 16 } else { 24 } +); // (✗ niche opt) - assert_size!( UnsafeCell<&[i32]> , PTR_SIZE * 2); - assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) - assert_size!( UnsafeCell<(&(), &())> , PTR_SIZE * 2); - assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) +assert_size!( UnsafeCell<&[i32]> , PTR_SIZE * 2); +assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) +assert_size!( UnsafeCell<(&(), &())> , PTR_SIZE * 2); +assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) - trait Trait {} - assert_size!( UnsafeCell<&dyn Trait> , PTR_SIZE * 2); - assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) +trait Trait {} +assert_size!( UnsafeCell<&dyn Trait> , PTR_SIZE * 2); +assert_size!(Option>, PTR_SIZE * 3); // (✗ niche opt) - #[repr(simd)] - pub struct Vec4([T; 4]); +#[repr(simd)] +pub struct Vec4([T; 4]); - assert_size!( UnsafeCell> , 16); - assert_size!(Option>>, 32); // (✗ niche opt) -} +assert_size!( UnsafeCell> , 16); +assert_size!(Option>>, 32); // (✗ niche opt)