-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New lint: [derive_partial_eq_without_eq
]
#8796
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
clippy_lints/src/derive.rs
Outdated
/// ``` | ||
#[clippy::version = "1.62.0"] | ||
pub DERIVE_PARTIAL_EQ_WITHOUT_EQ, | ||
nursery, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure about the right place to put this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rust-lang/clippy @dswij @Alexendoo @Jarcho Which category do you think is appropriate? I think suspicious
looks good, but the original code isn't wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it's more an API guideline, style
is the closest fit. It doesn't invite misuse, nor is there anything wrong with it other than a potential annoyance, so suspicious
seems a little to strong a category.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this might be me being silly, but when I see a type that implements PartialEq
but not Eq
, I kind of read that as an assertion that "This is not an equivalence relation, it's only a partial equivalence relation". In that sense I see it as suspicious to not implement Eq
when you do have an equivalence relation, but that's pretty pedantic. I think you're correct in saying that this is primarily a question of adhering to API guidelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason not to implement Eq
when it could be derived (assuming PartialEq
is derived), other than laziness, is when there's the potential to extend the type in a way which could not implement Eq
. This is not most cases, but it is a possibility. This possibility is, to me, enough of a reason to not categorize it as suspicious
.
If not deriving Eq
would cause the type to be misused, then suspicious
would be a perfectly reasonable category. I think all our suspicious
lints basically point out things which are easy to miswrite, or easy to misread in such a way that it creates a bug, but they are still reasonablish things to type. I haven't actually checked through all the suspicious
lints, so that might not actually describe all suspicious
lints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely agree with @Jarcho on this one. sus
lints are for code that is "most likely wrong or useless". Not implementing Eq
is not wrong, at least there is no way for Clippy to tell if it is intentional (possibly expanding the struct in the future). With that the API concern is the one left and for those, style
is the best group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments!
df6f215
to
0b9293c
Compare
Tentatively put the lint under Also had to fix a few places in clippy where trivial enums were not being marked as |
Took me a couple of tries to realize that |
@bors r+ Thanks! |
📌 Commit fe84ff3 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Introduces a new lint, [
derive_partial_eq_without_eq
].See: #1781 (doesn't close it though).
changelog: add lint [
derive_partial_eq_without_eq
]