Skip to content

instrument triggers clippy::blocks_in_conditions #2876

Closed
@ShahakShama

Description

@ShahakShama

Bug Report

Version

tracing v0.1.40
tracing-attributes v0.1.27 (proc-macro)
tracing-core v0.1.32
tracing-futures v0.2.5
tracing-log v0.2.0
tracing-subscriber v0.3.18

Platform

22.04.1-Ubuntu

Description

Running the following code with clippy version 1.76.0 (2024-02-04) caused an error

#[async_trait]
pub trait Bar {
    async fn foo(&self) -> Result<usize, usize>;
}

#[derive(Debug)]
struct Foo;

#[async_trait]
impl Bar for Foo {
    #[instrument(skip(self), level = "debug", err)]
    async fn foo(&self) -> Result<usize, usize> {
        Ok(8)
    }
}

The error is

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`
    --> ...:1515:49
     |
1515 |       async fn foo(&self) -> Result<usize, usize> {
     |  _________________________________________________^
1516 | |         Ok(8)
1517 | |     }
     | |_____^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

This only happens with async traits. The following caused no errors:

#[instrument(skip(bar), level = "debug", err)]
async fn foo1(bar: usize) -> Result<usize, usize> {
    Ok(bar)
}

struct Foo2;

impl Foo2 {
    #[instrument(skip(self), level = "debug", err)]
    async fn foo2(&self) -> Result<usize, usize> {
        Ok(8)
    }
}

pub trait Bar3 {
    fn foo3(&self) -> Result<usize, usize>;
}

#[derive(Debug)]
struct Foo3;

impl Bar3 for Foo3 {
    #[instrument(skip(self), level = "debug", err)]
    fn foo3(&self) -> Result<usize, usize> {
        Ok(8)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions