mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00
attributes: generate less dead code for async block return type hint (#2709)
## Motivation `#[tracing::instrument]` uses `unreachable!()` macro which needlessly expands to panicking and formatting code. It only needs any `!` type. ## Solution `loop {}` works just as well for a `!` type, and it crates less work for the compiler. The code is truly unreachable, so the message would never be useful. Rust used to be concerned about semantics of empty loops in LLVM, but this [has been solved](https://reviews.llvm.org/D85393).
This commit is contained in:
parent
e6c57d8e81
commit
df6793f7b7
@ -66,11 +66,11 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>(
|
|||||||
let fake_return_edge = quote_spanned! {return_span=>
|
let fake_return_edge = quote_spanned! {return_span=>
|
||||||
#[allow(
|
#[allow(
|
||||||
unknown_lints, unreachable_code, clippy::diverging_sub_expression,
|
unknown_lints, unreachable_code, clippy::diverging_sub_expression,
|
||||||
clippy::let_unit_value, clippy::unreachable, clippy::let_with_type_underscore
|
clippy::let_unit_value, clippy::unreachable, clippy::let_with_type_underscore,
|
||||||
|
clippy::empty_loop
|
||||||
)]
|
)]
|
||||||
if false {
|
if false {
|
||||||
let __tracing_attr_fake_return: #return_type =
|
let __tracing_attr_fake_return: #return_type = loop {};
|
||||||
unreachable!("this is just for type inference, and is unreachable code");
|
|
||||||
return __tracing_attr_fake_return;
|
return __tracing_attr_fake_return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user