]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0692.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0692.md
CommitLineData
60c5eb7d
XL
1A `repr(transparent)` type was also annotated with other, incompatible
2representation hints.
3
4Erroneous code example:
5
6```compile_fail,E0692
7#[repr(transparent, C)] // error: incompatible representation hints
8struct Grams(f32);
9```
10
11A type annotated as `repr(transparent)` delegates all representation concerns to
12another type, so adding more representation hints is contradictory. Remove
13either the `transparent` hint or the other hints, like this:
14
15```
16#[repr(transparent)]
17struct Grams(f32);
18```
19
20Alternatively, move the other attributes to the contained type:
21
22```
23#[repr(C)]
24struct Foo {
25 x: i32,
26 // ...
27}
28
29#[repr(transparent)]
30struct FooWrapper(Foo);
31```
32
33Note that introducing another `struct` just to have a place for the other
34attributes may have unintended side effects on the representation:
35
36```
37#[repr(transparent)]
38struct Grams(f32);
39
40#[repr(C)]
41struct Float(f32);
42
43#[repr(transparent)]
44struct Grams2(Float); // this is not equivalent to `Grams` above
45```
46
47Here, `Grams2` is a not equivalent to `Grams` -- the former transparently wraps
48a (non-transparent) struct containing a single float, while `Grams` is a
49transparent wrapper around a float. This can make a difference for the ABI.