Auto merge of #86279 - JohnTitor:transparent-zero-size-fields, r=nikomatsakis
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`
This commit is contained in:
commit
456a03227e
5 changed files with 51 additions and 81 deletions
|
@ -1,19 +1,19 @@
|
|||
A struct with the representation hint `repr(transparent)` had zero or more than
|
||||
one fields that were not guaranteed to be zero-sized.
|
||||
A struct with the representation hint `repr(transparent)` had two or more fields
|
||||
that were not guaranteed to be zero-sized.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0690
|
||||
#[repr(transparent)]
|
||||
struct LengthWithUnit<U> { // error: transparent struct needs exactly one
|
||||
struct LengthWithUnit<U> { // error: transparent struct needs at most one
|
||||
value: f32, // non-zero-sized field, but has 2
|
||||
unit: U,
|
||||
}
|
||||
```
|
||||
|
||||
Because transparent structs are represented exactly like one of their fields at
|
||||
run time, said field must be uniquely determined. If there is no field, or if
|
||||
there are multiple fields, it is not clear how the struct should be represented.
|
||||
run time, said field must be uniquely determined. If there are multiple fields,
|
||||
it is not clear how the struct should be represented.
|
||||
Note that fields of zero-sized types (e.g., `PhantomData`) can also exist
|
||||
alongside the field that contains the actual data, they do not count for this
|
||||
error. When generic types are involved (as in the above example), an error is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue