@@ -264,13 +264,29 @@ For all other enumerations, the layout is unspecified.
264
264
265
265
Likewise, combining two primitive representations together is unspecified.
266
266
267
+ ### The ` align ` Representation
268
+
269
+ The ` align ` representation can be used on ` struct ` s and ` union ` s to raise the
270
+ alignment of the type to a given value.
271
+
272
+ Alignment is specified as a parameter in the form of ` #[repr(align(x))] ` . The
273
+ alignment value must be a power of two of type ` u32 ` . The ` align ` representation
274
+ can raise the alignment of a type to be greater than it's primitive alignment,
275
+ it cannot lower the alignment of a type.
276
+
277
+ The ` align ` and ` packed ` representations cannot be applied on the same type and
278
+ a ` packed ` type cannot transitively contain another ` align ` ed type.
279
+
267
280
### The ` packed ` Representation
268
281
269
282
The ` packed ` representation can only be used on ` struct ` s and ` union ` s.
270
283
271
284
It modifies the representation (either the default or ` C ` ) by removing any
272
285
padding bytes and forcing the alignment of the type to ` 1 ` .
273
286
287
+ The ` align ` and ` packed ` representations cannot be applied on the same type and
288
+ a ` packed ` type cannot transitively contain another ` align ` ed type.
289
+
274
290
> Warning: Dereferencing an unaligned pointer is [ undefined behaviour] and it is
275
291
> possible to [ safely create unaligned pointers to ` packed ` fields] [ 27060 ] .
276
292
> Like all ways to create undefined behavior in safe Rust, this is a bug.
@@ -284,4 +300,4 @@ padding bytes and forcing the alignment of the type to `1`.
284
300
[ C-like enumerations ] : items/enumerations.html#c-like-enumerations
285
301
[ zero-variant enumerations ] : items/enumerations.html#zero-variant-enumerations
286
302
[ undefined behavior ] : behavior-considered-undefined.html
287
- [ 27060 ] : https://github.com/rust-lang/rust/issues/27060
303
+ [ 27060 ] : https://github.com/rust-lang/rust/issues/27060
0 commit comments