@@ -110,10 +110,13 @@ Closures have no layout guarantees.
110110## Representations
111111
112112All user-defined composite types (` struct ` s, ` enum ` s, and ` union ` s) have a
113- * representation* that specifies what the layout is for the type.
113+ * representation* that specifies what the layout is for the type. The possible
114+ representations for a type are:
114115
115- The possible representations for a type are the default representation, ` C ` ,
116- the primitive representations, and ` transparent ` .
116+ - [ Default]
117+ - [ ` C ` ]
118+ - The [ primitive representations]
119+ - [ ` transparent ` ]
117120
118121The representation of a type can be changed by applying the ` repr ` attribute
119122to it. The following example shows a struct with a ` C ` representation.
@@ -296,42 +299,28 @@ For all other enumerations, the layout is unspecified.
296299
297300Likewise, combining two primitive representations together is unspecified.
298301
299- ### The ` align ` modifier
302+ ### The alignment modifiers
300303
301- The ` align ` modifier can be used on ` struct ` s and ` union ` s to raise the
302- alignment of the type to a given value.
304+ The ` align ` and ` packed ` modifiers can be used to respectively raise or lower
305+ the alignment of ` struct ` s and ` union ` s. ` packed ` may also alter the padding
306+ between fields.
303307
304308The alignment is specified as an integer parameter in the form of
305- ` #[repr(align(x))] ` . The alignment value must be a power of two from 1 up to
306- 2<sup >29</sup >.
309+ ` #[repr(align(x))] ` or ` #[repr(packed(x))] ` . The alignment value must be a
310+ power of two from 1 up to 2<sup >29</sup >. For ` packed ` , if no value is given,
311+ as in ` #[repr(packed)] ` , then the value is 1.
307312
308- The ` align ` modifier raises the type's alignment to the specified alignment.
309- If the specified alignment is less than the alignment of the type without the
310- ` align ` modifier, then the alignment is unaffected.
313+ For ` align ` , if the specified alignment is less than the alignment of the type
314+ without the ` align ` modifier, then the alignment is unaffected.
311315
312- The ` align ` and ` packed ` modifiers cannot be applied on the same type and a
313- ` packed ` type cannot transitively contain another ` align ` ed type. ` align ` may
314- only be applied to the default and ` C ` representations.
315-
316- ### The ` packed ` modifier
317-
318- The ` packed ` modifier can be used on ` struct ` s and ` union ` s to lower the
319- alignment of the type to a given value.
320-
321- The packing value (hence: "value") is specified as an integer parameter in the form of
322- ` #[repr(packed(x))] ` . If no value is given, as in ` #[repr(packed)] ` , then the
323- value is 1. The value must be a power of two from 1 up to
324- 2<sup >29</sup >.
325-
326- The ` packed ` modifier lowers the type's alignment to the specified value. If
327- the specified value is greater than the type's alignment without the
328- ` packed ` modifier, then the alignment and layout is unaffected. The alignments
329- of each field, for the purpose of positioning fields, is the smaller of the
330- specified packing and the alignment of the field's type.
316+ For ` packed ` , if the specified alignment is greater than the type's alignment
317+ without the ` packed ` modifier, then the alignment and layout is unaffected.
318+ The alignments of each field, for the purpose of positioning fields, is the
319+ smaller of the specified alignment and the alignment of the field's type.
331320
332321The ` align ` and ` packed ` modifiers cannot be applied on the same type and a
333- ` packed ` type cannot transitively contain another ` align ` ed type. ` packed ` may
334- only be applied to the default and ` C ` representations.
322+ ` packed ` type cannot transitively contain another ` align ` ed type. ` align ` and
323+ ` packed ` may only be applied to the [ default] and [ ` C ` ] representations.
335324
336325<div class =" warning " >
337326
@@ -369,3 +358,7 @@ used with any other representation.
369358[ undefined behavior ] : behavior-considered-undefined.html
370359[ 27060 ] : https://github.com/rust-lang/rust/issues/27060
371360[ `PhantomData<T>` ] : special-types-and-traits.html#phantomdatat
361+ [ Default ] : #the-default-representation
362+ [ `C` ] : #the-c-representation
363+ [ primitive representations ] : #primitive-representations
364+ [ `transparent` ] : #the-transparent-representation
0 commit comments