Skip to content

Commit 866d25e

Browse files
committed
Remove layout.repr.align-packed
This more or less repeats what is already said in layout.repr.alignment.intro where it explains that they are modifiers that affect a representation.
1 parent fb53df7 commit 866d25e

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/type-layout.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,8 @@ The *`repr` [attribute][attributes]* can change the representation and layout of
138138
> [!NOTE]
139139
> As a consequence of the representation being an attribute on the item, the representation does not depend on generic parameters. Any two types with the same name have the same representation. For example, `Foo<Bar>` and `Foo<Baz>` both have the same representation.
140140
141-
r[layout.repr.align-packed]
142-
The alignment may be raised or lowered with the `align` and `packed` modifiers respectively. They alter the representation specified in the attribute. If no representation is specified, the default one is altered.
143141
144-
```rust
145-
// Default representation, alignment lowered to 2.
146-
#[repr(packed(2))]
147-
struct PackedStruct {
148-
first: i16,
149-
second: i8,
150-
third: i32
151-
}
152142
153-
// C representation, alignment raised to 8
154-
#[repr(C, align(8))]
155-
struct AlignedStruct {
156-
first: i16,
157-
second: i8,
158-
third: i32
159-
}
160-
```
161143
162144
r[layout.repr.inter-field]
163145
The representation of a type can change the padding between fields, but does not change the layout of the fields themselves. For example, a struct with a `C` representation that contains a struct `Inner` with the `Rust` representation will not change the layout of `Inner`.
@@ -495,6 +477,25 @@ r[layout.repr.alignment]
495477
r[layout.repr.alignment.intro]
496478
The `align` and `packed` modifiers can be used to respectively raise or lower the alignment of `struct`s and `union`s. `packed` may also alter the padding between fields (although it will not alter the padding inside of any field). On their own, `align` and `packed` do not provide guarantees about the order of fields in the layout of a struct or the layout of an enum variant, although they may be combined with representations (such as `C`) which do provide such guarantees.
497479

480+
> [!EXAMPLE]
481+
> ```rust
482+
> // Default representation, alignment lowered to 2.
483+
> #[repr(packed(2))]
484+
> struct PackedStruct {
485+
> first: i16,
486+
> second: i8,
487+
> third: i32
488+
> }
489+
>
490+
> // C representation, alignment raised to 8
491+
> #[repr(C, align(8))]
492+
> struct AlignedStruct {
493+
> first: i16,
494+
> second: i8,
495+
> third: i32
496+
> }
497+
> ```
498+
498499
r[layout.repr.alignment.constraint-alignment]
499500
The alignment is specified as an integer parameter in the form of `#[repr(align(x))]` or `#[repr(packed(x))]`. The alignment value must be a power of two from 1 up to 2<sup>29</sup>. For `packed`, if no value is given, as in `#[repr(packed)]`, then the value is 1.
500501

0 commit comments

Comments
 (0)