@@ -122,6 +122,25 @@ compiler will not reorder it, to allow for the possibility of
122122unsizing. E.g., ` struct Foo { x: u16, y: u32 } ` and `struct Foo<T > {
123123x: u16, y: T }` where ` T = u32` are not guaranteed to be identical.
124124
125+ #### Zero-sized structs
126+
127+ For ` repr(Rust) ` , ` repr(packed(N)) ` , ` repr(align(N)) ` , and ` repr(C) `
128+ structs: if all fields of a struct have size 0, then the struct has size 0.
129+
130+ For example, all these types are zero-sized:
131+
132+ ``` rust
133+ # use std :: mem :: size_of;
134+ #[repr(align(32))] struct Zst0 ;
135+ #[repr(C )] struct Zst1 (Zst0 );
136+ struct Zst2 (Zst1 , Zst0 );
137+ # fn main () {
138+ # assert_eq! (size_of :: <Zst0 >(), 0 );
139+ # assert_eq! (size_of :: <Zst1 >(), 0 );
140+ # assert_eq! (size_of :: <Zst2 >(), 0 );
141+ # }
142+ ```
143+
125144#### Unresolved questions
126145
127146During the course of the discussion in [ #11 ] and [ #12 ] , various
@@ -131,15 +150,6 @@ issue has been opened for further discussion on the repository. This
131150section documents the questions and gives a few light details, but the
132151reader is referred to the issues for further discussion.
133152
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-
143153** Single-field structs ([ #34 ] ).** If you have a struct with single field
144154(` struct Foo { x: T } ` ), should we guarantee that the memory layout of
145155` Foo ` is identical to the memory layout of ` T ` (note that ABI details
0 commit comments