diff --git a/actix-macros/CHANGES.md b/actix-macros/CHANGES.md index 20efed15..1badd6b7 100644 --- a/actix-macros/CHANGES.md +++ b/actix-macros/CHANGES.md @@ -2,6 +2,7 @@ ## Unreleased - 2023-xx-xx +- Update `syn` dependency to `2`. - Minimum supported Rust version (MSRV) is now 1.60. ## 0.2.3 - 2021-10-19 diff --git a/actix-macros/Cargo.toml b/actix-macros/Cargo.toml index 023fa1a8..902a6dd1 100644 --- a/actix-macros/Cargo.toml +++ b/actix-macros/Cargo.toml @@ -18,7 +18,7 @@ proc-macro = true [dependencies] quote = "1" -syn = { version = "1", features = ["full"] } +syn = { version = "2", features = ["full"] } [dev-dependencies] actix-rt = "2" diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index 284f6920..020b16db 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -15,6 +15,9 @@ use proc_macro::TokenStream; use quote::quote; +use syn::parse::Parser as _; + +type AttributeArgs = syn::punctuated::Punctuated; /// Marks async entry-point function to be executed by Actix system. /// @@ -25,9 +28,9 @@ use quote::quote; /// println!("Hello world"); /// } /// ``` -#[allow(clippy::needless_doctest_main)] +// #[allow(clippy::needless_doctest_main)] +// #[cfg(not(test))] // Work around for rust-lang/rust#62127 #[proc_macro_attribute] -#[cfg(not(test))] // Work around for rust-lang/rust#62127 pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { let mut input = match syn::parse::(item.clone()) { Ok(input) => input, @@ -35,7 +38,11 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { Err(err) => return input_and_compile_error(item, err), }; - let args = syn::parse_macro_input!(args as syn::AttributeArgs); + let parser = AttributeArgs::parse_terminated; + let args = match parser.parse(args.clone()) { + Ok(args) => args, + Err(err) => return input_and_compile_error(args, err), + }; let attrs = &input.attrs; let vis = &input.vis; @@ -55,11 +62,15 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { for arg in &args { match arg { - syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue { - lit: syn::Lit::Str(lit), + syn::Meta::NameValue(syn::MetaNameValue { path, + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(lit), + .. + }), .. - })) => match path + }) => match path .get_ident() .map(|i| i.to_string().to_lowercase()) .as_deref() @@ -78,6 +89,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { .into(); } }, + _ => { return syn::Error::new_spanned(arg, "Unknown attribute specified") .to_compile_error() @@ -114,7 +126,11 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { Err(err) => return input_and_compile_error(item, err), }; - let args = syn::parse_macro_input!(args as syn::AttributeArgs); + let parser = AttributeArgs::parse_terminated; + let args = match parser.parse(args.clone()) { + Ok(args) => args, + Err(err) => return input_and_compile_error(args, err), + }; let attrs = &input.attrs; let vis = &input.vis; @@ -123,7 +139,7 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { let mut has_test_attr = false; for attr in attrs { - if attr.path.is_ident("test") { + if attr.path().is_ident("test") { has_test_attr = true; } } @@ -149,11 +165,15 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { for arg in &args { match arg { - syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue { - lit: syn::Lit::Str(lit), + syn::Meta::NameValue(syn::MetaNameValue { path, + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(lit), + .. + }), .. - })) => match path + }) => match path .get_ident() .map(|i| i.to_string().to_lowercase()) .as_deref() diff --git a/actix-macros/tests/trybuild.rs b/actix-macros/tests/trybuild.rs index 51d152a4..7e399d49 100644 --- a/actix-macros/tests/trybuild.rs +++ b/actix-macros/tests/trybuild.rs @@ -2,6 +2,7 @@ #[test] fn compile_macros() { let t = trybuild::TestCases::new(); + t.pass("tests/trybuild/main-01-basic.rs"); t.compile_fail("tests/trybuild/main-02-only-async.rs"); t.pass("tests/trybuild/main-03-fn-params.rs");