@@ -122,6 +122,7 @@ 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
+ <<<<<<< HEAD
125
126
#### Zero-sized structs
126
127
127
128
For ` repr(Rust) ` , ` repr(packed(N)) ` , ` repr(align(N)) ` , and ` repr(C) `
@@ -141,6 +142,28 @@ struct Zst2(Zst1, Zst0);
141
142
# }
142
143
```
143
144
145
+ =======
146
+ #### Default layout of structs with a single non-zero-sized field
147
+
148
+ The default layout of structs with a single non-zero-sized field is the same as
149
+ the layout of that field if the alignment requirement of all other fields is 1.
150
+
151
+ For example, the layout of:
152
+
153
+ ``` rust
154
+ struct SomeStruct (i32 , ());
155
+ ```
156
+
157
+ is the same as the layout of ` i32 ` , but the layout of:
158
+
159
+ ``` rust
160
+ #[repr(align(16))] struct Zst ;
161
+ struct SomeOtherStruct (i32 , Zst );
162
+ ```
163
+
164
+ is ** unspecified** , since there is a zero-sized field in ` SomeOtherStruct ` with
165
+ alignment greater than 1.
166
+
144
167
#### Unresolved questions
145
168
146
169
During the course of the discussion in [ #11 ] and [ #12 ] , various
@@ -150,14 +173,14 @@ issue has been opened for further discussion on the repository. This
150
173
section documents the questions and gives a few light details, but the
151
174
reader is referred to the issues for further discussion.
152
175
153
- ** Single-field structs ([ #34 ] ).** If you have a struct with single field
154
- ( ` struct Foo { x: T } ` ), should we guarantee that the memory layout of
155
- ` Foo ` is identical to the memory layout of ` T ` (note that ABI details
156
- around function calls may still draw a distinction, which is why
157
- ` #[repr(transparent)] ` is needed ). What about zero-sized types like
158
- ` PhantomData ` ?
176
+ ** Zero-sized structs ([ #37 ] ).** If you have a struct which --
177
+ transitively -- contains no data of non-zero size, then the size of
178
+ that struct will be zero as well. These zero-sized structs appear
179
+ frequently as exceptions in other layout considerations (e.g.,
180
+ single-field structs ). An example of such a struct is
181
+ ` std::marker:: PhantomData` .
159
182
160
- [ #34 ] : https://github.com/rust-rfcs/unsafe-code-guidelines/issues/34
183
+ [ #37 ] : https://github.com/rust-rfcs/unsafe-code-guidelines/issues/37
161
184
162
185
** Homogeneous structs ([ #36 ] ).** If you have homogeneous structs, where all
163
186
the ` N ` fields are of a single type ` T ` , can we guarantee a mapping to
0 commit comments