diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-07-11 10:43:47 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-07-11 10:43:47 +0000 |
| commit | fcd7207d0e5ab4a9598e3b6caf6248134e5f95d6 (patch) | |
| tree | 11c140e06ad4b9f537a0eabf49decde0a19c63ea | |
| parent | 9a204509d2fe9d0ea72cb79ed6e341de7a3bcacb (diff) | |
| download | rust-fcd7207d0e5ab4a9598e3b6caf6248134e5f95d6.tar.gz rust-fcd7207d0e5ab4a9598e3b6caf6248134e5f95d6.zip | |
Make tests work on 32 bit and 64 bit
| -rw-r--r-- | src/test/ui/layout/unsafe-cell-hides-niche.rs | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/test/ui/layout/unsafe-cell-hides-niche.rs b/src/test/ui/layout/unsafe-cell-hides-niche.rs index 21ff0cb1e55..2833f49a27b 100644 --- a/src/test/ui/layout/unsafe-cell-hides-niche.rs +++ b/src/test/ui/layout/unsafe-cell-hides-niche.rs @@ -8,6 +8,7 @@ #![feature(repr_simd)] use std::cell::{UnsafeCell, RefCell, Cell}; +use std::mem::size_of; use std::num::NonZeroU32 as N32; use std::sync::{Mutex, RwLock}; @@ -22,11 +23,13 @@ struct Size<const S: usize>; // Overwriting the runtime assertion and making it a compile-time assertion macro_rules! assert_size { - ($a:ty, $b:literal) => {{ - const _: Size::<$b> = Size::<{std::mem::size_of::<$a>()}>; + ($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<Wrapper<u32>>, 8); assert_size!(Option<Wrapper<N32>>, 4); // (✓ niche opt) @@ -38,25 +41,25 @@ fn main() { assert_size!(Option<UnsafeCell<u32>>, 8); assert_size!(Option<UnsafeCell<N32>>, 8); // (✗ niche opt) - assert_size!( UnsafeCell<&()> , 8); - assert_size!(Option<UnsafeCell<&()>>, 16); // (✗ niche opt) - assert_size!( Cell<&()> , 8); - assert_size!(Option< Cell<&()>>, 16); // (✗ niche opt) - assert_size!( RefCell<&()> , 16); - assert_size!(Option< RefCell<&()>>, 24); // (✗ niche opt) - assert_size!( RwLock<&()> , 24); - assert_size!(Option< RwLock<&()>>, 32); // (✗ niche opt) - assert_size!( Mutex<&()> , 16); - assert_size!(Option< Mutex<&()>>, 24); // (✗ niche opt) - - assert_size!( UnsafeCell<&[i32]> , 16); - assert_size!(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt) - assert_size!( UnsafeCell<(&(), &())> , 16); - assert_size!(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt) + assert_size!( UnsafeCell<&()> , PTR_SIZE); + assert_size!(Option<UnsafeCell<&()>>, 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< RwLock<&()>>, 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< Mutex<&()>>, if cfg!(target_pointer_width = "32") { 16 } else { 24 }); // (✗ niche opt) + + assert_size!( UnsafeCell<&[i32]> , PTR_SIZE * 2); + assert_size!(Option<UnsafeCell<&[i32]>>, PTR_SIZE * 3); // (✗ niche opt) + assert_size!( UnsafeCell<(&(), &())> , PTR_SIZE * 2); + assert_size!(Option<UnsafeCell<(&(), &())>>, PTR_SIZE * 3); // (✗ niche opt) trait Trait {} - assert_size!( UnsafeCell<&dyn Trait> , 16); - assert_size!(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt) + assert_size!( UnsafeCell<&dyn Trait> , PTR_SIZE * 2); + assert_size!(Option<UnsafeCell<&dyn Trait>>, PTR_SIZE * 3); // (✗ niche opt) #[repr(simd)] pub struct Vec4<T>([T; 4]); |
