Skip to content

Commit 7269196

Browse files
committed
Always check Cell alongside with UnsafeCell
1 parent 24e8796 commit 7269196

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: src/test/ui/layout/unsafe-cell-hides-niche.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@ macro_rules! check_sizes {
2626
(check_one_specific_size: $ty:ty, $size:expr) => {
2727
const _: Size::<{$size}> = Size::<{size_of::<$ty>()}>;
2828
};
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+
};
2934
($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) => {
3040
check_sizes!(check_one_specific_size: $ty, $size);
3141
check_sizes!(check_one_specific_size: Option<$ty>, $optioned_size);
3242
check_sizes!(check_no_niche_opt: $size != $optioned_size, $ty);
3343
};
44+
// only check that there is no niche (size goes up when wrapped in an option),
45+
// don't check actual sizes
3446
($ty:ty) => {
3547
check_sizes!(check_no_niche_opt: true, $ty);
3648
};
@@ -52,7 +64,6 @@ check_sizes!(UnsafeCell<u32>: 4 => 8);
5264
check_sizes!(UnsafeCell<N32>: 4 => 8);
5365

5466
check_sizes!(UnsafeCell<&()>: PTR_SIZE => PTR_SIZE * 2);
55-
check_sizes!( Cell<&()>: PTR_SIZE => PTR_SIZE * 2);
5667
check_sizes!( RefCell<&()>: PTR_SIZE * 2 => PTR_SIZE * 3);
5768

5869
check_sizes!(RwLock<&()>);

0 commit comments

Comments
 (0)