Skip to content
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

Merged
merged 1 commit into from
May 10, 2022
Merged

Conversation

nsunderland1
Copy link
Contributor

Introduces a new lint, [derive_partial_eq_without_eq].

See: #1781 (doesn't close it though).

changelog: add lint [derive_partial_eq_without_eq]

@rust-highfive
Copy link

r? @giraffate

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 7, 2022
/// ```
#[clippy::version = "1.62.0"]
pub DERIVE_PARTIAL_EQ_WITHOUT_EQ,
nursery,
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@Jarcho Jarcho May 10, 2022

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.

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments!

@nsunderland1 nsunderland1 force-pushed the master branch 2 times, most recently from df6f215 to 0b9293c Compare May 8, 2022 18:46
@nsunderland1
Copy link
Contributor Author

Tentatively put the lint under style in the latest revision. As a side effect of this, I had to fix cases where tests were hitting the lint. In some of those I just added the derive, unless the tests cared specifically about whether Eq was implemented, in which case I just told them to ignore the lint. Tried to be fairly conservative there.

Also had to fix a few places in clippy where trivial enums were not being marked as Eq, and added a rustfix test for the lint.

@nsunderland1
Copy link
Contributor Author

nsunderland1 commented May 10, 2022

Took me a couple of tries to realize that cargo test --features deny-warnings,internal would catch everything for me :) Couple more places where this required an Eq added in clippy internals, but all the cases were pretty straightforward.

@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented May 10, 2022

📌 Commit fe84ff3 has been approved by giraffate

@bors
Copy link
Contributor

bors commented May 10, 2022

⌛ Testing commit fe84ff3 with merge d422baa...

@bors
Copy link
Contributor

bors commented May 10, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: giraffate
Pushing d422baa to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants