rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.4k stars 1.54k forks source link

Cargo does not seem to always propagate `cfg(clippy)` correctly to dependencies #13101

Open rmalmain opened 3 months ago

rmalmain commented 3 months ago

Summary

When using path dependencies in Cargo.toml, cargo does not seem to propagate the special cfg(clippy) to dependencies correctly. A minimized example is available here.

For reference, this issue has been first opened here and then transferred to this repository.

Reproducer

In the minimized example repo, run cargo clippy --features feature1,feature2.

As far as I understand, it should not trigger a compiler error.

Version

cargo 1.81.0-nightly (154fdac39 2024-07-07)
release: 1.81.0-nightly
commit-hash: 154fdac39ae9629954e19e9986fd2cf2cdd8d964
commit-date: 2024-07-07
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Arch Linux Rolling Release [64-bit]

Additional Labels

No response

Jarcho commented 3 months ago

cfg(clippy) is only set for the crates clippy is run on, not dependencies. This is the same for the deprecated cfg(feature = "cargo-clippy").

rmalmain commented 3 months ago

Thank you for the clarification!

If this is the intended behavior, is there a way to enable cfg(clippy) for dependencies as well? For now, we solved this by creating a dummy feature that we propagate during clippy runs, but I believe this is definitely not a good approach.

Alexendoo commented 3 months ago

Clippy gets run for dependencies that are in the workspace, so adding [workspace] to the root package would be enough since it automatically adds path deps to the workspace. I don't think we have this well documented

rmalmain commented 3 months ago

I can confirm it indeed solved the issue, thank you! I have not been able to see this information in the documentation so far.

It would be very helpful to add a few words about this around here IMHO.