@@ -22,12 +22,12 @@ the union for each of its variants. The `<-...->` and `[ ... ]` denote the
22
22
differently-sized gaps and fields, respectively.
23
23
24
24
The individual fields (` [field{i}_ty_] ` ) are blocks of fixed size determined by
25
- the field's [ layout] . The only degrees of freedom the compiler has when
26
- computing the layout of a union are the size of the union, which can be larger
27
- than the size of its largest field, and the offset of each union field within
28
- its variant. How these are picked depends on certain constraints like, for
29
- example, the alignment requirements of the fields, the ` #[repr] ` attribute of
30
- the ` union ` , etc.
25
+ the field's [ layout] . Since we allow creating references to union fields
26
+ ( ` &u.i ` ), the only degrees of freedom the compiler has when computing the layout
27
+ of a union are the size of the union, which can be larger than the size of its
28
+ largest field, and the offset of each union field within its variant. How these
29
+ are picked depends on certain constraints like, for example, the alignment
30
+ requirements of the fields, the ` #[repr] ` attribute of the ` union ` , etc.
31
31
32
32
[ padding ] : ../glossary.md#padding
33
33
[ layout ] : ../glossary.md#layout
@@ -45,14 +45,14 @@ whether all fields have the same offset, etc.
45
45
As of this writing, we want to keep the option of using non-zero offsets open
46
46
for the future; whether this is useful depends on what exactly the
47
47
compiler-assumed invariants about union contents are. This might become clearer
48
- after the validity of unions
49
- ([ unsafe-code-guidelines/73] ( https://github.com/rust-lang/unsafe-code-guidelines/issues/73 ) )
50
- is settled.
48
+ after the validity of unions [ #73 ] is settled.
51
49
52
50
Even if the offsets happen to be all 0, there might still be differences in the
53
51
function call ABI. If you need to pass unions by-value across an FFI boundary,
54
52
you have to use ` #[repr(C)] ` .
55
53
54
+ [ #73 ] : https://github.com/rust-lang/unsafe-code-guidelines/issues/73
55
+
56
56
</details >
57
57
58
58
#### Layout of unions with a single non-zero-sized field
0 commit comments