Skip to content

Commit 47a5caf

Browse files
committed
Restrict guarantees to constructible fields
1 parent be8acd0 commit 47a5caf

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/type-layout.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,15 @@ The `Rust` representation is the default representation for nominal types withou
166166
r[layout.repr.rust.layout]
167167
The only data layout guarantees made by this representation are those required for soundness. These are:
168168

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.
171-
3. For any field, its offset plus its size is at most the size of the type.
169+
1. The offset of a constructible field is divisible by that field's alignment.
170+
2. The alignment of the type is at least the maximum alignment of its constructible fields.
171+
3. For any constructible field, its offset plus its size is at most the size of the type.
172+
173+
r[layout.repr.rust.layout.constructible]
174+
175+
A field is considered constructible if it is possible to create a value of the type containing the field.
176+
177+
For example, given `enum E { A { x: u32 }, B { y: u32, z: ! } }`, the field `x` is constructible because you can create the value `E::A { x: 0 }`, but the fields `y` and `z` are not constructible because the type of `z` is uninhabited, so it is impossible to create an `E::B` value.
172178

173179
r[layout.repr.rust.layout.struct]
174180
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.

0 commit comments

Comments
 (0)