Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable unused variable warning in Rust?

Tags:

rust

According to this answer, #[allow(dead_code)] should work, but it doesn't

fn main() {
    #[allow(dead_code)]
    let x = 0;
}
like image 464
Guerlando OCs Avatar asked Nov 30 '25 14:11

Guerlando OCs


1 Answers

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

like image 94
Peter Hall Avatar answered Dec 04 '25 05:12

Peter Hall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!