Skip to content

Commit 3905456

Browse files
authored
Correct repr(Rust) overlapping fields rule for enums and unions
1 parent 4dfaa4f commit 3905456

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/type-layout.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ The only data layout guarantees made by this representation are those required
223223
for soundness. They are:
224224

225225
1. The fields are properly aligned.
226-
2. The fields do not overlap.
226+
2. For structs, within each enum variant, and excluding unions, the fields do not overlap.
227227
3. The alignment of the type is at least the maximum alignment of its fields.
228228

229229
r[layout.repr.rust.alignment]
@@ -235,7 +235,8 @@ The second guarantee means that the fields can be
235235
ordered such that the offset plus the size of any field is less than or equal to
236236
the offset of the next field in the ordering. The ordering does not have to be
237237
the same as the order in which the fields are specified in the declaration of
238-
the type.
238+
the type. This applies within each variant of an enum, but fields of
239+
different variants may overlap.
239240

240241
Be aware that the second guarantee does not imply that the fields have distinct
241242
addresses: zero-sized types may have the same address as other fields in the

0 commit comments

Comments
 (0)