diff options
Diffstat (limited to '')
-rw-r--r-- | tests/ui/layout/debug.rs | 16 | ||||
-rw-r--r-- | tests/ui/layout/debug.stderr | 86 | ||||
-rw-r--r-- | tests/ui/layout/enum.rs | 18 | ||||
-rw-r--r-- | tests/ui/layout/enum.stderr | 14 | ||||
-rw-r--r-- | tests/ui/layout/homogeneous-aggr-transparent.rs | 44 | ||||
-rw-r--r-- | tests/ui/layout/homogeneous-aggr-transparent.stderr | 32 | ||||
-rw-r--r-- | tests/ui/layout/layout-cycle.rs | 31 | ||||
-rw-r--r-- | tests/ui/layout/layout-cycle.stderr | 11 | ||||
-rw-r--r-- | tests/ui/layout/struct.rs | 12 | ||||
-rw-r--r-- | tests/ui/layout/struct.stderr | 14 | ||||
-rw-r--r-- | tests/ui/layout/zero-sized-array-enum-niche.stderr | 6 |
11 files changed, 246 insertions, 38 deletions
diff --git a/tests/ui/layout/debug.rs b/tests/ui/layout/debug.rs index 46171880a..65f2f3b89 100644 --- a/tests/ui/layout/debug.rs +++ b/tests/ui/layout/debug.rs @@ -1,4 +1,4 @@ -// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" +// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN" #![feature(never_type, rustc_attrs, type_alias_impl_trait, repr_simd)] #![crate_type = "lib"] @@ -17,6 +17,9 @@ type Test = Result<i32, i32>; //~ ERROR: layout_of #[rustc_layout(debug)] type T = impl std::fmt::Debug; //~ ERROR: layout_of +fn f() -> T { + 0i32 +} #[rustc_layout(debug)] pub union V { //~ ERROR: layout_of @@ -63,6 +66,13 @@ union P5 { zst: [u16; 0], byte: u8 } //~ ERROR: layout_of #[rustc_layout(debug)] type X = std::mem::MaybeUninit<u8>; //~ ERROR: layout_of -fn f() -> T { - 0i32 +#[rustc_layout(debug)] +const C: () = (); //~ ERROR: can only be applied to + +impl S { + #[rustc_layout(debug)] + const C: () = (); //~ ERROR: can only be applied to } + +#[rustc_layout(debug)] +type Impossible = (str, str); //~ ERROR: cannot be known at compilation time diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index eeffb3c5f..5162a771b 100644 --- a/tests/ui/layout/debug.stderr +++ b/tests/ui/layout/debug.stderr @@ -2,7 +2,7 @@ error: layout_of(E) = Layout { size: Size(12 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -40,7 +40,7 @@ error: layout_of(E) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -60,7 +60,7 @@ error: layout_of(E) = Layout { size: Size(12 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Uninhabited, fields: Arbitrary { @@ -96,7 +96,7 @@ error: layout_of(S) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: ScalarPair( Initialized { @@ -117,13 +117,13 @@ error: layout_of(S) = Layout { fields: Arbitrary { offsets: [ Size(0 bytes), - Size(0 bytes), + Size(8 bytes), Size(4 bytes), ], memory_index: [ - 1, 0, 2, + 1, ], }, largest_niche: None, @@ -142,7 +142,7 @@ error: layout_of(U) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -162,11 +162,11 @@ error: layout_of(U) = Layout { LL | union U { f1: (i32, i32), f3: i32 } | ^^^^^^^ -error: layout_of(std::result::Result<i32, i32>) = Layout { +error: layout_of(Result<i32, i32>) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: ScalarPair( Initialized { @@ -217,7 +217,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: ScalarPair( Initialized { @@ -254,7 +254,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: ScalarPair( Initialized { @@ -301,7 +301,7 @@ error: layout_of(i32) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Scalar( Initialized { @@ -329,7 +329,7 @@ error: layout_of(V) = Layout { size: Size(2 bytes), align: AbiAndPrefAlign { abi: Align(2 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -344,7 +344,7 @@ error: layout_of(V) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:22:1 + --> $DIR/debug.rs:25:1 | LL | pub union V { | ^^^^^^^^^^^ @@ -353,7 +353,7 @@ error: layout_of(W) = Layout { size: Size(2 bytes), align: AbiAndPrefAlign { abi: Align(2 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -368,7 +368,7 @@ error: layout_of(W) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:28:1 + --> $DIR/debug.rs:31:1 | LL | pub union W { | ^^^^^^^^^^^ @@ -377,7 +377,7 @@ error: layout_of(Y) = Layout { size: Size(0 bytes), align: AbiAndPrefAlign { abi: Align(2 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -392,7 +392,7 @@ error: layout_of(Y) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:34:1 + --> $DIR/debug.rs:37:1 | LL | pub union Y { | ^^^^^^^^^^^ @@ -401,7 +401,7 @@ error: layout_of(P1) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -416,7 +416,7 @@ error: layout_of(P1) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:41:1 + --> $DIR/debug.rs:44:1 | LL | union P1 { x: u32 } | ^^^^^^^^ @@ -425,7 +425,7 @@ error: layout_of(P2) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -440,7 +440,7 @@ error: layout_of(P2) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:45:1 + --> $DIR/debug.rs:48:1 | LL | union P2 { x: (u32, u32) } | ^^^^^^^^ @@ -449,7 +449,7 @@ error: layout_of(P3) = Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -464,7 +464,7 @@ error: layout_of(P3) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:53:1 + --> $DIR/debug.rs:56:1 | LL | union P3 { x: F32x4 } | ^^^^^^^^ @@ -473,7 +473,7 @@ error: layout_of(P4) = Layout { size: Size(12 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Aggregate { sized: true, @@ -488,7 +488,7 @@ error: layout_of(P4) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:57:1 + --> $DIR/debug.rs:60:1 | LL | union P4 { x: E } | ^^^^^^^^ @@ -497,7 +497,7 @@ error: layout_of(P5) = Layout { size: Size(1 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Scalar( Union { @@ -517,16 +517,16 @@ error: layout_of(P5) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:61:1 + --> $DIR/debug.rs:64:1 | LL | union P5 { zst: [u16; 0], byte: u8 } | ^^^^^^^^ -error: layout_of(std::mem::MaybeUninit<u8>) = Layout { +error: layout_of(MaybeUninit<u8>) = Layout { size: Size(1 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), - pref: $PREF_ALIGN, + pref: $SOME_ALIGN, }, abi: Scalar( Union { @@ -546,10 +546,32 @@ error: layout_of(std::mem::MaybeUninit<u8>) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:64:1 + --> $DIR/debug.rs:67:1 | LL | type X = std::mem::MaybeUninit<u8>; | ^^^^^^ -error: aborting due to 14 previous errors +error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases + --> $DIR/debug.rs:70:1 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/debug.rs:78:19 + | +LL | type Impossible = (str, str); + | ^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: only the last element of a tuple may have a dynamically sized type + +error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases + --> $DIR/debug.rs:74:5 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error: aborting due to 17 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/layout/enum.rs b/tests/ui/layout/enum.rs new file mode 100644 index 000000000..7ac2eaa86 --- /dev/null +++ b/tests/ui/layout/enum.rs @@ -0,0 +1,18 @@ +// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" +//! Various enum layout tests. + +#![feature(rustc_attrs)] +#![feature(never_type)] +#![crate_type = "lib"] + +#[rustc_layout(align)] +enum UninhabitedVariantAlign { //~ERROR: abi: Align(2 bytes) + A([u8; 32]), + B([u16; 0], !), // make sure alignment in uninhabited fields is respected +} + +#[rustc_layout(size)] +enum UninhabitedVariantSpace { //~ERROR: size: Size(16 bytes) + A, + B([u8; 15], !), // make sure there is space being reserved for this field. +} diff --git a/tests/ui/layout/enum.stderr b/tests/ui/layout/enum.stderr new file mode 100644 index 000000000..d6bc7780c --- /dev/null +++ b/tests/ui/layout/enum.stderr @@ -0,0 +1,14 @@ +error: align: AbiAndPrefAlign { abi: Align(2 bytes), pref: $PREF_ALIGN } + --> $DIR/enum.rs:9:1 + | +LL | enum UninhabitedVariantAlign { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: size: Size(16 bytes) + --> $DIR/enum.rs:15:1 + | +LL | enum UninhabitedVariantSpace { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/layout/homogeneous-aggr-transparent.rs b/tests/ui/layout/homogeneous-aggr-transparent.rs new file mode 100644 index 000000000..9703d2bf2 --- /dev/null +++ b/tests/ui/layout/homogeneous-aggr-transparent.rs @@ -0,0 +1,44 @@ +#![feature(rustc_attrs)] +#![feature(transparent_unions)] +use std::marker::PhantomData; + +// Regression test for #115664. We want to ensure that `repr(transparent)` wrappers do not affect +// the result of `homogeneous_aggregate`. + +type Tuple = (f32, f32, f32); + +struct Zst; + +#[repr(transparent)] +struct Wrapper1<T>(T); +#[repr(transparent)] +struct Wrapper2<T>((), Zst, T); +#[repr(transparent)] +struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>); +#[repr(transparent)] +union WrapperUnion<T: Copy> { + nothing: (), + something: T, +} + +#[rustc_layout(homogeneous_aggregate)] +pub type Test0 = Tuple; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test1 = Wrapper1<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test2 = Wrapper2<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test3 = Wrapper3<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test4 = WrapperUnion<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +fn main() {} diff --git a/tests/ui/layout/homogeneous-aggr-transparent.stderr b/tests/ui/layout/homogeneous-aggr-transparent.stderr new file mode 100644 index 000000000..99eb703ac --- /dev/null +++ b/tests/ui/layout/homogeneous-aggr-transparent.stderr @@ -0,0 +1,32 @@ +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:25:1 + | +LL | pub type Test0 = Tuple; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:29:1 + | +LL | pub type Test1 = Wrapper1<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:33:1 + | +LL | pub type Test2 = Wrapper2<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:37:1 + | +LL | pub type Test3 = Wrapper3<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:41:1 + | +LL | pub type Test4 = WrapperUnion<Tuple>; + | ^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/ui/layout/layout-cycle.rs b/tests/ui/layout/layout-cycle.rs new file mode 100644 index 000000000..85685058e --- /dev/null +++ b/tests/ui/layout/layout-cycle.rs @@ -0,0 +1,31 @@ +// build-fail +//~^ ERROR: a cycle occurred during layout computation +//~| ERROR: cycle detected when computing layout of + +// Issue #111176 -- ensure that we do not emit ICE on layout cycles + +use std::mem; + +pub struct S<T: Tr> { + pub f: <T as Tr>::I, +} + +pub trait Tr { + type I: Tr; +} + +impl<T: Tr> Tr for S<T> { + type I = S<S<T>>; +} + +impl Tr for () { + type I = (); +} + +fn foo<T: Tr>() -> usize { + mem::size_of::<S<T>>() +} + +fn main() { + println!("{}", foo::<S<()>>()); +} diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr new file mode 100644 index 000000000..a3cdb7edc --- /dev/null +++ b/tests/ui/layout/layout-cycle.stderr @@ -0,0 +1,11 @@ +error[E0391]: cycle detected when computing layout of `S<S<()>>` + | + = note: ...which requires computing layout of `<S<()> as Tr>::I`... + = note: ...which again requires computing layout of `S<S<()>>`, completing the cycle + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: failed to get layout for S<S<()>>: a cycle occurred during layout computation + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/layout/struct.rs b/tests/ui/layout/struct.rs new file mode 100644 index 000000000..e74cf5a95 --- /dev/null +++ b/tests/ui/layout/struct.rs @@ -0,0 +1,12 @@ +// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" +//! Various struct layout tests. + +#![feature(rustc_attrs)] +#![feature(never_type)] +#![crate_type = "lib"] + +#[rustc_layout(abi)] +struct AlignedZstPreventsScalar(i16, [i32; 0]); //~ERROR: abi: Aggregate + +#[rustc_layout(abi)] +struct AlignedZstButStillScalar(i32, [i16; 0]); //~ERROR: abi: Scalar diff --git a/tests/ui/layout/struct.stderr b/tests/ui/layout/struct.stderr new file mode 100644 index 000000000..b61c9a99c --- /dev/null +++ b/tests/ui/layout/struct.stderr @@ -0,0 +1,14 @@ +error: abi: Aggregate { sized: true } + --> $DIR/struct.rs:9:1 + | +LL | struct AlignedZstPreventsScalar(i16, [i32; 0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: abi: Scalar(Initialized { value: Int(I32, true), valid_range: 0..=4294967295 }) + --> $DIR/struct.rs:12:1 + | +LL | struct AlignedZstButStillScalar(i32, [i16; 0]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/layout/zero-sized-array-enum-niche.stderr b/tests/ui/layout/zero-sized-array-enum-niche.stderr index df9f1cc8d..8161f97dd 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.stderr +++ b/tests/ui/layout/zero-sized-array-enum-niche.stderr @@ -1,4 +1,4 @@ -error: layout_of(std::result::Result<[u32; 0], bool>) = Layout { +error: layout_of(Result<[u32; 0], bool>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), @@ -232,7 +232,7 @@ error: layout_of(MultipleAlignments) = Layout { LL | enum MultipleAlignments { | ^^^^^^^^^^^^^^^^^^^^^^^ -error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = Layout { +error: layout_of(Result<[u32; 0], Packed<NonZeroU16>>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), @@ -337,7 +337,7 @@ error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; | ^^^^^^^^^^^^^^^^^^^^^^^ -error: layout_of(std::result::Result<[u32; 0], Packed<U16IsZero>>) = Layout { +error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), |