From 326a9731e1ce153eb722d2e174a8dfbdb0745e2b Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Fri, 26 Jan 2024 23:14:00 +0100 Subject: [PATCH 1/2] attributes: change order of async and unsafe modifier (#2864) When using `#[tracing::instrument]` and the `async unsafe` modifiers the generated function read `unsafe async fn`, which is wrong. Corrected the order and added a test. Fixes: #2576 Signed-off-by: Gabriel Goller --- tracing-attributes/src/expand.rs | 2 +- tracing-attributes/tests/async_fn.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index b52cb12aba..b4da403324 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -92,7 +92,7 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( quote!( #(#outer_attrs) * - #vis #constness #unsafety #asyncness #abi fn #ident<#gen_params>(#params) #output + #vis #constness #asyncness #unsafety #abi fn #ident<#gen_params>(#params) #output #where_clause { #(#inner_attrs) * diff --git a/tracing-attributes/tests/async_fn.rs b/tracing-attributes/tests/async_fn.rs index 60d772ebd3..31d705c6b0 100644 --- a/tracing-attributes/tests/async_fn.rs +++ b/tracing-attributes/tests/async_fn.rs @@ -32,6 +32,9 @@ async fn test_ret_impl_trait_err(n: i32) -> Result, &' #[instrument] async fn test_async_fn_empty() {} +#[instrument] +async unsafe fn test_async_unsafe_fn_empty() {} + // Reproduces a compile error when an instrumented function body contains inner // attributes (https://github.com/tokio-rs/tracing/issues/2294). #[deny(unused_variables)] From 4b634c492db5128e3250ccdd848d539311f488b3 Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Tue, 12 Mar 2024 02:29:33 +0100 Subject: [PATCH 2/2] attributes: extract match scrutinee (#2880) On clippy version 1.76.0 this gives a warning, extracting the scrutinee to a variable fixes this. Fixes: #2876 --- tracing-attributes/src/expand.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index b4da403324..37034e3ede 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -277,7 +277,8 @@ 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 { + let __match_scrutinee = async move #block.await; + match __match_scrutinee { #[allow(clippy::unit_arg)] Ok(x) => { #ret_event;