rust-lang / rust-lang/rust

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

Open
#126,029 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug L-dead_code L-unused_imports T-clippy
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two commands, cargo clippy -- -Dwarnings -Fdead_code and cargo clippy -- -Dwarnings -Funused, using the reported clap and logging macro cases. Trace how lint groups expand and how incompatible allow attributes are diagnosed; done means explaining why the results differ and why one diagnostic remains a warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.