]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_error_codes/src/error_codes/E0784.md
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0784.md
CommitLineData
94222f64
XL
1A union expression does not have exactly one field.
2
3Erroneous code example:
4
5```compile_fail,E0784
6union Bird {
7 pigeon: u8,
8 turtledove: u16,
9}
10
11let bird = Bird {}; // error
12let bird = Bird { pigeon: 0, turtledove: 1 }; // error
13```
14
15The key property of unions is that all fields of a union share common storage.
16As a result, writes to one field of a union can overwrite its other fields, and
17size of a union is determined by the size of its largest field.
18
19You can find more information about the union types in the [Rust reference].
20
21Working example:
22
23```
24union Bird {
25 pigeon: u8,
26 turtledove: u16,
27}
28
29let bird = Bird { pigeon: 0 }; // OK
30```
31
32[Rust reference]: https://doc.rust-lang.org/reference/items/unions.html