Skip to content

Commit dbce150

Browse files
authored
update syn to v2 (#481
* update syn to v2 * update changelog
1 parent 54ec06c commit dbce150

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

actix-macros/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased - 2023-xx-xx
44

5+
- Update `syn` dependency to `2`.
56
- Minimum supported Rust version (MSRV) is now 1.60.
67

78
## 0.2.3 - 2021-10-19

actix-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ proc-macro = true
1818

1919
[dependencies]
2020
quote = "1"
21-
syn = { version = "1", features = ["full"] }
21+
syn = { version = "2", features = ["full"] }
2222

2323
[dev-dependencies]
2424
actix-rt = "2"

actix-macros/src/lib.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use proc_macro::TokenStream;
1717
use quote::quote;
18+
use syn::parse::Parser as _;
19+
20+
type AttributeArgs = syn::punctuated::Punctuated<syn::Meta, syn::Token![,]>;
1821

1922
/// Marks async entry-point function to be executed by Actix system.
2023
///
@@ -25,17 +28,21 @@ use quote::quote;
2528
/// println!("Hello world");
2629
/// }
2730
/// ```
28-
#[allow(clippy::needless_doctest_main)]
31+
// #[allow(clippy::needless_doctest_main)]
32+
// #[cfg(not(test))] // Work around for rust-lang/rust#62127
2933
#[proc_macro_attribute]
30-
#[cfg(not(test))] // Work around for rust-lang/rust#62127
3134
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
3235
let mut input = match syn::parse::<syn::ItemFn>(item.clone()) {
3336
Ok(input) => input,
3437
// on parse err, make IDEs happy; see fn docs
3538
Err(err) => return input_and_compile_error(item, err),
3639
};
3740

38-
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
41+
let parser = AttributeArgs::parse_terminated;
42+
let args = match parser.parse(args.clone()) {
43+
Ok(args) => args,
44+
Err(err) => return input_and_compile_error(args, err),
45+
};
3946

4047
let attrs = &input.attrs;
4148
let vis = &input.vis;
@@ -55,11 +62,15 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
5562

5663
for arg in &args {
5764
match arg {
58-
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
59-
lit: syn::Lit::Str(lit),
65+
syn::Meta::NameValue(syn::MetaNameValue {
6066
path,
67+
value:
68+
syn::Expr::Lit(syn::ExprLit {
69+
lit: syn::Lit::Str(lit),
70+
..
71+
}),
6172
..
62-
})) => match path
73+
}) => match path
6374
.get_ident()
6475
.map(|i| i.to_string().to_lowercase())
6576
.as_deref()
@@ -78,6 +89,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
7889
.into();
7990
}
8091
},
92+
8193
_ => {
8294
return syn::Error::new_spanned(arg, "Unknown attribute specified")
8395
.to_compile_error()
@@ -114,7 +126,11 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
114126
Err(err) => return input_and_compile_error(item, err),
115127
};
116128

117-
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
129+
let parser = AttributeArgs::parse_terminated;
130+
let args = match parser.parse(args.clone()) {
131+
Ok(args) => args,
132+
Err(err) => return input_and_compile_error(args, err),
133+
};
118134

119135
let attrs = &input.attrs;
120136
let vis = &input.vis;
@@ -123,7 +139,7 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
123139
let mut has_test_attr = false;
124140

125141
for attr in attrs {
126-
if attr.path.is_ident("test") {
142+
if attr.path().is_ident("test") {
127143
has_test_attr = true;
128144
}
129145
}
@@ -149,11 +165,15 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
149165

150166
for arg in &args {
151167
match arg {
152-
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
153-
lit: syn::Lit::Str(lit),
168+
syn::Meta::NameValue(syn::MetaNameValue {
154169
path,
170+
value:
171+
syn::Expr::Lit(syn::ExprLit {
172+
lit: syn::Lit::Str(lit),
173+
..
174+
}),
155175
..
156-
})) => match path
176+
}) => match path
157177
.get_ident()
158178
.map(|i| i.to_string().to_lowercase())
159179
.as_deref()

actix-macros/tests/trybuild.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#[test]
33
fn compile_macros() {
44
let t = trybuild::TestCases::new();
5+
56
t.pass("tests/trybuild/main-01-basic.rs");
67
t.compile_fail("tests/trybuild/main-02-only-async.rs");
78
t.pass("tests/trybuild/main-03-fn-params.rs");

0 commit comments

Comments
 (0)