Skip to content

Commit 4bfba76

Browse files
committed
Add tests for libstd types
1 parent 8d9f609 commit 4bfba76

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
// run-pass
77

8-
use std::cell::UnsafeCell;
8+
use std::cell::{UnsafeCell, RefCell, Cell};
99
use std::mem::size_of;
1010
use std::num::NonZeroU32 as N32;
11+
use std::sync::{Mutex, RwLock};
1112

1213
struct Wrapper<T>(T);
1314

@@ -18,12 +19,23 @@ struct NoNiche<T>(UnsafeCell<T>);
1819

1920
fn main() {
2021
assert_eq!(size_of::<Option<Wrapper<u32>>>(), 8);
21-
assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4);
22+
assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4); // (✓ niche opt)
2223
assert_eq!(size_of::<Option<Transparent<u32>>>(), 8);
23-
assert_eq!(size_of::<Option<Transparent<N32>>>(), 4);
24+
assert_eq!(size_of::<Option<Transparent<N32>>>(), 4); // (✓ niche opt)
2425
assert_eq!(size_of::<Option<NoNiche<u32>>>(), 8);
25-
assert_eq!(size_of::<Option<NoNiche<N32>>>(), 8);
26+
assert_eq!(size_of::<Option<NoNiche<N32>>>(), 8); // (✗ niche opt)
2627

2728
assert_eq!(size_of::<Option<UnsafeCell<u32>>>(), 8);
28-
assert_eq!(size_of::<Option<UnsafeCell<N32>>>(), 8);
29+
assert_eq!(size_of::<Option<UnsafeCell<N32>>>(), 8); // (✗ niche opt)
30+
31+
assert_eq!(size_of::< UnsafeCell<&()> >(), 8);
32+
assert_eq!(size_of::<Option<UnsafeCell<&()>>>(), 16); // (✗ niche opt)
33+
assert_eq!(size_of::< Cell<&()> >(), 8);
34+
assert_eq!(size_of::<Option< Cell<&()>>>(), 16); // (✗ niche opt)
35+
assert_eq!(size_of::< RefCell<&()> >(), 16);
36+
assert_eq!(size_of::<Option< RefCell<&()>>>(), 24); // (✗ niche opt)
37+
assert_eq!(size_of::< RwLock<&()> >(), 24);
38+
assert_eq!(size_of::<Option< RwLock<&()>>>(), 32); // (✗ niche opt)
39+
assert_eq!(size_of::< Mutex<&()> >(), 16);
40+
assert_eq!(size_of::<Option< Mutex<&()>>>(), 24); // (✗ niche opt)
2941
}

0 commit comments

Comments
 (0)