@@ -122,6 +122,27 @@ 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
+ #### Default layout of structs with a single non-zero-sized field
126
+
127
+ The default layout of structs with a single non-zero-sized field is the same as
128
+ the layout of that field if the alignment requirement of all other fields is 1.
129
+
130
+ For example, the layout of:
131
+
132
+ ``` rust
133
+ struct SomeStruct (i32 , ());
134
+ ```
135
+
136
+ is the same as the layout of ` i32 ` , but the layout of:
137
+
138
+ ``` rust
139
+ #[repr(align(16))] struct Zst ;
140
+ struct SomeOtherStruct (i32 , Zst );
141
+ ```
142
+
143
+ is ** unspecified** , since there is a zero-sized field in ` SomeOtherStruct ` with
144
+ alignment greater than 1.
145
+
125
146
#### Unresolved questions
126
147
127
148
During the course of the discussion in [ #11 ] and [ #12 ] , various
@@ -140,15 +161,6 @@ single-field structs). An example of such a struct is
140
161
141
162
[ #37 ] : https://github.com/rust-rfcs/unsafe-code-guidelines/issues/37
142
163
143
- ** Single-field structs ([ #34 ] ).** If you have a struct with single field
144
- (` struct Foo { x: T } ` ), should we guarantee that the memory layout of
145
- ` Foo ` is identical to the memory layout of ` T ` (note that ABI details
146
- around function calls may still draw a distinction, which is why
147
- ` #[repr(transparent)] ` is needed). What about zero-sized types like
148
- ` PhantomData ` ?
149
-
150
- [ #34 ] : https://github.com/rust-rfcs/unsafe-code-guidelines/issues/34
151
-
152
164
** Homogeneous structs ([ #36 ] ).** If you have homogeneous structs, where all
153
165
the ` N ` fields are of a single type ` T ` , can we guarantee a mapping to
154
166
the memory layout of ` [T; N] ` ? How do we map between the field names
0 commit comments