@@ -26,11 +26,23 @@ macro_rules! check_sizes {
26
26
( check_one_specific_size: $ty: ty, $size: expr) => {
27
27
const _: Size :: <{ $size} > = Size :: <{ size_of:: <$ty>( ) } >;
28
28
} ;
29
+ // Any tests run on `UnsafeCell` must be the same for `Cell`
30
+ ( UnsafeCell <$ty: ty>: $size: expr => $optioned_size: expr) => {
31
+ check_sizes!( Cell <$ty>: $size => $optioned_size) ;
32
+ check_sizes!( @actual_check: UnsafeCell <$ty>: $size => $optioned_size) ;
33
+ } ;
29
34
( $ty: ty: $size: expr => $optioned_size: expr) => {
35
+ check_sizes!( @actual_check: $ty: $size => $optioned_size) ;
36
+ } ;
37
+ // This branch does the actual checking logic, the `@actual_check` prefix is here to distinguish
38
+ // it from other branches and not accidentally match any.
39
+ ( @actual_check: $ty: ty: $size: expr => $optioned_size: expr) => {
30
40
check_sizes!( check_one_specific_size: $ty, $size) ;
31
41
check_sizes!( check_one_specific_size: Option <$ty>, $optioned_size) ;
32
42
check_sizes!( check_no_niche_opt: $size != $optioned_size, $ty) ;
33
43
} ;
44
+ // only check that there is no niche (size goes up when wrapped in an option),
45
+ // don't check actual sizes
34
46
( $ty: ty) => {
35
47
check_sizes!( check_no_niche_opt: true , $ty) ;
36
48
} ;
@@ -52,7 +64,6 @@ check_sizes!(UnsafeCell<u32>: 4 => 8);
52
64
check_sizes ! ( UnsafeCell <N32 >: 4 => 8 ) ;
53
65
54
66
check_sizes ! ( UnsafeCell <& ( ) >: PTR_SIZE => PTR_SIZE * 2 ) ;
55
- check_sizes ! ( Cell <& ( ) >: PTR_SIZE => PTR_SIZE * 2 ) ;
56
67
check_sizes ! ( RefCell <& ( ) >: PTR_SIZE * 2 => PTR_SIZE * 3 ) ;
57
68
58
69
check_sizes ! ( RwLock <& ( ) >) ;
0 commit comments