Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instrument triggers clippy::blocks_in_conditions #2876

Closed
ShahakShama opened this issue Feb 11, 2024 · 3 comments
Closed

instrument triggers clippy::blocks_in_conditions #2876

ShahakShama opened this issue Feb 11, 2024 · 3 comments

Comments

@ShahakShama
Copy link

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)
    }
}
Haennetz added a commit to Haennetz/vaultrs that referenced this issue Feb 11, 2024
tokio tracing instrument causes clippy to fail see tokio-rs/tracing#2876
Haennetz added a commit to Haennetz/vaultrs that referenced this issue Feb 11, 2024
tokio tracing instrument causes clippy to fail see tokio-rs/tracing#2876
ctron added a commit to ctron/csaf-walker that referenced this issue Feb 13, 2024
kaffarell added a commit to kaffarell/tracing that referenced this issue Feb 14, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: tokio-rs#2876
kaffarell added a commit to kaffarell/tracing that referenced this issue Feb 14, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: tokio-rs#2876
kaffarell added a commit to kaffarell/tracing that referenced this issue Feb 14, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: tokio-rs#2876
kaffarell added a commit to kaffarell/tracing that referenced this issue Mar 4, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: tokio-rs#2876
davidbarsky pushed a commit that referenced this issue Mar 12, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: #2876
@seanpianka
Copy link

#2880 is merged. Once released, it should close this issue.

@davidbarsky
Copy link
Member

davidbarsky commented Mar 12, 2024

#2880 is merged. Once released, it should close this issue.

We'd need to port it to master as well, yes?

EDIT: yes, we will. 2880 only targeted v0.1.x.

sandhose added a commit to matrix-org/matrix-authentication-service that referenced this issue May 6, 2024
This also ignores the clippy::blocks_in_conditions lint in two crates,
until tracing gets fixed: tokio-rs/tracing#2876
sandhose added a commit to matrix-org/matrix-authentication-service that referenced this issue May 6, 2024
This also ignores the clippy::blocks_in_conditions lint in two crates,
until tracing gets fixed: tokio-rs/tracing#2876
sandhose added a commit to matrix-org/matrix-authentication-service that referenced this issue May 7, 2024
This also ignores the clippy::blocks_in_conditions lint in two crates,
until tracing gets fixed: tokio-rs/tracing#2876
kaffarell added a commit to kaffarell/tracing that referenced this issue May 22, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: tokio-rs#2876
davidbarsky pushed a commit that referenced this issue Oct 2, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: #2876
davidbarsky pushed a commit that referenced this issue Oct 2, 2024
On clippy version 1.76.0 this gives a warning, extracting the
scrutinee to a variable fixes this.

Fixes: #2876
@mrozycki
Copy link

mrozycki commented Dec 4, 2024

This is still happening if you specify err, but not ret. I created a PR to apply the same fix to the err-only case: #3170

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

No branches or pull requests

4 participants