Skip to content

Silence clippy lints for #[instrument] on async functions for crates that warn on implicit_return#3485

Open
mjbshaw wants to merge 2 commits intotokio-rs:mainfrom
mjbshaw:patch-1
Open

Silence clippy lints for #[instrument] on async functions for crates that warn on implicit_return#3485
mjbshaw wants to merge 2 commits intotokio-rs:mainfrom
mjbshaw:patch-1

Conversation

@mjbshaw
Copy link

@mjbshaw mjbshaw commented Mar 6, 2026

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 rust-lang/rust-clippy#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:

#[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.

…hat warn on implicit_return

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.
@mjbshaw mjbshaw requested review from a team, hawkw and hds as code owners March 6, 2026 19:39
@mjbshaw mjbshaw changed the title Silent clippy lints for #[instrument] on async functions for crates that warn on implicit_return Silence clippy lints for #[instrument] on async functions for crates that warn on implicit_return Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant