Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn gen_block<B: ToTokens>(
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;
Expand All @@ -232,7 +232,7 @@ fn gen_block<B: ToTokens>(
),
(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) => {
Expand All @@ -244,13 +244,13 @@ fn gen_block<B: ToTokens>(
),
(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
),
};

Expand Down
17 changes: 17 additions & 0 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use tracing_mock::*;

use std::convert::Infallible;
use std::{future::Future, pin::Pin, sync::Arc};
use tracing::collect::with_default;
use tracing_attributes::instrument;
Expand Down Expand Up @@ -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<dyn Future<Output = ()>>> {
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<Output = Result<(), Infallible>> {
async { Ok(()) }
}
Comment on lines +55 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding tests for this! <3


#[test]
fn async_fn_only_enters_for_polls() {
let (collector, handle) = collector::mock()
Expand Down