Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression #127: support align in reprs again #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion derive/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ fn get_repr(attributes: &[Attribute]) -> Result<Representation> {
| (None, b) => b,
| _ => bail!("conflicting representation hints"),
},
align: match (a.align, b.align) {
| (a, None) => a,
| (None, b) => b,
| _ => bail!("conflicting representation hints"),
},
})
})
}
Expand Down Expand Up @@ -643,12 +648,13 @@ macro_rules! mk_repr {(
#[derive(Clone, Copy)]
struct Representation {
packed: Option<u32>,
align: Option<u32>,
repr: Repr,
}

impl Default for Representation {
fn default() -> Self {
Self { packed: None, repr: Repr::Rust }
Self { packed: None, align: None, repr: Repr::Rust }
}
}

Expand All @@ -672,6 +678,12 @@ macro_rules! mk_repr {(
let _: Option<Token![,]> = input.parse()?;
continue;
},
"align" => {
let contents; parenthesized!(contents in input);
ret.align = Some(LitInt::base10_parse::<u32>(&contents.parse()?)?);
let _: Option<Token![,]> = input.parse()?;
continue;
},
$(
stringify!($xn) => Repr::$Xn,
)*
Expand Down
4 changes: 4 additions & 0 deletions derive/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}