[solved] Different warnings in debug profile


#1

There are some warnings which are mostly about good coding style, e.g.

  • unnecessary parentheses around assigned value
  • variable does not need to be mutable

During development I often move code around, temporarily comment things out and cut&paste expressions, which causes these warnings. I don’t want to pay attention to the style of unfinished/experimental code that I may decide not to keep.

Is it possible to disable these warnings in debug mode only? e.g. via Cargo config?

I don’t want to permanently disable such warnings, and I’d rather avoid manually adding and removing #[allow()] directives when switching between debug/release modes.


#2

You can add a Cargo feature like “developing_code” in your Cargo.toml, and then use #![cfg_attr(developing_code, allow(dead_code))] in your crate.

You could in theory tie it to debug_assertions, but it’s better to tie it to a feature which is off by default. If someone else is modifying with your code, they might not realize that you disabled a bunch of warnings.


#3

Perfect!