Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
ibraheemdev and taiki-e committed May 7, 2021
1 parent 5180351 commit e40b5f9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions futures-macro/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
use proc_macro::TokenStream;
use quote::quote;

pub(crate) fn test(_: TokenStream, item: TokenStream) -> TokenStream {
pub(crate) fn test(args: TokenStream, item: TokenStream) -> TokenStream {
if !args.is_empty() {
return syn::Error::new_spanned(args, "invalid argument"))
.to_compile_error()
.into();
}
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;

if sig.asyncness.is_none() {
if sig.asyncness.take().is_none() {
return syn::Error::new_spanned(sig.fn_token, "Only async functions are supported")
.to_compile_error()
.into();
}

sig.asyncness = None;

let gen = quote! {
#[::core::prelude::v1::test]
#(#attrs)*
#vis #sig {
::futures_test::__private::block_on(async move { #body })
::futures_test::__private::block_on(async move #body)
}
};

Expand Down

0 comments on commit e40b5f9

Please sign in to comment.