Skip to content

Commit

Permalink
Apply the static level optimization to async fns and error printing
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 30, 2021
1 parent 27bd20e commit b1b0de2
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ fn gen_block(
if err {
quote_spanned!(block.span()=>
let __tracing_attr_span = #span;
tracing::Instrument::instrument(async move {
// See comment on the default case at the end of this function
// for why we do this a bit roundabout.
let fut = async move {
match async move { #block }.await {
#[allow(clippy::unit_arg)]
Ok(x) => Ok(x),
Expand All @@ -525,22 +527,46 @@ fn gen_block(
Err(e)
}
}
}, __tracing_attr_span).await
};
if tracing::level_enabled!(#level) {
tracing::Instrument::instrument(
fut,
__tracing_attr_span
)
.await
} else {
fut.await
}
)
} else {
quote_spanned!(block.span()=>
let __tracing_attr_span = #span;
// See comment on the default case at the end of this function
// for why we do this a bit roundabout.
let fut = async move { #block };
if tracing::level_enabled!(#level) {
tracing::Instrument::instrument(
async move { #block },
fut,
__tracing_attr_span
)
.await
} else {
fut.await
}
)
}
} else if err {
quote_spanned!(block.span()=>
let __tracing_attr_span = #span;
let __tracing_attr_guard = __tracing_attr_span.enter();
// See comment on the default case at the end of this function
// for why we do this a bit roundabout.
let __tracing_attr_span;
let __tracing_attr_guard;
if tracing::level_enabled!(#level) {
__tracing_attr_span = #span;
__tracing_attr_guard = __tracing_attr_span.enter();
}
// pacify clippy::suspicious_else_formatting
let _ = ();
#[allow(clippy::redundant_closure_call)]
match (move || #block)() {
#[allow(clippy::unit_arg)]
Expand Down

0 comments on commit b1b0de2

Please sign in to comment.