Repository: actix/actix-net (language: rust)

Issue:
Syn 2 upgrade
[Syn 2.x](https://github.com/dtolnay/syn/releases/tag/2.0.0) is now out, and [crates are starting](https://github.com/dtolnay/thiserror/pull/227) [to migrate over](https://github.com/palfrey/serial_test/issues/95). It's a non-trivial piece here though as various bits of the API relied on in actix-macros have been changed.


Discussion / hints:

Fix patch:
diff --git a/actix-macros/CHANGES.md b/actix-macros/CHANGES.md
index 20efed151c..1badd6b726 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 023fa1a864..902a6dd1e7 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 284f69200f..020b16dbcf 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<syn::Meta, syn::Token![,]>;
 
 /// 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::<syn::ItemFn>(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()


Test patch:
diff --git a/actix-macros/tests/trybuild.rs b/actix-macros/tests/trybuild.rs
index 51d152a431..7e399d495c 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");