tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.4k stars 709 forks source link

`#[instrument(err)]` triggers `clippy::blocks_in_conditions` when used inside of `#[async_trait]` on nightly #2912

Open Veetaha opened 6 months ago

Veetaha commented 6 months ago

Reproduction

Here is sample well-formed code that shouldn't trigger clippy lints:

#[async_trait::async_trait]
pub trait Foo {
    #[tracing::instrument(err)]
    async fn bar() -> Result<(), &'static str> {
        Ok(())
    }
}

When you give it to clippy you'll see a warning:

$ cargo +nightly clippy                              
    Checking sandbox v0.1.0 (/home/veetaha/sandbox/rust/crates/sandbox)
warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
 --> crates/sandbox/src/lib.rs:4:48
  |
4 |       async fn bar() -> Result<(), &'static str> {
  |  ________________________________________________^
5 | |         Ok(())
6 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
  = note: `#[warn(clippy::blocks_in_conditions)]` on by default

warning: `sandbox` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s

Version

cargo 1.78.0-nightly (a4c63fe53 2024-03-06)
cargo tree | rg 'tracing|async-trait'
├── async-trait v0.1.77 (proc-macro)
├── tracing v0.1.40
│   ├── tracing-attributes v0.1.27 (proc-macro)
│   └── tracing-core v0.1.32
└── tracing-core v0.1.32 (*)

Platform

uname -a                             
Linux devbox-vkryvenko 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
kaffarell commented 6 months ago

This has been fixed by #2880

Veetaha commented 4 months ago

@kaffarell could you get this change released please? The last tracing-attributes release was in October 2023

Veetaha commented 4 months ago

Or maybe I should ask @hawkw instead for a release. Without this fix we have to disable this clippy lint globally because we have a lot of usages of this pattern of code with tracing

srkaj commented 1 month ago

This also happens on stable rust 1.80.1, and there don't seem to be a release with the fix yet.

neolight1010 commented 1 month ago

I am adding #[allow(clippy::blocks_in_conditions)] everywhere this error pops up. It's annoying, but it works. I hope a new release comes out soon.

As a side note, the stabilization of RFC 2383 would be very handy for this specific issue, specifically expect(lint).