From a9f8ea0a1e8ba1206f8c28d96b924606847b85a9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 21 Jun 2020 17:22:07 -0700 Subject: [PATCH] Simplify search for packed repr attr --- serde_derive/Cargo.toml | 2 +- serde_derive/src/internals/attr.rs | 17 +++++------------ serde_derive_internals/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/serde_derive/Cargo.toml b/serde_derive/Cargo.toml index de03621b..5921d9dc 100644 --- a/serde_derive/Cargo.toml +++ b/serde_derive/Cargo.toml @@ -22,7 +22,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0" quote = "1.0" -syn = { version = "1.0", features = ["visit"] } +syn = { version = "1.0.33", features = ["visit"] } [dev-dependencies] serde = { version = "1.0", path = "../serde" } diff --git a/serde_derive/src/internals/attr.rs b/serde_derive/src/internals/attr.rs index d32c1f52..e6f72dfe 100644 --- a/serde_derive/src/internals/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -597,19 +597,12 @@ impl Container { for attr in &item.attrs { if attr.path.is_ident("repr") { let _ = attr.parse_args_with(|input: ParseStream| { - input.step(|cursor| { - let mut rest = *cursor; - while let Some((tt, next)) = rest.token_tree() { - match &tt { - TokenTree::Ident(ident) if ident == "packed" => { - is_packed |= true; - return Ok(((), next)); - } - _ => rest = next, - } + while let Some(token) = input.parse()? { + if let TokenTree::Ident(ident) = token { + is_packed |= ident == "packed"; } - Err(cursor.error("no `packed` was found in the reprs")) - }) + } + Ok(()) }); } } diff --git a/serde_derive_internals/Cargo.toml b/serde_derive_internals/Cargo.toml index 164f2751..64ee1c62 100644 --- a/serde_derive_internals/Cargo.toml +++ b/serde_derive_internals/Cargo.toml @@ -16,7 +16,7 @@ path = "lib.rs" [dependencies] proc-macro2 = "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] targets = ["x86_64-unknown-linux-gnu"]