Simplify search for packed repr attr

This commit is contained in:
David Tolnay 2020-06-21 17:22:07 -07:00
parent 04faac962a
commit a9f8ea0a1e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 7 additions and 14 deletions

View File

@ -22,7 +22,7 @@ proc-macro = true
[dependencies] [dependencies]
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = "1.0" quote = "1.0"
syn = { version = "1.0", features = ["visit"] } syn = { version = "1.0.33", features = ["visit"] }
[dev-dependencies] [dev-dependencies]
serde = { version = "1.0", path = "../serde" } serde = { version = "1.0", path = "../serde" }

View File

@ -597,19 +597,12 @@ impl Container {
for attr in &item.attrs { for attr in &item.attrs {
if attr.path.is_ident("repr") { if attr.path.is_ident("repr") {
let _ = attr.parse_args_with(|input: ParseStream| { let _ = attr.parse_args_with(|input: ParseStream| {
input.step(|cursor| { while let Some(token) = input.parse()? {
let mut rest = *cursor; if let TokenTree::Ident(ident) = token {
while let Some((tt, next)) = rest.token_tree() { is_packed |= ident == "packed";
match &tt {
TokenTree::Ident(ident) if ident == "packed" => {
is_packed |= true;
return Ok(((), next));
}
_ => rest = next,
} }
} }
Err(cursor.error("no `packed` was found in the reprs")) Ok(())
})
}); });
} }
} }

View File

@ -16,7 +16,7 @@ path = "lib.rs"
[dependencies] [dependencies]
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = "1.0" quote = "1.0"
syn = { version = "1.0", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] } syn = { version = "1.0.33", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
[package.metadata.docs.rs] [package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"] targets = ["x86_64-unknown-linux-gnu"]