Skip to content

Commit 2cfcc57

Browse files
committed
Fields must fit in the struct
1 parent 857cf11 commit 2cfcc57

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/type-layout.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ r[layout.repr.rust.layout]
167167
The only data layout guarantees made by this representation are those required for soundness. They are:
168168

169169
1. The fields are properly aligned.
170-
2. The fields do not overlap.
170+
2. The fields do not overlap and fit in the struct.
171171
3. The alignment of the type is at least the maximum alignment of its fields.
172172

173173
r[layout.repr.rust.alignment]
174174
Formally, the first guarantee means that the offset of any field is divisible by that field's alignment.
175175

176176
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.
177+
The second guarantee means that the fields can be ordered such that the offset plus the size of each field is less than or equal to the offset of the next field in the ordering, or for the last field, the size of the struct. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type.
178178

179179
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.
180180

0 commit comments

Comments
 (0)