Skip to content

Commit af115e0

Browse files
committed
Use 1-ZST terminology
1 parent 2b1c5b5 commit af115e0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

reference/src/layout/unions.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ the `union`, etc.
3434

3535
### Unions with default layout ("`repr(Rust)`")
3636

37-
The default layout of Rust unions is **unspecified**.
37+
Except for the guarantees provided below for some specific cases, the default
38+
layout of Rust unions is, _in general_, **unspecified**.
3839

39-
That is, there are no guarantees about the offset of the fields, whether all
40-
fields have the same offset, etc.
40+
That is, there are no _general_ guarantees about the offset of the fields,
41+
whether all fields have the same offset, etc.
4142

4243
<details><summary><b>Rationale</b></summary>
4344

@@ -59,8 +60,8 @@ you have to use `#[repr(C)]`.
5960
The layout of unions with a single non-zero-sized field is the same as the
6061
layout of that field if:
6162

62-
* that field has no padding bits, and
63-
* the alignment requirement of all zero-sized fields is 1.
63+
* all zero-sized fields are [1-ZST], and
64+
* the non-zero sized field has no padding bits.
6465

6566
For example, here:
6667

@@ -83,7 +84,7 @@ union U0 {
8384

8485
the union `U0` has the same layout as `SomeStruct`, because `SomeStruct` has no
8586
padding bits - it is equivalent to an `i32` due to `repr(transparent)` - and
86-
because the alignment of `Zst` is 1.
87+
because `Zst` is a [1-ZST].
8788

8889
On the other hand, here:
8990

@@ -104,9 +105,10 @@ assert_eq!(align_of::<Zst2>(), 16);
104105
# }
105106
```
106107

107-
the alignment requirement of `Zst2` is not 1, and `SomeOtherStruct` has an
108-
unspecified layout and could contain padding bits. Therefore, the layout of `U1`
109-
is **unspecified**.
108+
the layout of `U1` is **unspecified** because:
109+
110+
* `Zst2` is not a [1-ZST], and
111+
* `SomeOtherStruct` has an unspecified layout and could contain padding bits.
110112

111113
### C-compatible layout ("repr C")
112114

@@ -117,3 +119,5 @@ a field type to obtain a pointer to any field, and vice versa.
117119

118120
[6.5.8.5]: http://port70.net/~nsz/c/c11/n1570.html#6.5.8p5
119121
[6.7.2.1.16]: http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1p16
122+
123+
[1-ZST]: ../glossary.md#zero-sized-type--zst

0 commit comments

Comments
 (0)