Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2a899dc
`UnsafeCell` now has no niches, ever.
oli-obk Jul 7, 2022
8d9f609
Comment update
oli-obk Jul 7, 2022
4bfba76
Add tests for libstd types
oli-obk Jul 8, 2022
69b1b3c
Create a custom layout path for UnsafeCell instead of piggy backing o…
oli-obk Jul 8, 2022
bfb3afe
Add some autolabels for A-bootstrap and T-infra
jyn514 Jul 10, 2022
4239155
More obvious closure name
oli-obk Jul 11, 2022
984db78
Hide niches in SIMD types, too
oli-obk Jul 11, 2022
3f4cf59
Move checks to compile-time
oli-obk Jul 11, 2022
af8536e
Simplify assertion macro
oli-obk Jul 11, 2022
fef596f
Rename assertion macro
oli-obk Jul 11, 2022
9a20450
Show sizes in error output
oli-obk Jul 11, 2022
fcd7207
Make tests work on 32 bit and 64 bit
oli-obk Jul 11, 2022
8440208
tidy
oli-obk Jul 11, 2022
b608043
factor 'is this type allowed as union field on stable' into separate …
RalfJung Jun 11, 2022
55a1ccf
allow unions with mutable references and tuples of allowed types
RalfJung Jun 11, 2022
cafbd73
also allow arrays of allowed types
RalfJung Jun 19, 2022
1401396
remove untagged_union feature gate
RalfJung Jun 30, 2022
1cf6f5c
assigning to a union field can never drop now
RalfJung Jun 30, 2022
d935c70
Don't allow accidental runtime-checks
oli-obk Jul 11, 2022
cdd6bba
Simplify size checking
oli-obk Jul 11, 2022
0318b70
tidy
oli-obk Jul 11, 2022
7a24f8e
add array tests, cleanup, tidy, and bless
RalfJung Jun 30, 2022
3338593
Only check relative sizes on platform specific types
oli-obk Jul 11, 2022
24e8796
Use some more visible sigils than `,`
oli-obk Jul 12, 2022
7269196
Always check Cell alongside with `UnsafeCell`
oli-obk Jul 12, 2022
944c0e2
check non_exhaustive attr and private fields for transparent types
fee1-dead Jul 7, 2022
e652147
add more tests
fee1-dead Jul 10, 2022
d812850
fix documentation
fee1-dead Jul 12, 2022
697dfb5
:arrow_up: rust-analyzer
lnicola Jul 12, 2022
6d3f51d
Rollup merge of #97995 - RalfJung:union-more-nodrop, r=Mark-Simulacrum
Dylan-DPC Jul 12, 2022
46fa356
Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddyb
Dylan-DPC Jul 12, 2022
454e597
Rollup merge of #99020 - fee1-dead-contrib:repr_transparent_non_exhau…
Dylan-DPC Jul 12, 2022
eccfe58
Rollup merge of #99132 - jyn514:autolabel, r=Mark-Simulacrum
Dylan-DPC Jul 12, 2022
de5950f
Rollup merge of #99176 - lnicola:rust-analyzer-2022-07-12, r=lnicola
Dylan-DPC Jul 12, 2022
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
Prev Previous commit
Next Next commit
Rename assertion macro
  • Loading branch information
oli-obk committed Jul 11, 2022
commit fef596f6a243d311dc50b50f83f8339e326f1f66
54 changes: 27 additions & 27 deletions src/test/ui/layout/unsafe-cell-hides-niche.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@ struct Transparent<T>(T);
struct NoNiche<T>(UnsafeCell<T>);

// Overwriting the runtime assertion and making it a compile-time assertion
macro_rules! assert_eq {
macro_rules! assert_size {
($a:ty, $b:literal) => {{
const _: () = assert!(std::mem::size_of::<$a>() == $b);
}};
}

fn main() {
assert_eq!(Option<Wrapper<u32>>, 8);
assert_eq!(Option<Wrapper<N32>>, 4); // (✓ niche opt)
assert_eq!(Option<Transparent<u32>>, 8);
assert_eq!(Option<Transparent<N32>>, 4); // (✓ niche opt)
assert_eq!(Option<NoNiche<u32>>, 8);
assert_eq!(Option<NoNiche<N32>>, 8); // (✗ niche opt)
assert_size!(Option<Wrapper<u32>>, 8);
assert_size!(Option<Wrapper<N32>>, 4); // (✓ niche opt)
assert_size!(Option<Transparent<u32>>, 8);
assert_size!(Option<Transparent<N32>>, 4); // (✓ niche opt)
assert_size!(Option<NoNiche<u32>>, 8);
assert_size!(Option<NoNiche<N32>>, 8); // (✗ niche opt)

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

assert_eq!( UnsafeCell<&()> , 8);
assert_eq!(Option<UnsafeCell<&()>>, 16); // (✗ niche opt)
assert_eq!( Cell<&()> , 8);
assert_eq!(Option< Cell<&()>>, 16); // (✗ niche opt)
assert_eq!( RefCell<&()> , 16);
assert_eq!(Option< RefCell<&()>>, 24); // (✗ niche opt)
assert_eq!( RwLock<&()> , 24);
assert_eq!(Option< RwLock<&()>>, 32); // (✗ niche opt)
assert_eq!( Mutex<&()> , 16);
assert_eq!(Option< Mutex<&()>>, 24); // (✗ niche opt)
assert_size!( UnsafeCell<&()> , 8);
assert_size!(Option<UnsafeCell<&()>>, 16); // (✗ niche opt)
assert_size!( Cell<&()> , 8);
assert_size!(Option< Cell<&()>>, 16); // (✗ niche opt)
assert_size!( RefCell<&()> , 16);
assert_size!(Option< RefCell<&()>>, 24); // (✗ niche opt)
assert_size!( RwLock<&()> , 24);
assert_size!(Option< RwLock<&()>>, 32); // (✗ niche opt)
assert_size!( Mutex<&()> , 16);
assert_size!(Option< Mutex<&()>>, 24); // (✗ niche opt)

assert_eq!( UnsafeCell<&[i32]> , 16);
assert_eq!(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt)
assert_eq!( UnsafeCell<(&(), &())> , 16);
assert_eq!(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt)
assert_size!( UnsafeCell<&[i32]> , 16);
assert_size!(Option<UnsafeCell<&[i32]>>, 24); // (✗ niche opt)
assert_size!( UnsafeCell<(&(), &())> , 16);
assert_size!(Option<UnsafeCell<(&(), &())>>, 24); // (✗ niche opt)

trait Trait {}
assert_eq!( UnsafeCell<&dyn Trait> , 16);
assert_eq!(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt)
assert_size!( UnsafeCell<&dyn Trait> , 16);
assert_size!(Option<UnsafeCell<&dyn Trait>>, 24); // (✗ niche opt)

#[repr(simd)]
pub struct Vec4<T>([T; 4]);

assert_eq!( UnsafeCell<Vec4<N32>> , 16);
assert_eq!(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
assert_size!( UnsafeCell<Vec4<N32>> , 16);
assert_size!(Option<UnsafeCell<Vec4<N32>>>, 32); // (✗ niche opt)
}