mirror of
https://github.com/tokio-rs/tracing.git
synced 2026-04-11 11:44:28 +00:00
attributes: silence clippy lints for #[instrument] on async functions for crates that warn on implicit_return (#3485)
The macro expands to a trialing if statement that is used as an implicit return value for the function. That works, but for users who set `implicit_return = "deny"` then this results in triggering clippy. ## Motivation See https://github.com/rust-lang/rust-clippy/issues/16676 Minimum reproducible example: **Cargo.toml:** ``` [package] name = "clippy-implicit-return-instrument-repro" edition = "2024" [dependencies] tracing = { version = "0.1.44", features = ["attributes"] } [lints.clippy] implicit_return = "deny" ``` **src/lib.rs:** ```rust #[tracing::instrument] pub async fn run() { } ``` If you then run `cargo clippy` you get this result: ``` error: missing `return` statement --> src/lib.rs:1:1 | 1 | #[tracing::instrument] | ^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#implicit_return = note: requested on the command line with `-D clippy::implicit-return` = note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ## Solution `#[allow(clippy::implicit_return)]` on the trailing return so it doesn't trigger clippy.
This commit is contained in:
@@ -347,6 +347,7 @@ fn gen_block<B: ToTokens>(
|
||||
return quote!(
|
||||
let __tracing_attr_span = #span;
|
||||
let __tracing_instrument_future = #mk_fut;
|
||||
#[allow(clippy::implicit_return)]
|
||||
if !__tracing_attr_span.is_disabled() {
|
||||
#follows_from
|
||||
::tracing::Instrument::instrument(
|
||||
|
||||
Reference in New Issue
Block a user