Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsafeCell blocks niches inside its nested type from being available outside #99011

Merged
merged 19 commits into from
Jul 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/test/ui/layout/unsafe-cell-hides-niche.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

// run-pass

use std::cell::UnsafeCell;
use std::cell::{UnsafeCell, RefCell, Cell};
use std::mem::size_of;
use std::num::NonZeroU32 as N32;
use std::sync::{Mutex, RwLock};

struct Wrapper<T>(T);

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

fn main() {
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(size_of::<Option<Wrapper<u32>>>(), 8);
assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4);
assert_eq!(size_of::<Option<Wrapper<N32>>>(), 4); // (✓ niche opt)
assert_eq!(size_of::<Option<Transparent<u32>>>(), 8);
assert_eq!(size_of::<Option<Transparent<N32>>>(), 4);
assert_eq!(size_of::<Option<Transparent<N32>>>(), 4); // (✓ niche opt)
assert_eq!(size_of::<Option<NoNiche<u32>>>(), 8);
assert_eq!(size_of::<Option<NoNiche<N32>>>(), 8);
assert_eq!(size_of::<Option<NoNiche<N32>>>(), 8); // (✗ niche opt)

assert_eq!(size_of::<Option<UnsafeCell<u32>>>(), 8);
assert_eq!(size_of::<Option<UnsafeCell<N32>>>(), 8);
assert_eq!(size_of::<Option<UnsafeCell<N32>>>(), 8); // (✗ niche opt)

assert_eq!(size_of::< UnsafeCell<&()> >(), 8);
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(size_of::<Option<UnsafeCell<&()>>>(), 16); // (✗ niche opt)
assert_eq!(size_of::< Cell<&()> >(), 8);
assert_eq!(size_of::<Option< Cell<&()>>>(), 16); // (✗ niche opt)
assert_eq!(size_of::< RefCell<&()> >(), 16);
assert_eq!(size_of::<Option< RefCell<&()>>>(), 24); // (✗ niche opt)
assert_eq!(size_of::< RwLock<&()> >(), 24);
assert_eq!(size_of::<Option< RwLock<&()>>>(), 32); // (✗ niche opt)
assert_eq!(size_of::< Mutex<&()> >(), 16);
assert_eq!(size_of::<Option< Mutex<&()>>>(), 24); // (✗ niche opt)
}