rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.9k stars 12.68k forks source link

weird behavior from `-Fdead_code` vs `-Funused` #126029

Open andrewbanchich opened 4 months ago

andrewbanchich commented 4 months ago

running cargo clippy -- -Dwarnings -Fdead_code in my binary produces two errors and no warnings. both errors are coming from clap.

error[E0453]: allow(dead_code) incompatible with previous forbid
  |
  | #[derive(Parser, Debug, Clone)]
  |          ^^^^^^ overruled by previous forbid
  |
  = note: `forbid` lint level was set on command line
  = note: this error originates in the derive macro `Parser` (in Nightly builds, run with -Z macro-backtrace for more info)

however, running cargo clippy -- -Dwarnings -Funused produces 1158 warnings and no errors. and example of one of the warnings is

warning: allow(unused_imports) incompatible with previous forbid
    |
    |         info!("a log message");
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
    = note: `forbid` lint level was set on command line
    = note: this warning originates in the macro `$crate::valueset` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info)
  1. i thought since dead_code is a subset of the unused lint group that if -Fdead_code produced errors that -Funused should produce at least the same number of errors.
  2. why is that a warning? shouldn't warning: allow(unused_imports) incompatible with previous forbid be an error since i added a forbid?
bjorn3 commented 4 months ago

why is that a warning? shouldn't warning: allow(unused_imports) incompatible with previous forbid be an error since i added a forbid?

It was accidentally allowed entirely. To give existing code a chance to fix the issue we are now emitting a future compatibility warning with the intent to turn it into an error in the future rather than immediately making it an error.

veera-sivarajan commented 4 months ago

@rustbot label -needs-triage +A-clippy +L-dead_code +A-lint +L-unused_imports