Skip to content

Commit f18d4a9

Browse files
committed
Clarify dofs, fix link
1 parent 4d777f1 commit f18d4a9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

reference/src/layout/unions.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ the union for each of its variants. The `<-...->` and `[ ... ]` denote the
2222
differently-sized gaps and fields, respectively.
2323

2424
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.
3131

3232
[padding]: ../glossary.md#padding
3333
[layout]: ../glossary.md#layout
@@ -45,14 +45,14 @@ whether all fields have the same offset, etc.
4545
As of this writing, we want to keep the option of using non-zero offsets open
4646
for the future; whether this is useful depends on what exactly the
4747
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.
5149

5250
Even if the offsets happen to be all 0, there might still be differences in the
5351
function call ABI. If you need to pass unions by-value across an FFI boundary,
5452
you have to use `#[repr(C)]`.
5553

54+
[#73]: https://github.com/rust-lang/unsafe-code-guidelines/issues/73
55+
5656
</details>
5757

5858
#### Layout of unions with a single non-zero-sized field

0 commit comments

Comments
 (0)