derive_partial_eq_without_eq triggers for test-only PartialEq derives
Summary
The derive_partial_eq_without_eq lint triggers on #[cfg_attr(test, derive(PartialEq))], I think it shouldn't.
Lint Name
derive_partial_eq_without_eq
Reproducer
I tried this code:
#[cfg_attr(test, derive(PartialEq))]
pub struct Foo {}
I saw this happen with cargo clippy --tests:
warning: you are deriving `PartialEq` and can implement `Eq`
--> src/lib.rs:1:25
|
1 | #[cfg_attr(test, derive(PartialEq))]
| ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`
|
= note: `#[warn(clippy::derive_partial_eq_without_eq)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
I expected to see this happen: no warnings
Version
rustc 1.63.0-nightly (5750a6aa2 2022-06-20)
binary: rustc
commit-hash: 5750a6aa2777382bf421b726f234da23f990a953
commit-date: 2022-06-20
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5
Additional Labels
No response
Additionally, the lint also still fires for types that are public within their module, but not part of the crate API (I noticed this in a proc-macro crate and a binary crate).
@jplatte experienced this error in my builds today. I just ignored the linting error to fix my builds
#![allow(
...
clippy::derive_partial_eq_without_eq
)]
This also potentially warns on type in binary crates, where the type will not be used elsewhere. https://github.com/rust-lang/rust/issues/74970 may help with the fix, but I think the number of false positives now is worth a quicker fix.