From 8aabb8d9c0a4997336b5bd1fa399132e4ac43d23 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Thu, 23 Mar 2023 18:54:19 +0000 Subject: [PATCH] Update to syn-2 Change-Id: I0043acbdcd7a697063931a3505f6e90354f92d2a Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5078521 Commit-Queue: Frederick Mayle Reviewed-by: Daniel Verkamp --- Cargo.lock | 8 +++--- argh_helpers/Cargo.toml | 2 +- argh_helpers/src/lib.rs | 24 ++++++++++------- base/base_event_token_derive/Cargo.toml | 2 +- bit_field/bit_field_derive/Cargo.toml | 2 +- .../bit_field_derive/bit_field_derive.rs | 26 ++++++++++++------- .../serde_keyvalue_derive/Cargo.toml | 2 +- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c11381921..7a5f139aee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,7 +127,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote 1.0.33", - "syn 1.0.103", + "syn 2.0.37", ] [[package]] @@ -252,7 +252,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote 1.0.33", - "syn 1.0.103", + "syn 2.0.37", ] [[package]] @@ -310,7 +310,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote 1.0.33", - "syn 1.0.103", + "syn 2.0.37", ] [[package]] @@ -2423,7 +2423,7 @@ dependencies = [ "argh", "proc-macro2", "quote 1.0.33", - "syn 1.0.103", + "syn 2.0.37", ] [[package]] diff --git a/argh_helpers/Cargo.toml b/argh_helpers/Cargo.toml index c9431921a2..71b9c4d51e 100644 --- a/argh_helpers/Cargo.toml +++ b/argh_helpers/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" proc-macro = true [dependencies] -syn = {version = "1.0", features = ["extra-traits"]} +syn = { version = "2", features = ["extra-traits"] } quote = "1.0" proc-macro2 = "1.0" diff --git a/argh_helpers/src/lib.rs b/argh_helpers/src/lib.rs index 2441d72698..c695f4475a 100644 --- a/argh_helpers/src/lib.rs +++ b/argh_helpers/src/lib.rs @@ -136,20 +136,26 @@ pub fn pad_description_for_argh( if let syn::Fields::Named(fields) = &mut s.fields { for f in fields.named.iter_mut() { for a in f.attrs.iter_mut() { - if a.path + if a.path() .get_ident() .map(|i| i.to_string()) .unwrap_or_default() == *"doc" { - if let Ok(syn::Meta::NameValue(nv)) = a.parse_meta() { - if let syn::Lit::Str(s) = nv.lit { - let doc = s.value().lines().fold(String::new(), |mut output, s| { - let _ = write!(output, "{: <61}", s); - output - }); - *a = syn::parse_quote! { #[doc= #doc] }; - } + if let syn::Meta::NameValue(syn::MetaNameValue { + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(s), + .. + }), + .. + }) = &a.meta + { + let doc = s.value().lines().fold(String::new(), |mut output, s| { + let _ = write!(output, "{: <61}", s); + output + }); + *a = syn::parse_quote! { #[doc= #doc] }; } } } diff --git a/base/base_event_token_derive/Cargo.toml b/base/base_event_token_derive/Cargo.toml index cd55db3d85..be3316b7b2 100644 --- a/base/base_event_token_derive/Cargo.toml +++ b/base/base_event_token_derive/Cargo.toml @@ -11,4 +11,4 @@ proc-macro = true [dependencies] proc-macro2 = "^1" quote = "^1" -syn = "^1" +syn = "2" diff --git a/bit_field/bit_field_derive/Cargo.toml b/bit_field/bit_field_derive/Cargo.toml index be1010b9c0..cf59cfa4a3 100644 --- a/bit_field/bit_field_derive/Cargo.toml +++ b/bit_field/bit_field_derive/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] proc-macro2 = "^1" quote = "^1" -syn = "^1" +syn = { version = "2", features = ["full"] } [lib] proc-macro = true diff --git a/bit_field/bit_field_derive/bit_field_derive.rs b/bit_field/bit_field_derive/bit_field_derive.rs index ee54199424..b3c0dd0ece 100644 --- a/bit_field/bit_field_derive/bit_field_derive.rs +++ b/bit_field/bit_field_derive/bit_field_derive.rs @@ -24,6 +24,7 @@ use syn::Ident; use syn::Lit; use syn::LitInt; use syn::Meta; +use syn::MetaNameValue; use syn::Type; use syn::Visibility; @@ -391,10 +392,10 @@ fn parse_bits_attr(attrs: &[Attribute]) -> Result> { let mut expected_bits = None; for attr in attrs { - if attr.path.is_ident("doc") { + if attr.path().is_ident("doc") { continue; } - if let Some(v) = try_parse_bits_attr(attr)? { + if let Some(v) = try_parse_bits_attr(attr) { expected_bits = Some(v); continue; } @@ -406,15 +407,20 @@ fn parse_bits_attr(attrs: &[Attribute]) -> Result> { } // This function will return None if the attribute is not #[bits = *]. -fn try_parse_bits_attr(attr: &Attribute) -> Result> { - if attr.path.is_ident("bits") { - if let Meta::NameValue(name_value) = attr.parse_meta()? { - if let Lit::Int(int) = name_value.lit { - return Ok(Some(int)); - } +fn try_parse_bits_attr(attr: &Attribute) -> Option { + if attr.path().is_ident("bits") { + if let Meta::NameValue(MetaNameValue { + value: + syn::Expr::Lit(syn::ExprLit { + lit: Lit::Int(int), .. + }), + .. + }) = &attr.meta + { + return Some(int).cloned(); } } - Ok(None) + None } fn parse_remove_bits_attr(ast: &mut DeriveInput) -> Result> { @@ -422,7 +428,7 @@ fn parse_remove_bits_attr(ast: &mut DeriveInput) -> Result> { let mut bits_idx = 0; for (i, attr) in ast.attrs.iter().enumerate() { - if let Some(w) = try_parse_bits_attr(attr)? { + if let Some(w) = try_parse_bits_attr(attr) { bits_idx = i; width = Some(w.base10_parse()?); } diff --git a/serde_keyvalue/serde_keyvalue_derive/Cargo.toml b/serde_keyvalue/serde_keyvalue_derive/Cargo.toml index 1ece8456d2..7c0885d309 100644 --- a/serde_keyvalue/serde_keyvalue_derive/Cargo.toml +++ b/serde_keyvalue/serde_keyvalue_derive/Cargo.toml @@ -9,5 +9,5 @@ proc-macro = true [dependencies] argh = "0.1.7" proc-macro2 = "1.0" -syn = "1.0" +syn = "2" quote = "1.0"