From da8d6f678ed3884929c578414cedba5d0c2d085e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 9 May 2020 23:01:47 -0700 Subject: [PATCH] Simplify finding of repr(packed) attributes --- serde_derive/src/internals/attr.rs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/serde_derive/src/internals/attr.rs b/serde_derive/src/internals/attr.rs index 8b1e17e7b..44f757021 100644 --- a/serde_derive/src/internals/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -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::(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::()? == "packed"; + Ok(()) + }); } - _ => false, - }); + } Container { name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),