Skip to content

Override clippy::pedantic in Cargo.toml #11830

Closed
@davidhewitt

Description

@davidhewitt

Description

I'm testing the new [lints] functionality in Cargo.toml, which I'm very excited to have on stable!

I've just tried the following Cargo.toml configuration:

[lints.clippy]
pedantic = "warn"
similar_names = "allow"
# and a number of other "allow" lints from the pedantic category

The idea is that I want to lint against the whole pedantic category but then whitelist specific lints from that category which I'm ok with not complying with.

However, this doesn't work, the simliar_names lint is still reported:

warning: binding's name is too similar to existing binding
   --> src/validators/union.rs:353:17
    |
353 |             let tag_repr = choice_key.repr()?.to_string();
    |                 ^^^^^^^^
    |
note: existing binding defined here
   --> src/validators/union.rs:344:17
    |
344 |         let mut tags_repr = String::with_capacity(50);
    |                 ^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
    = note: `-W clippy::similar-names` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::similar_names)]`

I believe this is because the order which Cargo has passed the flags to clippy on the command line has placed the allow lints before the warn.

 Running `/home/david/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/clippy-driver [...] '--allow=clippy::similar_names' '--warn=clippy::pedantic' [...]

One fix I can imagine is that clippy should prioritize individual lint flags over their category flags, ignoring the command line order for this case, but this is probably a (minor) breaking change, so there would need to be discussion on whether it's valid to do so.

Version

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4

Additional Labels

@rustbot-label +C-enhancement

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