From 7d41eadaa9a1b0dab5a01c9f0cbc39764e74b5bd Mon Sep 17 00:00:00 2001 From: Gnome! Date: Sat, 18 Nov 2023 03:18:51 +0000 Subject: [PATCH] Upgrade to darling 0.20 and syn v2 (#222) --- Cargo.lock | 18 +++++++++--------- macros/Cargo.lock | 26 +++++++++++++------------- macros/Cargo.toml | 4 ++-- macros/src/choice_parameter.rs | 6 +++--- macros/src/command/mod.rs | 20 +++++++++++--------- macros/src/lib.rs | 6 +++++- macros/src/modal.rs | 16 ++++++++-------- macros/src/util.rs | 4 ++-- 8 files changed, 53 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0901582f1f6..85b42e3b6721 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,9 +204,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ "darling_core", "darling_macro", @@ -214,27 +214,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 1.0.109", + "syn 2.0.32", ] [[package]] name = "darling_macro" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 1.0.109", + "syn 2.0.32", ] [[package]] @@ -906,7 +906,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.32", ] [[package]] diff --git a/macros/Cargo.lock b/macros/Cargo.lock index 7a86c229e860..de9713ee6919 100644 --- a/macros/Cargo.lock +++ b/macros/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "darling" -version = "0.14.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ "darling_core", "darling_macro", @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ "fnv", "ident_case", @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", @@ -51,7 +51,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "poise_macros" -version = "0.2.1" +version = "0.5.7" dependencies = [ "darling", "proc-macro2", @@ -61,18 +61,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -85,9 +85,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.96" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 6feb4cccc649..50014ef490ba 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/serenity-rs/poise/" proc-macro = true [dependencies] -syn = { version = "1.0.64", features = ["full", "fold"] } +syn = { version = "2", features = ["fold"] } quote = "1.0.9" proc-macro2 = "1.0.24" -darling = "0.14.1" +darling = "0.20" diff --git a/macros/src/choice_parameter.rs b/macros/src/choice_parameter.rs index 43cafda5ad1e..6b3ff2ba41b1 100644 --- a/macros/src/choice_parameter.rs +++ b/macros/src/choice_parameter.rs @@ -41,11 +41,11 @@ pub fn choice_parameter(input: syn::DeriveInput) -> Result = variant .attrs .into_iter() - .map(|attr| attr.parse_meta().map(syn::NestedMeta::Meta)) - .collect::, _>>()?; + .map(|attr| darling::ast::NestedMeta::Meta(attr.meta)) + .collect(); let mut attrs = ::from_list(&attrs)?; let main_name = if attrs.name.is_empty() { diff --git a/macros/src/command/mod.rs b/macros/src/command/mod.rs index b54caf9430ff..0d60280fae21 100644 --- a/macros/src/command/mod.rs +++ b/macros/src/command/mod.rs @@ -100,11 +100,13 @@ pub struct Invocation { fn extract_help_from_doc_comments(attrs: &[syn::Attribute]) -> (Option, Option) { let mut doc_lines = String::new(); for attr in attrs { - if attr.path == quote::format_ident!("doc").into() { - for token in attr.tokens.clone() { - if let Ok(literal) = syn::parse2::(token.into()) { - doc_lines += literal.value().trim(); // Trim lines like rustdoc does - doc_lines += "\n"; + if let syn::Meta::NameValue(doc_attr) = &attr.meta { + if doc_attr.path == quote::format_ident!("doc").into() { + if let syn::Expr::Lit(lit_expr) = &doc_attr.value { + if let syn::Lit::Str(literal) = &lit_expr.lit { + doc_lines += literal.value().trim(); // Trim lines like rustdoc does + doc_lines += "\n"; + } } } } @@ -170,11 +172,11 @@ pub fn command( } }; - let attrs = pattern + let attrs: Vec<_> = pattern .attrs .drain(..) - .map(|attr| attr.parse_meta().map(syn::NestedMeta::Meta)) - .collect::, _>>()?; + .map(|attr| darling::ast::NestedMeta::Meta(attr.meta)) + .collect(); let attrs = ::from_list(&attrs)?; let name = if let Some(rename) = &attrs.rename { @@ -332,7 +334,7 @@ fn generate_command(mut inv: Invocation) -> Result ::poise::Command< + #function_visibility fn #function_ident #function_generics() -> ::poise::Command< <#ctx_type_with_static as poise::_GetGenerics>::U, <#ctx_type_with_static as poise::_GetGenerics>::E, > { diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 01e1595fddec..1411b25b3e47 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -185,7 +185,11 @@ exact desugaring */ #[proc_macro_attribute] pub fn command(args: TokenStream, function: TokenStream) -> TokenStream { - let args = syn::parse_macro_input!(args as Vec); + let args = match darling::ast::NestedMeta::parse_meta_list(args.into()) { + Ok(x) => x, + Err(e) => return e.into_compile_error().into(), + }; + let args = match ::from_list(&args) { Ok(x) => x, Err(e) => return e.write_errors().into(), diff --git a/macros/src/modal.rs b/macros/src/modal.rs index c07118e1d91c..866196792462 100644 --- a/macros/src/modal.rs +++ b/macros/src/modal.rs @@ -35,22 +35,22 @@ pub fn modal(input: syn::DeriveInput) -> Result { } }; - let struct_attrs = input + let struct_attrs: Vec<_> = input .attrs - .iter() - .map(|attr| attr.parse_meta().map(syn::NestedMeta::Meta)) - .collect::, _>>()?; + .into_iter() + .map(|attr| darling::ast::NestedMeta::Meta(attr.meta)) + .collect(); let struct_attrs = ::from_list(&struct_attrs)?; let mut builders = Vec::new(); let mut parsers = Vec::new(); for field in fields { // Extract data from syn::Field - let field_attrs = field + let field_attrs: Vec<_> = field .attrs - .iter() - .map(|attr| attr.parse_meta().map(syn::NestedMeta::Meta)) - .collect::, _>>()?; + .into_iter() + .map(|attr| darling::ast::NestedMeta::Meta(attr.meta)) + .collect(); let field_attrs = ::from_list(&field_attrs)?; let field_ident = field.ident.unwrap(); diff --git a/macros/src/util.rs b/macros/src/util.rs index ae2bb8eb8eaf..f7a1b0bd212a 100644 --- a/macros/src/util.rs +++ b/macros/src/util.rs @@ -39,7 +39,7 @@ impl syn::fold::Fold for AllLifetimesToStatic { #[derive(Debug)] pub struct List(pub Vec); impl darling::FromMeta for List { - fn from_list(items: &[::syn::NestedMeta]) -> darling::Result { + fn from_list(items: &[::darling::ast::NestedMeta]) -> darling::Result { items .iter() .map(|item| T::from_nested_meta(item)) @@ -57,7 +57,7 @@ impl Default for List { #[derive(Debug)] pub struct Tuple2(pub T, pub T); impl darling::FromMeta for Tuple2 { - fn from_list(items: &[::syn::NestedMeta]) -> darling::Result { + fn from_list(items: &[::darling::ast::NestedMeta]) -> darling::Result { Ok(match items { [a, b] => Self(T::from_nested_meta(a)?, T::from_nested_meta(b)?), _ => {