about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-07-11 10:30:50 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-07-11 10:30:50 +0000
commitaf8536e32ff8840bb41c65a438ccf33568548e02 (patch)
treed3df5548d9e7fc6fad0d190715755846e5dfd776 /src
parent3f4cf59323304a2e785aba564a6eb3bd473d5499 (diff)
downloadrust-af8536e32ff8840bb41c65a438ccf33568548e02.tar.gz
rust-af8536e32ff8840bb41c65a438ccf33568548e02.zip
Simplify assertion macro
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/layout/unsafe-cell-hides-niche.rs57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/test/ui/layout/unsafe-cell-hides-niche.rs b/src/test/ui/layout/unsafe-cell-hides-niche.rs
index 385472ac88a..f5c1fe1320c 100644
--- a/src/test/ui/layout/unsafe-cell-hides-niche.rs
+++ b/src/test/ui/layout/unsafe-cell-hides-niche.rs
@@ -8,7 +8,6 @@
 #![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};
 
@@ -21,45 +20,45 @@ struct NoNiche<T>(UnsafeCell<T>);
 
 // Overwriting the runtime assertion and making it a compile-time assertion
 macro_rules! assert_eq {
-    ($a:expr, $b:literal) => {{
-        const _: () = assert!($a == $b);
+    ($a:ty, $b:literal) => {{
+        const _: () = assert!(std::mem::size_of::<$a>() == $b);
     }};
 }
 
 fn main() {
-    assert_eq!(size_of::<Option<Wrapper<u32>>>(),     8);
-    assert_eq!(size_of::<Option<Wrapper<N32>>>(),     4); // (✓ niche opt)
-    assert_eq!(size_of::<Option<Transparent<u32>>>(), 8);
-    assert_eq!(size_of::<Option<Transparent<N32>>>(), 4); // (✓ niche opt)
-    assert_eq!(size_of::<Option<NoNiche<u32>>>(),     8);
-    assert_eq!(size_of::<Option<NoNiche<N32>>>(),     8); // (✗ niche opt)
+    assert_eq!(Option<Wrapper<u32>>,     8);
+    assert_eq!(Option<Wrapper<N32>>,     4); // (✓ niche opt)
+    assert_eq!(Option<Transparent<u32>>, 8);
+    assert_eq!(Option<Transparent<N32>>, 4); // (✓ niche opt)
+    assert_eq!(Option<NoNiche<u32>>,     8);
+    assert_eq!(Option<NoNiche<N32>>,     8); // (✗ niche opt)
 
-    assert_eq!(size_of::<Option<UnsafeCell<u32>>>(),  8);
-    assert_eq!(size_of::<Option<UnsafeCell<N32>>>(),  8); // (✗ niche opt)
+    assert_eq!(Option<UnsafeCell<u32>>,  8);
+    assert_eq!(Option<UnsafeCell<N32>>,  8); // (✗ niche opt)
 
-    assert_eq!(size_of::<       UnsafeCell<&()> >(), 8);
-    assert_eq!(size_of::<Option<UnsafeCell<&()>>>(), 16); // (✗ niche opt)
-    assert_eq!(size_of::<             Cell<&()> >(), 8);
-    assert_eq!(size_of::<Option<      Cell<&()>>>(), 16); // (✗ niche opt)
-    assert_eq!(size_of::<          RefCell<&()> >(), 16);
-    assert_eq!(size_of::<Option<   RefCell<&()>>>(), 24); // (✗ niche opt)
-    assert_eq!(size_of::<           RwLock<&()> >(), 24);
-    assert_eq!(size_of::<Option<    RwLock<&()>>>(), 32); // (✗ niche opt)
-    assert_eq!(size_of::<            Mutex<&()> >(), 16);
-    assert_eq!(size_of::<Option<     Mutex<&()>>>(), 24); // (✗ niche opt)
+    assert_eq!(       UnsafeCell<&()> , 8);
+    assert_eq!(Option<UnsafeCell<&()>>, 16); // (✗ niche opt)
+    assert_eq!(             Cell<&()> , 8);
+    assert_eq!(Option<      Cell<&()>>, 16); // (✗ niche opt)
+    assert_eq!(          RefCell<&()> , 16);
+    assert_eq!(Option<   RefCell<&()>>, 24); // (✗ niche opt)
+    assert_eq!(           RwLock<&()> , 24);
+    assert_eq!(Option<    RwLock<&()>>, 32); // (✗ niche opt)
+    assert_eq!(            Mutex<&()> , 16);
+    assert_eq!(Option<     Mutex<&()>>, 24); // (✗ niche opt)
 
-    assert_eq!(size_of::<       UnsafeCell<&[i32]> >(), 16);
-    assert_eq!(size_of::<Option<UnsafeCell<&[i32]>>>(), 24); // (✗ niche opt)
-    assert_eq!(size_of::<       UnsafeCell<(&(), &())> >(), 16);
-    assert_eq!(size_of::<Option<UnsafeCell<(&(), &())>>>(), 24); // (✗ niche opt)
+    assert_eq!(       UnsafeCell<&[i32]> , 16);
+    assert_eq!(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt)
+    assert_eq!(       UnsafeCell<(&(), &())> , 16);
+    assert_eq!(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt)
 
     trait Trait {}
-    assert_eq!(size_of::<       UnsafeCell<&dyn Trait> >(), 16);
-    assert_eq!(size_of::<Option<UnsafeCell<&dyn Trait>>>(), 24); // (✗ niche opt)
+    assert_eq!(       UnsafeCell<&dyn Trait> , 16);
+    assert_eq!(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt)
 
     #[repr(simd)]
     pub struct Vec4<T>([T; 4]);
 
-    assert_eq!(size_of::<       UnsafeCell<Vec4<N32>> >(), 16);
-    assert_eq!(size_of::<Option<UnsafeCell<Vec4<N32>>>>(), 32); // (✗ niche opt)
+    assert_eq!(       UnsafeCell<Vec4<N32>> , 16);
+    assert_eq!(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
 }