Reputation: 2147
According to this answer, #[allow(dead_code)]
should work, but it doesn't
fn main() {
#[allow(dead_code)]
let x = 0;
}
Upvotes: 19
Views: 19928
Reputation: 2147
The correct is
fn main() {
#[allow(unused_variables)]
let x = 0;
}
Upvotes: 18
Reputation: 58735
These are different lints. dead_code
refers to unused code at the item level, e.g. imports, functions and types. unused_variables
refers to variables that are never accessed.
You can also cover both cases with #[allow(unused)]
.
Upvotes: 25