Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update syn to v2 (#481 #481

Merged
merged 4 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions actix-macros/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actix-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 31 additions & 11 deletions actix-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -25,17 +28,21 @@ 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,
// on parse err, make IDEs happy; see fn docs
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;
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions actix-macros/tests/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down