]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0690.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0690.md
1 A struct with the representation hint `repr(transparent)` had zero or more than
2 one fields that were not guaranteed to be zero-sized.
3
4 Erroneous code example:
5
6 ```compile_fail,E0690
7 #[repr(transparent)]
8 struct LengthWithUnit<U> { // error: transparent struct needs exactly one
9     value: f32,            //        non-zero-sized field, but has 2
10     unit: U,
11 }
12 ```
13
14 Because transparent structs are represented exactly like one of their fields at
15 run time, said field must be uniquely determined. If there is no field, or if
16 there are multiple fields, it is not clear how the struct should be represented.
17 Note that fields of zero-typed types (e.g., `PhantomData`) can also exist
18 alongside the field that contains the actual data, they do not count for this
19 error. When generic types are involved (as in the above example), an error is
20 reported because the type parameter could be non-zero-sized.
21
22 To combine `repr(transparent)` with type parameters, `PhantomData` may be
23 useful:
24
25 ```
26 use std::marker::PhantomData;
27
28 #[repr(transparent)]
29 struct LengthWithUnit<U> {
30     value: f32,
31     unit: PhantomData<U>,
32 }
33 ```