Skip to content

Commit

Permalink
Simplify finding of repr(packed) attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 10, 2020
1 parent 548eb8f commit da8d6f6
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,25 +593,15 @@ impl Container {
}
}

use proc_macro2::Delimiter;
let is_packed = item.attrs.iter().any(|attr| match attr.style {
syn::AttrStyle::Outer => {
attr.path
.get_ident()
.map_or(false, |ident| *ident == "repr")
&& syn::parse2::<Group>(attr.tokens.clone())
.ok()
.filter(|g| g.delimiter() == Delimiter::Parenthesis)
.map(|g| g.stream().to_string())
.map_or(false, |repr| {
let repr = repr.trim();
repr == "packed"
|| repr.starts_with("packed(")
|| repr.starts_with("packed ")
})
let mut is_packed = false;
for attr in &item.attrs {
if attr.path.is_ident("repr") {
let _ = attr.parse_args_with(|input: ParseStream| {
is_packed |= input.parse::<Ident>()? == "packed";
Ok(())
});
}
_ => false,
});
}

Container {
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
Expand Down

0 comments on commit da8d6f6

Please sign in to comment.