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

cargo clippy not obeying [lints.clippy] from Cargo.toml, but only for some lints #11237

Closed
Kmeakin opened this issue Jul 27, 2023 · 4 comments
Closed
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Kmeakin
Copy link

Kmeakin commented Jul 27, 2023

Summary

Clippy does not obey the lint_name = "allow" key under [lints.clippy] from Cargo.toml for certain lints, but does work as expected for others. The lints have to be silenced with #[allow(...)] instead.

In the example below, must_use_candidate obeys the [lints.clippy] settings, but wildcard_imports doesn't.

Other lints that don't obey [lints.clippy] that I have encountered:

  • too_many_lines
  • option_if_let_else

Reproducer

Cargo.toml:

[package]
name = "clippy-test"
version = "0.1.0"
edition = "2021"

[lints.clippy]
pedantic = "warn"

must_use_candidate = "allow"
wildcard_imports = "allow"

.cargo/config.toml:

[unstable]
lints = true

src/lib.rs:

mod foo {
    pub struct A;
}

// "usage of wildcard import" reported
use foo::*;

// "this function could have a `#[must_use]` attribute" not reported
pub fn a() -> A {
    A
}

Version

rustc 1.73.0-nightly (864bdf784 2023-07-25)
binary: rustc
commit-hash: 864bdf7843e1ceabc824ed86d97006acad6af643
commit-date: 2023-07-25
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5


### Additional Labels

_No response_
@Kmeakin Kmeakin added the C-bug Category: Clippy is not doing the correct thing label Jul 27, 2023
@Alexendoo
Copy link
Member

Looks like a cargo issue, it sorts the flags before passing them to clippy but the order matters

'--allow=clippy::wildcard_imports' '--warn=clippy::pedantic' '--allow=clippy::must_use_candidate'

@Alexendoo
Copy link
Member

Closing in favour of rust-lang/cargo#12918

@kristof-mattei
Copy link
Contributor

As posted here rust-lang/cargo#12918 (comment)

The behavior here seems different than rustc. rustc seems to consolidate the lints, apply groups and then the individual settings, whereas Clippy seems to go by the order of the params (and thus the priority).

Wouldn't it be better to match rustc's behavior?

@Alexendoo
Copy link
Member

Clippy has no knowledge of the lint table, cargo turns it into --allow/--warn/etc flags the same as it would pass to rustc in cargo check/cargo build

bors added a commit that referenced this issue Jan 31, 2024
Add `lint_groups_priority` lint

Warns when a lint group in Cargo.toml's `[lints]` section shares the same priority as a lint. This is in the cargo section but is categorised as `correctness` so it's on by default, it doesn't call `cargo metadata` though and parses the `Cargo.toml` directly

The lint should be temporary until rust-lang/cargo#12918 is resolved, but in the meanwhile this is an common issue to run into

- #11237
- #11751
- #11830

changelog: Add [`lint_groups_priority`] lint

r? `@flip1995`
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

3 participants