Skip to content

Suggested cargo clippy --fix command doesn't include lints enabled on command line #16547

@ada4a

Description

@ada4a

If I have some code that raises an allow-by-default lint:

fn foo(s: &str) {
    dbg!(s); // would raise `dbg_macro`
}

and run Clippy with that lint explicitly enabled:

cargo clippy -- -W clippy::dbg_macro

then I get the following output:

warning: the `dbg!` macro is intended as a debugging tool
 --> src/main.rs:3:5
  |
3 |     dbg!(s);
  |     ^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#dbg_macro
  = note: requested on the command line with `-W clippy::dbg-macro`
help: remove the invocation before committing it to a version control system
  |
3 -     dbg!(s);
3 +     s;
  |

warning: `tst` (bin "tst") generated 1 warning (run `cargo clippy --fix --bin "tst" -p tst` to apply 1 suggestion)

but running the suggested command (cargo clippy --fix --bin "tst" -p tst) won't actually apply the suggestion, as Clippy won't even think about linting on dbg!() -- what's needed is cargo clippy --fix --bin "tst" -p tst -- -W clippy::dbg_macro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions