Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[workspace.lints.clippy] cannot override a category "warn" with a lint specific "allow" #12716

Closed
Kriskras99 opened this issue Apr 25, 2024 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Kriskras99
Copy link

Summary

I like to set categories as "warn" or "deny", and then allow specific lints. For example "warn" on cargo lints, but "allow" the multiple_crate_versions.
Currently this does not work, and I have to add an override when running Clippy on the command line

Reproducer

I tried this code:

[workspace.lints.clippy]
cargo = "warn"
multiple_crate_versions = "allow"

I expected to see this happen:
Warnings for cargo lints, but not for multiple_crate_versions

Instead, this happened:

warning: multiple versions for dependency `hashbrown`: 0.12.3, 0.14.3
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions

warning: multiple versions for dependency `indexmap`: 1.9.3, 2.2.6
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions

warning: multiple versions for dependency `regex-automata`: 0.1.10, 0.4.6
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions

warning: multiple versions for dependency `regex-syntax`: 0.6.29, 0.8.3
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions

warning: multiple versions for dependency `strsim`: 0.10.0, 0.11.1
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions

Version

rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Additional Labels

No response

@Kriskras99 Kriskras99 added the C-bug Category: Clippy is not doing the correct thing label Apr 25, 2024
@y21
Copy link
Member

y21 commented Apr 25, 2024

This is more or less expected behavior with how lint tables are implemented in cargo currently. You need to give the lint group cargo a lower priority so that the specific lint multiple_crate_versions overrides it, e.g. cargo = { level = "warn", priority = -1 }.
See also #12161 and #12093 for similar issues where this has caused confusion in the past.

Clippy does have a lint against this kind of mistake, but it does not work for workspaces.

error: lint group `cargo` has the same priority (0) as a lint
  --> Cargo.toml:16:1
   |
16 | cargo = "warn"
   | ^^^^^   ------ has an implicit priority of 0
17 | multiple_crate_versions = "allow"
   | ----------------------- has the same priority as this lint
   |
   = note: the order of the lints in the table is ignored by Cargo
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lint_groups_priority
   = note: `#[deny(clippy::lint_groups_priority)]` on by default
help: to have lints override the group set `cargo` to a lower priority
   |
16 | cargo = { level = "warn", priority = -1 }
   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Kriskras99
Copy link
Author

Ah, that makes sense.
Should I open an issue for lint_groups_priority not firing for workspaces? Or reuse this one?

@Kriskras99
Copy link
Author

Closing in favor of #12729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants