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

Deriving only one of Hash/Eq considered harmful #430

Closed
Gankra opened this issue Nov 2, 2015 · 4 comments
Closed

Deriving only one of Hash/Eq considered harmful #430

Gankra opened this issue Nov 2, 2015 · 4 comments
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@Gankra
Copy link

Gankra commented Nov 2, 2015

If you derive Hash, but implement (Partial)Eq manually, you're probably doing it wrong, because those two need to agree for e.g. HashMap to work right.

@Manishearth Manishearth added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Nov 2, 2015
@Manishearth
Copy link
Member

This basically needs to look for the automatic_derive annotation on impls and compare.

@apasel422
Copy link
Contributor

@Manishearth I assume the best way to do this is to have LateLintPass::check_struct_def query the context for the presence of PartialEq and Hash impls for the struct/enum and then see if one contains the automatic_derive annotation and the other does not. We can extract this data from cx.tcx more efficiently than recomputing it ourselves, right?

@Manishearth
Copy link
Member

Yes. I don't know exactly which side tables it's in the tcx, but the info should be there.

Actually, a check_item for partialeq impls might be easier.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2016

rust-lang/rfcs#1499 suggests that this issue is not yet resolved, since only derived Hash + implemented PartialEq is linted, but not derived PartialEq + implemented Hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

5 participants