Skip to content

Commit

Permalink
bind params
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakuyume committed Jan 9, 2024
1 parent 2d47a74 commit fc810e2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,22 @@ fn gen_block<B: ToTokens>(
__tracing_attr_guard = __tracing_attr_span.enter();
}
);
let bindings = params.clone().into_iter().flat_map(|param| {
if let FnArg::Typed(PatType { pat, .. }) = param {
Some(quote!(let #pat = #pat;))
} else {
None
}
});

match (err_event, ret_event) {
(Some(err_event), Some(ret_event)) => quote_spanned! {block.span()=>
#span
#[allow(clippy::redundant_closure_call)]
match (move || #block)() {
match (move || {
#(#bindings)*
#block
})() {
#[allow(clippy::unit_arg)]
Ok(x) => {
#ret_event;
Expand All @@ -369,7 +379,10 @@ fn gen_block<B: ToTokens>(
(Some(err_event), None) => quote_spanned!(block.span()=>
#span
#[allow(clippy::redundant_closure_call)]
match (move || #block)() {
match (move || {
#(#bindings)*
#block
})() {
#[allow(clippy::unit_arg)]
Ok(x) => Ok(x),
Err(e) => {
Expand All @@ -381,7 +394,10 @@ fn gen_block<B: ToTokens>(
(None, Some(ret_event)) => quote_spanned!(block.span()=>
#span
#[allow(clippy::redundant_closure_call)]
let x = (move || #block)();
let x = (move || {
#(#bindings)*
#block
})();
#ret_event;
x
),
Expand Down

0 comments on commit fc810e2

Please sign in to comment.