4
4
// size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes).
5
5
6
6
// check-pass
7
+ // compile-flags: --crate-type=lib
7
8
8
9
#![ feature( repr_simd) ]
9
10
@@ -23,59 +24,57 @@ struct Size<const S: usize>;
23
24
24
25
// Overwriting the runtime assertion and making it a compile-time assertion
25
26
macro_rules! assert_size {
26
- ( $a: ty, $b: expr) => { {
27
+ ( $a: ty, $b: expr) => {
27
28
const _: Size :: <{ $b} > = Size :: <{ size_of:: <$a>( ) } >;
28
- } } ;
29
+ } ;
29
30
}
30
31
31
32
const PTR_SIZE : usize = std:: mem:: size_of :: < * const ( ) > ( ) ;
32
33
33
- fn main ( ) {
34
- assert_size ! ( Option <Wrapper <u32 >>, 8 ) ;
35
- assert_size ! ( Option <Wrapper <N32 >>, 4 ) ; // (✓ niche opt)
36
- assert_size ! ( Option <Transparent <u32 >>, 8 ) ;
37
- assert_size ! ( Option <Transparent <N32 >>, 4 ) ; // (✓ niche opt)
38
- assert_size ! ( Option <NoNiche <u32 >>, 8 ) ;
39
- assert_size ! ( Option <NoNiche <N32 >>, 8 ) ; // (✗ niche opt)
40
-
41
- assert_size ! ( Option <UnsafeCell <u32 >>, 8 ) ;
42
- assert_size ! ( Option <UnsafeCell <N32 >>, 8 ) ; // (✗ niche opt)
43
-
44
- assert_size ! ( UnsafeCell <& ( ) > , PTR_SIZE ) ;
45
- assert_size ! ( Option <UnsafeCell <& ( ) >>, PTR_SIZE * 2 ) ; // (✗ niche opt)
46
- assert_size ! ( Cell <& ( ) > , PTR_SIZE ) ;
47
- assert_size ! ( Option < Cell <& ( ) >>, PTR_SIZE * 2 ) ; // (✗ niche opt)
48
- assert_size ! ( RefCell <& ( ) > , PTR_SIZE * 2 ) ;
49
- assert_size ! ( Option < RefCell <& ( ) >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
50
- assert_size ! (
51
- RwLock <& ( ) >,
52
- if cfg!( target_pointer_width = "32" ) { 16 } else { 24 }
53
- ) ;
54
- assert_size ! (
55
- Option <RwLock <& ( ) >>,
56
- if cfg!( target_pointer_width = "32" ) { 20 } else { 32 }
57
- ) ; // (✗ niche opt)
58
- assert_size ! (
59
- Mutex <& ( ) > ,
60
- if cfg!( target_pointer_width = "32" ) { 12 } else { 16 }
61
- ) ;
62
- assert_size ! (
63
- Option <Mutex <& ( ) >>,
64
- if cfg!( target_pointer_width = "32" ) { 16 } else { 24 }
65
- ) ; // (✗ niche opt)
66
-
67
- assert_size ! ( UnsafeCell <& [ i32 ] > , PTR_SIZE * 2 ) ;
68
- assert_size ! ( Option <UnsafeCell <& [ i32 ] >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
69
- assert_size ! ( UnsafeCell <( & ( ) , & ( ) ) > , PTR_SIZE * 2 ) ;
70
- assert_size ! ( Option <UnsafeCell <( & ( ) , & ( ) ) >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
71
-
72
- trait Trait { }
73
- assert_size ! ( UnsafeCell <& dyn Trait > , PTR_SIZE * 2 ) ;
74
- assert_size ! ( Option <UnsafeCell <& dyn Trait >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
75
-
76
- #[ repr( simd) ]
77
- pub struct Vec4 < T > ( [ T ; 4 ] ) ;
78
-
79
- assert_size ! ( UnsafeCell <Vec4 <N32 >> , 16 ) ;
80
- assert_size ! ( Option <UnsafeCell <Vec4 <N32 >>>, 32 ) ; // (✗ niche opt)
81
- }
34
+ assert_size ! ( Option <Wrapper <u32 >>, 8 ) ;
35
+ assert_size ! ( Option <Wrapper <N32 >>, 4 ) ; // (✓ niche opt)
36
+ assert_size ! ( Option <Transparent <u32 >>, 8 ) ;
37
+ assert_size ! ( Option <Transparent <N32 >>, 4 ) ; // (✓ niche opt)
38
+ assert_size ! ( Option <NoNiche <u32 >>, 8 ) ;
39
+ assert_size ! ( Option <NoNiche <N32 >>, 8 ) ; // (✗ niche opt)
40
+
41
+ assert_size ! ( Option <UnsafeCell <u32 >>, 8 ) ;
42
+ assert_size ! ( Option <UnsafeCell <N32 >>, 8 ) ; // (✗ niche opt)
43
+
44
+ assert_size ! ( UnsafeCell <& ( ) > , PTR_SIZE ) ;
45
+ assert_size ! ( Option <UnsafeCell <& ( ) >>, PTR_SIZE * 2 ) ; // (✗ niche opt)
46
+ assert_size ! ( Cell <& ( ) > , PTR_SIZE ) ;
47
+ assert_size ! ( Option < Cell <& ( ) >>, PTR_SIZE * 2 ) ; // (✗ niche opt)
48
+ assert_size ! ( RefCell <& ( ) > , PTR_SIZE * 2 ) ;
49
+ assert_size ! ( Option < RefCell <& ( ) >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
50
+ assert_size ! (
51
+ RwLock <& ( ) >,
52
+ if cfg!( target_pointer_width = "32" ) { 16 } else { 24 }
53
+ ) ;
54
+ assert_size ! (
55
+ Option <RwLock <& ( ) >>,
56
+ if cfg!( target_pointer_width = "32" ) { 20 } else { 32 }
57
+ ) ; // (✗ niche opt)
58
+ assert_size ! (
59
+ Mutex <& ( ) > ,
60
+ if cfg!( target_pointer_width = "32" ) { 12 } else { 16 }
61
+ ) ;
62
+ assert_size ! (
63
+ Option <Mutex <& ( ) >>,
64
+ if cfg!( target_pointer_width = "32" ) { 16 } else { 24 }
65
+ ) ; // (✗ niche opt)
66
+
67
+ assert_size ! ( UnsafeCell <& [ i32 ] > , PTR_SIZE * 2 ) ;
68
+ assert_size ! ( Option <UnsafeCell <& [ i32 ] >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
69
+ assert_size ! ( UnsafeCell <( & ( ) , & ( ) ) > , PTR_SIZE * 2 ) ;
70
+ assert_size ! ( Option <UnsafeCell <( & ( ) , & ( ) ) >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
71
+
72
+ trait Trait { }
73
+ assert_size ! ( UnsafeCell <& dyn Trait > , PTR_SIZE * 2 ) ;
74
+ assert_size ! ( Option <UnsafeCell <& dyn Trait >>, PTR_SIZE * 3 ) ; // (✗ niche opt)
75
+
76
+ #[ repr( simd) ]
77
+ pub struct Vec4 < T > ( [ T ; 4 ] ) ;
78
+
79
+ assert_size ! ( UnsafeCell <Vec4 <N32 >> , 16 ) ;
80
+ assert_size ! ( Option <UnsafeCell <Vec4 <N32 >>>, 32 ) ; // (✗ niche opt)
0 commit comments