rust-lang / rust-lang/rust-clippy
New lint: `derived_partial_eq_with_manual_eq`
Open
@wasd243 is already working on this.
Since Sep 15, 2026.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Disallows a type from having a derived PartialEq with a manual Eq implementation.
Advantage
- Prevents accidental wrong
Eqimplementations for types containing floats (for instance: https://github.com/mongodb/bson-rust/issues/683)
Drawbacks
No response
Example
#[derive(PartialEq)]
struct Foo {
value: u32,
}
impl Eq for Foo {}
#[derive(PartialEq)]
struct Bar {
value: f32,
}
impl Eq for Bar {}
Either both PartialEq and Eq should be manually implemented or both should be derived:
#[derive(PartialEq, Eq)]
struct Foo {
value: u32,
}
struct Bar {
value: f32,
}
impl PartialEq for Bar {
fn eq(&self, other: &Self) -> bool {
return self.value.to_bits() == other.value.to_bits()
}
}
impl Eq for Bar {}
Note that the following doesn't compile:
#[derive(PartialEq, Eq)]
struct Bar {
value: f32,
}
Comparison with existing lints
No response
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.