Skip to content

Commit

Permalink
attributes: change order of async and unsafe modifier (#2864)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kaffarell authored and davidbarsky committed Oct 2, 2024
1 parent fafc5c9 commit 4779211
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) *
Expand Down
3 changes: 3 additions & 0 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ async fn test_ret_impl_trait_err(n: i32) -> Result<impl Iterator<Item = i32>, &'
#[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)]
Expand Down

0 comments on commit 4779211

Please sign in to comment.