mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 22:51:07 +01:00
parent
54ec06cd23
commit
dbce150993
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased - 2023-xx-xx
|
## Unreleased - 2023-xx-xx
|
||||||
|
|
||||||
|
- Update `syn` dependency to `2`.
|
||||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||||
|
|
||||||
## 0.2.3 - 2021-10-19
|
## 0.2.3 - 2021-10-19
|
||||||
|
@ -18,7 +18,7 @@ proc-macro = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "1"
|
quote = "1"
|
||||||
syn = { version = "1", features = ["full"] }
|
syn = { version = "2", features = ["full"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
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.
|
/// Marks async entry-point function to be executed by Actix system.
|
||||||
///
|
///
|
||||||
@ -25,9 +28,9 @@ use quote::quote;
|
|||||||
/// println!("Hello world");
|
/// 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]
|
#[proc_macro_attribute]
|
||||||
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
|
||||||
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let mut input = match syn::parse::<syn::ItemFn>(item.clone()) {
|
let mut input = match syn::parse::<syn::ItemFn>(item.clone()) {
|
||||||
Ok(input) => input,
|
Ok(input) => input,
|
||||||
@ -35,7 +38,11 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
Err(err) => return input_and_compile_error(item, err),
|
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 attrs = &input.attrs;
|
||||||
let vis = &input.vis;
|
let vis = &input.vis;
|
||||||
@ -55,11 +62,15 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
for arg in &args {
|
for arg in &args {
|
||||||
match arg {
|
match arg {
|
||||||
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
|
syn::Meta::NameValue(syn::MetaNameValue {
|
||||||
lit: syn::Lit::Str(lit),
|
|
||||||
path,
|
path,
|
||||||
|
value:
|
||||||
|
syn::Expr::Lit(syn::ExprLit {
|
||||||
|
lit: syn::Lit::Str(lit),
|
||||||
|
..
|
||||||
|
}),
|
||||||
..
|
..
|
||||||
})) => match path
|
}) => match path
|
||||||
.get_ident()
|
.get_ident()
|
||||||
.map(|i| i.to_string().to_lowercase())
|
.map(|i| i.to_string().to_lowercase())
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@ -78,6 +89,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return syn::Error::new_spanned(arg, "Unknown attribute specified")
|
return syn::Error::new_spanned(arg, "Unknown attribute specified")
|
||||||
.to_compile_error()
|
.to_compile_error()
|
||||||
@ -114,7 +126,11 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
Err(err) => return input_and_compile_error(item, err),
|
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 attrs = &input.attrs;
|
||||||
let vis = &input.vis;
|
let vis = &input.vis;
|
||||||
@ -123,7 +139,7 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
let mut has_test_attr = false;
|
let mut has_test_attr = false;
|
||||||
|
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
if attr.path.is_ident("test") {
|
if attr.path().is_ident("test") {
|
||||||
has_test_attr = true;
|
has_test_attr = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,11 +165,15 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
for arg in &args {
|
for arg in &args {
|
||||||
match arg {
|
match arg {
|
||||||
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
|
syn::Meta::NameValue(syn::MetaNameValue {
|
||||||
lit: syn::Lit::Str(lit),
|
|
||||||
path,
|
path,
|
||||||
|
value:
|
||||||
|
syn::Expr::Lit(syn::ExprLit {
|
||||||
|
lit: syn::Lit::Str(lit),
|
||||||
|
..
|
||||||
|
}),
|
||||||
..
|
..
|
||||||
})) => match path
|
}) => match path
|
||||||
.get_ident()
|
.get_ident()
|
||||||
.map(|i| i.to_string().to_lowercase())
|
.map(|i| i.to_string().to_lowercase())
|
||||||
.as_deref()
|
.as_deref()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#[test]
|
#[test]
|
||||||
fn compile_macros() {
|
fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
|
|
||||||
t.pass("tests/trybuild/main-01-basic.rs");
|
t.pass("tests/trybuild/main-01-basic.rs");
|
||||||
t.compile_fail("tests/trybuild/main-02-only-async.rs");
|
t.compile_fail("tests/trybuild/main-02-only-async.rs");
|
||||||
t.pass("tests/trybuild/main-03-fn-params.rs");
|
t.pass("tests/trybuild/main-03-fn-params.rs");
|
||||||
|
Loading…
Reference in New Issue
Block a user