Skip to content

Clippy doesn't take into account configuration overrides given through cargo --config CLI #14786

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

Closed
anlavandier opened this issue May 12, 2025 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@anlavandier
Copy link

Summary

Clippy will not take into account cargo --config CLI arguments. This leads to cases where cargo clippy is unable to resolve dependencies when cargo build and cargo check both can.

Reproducer

I built a new empty cargo project and added a single dependency (in my case itertools but it doesn't matter) and asked for a feature that doesn't exist in the version on crates.io. This leads to the following Cargo.toml :

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

[dependencies]
itertools = { version = "0.14", default-features = false, features = ["SomeNewFeature"] }

Naturally this doesn't compile.

Now to simulate having made a fork of itertools that includes the aforementioned feature (SomeNewFeature), I simply created another empty project in the directory my-itertools, named it itertools and added this single feature. Here's the Cargo.toml:

[package]
name = "itertools"
version = "0.14.0"
edition = "2024"

[features]
SomeNewFeature = []

The crate clippy-bug-test can now be build by using the following command:

~/clippy-bug-test$ cargo --config "patch.crates-io.itertools.path='/path/to/my-itertools'" build

I expected to see this happen:

~/clippy-bug-test$ cargo --config "patch.crates-io.itertools.path='/path/to/my-itertools'" clippy

to work normally, like cargo build and cargo check did.

Instead, this happened:

~/clippy-bug-test$ cargo --config "patch.crates-io.itertools.path='/path/to/my-itertools'" clippy
    Updating crates.io index
error: failed to select a version for `itertools`.
    ... required by package `clippy-bug-test v0.1.0 (/home/tribe/clippy-bug-test)`
versions that meet the requirements `^0.14` are: 0.14.0

the package `clippy-bug-test` depends on `itertools`, with features: `SomeNewFeature` but `itertools` does not have these features.


failed to select a version for `itertools` which could resolve this conflict

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

@anlavandier anlavandier added the C-bug Category: Clippy is not doing the correct thing label May 12, 2025
@anlavandier
Copy link
Author

This example looks very contrived and it's not a real problem anyway as puttin the patch either in the Cargo.toml or in .cargo/config.toml. This also happens if the patch is given to cargo as cargo --config some-additionnal-config.toml instead of through key-value pairs.

@Alexendoo
Copy link
Member

This would be down to rust-lang/cargo#11031

I believe that cargo clippy --config .. works

@anlavandier
Copy link
Author

Thanks. I don't know how my various internet searches didn't lead me to that cargo issue. In any case, Seeing as this isn't directly related to clippy, I'm closing this issue.

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