-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #86279 - JohnTitor:transparent-zero-size-fields, r=niko…
…matsakis Permit zero non-zero-field on transparent types Fixes #77841 This makes the transparent fields meet the below: > * A `repr(transparent)` type `T` must meet the following rules: > * It may have any number of 1-ZST fields > * In addition, it may have at most one other field of type U r? `@nikomatsakis`
- Loading branch information
Showing
5 changed files
with
51 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,92 @@ | ||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:11:1 | ||
| | ||
LL | struct NoFields; | ||
| ^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:14:1 | ||
| | ||
LL | struct ContainsOnlyZst(()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:17:1 | ||
| | ||
LL | struct ContainsOnlyZstArray([bool; 0]); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:20:1 | ||
| | ||
LL | struct ContainsMultipleZst(PhantomData<*const i32>, NoFields); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:24:1 | ||
error[E0690]: transparent struct needs at most one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:26:1 | ||
| | ||
LL | struct MultipleNonZst(u8, u8); | ||
| ^^^^^^^^^^^^^^^^^^^^^^--^^--^^ | ||
| | | | | ||
| | | this field is non-zero-sized | ||
| | this field is non-zero-sized | ||
| needs exactly one non-zero-sized field, but has 2 | ||
| needs at most one non-zero-sized field, but has 2 | ||
|
||
error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:30:1 | ||
error[E0690]: transparent struct needs at most one non-zero-sized field, 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 is non-zero-sized | ||
| needs exactly one non-zero-sized field, but has 2 | ||
| needs at most one non-zero-sized field, but has 2 | ||
|
||
error[E0691]: zero-sized field in transparent struct has alignment larger than 1 | ||
--> $DIR/repr-transparent.rs:34:32 | ||
--> $DIR/repr-transparent.rs:36:32 | ||
| | ||
LL | struct NontrivialAlignZst(u32, [u16; 0]); | ||
| ^^^^^^^^ has alignment larger than 1 | ||
|
||
error[E0691]: zero-sized field in transparent struct has alignment larger than 1 | ||
--> $DIR/repr-transparent.rs:40:24 | ||
--> $DIR/repr-transparent.rs:42:24 | ||
| | ||
LL | struct GenericAlign<T>(ZstAlign32<T>, u32); | ||
| ^^^^^^^^^^^^^ has alignment larger than 1 | ||
|
||
error[E0084]: unsupported representation for zero-variant enum | ||
--> $DIR/repr-transparent.rs:42:1 | ||
--> $DIR/repr-transparent.rs:44:1 | ||
| | ||
LL | #[repr(transparent)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
LL | enum Void {} | ||
| ------------ zero-variant enum | ||
|
||
error[E0731]: transparent enum needs exactly one variant, but has 0 | ||
--> $DIR/repr-transparent.rs:43:1 | ||
--> $DIR/repr-transparent.rs:45:1 | ||
| | ||
LL | enum Void {} | ||
| ^^^^^^^^^ needs exactly one variant, but has 0 | ||
|
||
error[E0690]: the variant of a transparent enum needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:47:1 | ||
| | ||
LL | enum FieldlessEnum { | ||
| ^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: the variant of a transparent enum needs exactly one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:52:1 | ||
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 | ||
| | ||
LL | enum TooManyFieldsEnum { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2 | ||
| ^^^^^^^^^^^^^^^^^^^^^^ needs at most one non-zero-sized field, but has 2 | ||
LL | Foo(u32, String), | ||
| --- ------ this field is non-zero-sized | ||
| | | ||
| this field is non-zero-sized | ||
|
||
error[E0731]: transparent enum needs exactly one variant, but has 2 | ||
--> $DIR/repr-transparent.rs:58:1 | ||
--> $DIR/repr-transparent.rs:64:1 | ||
| | ||
LL | enum TooManyVariants { | ||
| ^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2 | ||
LL | enum MultipleVariants { | ||
| ^^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2 | ||
LL | Foo(String), | ||
| ----------- | ||
LL | Bar, | ||
| --- too many variants in `TooManyVariants` | ||
| --- too many variants in `MultipleVariants` | ||
|
||
error[E0691]: zero-sized field in transparent enum has alignment larger than 1 | ||
--> $DIR/repr-transparent.rs:65:14 | ||
--> $DIR/repr-transparent.rs:71:14 | ||
| | ||
LL | Foo(u32, [u16; 0]), | ||
| ^^^^^^^^ has alignment larger than 1 | ||
|
||
error[E0691]: zero-sized field in transparent enum has alignment larger than 1 | ||
--> $DIR/repr-transparent.rs:70:11 | ||
--> $DIR/repr-transparent.rs:76:11 | ||
| | ||
LL | Foo { bar: ZstAlign32<T>, baz: u32 } | ||
| ^^^^^^^^^^^^^^^^^^ has alignment larger than 1 | ||
|
||
error[E0690]: transparent union needs exactly one non-zero-sized field, but has 0 | ||
--> $DIR/repr-transparent.rs:74:1 | ||
| | ||
LL | union UnitUnion { | ||
| ^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 | ||
|
||
error[E0690]: transparent union needs exactly one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:79:1 | ||
error[E0690]: transparent union needs at most one non-zero-sized field, but has 2 | ||
--> $DIR/repr-transparent.rs:85:1 | ||
| | ||
LL | union TooManyFields { | ||
| ^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2 | ||
| ^^^^^^^^^^^^^^^^^^^ needs at most one non-zero-sized field, but has 2 | ||
LL | u: u32, | ||
| ------ this field is non-zero-sized | ||
LL | s: i32 | ||
| ------ this field is non-zero-sized | ||
|
||
error: aborting due to 17 previous errors | ||
error: aborting due to 11 previous errors | ||
|
||
Some errors have detailed explanations: E0084, E0690, E0691, E0731. | ||
For more information about an error, try `rustc --explain E0084`. |