From d47d527ac2b8de0544bd3c5c5ab1361be52e8de1 Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Tue, 16 Aug 2022 20:42:07 +0200 Subject: [PATCH] Fix regression #127: support `align` in `repr`s again (#128) --- derive/src/traits.rs | 14 +++++++++++++- derive/tests/basic.rs | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/derive/src/traits.rs b/derive/src/traits.rs index 455d1ef..815e77c 100644 --- a/derive/src/traits.rs +++ b/derive/src/traits.rs @@ -592,6 +592,11 @@ fn get_repr(attributes: &[Attribute]) -> Result { | (None, b) => b, | _ => bail!("conflicting representation hints"), }, + align: match (a.align, b.align) { + | (a, None) => a, + | (None, b) => b, + | _ => bail!("conflicting representation hints"), + }, }) }) } @@ -643,12 +648,13 @@ macro_rules! mk_repr {( #[derive(Clone, Copy)] struct Representation { packed: Option, + align: Option, repr: Repr, } impl Default for Representation { fn default() -> Self { - Self { packed: None, repr: Repr::Rust } + Self { packed: None, align: None, repr: Repr::Rust } } } @@ -672,6 +678,12 @@ macro_rules! mk_repr {( let _: Option = input.parse()?; continue; }, + "align" => { + let contents; parenthesized!(contents in input); + ret.align = Some(LitInt::base10_parse::(&contents.parse()?)?); + let _: Option = input.parse()?; + continue; + }, $( stringify!($xn) => Repr::$Xn, )* diff --git a/derive/tests/basic.rs b/derive/tests/basic.rs index 3e164bb..5e05555 100644 --- a/derive/tests/basic.rs +++ b/derive/tests/basic.rs @@ -185,3 +185,7 @@ fn anybitpattern_implies_zeroable() { let test = AnyBitPatternTest::zeroed(); assert_eq!(test, AnyBitPatternTest { a: 0, b: 0 }); } + +#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +#[repr(C, align(16))] +struct Issue127 {}