]> git.lizzy.rs Git - rust.git/commitdiff
Clarify semantics of #[repr(align(x))] on enums
authorNiklas Fiekas <niklas.fiekas@backscattering.de>
Thu, 31 Jan 2019 20:24:23 +0000 (21:24 +0100)
committerNiklas Fiekas <niklas.fiekas@backscattering.de>
Thu, 31 Jan 2019 20:24:23 +0000 (21:24 +0100)
src/doc/unstable-book/src/language-features/repr-align-enum.md

index 1fd9bd20f3f0d928f3ac3776b56bcabd0e9cebe4..415c6ebe8b4bcfe7e45026f4e0dda575da807bcb 100644 (file)
@@ -24,3 +24,19 @@ fn main() {
     assert_eq!(std::mem::align_of::<Aligned>(), 8);
 }
 ```
+
+This is equivalent to using an aligned wrapper struct everywhere:
+
+```rust
+#[repr(align(8))]
+struct Aligned(Unaligned);
+
+enum Unaligned {
+    Foo,
+    Bar { value: u32 },
+}
+
+fn main() {
+    assert_eq!(std::mem::align_of::<Aligned>(), 8);
+}
+```