2

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

fn main() {
    #[allow(dead_code)]
    let x = 0;
}
Peter Hall
  • 43,946
  • 11
  • 101
  • 168
Guerlando OCs
  • 162
  • 1
  • 29
  • 87
  • The best way would be to remove the unused code. Maybe you'd be better off explaining why that approach is one you're avoiding, someone might be able to give you a better solution. – loganfsmyth Jun 22 '21 at 01:18
  • For machine disabling you can look to my answer at below link. https://stackoverflow.com/a/71119013/10943567 – Kargat TTT Feb 14 '22 at 22:30

2 Answers2

7

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

Peter Hall
  • 43,946
  • 11
  • 101
  • 168
  • Also, prefixing the variable name with an underscore suppresses the warning: `let _x = 0;` – Jmb Jun 22 '21 at 07:03
3

The correct is

fn main() {
    #[allow(unused_variables)]
    let x = 0;
}
Ryan M
  • 15,686
  • 29
  • 53
  • 64
Guerlando OCs
  • 162
  • 1
  • 29
  • 87