From 9545be16f5df3ce78df50340a66845e23372ff41 Mon Sep 17 00:00:00 2001 From: Michael Bradshaw Date: Fri, 27 Mar 2026 09:16:47 -0600 Subject: [PATCH] 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. --- tracing-attributes/src/expand.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index ff86a5c7..f9c75b9c 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -347,6 +347,7 @@ fn gen_block( 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(