diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /tests/ui/repr | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/repr')
-rw-r--r-- | tests/ui/repr/16-bit-repr-c-enum.rs | 2 | ||||
-rw-r--r-- | tests/ui/repr/explicit-rust-repr-conflicts.rs | 23 | ||||
-rw-r--r-- | tests/ui/repr/explicit-rust-repr-conflicts.stderr | 39 | ||||
-rw-r--r-- | tests/ui/repr/invalid_repr_list_help.stderr | 10 | ||||
-rw-r--r-- | tests/ui/repr/repr-transparent-non-exhaustive.rs | 40 | ||||
-rw-r--r-- | tests/ui/repr/repr-transparent-non-exhaustive.stderr | 42 | ||||
-rw-r--r-- | tests/ui/repr/repr-transparent.rs | 23 | ||||
-rw-r--r-- | tests/ui/repr/repr-transparent.stderr | 82 |
8 files changed, 210 insertions, 51 deletions
diff --git a/tests/ui/repr/16-bit-repr-c-enum.rs b/tests/ui/repr/16-bit-repr-c-enum.rs index 2acfde4be..d4fea2b19 100644 --- a/tests/ui/repr/16-bit-repr-c-enum.rs +++ b/tests/ui/repr/16-bit-repr-c-enum.rs @@ -5,7 +5,7 @@ // [avr] compile-flags: --target=avr-unknown-gnu-atmega328 --crate-type=rlib // [msp430] needs-llvm-components: msp430 // [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib -#![feature(no_core, lang_items, intrinsics, staged_api)] +#![feature(no_core, lang_items, intrinsics, staged_api, rustc_attrs)] #![no_core] #![crate_type = "lib"] #![stable(feature = "", since = "")] diff --git a/tests/ui/repr/explicit-rust-repr-conflicts.rs b/tests/ui/repr/explicit-rust-repr-conflicts.rs new file mode 100644 index 000000000..22dd12d31 --- /dev/null +++ b/tests/ui/repr/explicit-rust-repr-conflicts.rs @@ -0,0 +1,23 @@ +#[repr(C, Rust)] //~ ERROR conflicting representation hints +struct S { + a: i32, +} + + +#[repr(Rust)] //~ ERROR conflicting representation hints +#[repr(C)] +struct T { + a: i32, +} + +#[repr(Rust, u64)] //~ ERROR conflicting representation hints +enum U { + V, +} + +#[repr(Rust, simd)] +//~^ ERROR conflicting representation hints +//~| ERROR SIMD types are experimental and possibly buggy +struct F32x4(f32, f32, f32, f32); + +fn main() {} diff --git a/tests/ui/repr/explicit-rust-repr-conflicts.stderr b/tests/ui/repr/explicit-rust-repr-conflicts.stderr new file mode 100644 index 000000000..7126da574 --- /dev/null +++ b/tests/ui/repr/explicit-rust-repr-conflicts.stderr @@ -0,0 +1,39 @@ +error[E0658]: SIMD types are experimental and possibly buggy + --> $DIR/explicit-rust-repr-conflicts.rs:18:1 + | +LL | #[repr(Rust, simd)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information + = help: add `#![feature(repr_simd)]` to the crate attributes to enable + +error[E0566]: conflicting representation hints + --> $DIR/explicit-rust-repr-conflicts.rs:1:8 + | +LL | #[repr(C, Rust)] + | ^ ^^^^ + +error[E0566]: conflicting representation hints + --> $DIR/explicit-rust-repr-conflicts.rs:7:8 + | +LL | #[repr(Rust)] + | ^^^^ +LL | #[repr(C)] + | ^ + +error[E0566]: conflicting representation hints + --> $DIR/explicit-rust-repr-conflicts.rs:13:8 + | +LL | #[repr(Rust, u64)] + | ^^^^ ^^^ + +error[E0566]: conflicting representation hints + --> $DIR/explicit-rust-repr-conflicts.rs:18:8 + | +LL | #[repr(Rust, simd)] + | ^^^^ ^^^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0566, E0658. +For more information about an error, try `rustc --explain E0566`. diff --git a/tests/ui/repr/invalid_repr_list_help.stderr b/tests/ui/repr/invalid_repr_list_help.stderr index 48a6af3dd..7ffe1287e 100644 --- a/tests/ui/repr/invalid_repr_list_help.stderr +++ b/tests/ui/repr/invalid_repr_list_help.stderr @@ -4,7 +4,7 @@ error[E0552]: unrecognized representation hint LL | #[repr(uwu)] | ^^^ | - = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:6:8 @@ -12,7 +12,7 @@ error[E0552]: unrecognized representation hint LL | #[repr(uwu = "a")] | ^^^^^^^^^ | - = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:9:8 @@ -20,7 +20,7 @@ error[E0552]: unrecognized representation hint LL | #[repr(uwu(4))] | ^^^^^^ | - = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:14:8 @@ -28,7 +28,7 @@ error[E0552]: unrecognized representation hint LL | #[repr(uwu, u8)] | ^^^ | - = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` warning: unknown `doc` attribute `owo` --> $DIR/invalid_repr_list_help.rs:20:7 @@ -46,7 +46,7 @@ error[E0552]: unrecognized representation hint LL | #[repr(uwu)] | ^^^ | - = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` error: aborting due to 5 previous errors; 1 warning emitted diff --git a/tests/ui/repr/repr-transparent-non-exhaustive.rs b/tests/ui/repr/repr-transparent-non-exhaustive.rs index 506f1dcf3..84dd3f492 100644 --- a/tests/ui/repr/repr-transparent-non-exhaustive.rs +++ b/tests/ui/repr/repr-transparent-non-exhaustive.rs @@ -93,4 +93,44 @@ pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>); //~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types //~| WARN this was previously accepted by the compiler +#[repr(transparent)] +pub struct T17(NonExhaustive, Sized); +//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types +//~| WARN this was previously accepted by the compiler + +#[repr(transparent)] +pub struct T18(NonExhaustive, NonExhaustive); +//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types +//~| WARN this was previously accepted by the compiler + +#[repr(transparent)] +pub struct T19(NonExhaustive, Private); +//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types +//~| WARN this was previously accepted by the compiler + +#[repr(transparent)] +pub struct T19Flipped(Private, NonExhaustive); +//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types +//~| WARN this was previously accepted by the compiler + +#[repr(transparent)] +pub struct T20(NonExhaustive); +// Okay, since it's the only field. + +#[repr(transparent)] +pub struct T21(NonExhaustive, InternalNonExhaustive); +// Okay, since there's only 1 foreign non-exhaustive type. + +#[repr(transparent)] +pub struct T21Flipped(InternalNonExhaustive, NonExhaustive); +// Okay, since there's only 1 foreign non-exhaustive type. + +#[repr(transparent)] +pub struct T22(NonExhaustive, InternalPrivate); +// Okay, since there's only 1 foreign non-exhaustive type. + +#[repr(transparent)] +pub struct T22Flipped(InternalPrivate, NonExhaustive); +// Okay, since there's only 1 foreign non-exhaustive type. + fn main() {} diff --git a/tests/ui/repr/repr-transparent-non-exhaustive.stderr b/tests/ui/repr/repr-transparent-non-exhaustive.stderr index 16edf59c7..808b9bc98 100644 --- a/tests/ui/repr/repr-transparent-non-exhaustive.stderr +++ b/tests/ui/repr/repr-transparent-non-exhaustive.stderr @@ -123,5 +123,45 @@ LL | pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>); = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> = note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. -error: aborting due to 12 previous errors +error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types + --> $DIR/repr-transparent-non-exhaustive.rs:97:16 + | +LL | pub struct T17(NonExhaustive, Sized); + | ^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> + = note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. + +error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types + --> $DIR/repr-transparent-non-exhaustive.rs:102:31 + | +LL | pub struct T18(NonExhaustive, NonExhaustive); + | ^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> + = note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. + +error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types + --> $DIR/repr-transparent-non-exhaustive.rs:107:31 + | +LL | pub struct T19(NonExhaustive, Private); + | ^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> + = note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future. + +error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types + --> $DIR/repr-transparent-non-exhaustive.rs:112:32 + | +LL | pub struct T19Flipped(Private, NonExhaustive); + | ^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> + = note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. + +error: aborting due to 16 previous errors diff --git a/tests/ui/repr/repr-transparent.rs b/tests/ui/repr/repr-transparent.rs index 8c9d1639c..87cf59ce9 100644 --- a/tests/ui/repr/repr-transparent.rs +++ b/tests/ui/repr/repr-transparent.rs @@ -23,23 +23,26 @@ struct ContainsMultipleZst(PhantomData<*const i32>, NoFields); struct ContainsZstAndNonZst((), [i32; 2]); #[repr(transparent)] -struct MultipleNonZst(u8, u8); //~ ERROR needs at most one non-zero-sized field +struct MultipleNonZst(u8, u8); //~ ERROR needs at most one field with non-trivial size or alignment trait Mirror { type It: ?Sized; } impl<T: ?Sized> Mirror for T { type It = Self; } #[repr(transparent)] pub struct StructWithProjection(f32, <f32 as Mirror>::It); -//~^ ERROR needs at most one non-zero-sized field +//~^ ERROR needs at most one field with non-trivial size or alignment #[repr(transparent)] -struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1 +struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR needs at most one field with non-trivial size or alignment #[repr(align(32))] struct ZstAlign32<T>(PhantomData<T>); #[repr(transparent)] -struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1 +struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR needs at most one field with non-trivial size or alignment + +#[repr(transparent)] +struct WrapsZstWithAlignment([i32; 0]); #[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0 @@ -58,7 +61,7 @@ enum UnitFieldEnum { enum TooManyFieldsEnum { Foo(u32, String), } -//~^^^ ERROR transparent enum needs at most one non-zero-sized field, but has 2 +//~^^^ ERROR transparent enum needs at most one field with non-trivial size or alignment, but has 2 #[repr(transparent)] enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2 @@ -67,13 +70,13 @@ enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, bu } #[repr(transparent)] -enum NontrivialAlignZstEnum { - Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1 +enum NontrivialAlignZstEnum { //~ ERROR needs at most one field with non-trivial size or alignment + Foo(u32, [u16; 0]), } #[repr(transparent)] -enum GenericAlignEnum<T> { - Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1 +enum GenericAlignEnum<T> { //~ ERROR needs at most one field with non-trivial size or alignment + Foo { bar: ZstAlign32<T>, baz: u32 } } #[repr(transparent)] @@ -82,7 +85,7 @@ union UnitUnion { } #[repr(transparent)] -union TooManyFields { //~ ERROR transparent union needs at most one non-zero-sized field, but has 2 +union TooManyFields { //~ ERROR transparent union needs at most one field with non-trivial size or alignment, but has 2 u: u32, s: i32 } diff --git a/tests/ui/repr/repr-transparent.stderr b/tests/ui/repr/repr-transparent.stderr index 028fc25db..d0c78a841 100644 --- a/tests/ui/repr/repr-transparent.stderr +++ b/tests/ui/repr/repr-transparent.stderr @@ -1,35 +1,41 @@ -error[E0690]: transparent struct needs at most one non-zero-sized field, but has 2 +error[E0690]: transparent struct needs at most one field with non-trivial size or alignment, but has 2 --> $DIR/repr-transparent.rs:26:1 | LL | struct MultipleNonZst(u8, u8); - | ^^^^^^^^^^^^^^^^^^^^^ -- -- this field is non-zero-sized + | ^^^^^^^^^^^^^^^^^^^^^ -- -- this field has non-zero size or requires alignment | | | - | | this field is non-zero-sized - | needs at most one non-zero-sized field, but has 2 + | | this field has non-zero size or requires alignment + | needs at most one field with non-trivial size or alignment, but has 2 -error[E0690]: transparent struct needs at most one non-zero-sized field, but has 2 +error[E0690]: transparent struct needs at most one field with non-trivial size or alignment, but has 2 --> $DIR/repr-transparent.rs:32:1 | LL | pub struct StructWithProjection(f32, <f32 as Mirror>::It); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- ------------------- this field is non-zero-sized + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- ------------------- this field has non-zero size or requires alignment | | | - | | this field is non-zero-sized - | needs at most one non-zero-sized field, but has 2 + | | this field has non-zero size or requires alignment + | needs at most one field with non-trivial size or alignment, but has 2 -error[E0691]: zero-sized field in transparent struct has alignment larger than 1 - --> $DIR/repr-transparent.rs:36:32 +error[E0690]: transparent struct needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:36:1 | LL | struct NontrivialAlignZst(u32, [u16; 0]); - | ^^^^^^^^ has alignment of 2, which is larger than 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ --- -------- this field has non-zero size or requires alignment + | | | + | | this field has non-zero size or requires alignment + | needs at most one field with non-trivial size or alignment, but has 2 -error[E0691]: zero-sized field in transparent struct has alignment larger than 1 - --> $DIR/repr-transparent.rs:42:24 +error[E0690]: transparent struct needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:42:1 | LL | struct GenericAlign<T>(ZstAlign32<T>, u32); - | ^^^^^^^^^^^^^ has alignment of 32, which is larger than 1 + | ^^^^^^^^^^^^^^^^^^^^^^ ------------- --- this field has non-zero size or requires alignment + | | | + | | this field has non-zero size or requires alignment + | needs at most one field with non-trivial size or alignment, but has 2 error[E0084]: unsupported representation for zero-variant enum - --> $DIR/repr-transparent.rs:44:1 + --> $DIR/repr-transparent.rs:47:1 | LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^^^^ @@ -37,23 +43,23 @@ LL | enum Void {} | --------- zero-variant enum error[E0731]: transparent enum needs exactly one variant, but has 0 - --> $DIR/repr-transparent.rs:45:1 + --> $DIR/repr-transparent.rs:48:1 | LL | enum Void {} | ^^^^^^^^^ needs exactly one variant, but has 0 -error[E0690]: the variant of a transparent enum needs at most one non-zero-sized field, but has 2 - --> $DIR/repr-transparent.rs:58:1 +error[E0690]: the variant of a transparent enum needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:61:1 | LL | enum TooManyFieldsEnum { - | ^^^^^^^^^^^^^^^^^^^^^^ needs at most one non-zero-sized field, but has 2 + | ^^^^^^^^^^^^^^^^^^^^^^ needs at most one field with non-trivial size or alignment, but has 2 LL | Foo(u32, String), - | --- ------ this field is non-zero-sized + | --- ------ this field has non-zero size or requires alignment | | - | this field is non-zero-sized + | this field has non-zero size or requires alignment error[E0731]: transparent enum needs exactly one variant, but has 2 - --> $DIR/repr-transparent.rs:64:1 + --> $DIR/repr-transparent.rs:67:1 | LL | enum MultipleVariants { | ^^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2 @@ -62,29 +68,37 @@ LL | Foo(String), LL | Bar, | --- too many variants in `MultipleVariants` -error[E0691]: zero-sized field in transparent enum has alignment larger than 1 - --> $DIR/repr-transparent.rs:71:14 +error[E0690]: the variant of a transparent enum needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:73:1 | +LL | enum NontrivialAlignZstEnum { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs at most one field with non-trivial size or alignment, but has 2 LL | Foo(u32, [u16; 0]), - | ^^^^^^^^ has alignment of 2, which is larger than 1 + | --- -------- this field has non-zero size or requires alignment + | | + | this field has non-zero size or requires alignment -error[E0691]: zero-sized field in transparent enum has alignment larger than 1 - --> $DIR/repr-transparent.rs:76:11 +error[E0690]: the variant of a transparent enum needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:78:1 | +LL | enum GenericAlignEnum<T> { + | ^^^^^^^^^^^^^^^^^^^^^^^^ needs at most one field with non-trivial size or alignment, but has 2 LL | Foo { bar: ZstAlign32<T>, baz: u32 } - | ^^^^^^^^^^^^^^^^^^ has alignment of 32, which is larger than 1 + | ------------------ -------- this field has non-zero size or requires alignment + | | + | this field has non-zero size or requires alignment -error[E0690]: transparent union needs at most one non-zero-sized field, but has 2 - --> $DIR/repr-transparent.rs:85:1 +error[E0690]: transparent union needs at most one field with non-trivial size or alignment, but has 2 + --> $DIR/repr-transparent.rs:88:1 | LL | union TooManyFields { - | ^^^^^^^^^^^^^^^^^^^ needs at most one non-zero-sized field, but has 2 + | ^^^^^^^^^^^^^^^^^^^ needs at most one field with non-trivial size or alignment, but has 2 LL | u: u32, - | ------ this field is non-zero-sized + | ------ this field has non-zero size or requires alignment LL | s: i32 - | ------ this field is non-zero-sized + | ------ this field has non-zero size or requires alignment error: aborting due to 11 previous errors -Some errors have detailed explanations: E0084, E0690, E0691, E0731. +Some errors have detailed explanations: E0084, E0690, E0731. For more information about an error, try `rustc --explain E0084`. |