0

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.

Dalit Sairio
  • 125
  • 3

2 Answers2

1

The unstable feature (currently only usable using the nightly Rust compiler) lint_reasons includes the ability to use expect( instead of allow(, which allows the lint but warns if the lint is not detected.

#![feature(lint_reasons)]

#[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

There is no current schedule for this to make it to stable but at least people want to see it and there's an implementation.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
0

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)].