Dalit Sairio
Dalit Sairio

Reputation: 155

Is there a way to check for obsolete clippy allowances?

Sometimes you want to suppress a clippy warning for the time being and you let clippy ignore a specific rule for a specific code block by adding lines like the following:

#[allow(dead_code)]

But as the project continues, it can actually happen that you remove the problem, without actually removing the allowing of the clippy lint. So is there a way to check for allowed clippy warnings that are actually not being used anymore? So in this example I'd like to be informed when I #[allow(dead_code)] but there is actually no dead code to be found in the given code block.

Upvotes: 2

Views: 266

Answers (2)

Kevin Reid
Kevin Reid

Reputation: 43782

Since Rust 1.81, the #[expect] attribute can be used to allow the lint, but also warn if the lint is not detected.

#[expect(dead_code)]
fn foo() {}

fn main() {
    foo();
}

Output:

warning: this lint expectation is unfulfilled
 --> src/main.rs:3:10
  |
3 | #[expect(dead_code)]
  |          ^^^^^^^^^
  |
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

Upvotes: 4

mikayelgrigoryan
mikayelgrigoryan

Reputation: 563

You could try prefixing unused functions/variables/etc. with a _ (the compiler will also mention this.) if you do not want the warnings to appear. If you remove the any of the temporary/dead code containing the prefix, you won't have to worry about #![allow(dead_code)].

Upvotes: 0

Related Questions