From e35c261c9fe609bbb779ad5ca4298b101575ac77 Mon Sep 17 00:00:00 2001 From: Daniel Pintara Date: Wed, 22 Apr 2020 00:11:48 +0700 Subject: [PATCH] actix-macros: test: Simplify by using #sig instead of #name(#inputs) #ret --- actix-macros/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index ffd814752b..04c374a59f 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -55,13 +55,11 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { /// ``` #[proc_macro_attribute] pub fn test(_: TokenStream, item: TokenStream) -> TokenStream { - let input = syn::parse_macro_input!(item as syn::ItemFn); - - let ret = &input.sig.output; - let inputs = &input.sig.inputs; - let name = &input.sig.ident; - let body = &input.block; + let mut input = syn::parse_macro_input!(item as syn::ItemFn); let attrs = &input.attrs; + let vis = &input.vis; + let sig = &mut input.sig; + let body = &input.block; let mut has_test_attr = false; for attr in attrs { @@ -70,7 +68,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream { } } - if input.sig.asyncness.is_none() { + if sig.asyncness.is_none() { return syn::Error::new_spanned( input.sig.fn_token, format!("only async fn is supported, {}", input.sig.ident), @@ -79,10 +77,12 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream { .into(); } + sig.asyncness = None; + let result = if has_test_attr { quote! { #(#attrs)* - fn #name(#inputs) #ret { + #vis #sig { actix_rt::System::new("test") .block_on(async { #body }) } @@ -91,7 +91,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream { quote! { #[test] #(#attrs)* - fn #name(#inputs) #ret { + #vis #sig { actix_rt::System::new("test") .block_on(async { #body }) }