From a28f858b55d537143e03c79fd301de7125b56d63 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Tue, 21 Nov 2023 16:49:01 -0800 Subject: [PATCH] type-layout.md: Warn about repr(align)/repr(packed) and field order --- src/type-layout.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/type-layout.md b/src/type-layout.md index aae3577f5..d338eb7bc 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -524,6 +524,10 @@ assert_eq!(std::mem::size_of::(), 4); 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. 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