Skip to content

Commit 3199c6a

Browse files
authored
Merge pull request #2168 from Darksonn/type-layout-struct
Fields of enums and unions should be allowed to overlap
2 parents 49cff71 + a9f61c2 commit 3199c6a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/type-layout.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,15 @@ r[layout.repr.rust.intro]
164164
The `Rust` representation is the default representation for nominal types without a `repr` attribute. Using this representation explicitly through a `repr` attribute is guaranteed to be the same as omitting the attribute entirely.
165165

166166
r[layout.repr.rust.layout]
167-
The only data layout guarantees made by this representation are those required for soundness. They are:
167+
The only data layout guarantees made by this representation are those required for soundness. These are:
168168

169-
1. The fields are properly aligned.
170-
2. The fields do not overlap.
171-
3. The alignment of the type is at least the maximum alignment of its fields.
169+
1. The offset of a field is divisible by that field's alignment.
170+
2. The alignment of the type is at least the maximum alignment of its fields.
172171

173-
r[layout.repr.rust.alignment]
174-
Formally, the first guarantee means that the offset of any field is divisible by that field's alignment.
172+
r[layout.repr.rust.layout.struct]
173+
For [structs], it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type.
175174

176-
r[layout.repr.rust.field-storage]
177-
The second guarantee means that the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type.
178-
179-
Be aware that the second guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct.
175+
Be aware that this guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct.
180176

181177
r[layout.repr.rust.unspecified]
182178
There are no other guarantees of data layout made by this representation.

0 commit comments

Comments
 (0)