@@ -122,6 +122,25 @@ compiler will not reorder it, to allow for the possibility of
122
122
unsizing. E.g., ` struct Foo { x: u16, y: u32 } ` and `struct Foo<T > {
123
123
x: u16, y: T }` where ` T = u32` are not guaranteed to be identical.
124
124
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
+
125
144
#### Unresolved questions
126
145
127
146
During 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
131
150
section documents the questions and gives a few light details, but the
132
151
reader is referred to the issues for further discussion.
133
152
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
-
143
153
** Single-field structs ([ #34 ] ).** If you have a struct with single field
144
154
(` struct Foo { x: T } ` ), should we guarantee that the memory layout of
145
155
` Foo ` is identical to the memory layout of ` T ` (note that ABI details
0 commit comments