diff --git a/tracing-attributes/src/lib.rs b/tracing-attributes/src/lib.rs index ca74ea8b05..27936c7d5f 100644 --- a/tracing-attributes/src/lib.rs +++ b/tracing-attributes/src/lib.rs @@ -631,6 +631,7 @@ fn gen_body( let __tracing_attr_span = #span; tracing::Instrument::instrument(async move { match async move { #block }.await { + #[allow(clippy::unit_arg)] Ok(x) => Ok(x), Err(e) => { tracing::error!(error = %e); @@ -653,7 +654,8 @@ fn gen_body( quote_spanned!(block.span()=> let __tracing_attr_span = #span; let __tracing_attr_guard = __tracing_attr_span.enter(); - match { #block } { + match move || #return_type #block () { + #[allow(clippy::unit_arg)] Ok(x) => Ok(x), Err(e) => { tracing::error!(error = %e); diff --git a/tracing-attributes/tests/err.rs b/tracing-attributes/tests/err.rs index eb8b00218d..6c3e85dca3 100644 --- a/tracing-attributes/tests/err.rs +++ b/tracing-attributes/tests/err.rs @@ -62,3 +62,57 @@ fn test_async() { }); handle.assert_finished(); } + +#[instrument(err)] +fn err_mut(out: &mut u8) -> Result<(), TryFromIntError> { + *out = u8::try_from(1234)?; + Ok(()) +} + +#[test] +fn test_mut() { + let span = span::mock().named("err_mut"); + let (subscriber, handle) = subscriber::mock() + .new_span(span.clone()) + .enter(span.clone()) + .event(event::mock().at_level(Level::ERROR)) + .exit(span.clone()) + .drop_span(span) + .done() + .run_with_handle(); + with_default(subscriber, || err_mut(&mut 0).ok()); + handle.assert_finished(); +} + +#[instrument(err)] +async fn err_mut_async(polls: usize, out: &mut u8) -> Result<(), TryFromIntError> { + let future = PollN::new_ok(polls); + tracing::trace!(awaiting = true); + future.await.ok(); + *out = u8::try_from(1234)?; + Ok(()) +} + +#[test] +fn test_mut_async() { + let span = span::mock().named("err_mut_async"); + let (subscriber, handle) = subscriber::mock() + .new_span(span.clone()) + .enter(span.clone()) + .event( + event::mock() + .with_fields(field::mock("awaiting").with_value(&true)) + .at_level(Level::TRACE), + ) + .exit(span.clone()) + .enter(span.clone()) + .event(event::mock().at_level(Level::ERROR)) + .exit(span.clone()) + .drop_span(span) + .done() + .run_with_handle(); + with_default(subscriber, || { + block_on_future(async { err_mut_async(2, &mut 0).await }).ok(); + }); + handle.assert_finished(); +}