Skip to content

tracing::instrument triggers blocks_in_conditions #12281

Closed
@fenollp

Description

@fenollp

Summary

Basically #12016 (comment)

Since 1.76.0, any async fn impl that is decorated with #[tracing::instrument(..)] will trigger https://rust-lang.github.io/rust-clippy/master/index.html#/blocks_in_conditions

Lint Name

blocks_in_conditions

Reproducer

I tried this code:

    #[tracing::instrument(skip(self), err)]
    async fn get_private_network(&mut self, private_network_id: Uuid) -> Result<PrivateNetwork> {
        let req = GetPrivateNetworkRequest { private_network_id: private_network_id.to_string() };
        match self.client.get_private_network(req).await {
            Ok(r) => Ok(r.into_inner().try_into()?),
            Err(s) => match s.code() {
                Code::NotFound => Err(Error::NotFound {
                    kind: "private_network",
                    id: private_network_id.to_string(),
                }),
                _ => Err(Error::ApiError(s.to_string())),
            },
        }
    }

I saw this happen:

error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
  --> api_clients/src/clients/vpc_v2.rs:28:97
   |
28 |       async fn get_private_network(&mut self, private_network_id: Uuid) -> Result<PrivateNetwork> {
   |  _________________________________________________________________________________________________^
29 | |         let req = GetPrivateNetworkRequest { private_network_id: private_network_id.to_string() };
30 | |         match self.client.get_private_network(req).await {
31 | |             Ok(r) => Ok(r.into_inner().try_into()?),
...  |
39 | |         }
40 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

I expected to see this happen: no warnings

Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions