diff options
Diffstat (limited to 'tests/ui/layout')
| -rw-r--r-- | tests/ui/layout/unsafe-cell-hides-niche.rs | 28 | ||||
| -rw-r--r-- | tests/ui/layout/zero-sized-array-enum-niche.rs | 5 | ||||
| -rw-r--r-- | tests/ui/layout/zero-sized-array-enum-niche.stderr | 10 |
3 files changed, 23 insertions, 20 deletions
diff --git a/tests/ui/layout/unsafe-cell-hides-niche.rs b/tests/ui/layout/unsafe-cell-hides-niche.rs index b3158839de0..568eb819be2 100644 --- a/tests/ui/layout/unsafe-cell-hides-niche.rs +++ b/tests/ui/layout/unsafe-cell-hides-niche.rs @@ -1,17 +1,17 @@ // For rust-lang/rust#68303: the contents of `UnsafeCell<T>` cannot // participate in the niche-optimization for enum discriminants. This -// test checks that an `Option<UnsafeCell<NonZeroU32>>` has the same +// test checks that an `Option<UnsafeCell<NonZero<u32>>>` has the same // size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes). - +// //@ check-pass //@ compile-flags: --crate-type=lib //@ only-x86 - +#![feature(generic_nonzero)] #![feature(repr_simd)] use std::cell::{UnsafeCell, RefCell, Cell}; use std::mem::size_of; -use std::num::NonZeroU32 as N32; +use std::num::NonZero; use std::sync::{Mutex, RwLock}; struct Wrapper<T>(#[allow(dead_code)] T); @@ -54,15 +54,17 @@ macro_rules! check_sizes { const PTR_SIZE: usize = std::mem::size_of::<*const ()>(); -check_sizes!(Wrapper<u32>: 4 => 8); -check_sizes!(Wrapper<N32>: 4 => 4); // (✓ niche opt) -check_sizes!(Transparent<u32>: 4 => 8); -check_sizes!(Transparent<N32>: 4 => 4); // (✓ niche opt) -check_sizes!(NoNiche<u32>: 4 => 8); -check_sizes!(NoNiche<N32>: 4 => 8); +check_sizes!(Wrapper<u32>: 4 => 8); +check_sizes!(Wrapper<NonZero<u32>>: 4 => 4); // (✓ niche opt) + +check_sizes!(Transparent<u32>: 4 => 8); +check_sizes!(Transparent<NonZero<u32>>: 4 => 4); // (✓ niche opt) + +check_sizes!(NoNiche<u32>: 4 => 8); +check_sizes!(NoNiche<NonZero<u32>>: 4 => 8); -check_sizes!(UnsafeCell<u32>: 4 => 8); -check_sizes!(UnsafeCell<N32>: 4 => 8); +check_sizes!(UnsafeCell<u32>: 4 => 8); +check_sizes!(UnsafeCell<NonZero<u32>>: 4 => 8); check_sizes!(UnsafeCell<&()>: PTR_SIZE => PTR_SIZE * 2); check_sizes!( RefCell<&()>: PTR_SIZE * 2 => PTR_SIZE * 3); @@ -79,4 +81,4 @@ check_sizes!(UnsafeCell<&dyn Trait>: PTR_SIZE * 2 => PTR_SIZE * 3); #[repr(simd)] pub struct Vec4<T>([T; 4]); -check_sizes!(UnsafeCell<Vec4<N32>>: 16 => 32); +check_sizes!(UnsafeCell<Vec4<NonZero<u32>>>: 16 => 32); diff --git a/tests/ui/layout/zero-sized-array-enum-niche.rs b/tests/ui/layout/zero-sized-array-enum-niche.rs index 095afc4337a..058f5923487 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.rs +++ b/tests/ui/layout/zero-sized-array-enum-niche.rs @@ -1,6 +1,7 @@ //@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" -#![feature(rustc_attrs)] #![crate_type = "lib"] +#![feature(generic_nonzero)] +#![feature(rustc_attrs)] // Various tests around the behavior of zero-sized arrays and // enum niches, especially that they have coherent size and alignment. @@ -34,7 +35,7 @@ enum MultipleAlignments { //~ ERROR: layout_of struct Packed<T>(T); #[rustc_layout(debug)] -type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; //~ ERROR: layout_of +type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZero<u16>>>; //~ ERROR: layout_of // Should get tag_encoding: Direct, size == align == 4. #[repr(u16)] diff --git a/tests/ui/layout/zero-sized-array-enum-niche.stderr b/tests/ui/layout/zero-sized-array-enum-niche.stderr index 0ed743818c5..af049125de4 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.stderr +++ b/tests/ui/layout/zero-sized-array-enum-niche.stderr @@ -98,7 +98,7 @@ error: layout_of(Result<[u32; 0], bool>) = Layout { max_repr_align: None, unadjusted_abi_align: Align(4 bytes), } - --> $DIR/zero-sized-array-enum-niche.rs:13:1 + --> $DIR/zero-sized-array-enum-niche.rs:14:1 | LL | type AlignedResult = Result<[u32; 0], bool>; | ^^^^^^^^^^^^^^^^^^ @@ -227,7 +227,7 @@ error: layout_of(MultipleAlignments) = Layout { max_repr_align: None, unadjusted_abi_align: Align(4 bytes), } - --> $DIR/zero-sized-array-enum-niche.rs:21:1 + --> $DIR/zero-sized-array-enum-niche.rs:22:1 | LL | enum MultipleAlignments { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -332,9 +332,9 @@ error: layout_of(Result<[u32; 0], Packed<NonZero<u16>>>) = Layout { max_repr_align: None, unadjusted_abi_align: Align(4 bytes), } - --> $DIR/zero-sized-array-enum-niche.rs:37:1 + --> $DIR/zero-sized-array-enum-niche.rs:38:1 | -LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; +LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZero<u16>>>; | ^^^^^^^^^^^^^^^^^^^^^^^ error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout { @@ -441,7 +441,7 @@ error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout { max_repr_align: None, unadjusted_abi_align: Align(4 bytes), } - --> $DIR/zero-sized-array-enum-niche.rs:44:1 + --> $DIR/zero-sized-array-enum-niche.rs:45:1 | LL | type NicheWinsOverTagged = Result<[u32; 0], Packed<U16IsZero>>; | ^^^^^^^^^^^^^^^^^^^^^^^^ |
