Repository: tokio-rs/tokio
File: tokio-macros/src/entry.rs (Rust)

Code before:
                .expect("Failed building the Runtime")
                .block_on(body);
        }
    };

    // For test functions wrap the body in a `Box` to reduce the amount
    // `Runtime::block_on` (and related functions) copies we generate during
    // compilation due to the generic parameter `F` (the future to block on).
    // This could have an impact on performance, but because it's only for
    // testing and the runtime already boxes the future to run it, it's unlikely
    // to be very large.
    //
    // We don't do this for the main function as it should only be used once so
    // there will be no benefit.
    let body = if is_test {
        let output_type = match &input.sig.output {
            // For functions with no return value syn doesn't print anything,
            // but that doesn't work as `Output` for our boxed `Future`, so
            // default to `()` (the same type as the function output).
            syn::ReturnType::Default => quote! { () },
            syn::ReturnType::Type(_, ret_type) => quote! { #ret_type },
        };
        quote! {
            let body = async #body;
            ::tokio::pin!(body);
            let body: ::std::pin::Pin<&mut dyn ::std::future::Future<Output = #output_type>> = body;
        }
    } else {
        quote! {
            let body = async #body;
        }
    };

    input.block = syn::parse2(quote! {
        {
            #body
            #block_expr
        }
    })
    .expect("Parsing failure");
    input.block.brace_token = brace_token;

    let result = quote! {
        #header
        #input
    };

    result.into()
}

fn token_stream_with_error(mut tokens: TokenStream, error: syn::Error) -> TokenStream {

Review comment (bug):
~~This is a breaking change because impl trait is not supported in binding.~~

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ad52f717075b72e126f85dd06b7d0fe2

Code after:
                .expect("Failed building the Runtime")
                .block_on(body);
        }
    };

    // For test functions pin the body to the stack and use `Pin<&mut dyn
    // Future>` to reduce the amount of `Runtime::block_on` (and related
    // functions) copies we generate during compilation due to the generic
    // parameter `F` (the future to block on). This could have an impact on
    // performance, but because it's only for testing it's unlikely to be very
    // large.
    //
    // We don't do this for the main function as it should only be used once so
    // there will be no benefit.
    let body = if is_test {
        let output_type = match &input.sig.output {
            // For functions with no return value syn doesn't print anything,
            // but that doesn't work as `Output` for our boxed `Future`, so
            // default to `()` (the same type as the function output).
            syn::ReturnType::Default => quote! { () },
            syn::ReturnType::Type(_, ret_type) => quote! { #ret_type },
        };
        quote! {
            let body = async #body;
            #crate_ident::pin!(body);
            let body: ::std::pin::Pin<&mut dyn ::std::future::Future<Output = #output_type>> = body;
        }
    } else {
        quote! {
            let body = async #body;
        }
    };

    input.block = syn::parse2(quote! {
        {
            #body
            #block_expr
        }
    })
    .expect("Parsing failure");
    input.block.brace_token = brace_token;

    let result = quote! {
        #header
        #input
    };

    result.into()
}

fn token_stream_with_error(mut tokens: TokenStream, error: syn::Error) -> TokenStream {