From 062622fe2dd4cb0e5c2bcd407640986218084b53 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 18 Mar 2023 08:50:41 -0500 Subject: [PATCH] chore(derive): Update syn --- Cargo.lock | 43 ++++++++++++++++---------- clap_derive/Cargo.toml | 2 +- clap_derive/src/attr.rs | 26 ++++++++-------- clap_derive/src/utils/doc_comments.rs | 24 +++++++------- tests/derive_ui/clap_empty_attr.stderr | 4 +-- 5 files changed, 56 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c98170b6606..f553c398ae7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,7 +244,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.8", ] [[package]] @@ -680,18 +680,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -790,22 +790,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.8", ] [[package]] @@ -881,9 +881,20 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9" dependencies = [ "proc-macro2", "quote", @@ -1030,9 +1041,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-width" @@ -1099,7 +1110,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -1121,7 +1132,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/clap_derive/Cargo.toml b/clap_derive/Cargo.toml index 29b92447e19..68d90771abe 100644 --- a/clap_derive/Cargo.toml +++ b/clap_derive/Cargo.toml @@ -29,7 +29,7 @@ proc-macro = true bench = false [dependencies] -syn = { version = "1.0.74", features = ["full"] } +syn = { version = "2.0.8", features = ["full"] } quote = "1.0.9" proc-macro2 = "1.0.42" heck = "0.4.0" diff --git a/clap_derive/src/attr.rs b/clap_derive/src/attr.rs index 3f8433f7a70..3bc9ac0140d 100644 --- a/clap_derive/src/attr.rs +++ b/clap_derive/src/attr.rs @@ -25,18 +25,18 @@ impl ClapAttr { pub fn parse_all(all_attrs: &[Attribute]) -> Result, syn::Error> { let mut parsed = Vec::new(); for attr in all_attrs { - let kind = if attr.path.is_ident("clap") { - Sp::new(AttrKind::Clap, attr.path.span()) - } else if attr.path.is_ident("structopt") { - Sp::new(AttrKind::StructOpt, attr.path.span()) - } else if attr.path.is_ident("command") { - Sp::new(AttrKind::Command, attr.path.span()) - } else if attr.path.is_ident("group") { - Sp::new(AttrKind::Group, attr.path.span()) - } else if attr.path.is_ident("arg") { - Sp::new(AttrKind::Arg, attr.path.span()) - } else if attr.path.is_ident("value") { - Sp::new(AttrKind::Value, attr.path.span()) + let kind = if attr.path().is_ident("clap") { + Sp::new(AttrKind::Clap, attr.path().span()) + } else if attr.path().is_ident("structopt") { + Sp::new(AttrKind::StructOpt, attr.path().span()) + } else if attr.path().is_ident("command") { + Sp::new(AttrKind::Command, attr.path().span()) + } else if attr.path().is_ident("group") { + Sp::new(AttrKind::Group, attr.path().span()) + } else if attr.path().is_ident("arg") { + Sp::new(AttrKind::Arg, attr.path().span()) + } else if attr.path().is_ident("value") { + Sp::new(AttrKind::Value, attr.path().span()) } else { continue; }; @@ -126,7 +126,7 @@ impl Parse for ClapAttr { let nested; parenthesized!(nested in input); - let method_args: Punctuated<_, Token![,]> = nested.parse_terminated(Expr::parse)?; + let method_args: Punctuated<_, _> = nested.parse_terminated(Expr::parse, Token![,])?; Some(AttrValue::Call(Vec::from_iter(method_args))) } else { None diff --git a/clap_derive/src/utils/doc_comments.rs b/clap_derive/src/utils/doc_comments.rs index 5183b6b25e1..63c6ad1ef32 100644 --- a/clap_derive/src/utils/doc_comments.rs +++ b/clap_derive/src/utils/doc_comments.rs @@ -6,24 +6,26 @@ use std::iter; pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Vec { - use syn::Lit::*; - use syn::Meta::*; - use syn::MetaNameValue; - // multiline comments (`/** ... */`) may have LFs (`\n`) in them, // we need to split so we could handle the lines correctly // // we also need to remove leading and trailing blank lines let mut lines: Vec<_> = attrs .iter() - .filter(|attr| attr.path.is_ident("doc")) + .filter(|attr| attr.path().is_ident("doc")) .filter_map(|attr| { - if let Ok(NameValue(MetaNameValue { lit: Str(s), .. })) = attr.parse_meta() { - Some(s.value()) - } else { - // non #[doc = "..."] attributes are not our concern - // we leave them for rustc to handle - None + // non #[doc = "..."] attributes are not our concern + // we leave them for rustc to handle + match &attr.meta { + syn::Meta::NameValue(syn::MetaNameValue { + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(s), + .. + }), + .. + }) => Some(s.value()), + _ => None, } }) .skip_while(|s| is_blank(s)) diff --git a/tests/derive_ui/clap_empty_attr.stderr b/tests/derive_ui/clap_empty_attr.stderr index 414ffdc0f49..596fbe09db7 100644 --- a/tests/derive_ui/clap_empty_attr.stderr +++ b/tests/derive_ui/clap_empty_attr.stderr @@ -1,8 +1,8 @@ error: expected attribute arguments in parentheses: #[command(...)] - --> tests/derive_ui/clap_empty_attr.rs:4:1 + --> tests/derive_ui/clap_empty_attr.rs:4:3 | 4 | #[command] - | ^^^^^^^^^^ + | ^^^^^^^ error: expected parentheses: #[arg(...)] --> tests/derive_ui/clap_empty_attr.rs:9:11