Skip to content

Commit 8e76a8b

Browse files
committed
Documented the #[repr(align(x))] attribute.
1 parent 36fc52c commit 8e76a8b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: src/attributes.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,14 @@ On `enum`s:
142142
On `struct`s:
143143

144144
- `repr` - specifies the representation to use for this struct. Takes a list
145-
of options. The currently accepted ones are `C` and `packed`, which may be
146-
combined. `C` will use a C ABI compatible struct layout, and `packed` will
147-
remove any padding between fields (note that this is very fragile and may
148-
break platforms which require aligned access).
145+
of options. The currently accepted ones are `C`, `align` and `packed`.
146+
`C` will use a C ABI compatible struct layout. `C` can be used in conjunction
147+
with `align` or `packed`. `#[repr(align(x))]` takes one argument which
148+
increases alignment of the `struct` to the given value. The alignment must be
149+
an unsigned power of two. `packed` will remove any padding between
150+
fields (note that this is very fragile and may break platforms which require
151+
aligned access). `align` and `packed` cannot be applied on the same struct,
152+
and a `packed` struct cannot transitively contain another struct with `align`.
149153

150154
On `union`s:
151155

@@ -416,4 +420,4 @@ You can implement `derive` for your own type through [procedural macros].
416420

417421
[Doc comments]: comments.html#doc-comments
418422
[The Rustdoc Book]: ../rustdoc/the-doc-attribute.html
419-
[procedural macros]: procedural-macros.html
423+
[procedural macros]: procedural-macros.html

0 commit comments

Comments
 (0)