Skip to content

Commit 4ba0917

Browse files
committed
Guarantee that some structs are zero sized
1 parent 97cbda4 commit 4ba0917

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ compiler will not reorder it, to allow for the possibility of
122122
unsizing. E.g., `struct Foo { x: u16, y: u32 }` and `struct Foo<T> {
123123
x: u16, y: T }` where `T = u32` are not guaranteed to be identical.
124124

125+
#### Zero-sized structs
126+
127+
Structs with default layout are zero-sized, if they contain no fields of
128+
non-zero size. That is, either the type has no fields, or all of its fields have
129+
zero size.
130+
125131
#### Unresolved questions
126132

127133
During the course of the discussion in [#11] and [#12], various
@@ -131,15 +137,6 @@ issue has been opened for further discussion on the repository. This
131137
section documents the questions and gives a few light details, but the
132138
reader is referred to the issues for further discussion.
133139

134-
**Zero-sized structs ([#37]).** If you have a struct which --
135-
transitively -- contains no data of non-zero size, then the size of
136-
that struct will be zero as well. These zero-sized structs appear
137-
frequently as exceptions in other layout considerations (e.g.,
138-
single-field structs). An example of such a struct is
139-
`std::marker::PhantomData`.
140-
141-
[#37]: https://github.com/rust-rfcs/unsafe-code-guidelines/issues/37
142-
143140
**Single-field structs ([#34]).** If you have a struct with single field
144141
(`struct Foo { x: T }`), should we guarantee that the memory layout of
145142
`Foo` is identical to the memory layout of `T` (note that ABI details

0 commit comments

Comments
 (0)