8
8
#![ feature( repr_simd) ]
9
9
10
10
use std:: cell:: { UnsafeCell , RefCell , Cell } ;
11
- use std:: mem:: size_of;
12
11
use std:: num:: NonZeroU32 as N32 ;
13
12
use std:: sync:: { Mutex , RwLock } ;
14
13
@@ -21,45 +20,45 @@ struct NoNiche<T>(UnsafeCell<T>);
21
20
22
21
// Overwriting the runtime assertion and making it a compile-time assertion
23
22
macro_rules! assert_eq {
24
- ( $a: expr , $b: literal) => { {
25
- const _: ( ) = assert!( $a == $b) ;
23
+ ( $a: ty , $b: literal) => { {
24
+ const _: ( ) = assert!( std :: mem :: size_of :: <$a> ( ) == $b) ;
26
25
} } ;
27
26
}
28
27
29
28
fn main ( ) {
30
- assert_eq ! ( size_of :: < Option <Wrapper <u32 >>> ( ) , 8 ) ;
31
- assert_eq ! ( size_of :: < Option <Wrapper <N32 >>> ( ) , 4 ) ; // (✓ niche opt)
32
- assert_eq ! ( size_of :: < Option <Transparent <u32 >>> ( ) , 8 ) ;
33
- assert_eq ! ( size_of :: < Option <Transparent <N32 >>> ( ) , 4 ) ; // (✓ niche opt)
34
- assert_eq ! ( size_of :: < Option <NoNiche <u32 >>> ( ) , 8 ) ;
35
- assert_eq ! ( size_of :: < Option <NoNiche <N32 >>> ( ) , 8 ) ; // (✗ niche opt)
29
+ assert_eq ! ( Option <Wrapper <u32 >>, 8 ) ;
30
+ assert_eq ! ( Option <Wrapper <N32 >>, 4 ) ; // (✓ niche opt)
31
+ assert_eq ! ( Option <Transparent <u32 >>, 8 ) ;
32
+ assert_eq ! ( Option <Transparent <N32 >>, 4 ) ; // (✓ niche opt)
33
+ assert_eq ! ( Option <NoNiche <u32 >>, 8 ) ;
34
+ assert_eq ! ( Option <NoNiche <N32 >>, 8 ) ; // (✗ niche opt)
36
35
37
- assert_eq ! ( size_of :: < Option <UnsafeCell <u32 >>> ( ) , 8 ) ;
38
- assert_eq ! ( size_of :: < Option <UnsafeCell <N32 >>> ( ) , 8 ) ; // (✗ niche opt)
36
+ assert_eq ! ( Option <UnsafeCell <u32 >>, 8 ) ;
37
+ assert_eq ! ( Option <UnsafeCell <N32 >>, 8 ) ; // (✗ niche opt)
39
38
40
- assert_eq ! ( size_of :: < UnsafeCell <& ( ) > > ( ) , 8 ) ;
41
- assert_eq ! ( size_of :: < Option <UnsafeCell <& ( ) >>> ( ) , 16 ) ; // (✗ niche opt)
42
- assert_eq ! ( size_of :: < Cell <& ( ) > > ( ) , 8 ) ;
43
- assert_eq ! ( size_of :: < Option < Cell <& ( ) >>> ( ) , 16 ) ; // (✗ niche opt)
44
- assert_eq ! ( size_of :: < RefCell <& ( ) > > ( ) , 16 ) ;
45
- assert_eq ! ( size_of :: < Option < RefCell <& ( ) >>> ( ) , 24 ) ; // (✗ niche opt)
46
- assert_eq ! ( size_of :: < RwLock <& ( ) > > ( ) , 24 ) ;
47
- assert_eq ! ( size_of :: < Option < RwLock <& ( ) >>> ( ) , 32 ) ; // (✗ niche opt)
48
- assert_eq ! ( size_of :: < Mutex <& ( ) > > ( ) , 16 ) ;
49
- assert_eq ! ( size_of :: < Option < Mutex <& ( ) >>> ( ) , 24 ) ; // (✗ niche opt)
39
+ assert_eq ! ( UnsafeCell <& ( ) > , 8 ) ;
40
+ assert_eq ! ( Option <UnsafeCell <& ( ) >>, 16 ) ; // (✗ niche opt)
41
+ assert_eq ! ( Cell <& ( ) > , 8 ) ;
42
+ assert_eq ! ( Option < Cell <& ( ) >>, 16 ) ; // (✗ niche opt)
43
+ assert_eq ! ( RefCell <& ( ) > , 16 ) ;
44
+ assert_eq ! ( Option < RefCell <& ( ) >>, 24 ) ; // (✗ niche opt)
45
+ assert_eq ! ( RwLock <& ( ) > , 24 ) ;
46
+ assert_eq ! ( Option < RwLock <& ( ) >>, 32 ) ; // (✗ niche opt)
47
+ assert_eq ! ( Mutex <& ( ) > , 16 ) ;
48
+ assert_eq ! ( Option < Mutex <& ( ) >>, 24 ) ; // (✗ niche opt)
50
49
51
- assert_eq ! ( size_of :: < UnsafeCell <& [ i32 ] > > ( ) , 16 ) ;
52
- assert_eq ! ( size_of :: < Option <UnsafeCell <& [ i32 ] >>> ( ) , 24 ) ; // (✗ niche opt)
53
- assert_eq ! ( size_of :: < UnsafeCell <( & ( ) , & ( ) ) > > ( ) , 16 ) ;
54
- assert_eq ! ( size_of :: < Option <UnsafeCell <( & ( ) , & ( ) ) >>> ( ) , 24 ) ; // (✗ niche opt)
50
+ assert_eq ! ( UnsafeCell <& [ i32 ] > , 16 ) ;
51
+ assert_eq ! ( Option <UnsafeCell <& [ i32 ] >>, 24 ) ; // (✗ niche opt)
52
+ assert_eq ! ( UnsafeCell <( & ( ) , & ( ) ) > , 16 ) ;
53
+ assert_eq ! ( Option <UnsafeCell <( & ( ) , & ( ) ) >>, 24 ) ; // (✗ niche opt)
55
54
56
55
trait Trait { }
57
- assert_eq ! ( size_of :: < UnsafeCell <& dyn Trait > > ( ) , 16 ) ;
58
- assert_eq ! ( size_of :: < Option <UnsafeCell <& dyn Trait >>> ( ) , 24 ) ; // (✗ niche opt)
56
+ assert_eq ! ( UnsafeCell <& dyn Trait > , 16 ) ;
57
+ assert_eq ! ( Option <UnsafeCell <& dyn Trait >>, 24 ) ; // (✗ niche opt)
59
58
60
59
#[ repr( simd) ]
61
60
pub struct Vec4 < T > ( [ T ; 4 ] ) ;
62
61
63
- assert_eq ! ( size_of :: < UnsafeCell <Vec4 <N32 >> > ( ) , 16 ) ;
64
- assert_eq ! ( size_of :: < Option <UnsafeCell <Vec4 <N32 >>>> ( ) , 32 ) ; // (✗ niche opt)
62
+ assert_eq ! ( UnsafeCell <Vec4 <N32 >> , 16 ) ;
63
+ assert_eq ! ( Option <UnsafeCell <Vec4 <N32 >>>, 32 ) ; // (✗ niche opt)
65
64
}
0 commit comments