Adjust documentation

This commit is contained in:
Yuki Okushi 2021-06-14 07:05:14 +09:00
parent ea188e9d21
commit 4e755a96a7
No known key found for this signature in database
GPG Key ID: DABA5B072961C18A

View File

@ -1,19 +1,19 @@
A struct with the representation hint `repr(transparent)` had zero or more than A struct with the representation hint `repr(transparent)` had two or more fields
one fields that were not guaranteed to be zero-sized. that were not guaranteed to be zero-sized.
Erroneous code example: Erroneous code example:
```compile_fail,E0690 ```compile_fail,E0690
#[repr(transparent)] #[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 value: f32, // non-zero-sized field, but has 2
unit: U, unit: U,
} }
``` ```
Because transparent structs are represented exactly like one of their fields at 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 run time, said field must be uniquely determined. If there are multiple fields,
there are multiple fields, it is not clear how the struct should be represented. it is not clear how the struct should be represented.
Note that fields of zero-sized types (e.g., `PhantomData`) can also exist 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 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 error. When generic types are involved (as in the above example), an error is