Skip to content

Commit bd8e2fe

Browse files
committed
1-ZST fields are ignored
1 parent 8df48e4 commit bd8e2fe

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

reference/src/layout/structs-and-tuples.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,21 @@ struct Zst2(Zst1, Zst0);
141141
# }
142142
```
143143

144-
#### Default layout of structs where only a single field is not a 1-ZST
144+
#### Structs with 1-ZST fields
145145

146-
The default layout of structs where only a single field is not a 1-ZST is the
147-
same as the layout of that non-1-ZST field.
146+
For the purposes of struct layout [1-ZST] fields are ignored.
148147

149-
For example, the layout of:
148+
For example,
150149

151150
```rust
152-
struct SomeStruct(i32, ());
153-
```
154-
155-
is the same as the layout of `i32`, but the layout of:
151+
type Zst1 = ();
152+
struct S1(i32, Zst1);
156153

157-
```rust
158-
#[repr(align(16))] struct Zst;
159-
struct SomeOtherStruct(i32, Zst);
154+
type Zst2 = [u16; 0];
155+
struct S2(Zst2, Zst1);
160156
```
161-
is **unspecified**, since `Zst` is not a [1-ZST].
157+
158+
the layout of `S1` is the same as that of `i32` and the layout of `S2` as that of `Zst2`.
162159

163160
#### Unresolved questions
164161

@@ -169,15 +166,6 @@ issue has been opened for further discussion on the repository. This
169166
section documents the questions and gives a few light details, but the
170167
reader is referred to the issues for further discussion.
171168

172-
**Zero-sized structs ([#37]).** If you have a struct which --
173-
transitively -- contains no data of non-zero size, then the size of
174-
that struct will be zero as well. These zero-sized structs appear
175-
frequently as exceptions in other layout considerations (e.g.,
176-
single-field structs). An example of such a struct is
177-
`std::marker::PhantomData`.
178-
179-
[#37]: https://github.com/rust-rfcs/unsafe-code-guidelines/issues/37
180-
181169
**Homogeneous structs ([#36]).** If you have homogeneous structs, where all
182170
the `N` fields are of a single type `T`, can we guarantee a mapping to
183171
the memory layout of `[T; N]`? How do we map between the field names

0 commit comments

Comments
 (0)