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