diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index 3928441e1f..458b75f46c 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -217,7 +217,7 @@ fn gen_block( let mk_fut = match (err_event, ret_event) { (Some(err_event), Some(ret_event)) => quote_spanned!(block.span()=> async move { - match async move { #block }.await { + match async move #block.await { #[allow(clippy::unit_arg)] Ok(x) => { #ret_event; @@ -232,7 +232,7 @@ fn gen_block( ), (Some(err_event), None) => quote_spanned!(block.span()=> async move { - match async move { #block }.await { + match async move #block.await { #[allow(clippy::unit_arg)] Ok(x) => Ok(x), Err(e) => { @@ -244,13 +244,13 @@ fn gen_block( ), (None, Some(ret_event)) => quote_spanned!(block.span()=> async move { - let x = async move { #block }.await; + let x = async move #block.await; #ret_event; x } ), (None, None) => quote_spanned!(block.span()=> - async move { #block } + async move #block ), }; diff --git a/tracing-attributes/tests/async_fn.rs b/tracing-attributes/tests/async_fn.rs index 0468c874c9..7e27fb5ce2 100644 --- a/tracing-attributes/tests/async_fn.rs +++ b/tracing-attributes/tests/async_fn.rs @@ -1,5 +1,6 @@ use tracing_mock::*; +use std::convert::Infallible; use std::{future::Future, pin::Pin, sync::Arc}; use tracing::subscriber::with_default; use tracing_attributes::instrument; @@ -51,6 +52,22 @@ async fn repro_1613_2() { // else } +// Reproduces https://github.com/tokio-rs/tracing/issues/1831 +#[instrument] +#[deny(unused_braces)] +fn repro_1831() -> Pin>> { + Box::pin(async move {}) +} + +// This replicates the pattern used to implement async trait methods on nightly using the +// `type_alias_impl_trait` feature +#[instrument(ret, err)] +#[deny(unused_braces)] +#[allow(clippy::manual_async_fn)] +fn repro_1831_2() -> impl Future> { + async { Ok(()) } +} + #[test] fn async_fn_only_enters_for_polls() { let (subscriber, handle) = subscriber::mock()