diff --git a/src/test/ui/layout/unsafe-cell-hides-niche.rs b/src/test/ui/layout/unsafe-cell-hides-niche.rs index 7f159887ba1..9eed2ad361c 100644 --- a/src/test/ui/layout/unsafe-cell-hides-niche.rs +++ b/src/test/ui/layout/unsafe-cell-hides-niche.rs @@ -22,54 +22,49 @@ struct Size; -// Overwriting the runtime assertion and making it a compile-time assertion -macro_rules! assert_size_eq { - ($ty:ty, $size:expr) => { +macro_rules! check_sizes { + (check_one_specific_size: $ty:ty, $size:expr) => { const _: Size::<{$size}> = Size::<{size_of::<$ty>()}>; }; ($ty:ty, $size:expr, $optioned_size:expr) => { - assert_size_eq!($ty, $size); - assert_size_eq!(Option<$ty>, $optioned_size); - const _: () = assert!( - $size == $optioned_size || - size_of::<$ty>() < size_of::>() - ); + check_sizes!(check_one_specific_size: $ty, $size); + check_sizes!(check_one_specific_size: Option<$ty>, $optioned_size); + check_sizes!(check_no_niche_opt: $size != $optioned_size, $ty); + }; + ($ty:ty) => { + check_sizes!(check_no_niche_opt: true, $ty); + }; + (check_no_niche_opt: $no_niche_opt:expr, $ty:ty) => { + const _: () = if $no_niche_opt { assert!(size_of::<$ty>() < size_of::>()); }; }; } const PTR_SIZE: usize = std::mem::size_of::<*const ()>(); -assert_size_eq!(Wrapper, 4, 8); -assert_size_eq!(Wrapper, 4, 4); // (✓ niche opt) -assert_size_eq!(Transparent, 4, 8); -assert_size_eq!(Transparent, 4, 4); // (✓ niche opt) -assert_size_eq!(NoNiche, 4, 8); -assert_size_eq!(NoNiche, 4, 8); +check_sizes!(Wrapper, 4, 8); +check_sizes!(Wrapper, 4, 4); // (✓ niche opt) +check_sizes!(Transparent, 4, 8); +check_sizes!(Transparent, 4, 4); // (✓ niche opt) +check_sizes!(NoNiche, 4, 8); +check_sizes!(NoNiche, 4, 8); -assert_size_eq!(UnsafeCell, 4, 8); -assert_size_eq!(UnsafeCell, 4, 8); +check_sizes!(UnsafeCell, 4, 8); +check_sizes!(UnsafeCell, 4, 8); -assert_size_eq!(UnsafeCell<&()> , PTR_SIZE, PTR_SIZE * 2); -assert_size_eq!( Cell<&()> , PTR_SIZE, PTR_SIZE * 2); -assert_size_eq!( RefCell<&()> , PTR_SIZE * 2, PTR_SIZE * 3); -assert_size_eq!( - RwLock<&()>, - if cfg!(target_pointer_width = "32") { 16 } else { 24 }, - if cfg!(target_pointer_width = "32") { 20 } else { 32 } -); -assert_size_eq!( - Mutex<&()> , - if cfg!(target_pointer_width = "32") { 12 } else { 16 }, - if cfg!(target_pointer_width = "32") { 16 } else { 24 } -); +check_sizes!(UnsafeCell<&()> , PTR_SIZE, PTR_SIZE * 2); +check_sizes!( Cell<&()> , PTR_SIZE, PTR_SIZE * 2); +check_sizes!( RefCell<&()> , PTR_SIZE * 2, PTR_SIZE * 3); -assert_size_eq!(UnsafeCell<&[i32]> , PTR_SIZE * 2, PTR_SIZE * 3); -assert_size_eq!(UnsafeCell<(&(), &())> , PTR_SIZE * 2, PTR_SIZE * 3); +check_sizes!(RwLock<&()>); +check_sizes!(Mutex<&()>); + +check_sizes!(UnsafeCell<&[i32]> , PTR_SIZE * 2, PTR_SIZE * 3); +check_sizes!(UnsafeCell<(&(), &())> , PTR_SIZE * 2, PTR_SIZE * 3); trait Trait {} -assert_size_eq!(UnsafeCell<&dyn Trait> , PTR_SIZE * 2, PTR_SIZE * 3); +check_sizes!(UnsafeCell<&dyn Trait> , PTR_SIZE * 2, PTR_SIZE * 3); #[repr(simd)] pub struct Vec4([T; 4]); -assert_size_eq!(UnsafeCell> , 16, 32); +check_sizes!(UnsafeCell> , 16, 32);