-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Remove requirement that forces symmetric and transitive PartialEq impls to exist #81198
Conversation
r? @sfackler (rust-highfive has picked a reviewer for you, use r? to override) |
@rfcbot fcp merge |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I think we should at least have something that says symmetry and transitivity are encouraged if they can be done without undue difficulty. |
This comment has been minimized.
This comment has been minimized.
Agreed that it would be good to recommend the symmetric impl when possible. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@sfackler Can you register a Concern, then? (Can I?) |
This seems reasonable to me. I could imagine we could find ways to help users around symmetry and transitivity issues through error messages or explicitly codified
and for
|
I don't necessarily agree with this. Skimming the If your recommendation was intended to apply to public APIs only, that seems more suited to API design guidelines than any official requirement of the trait. |
On the topic of public APIs specifically I opened up a discussion in the API Guidelines for it: rust-lang/api-guidelines#235 |
Aside from when it's not possible, is there ever a reason to not make an impl symmetric? If they're not, comparisons need to have a specific order, which should only be a style decision. This can make That's why more |
Yes, there is. If I'm only going to perform the comparisons in one direction in my codebase, I'm not going to write 2 impls, one of which is dead code. I pointed this out in #81198 (comment). |
Sorry for not reading the comments well enough. I was looking closer through #80595.
I can understand this, even though I don't think I would do it myself. Requiring both to exist does seem unnecessary, but shouldn't a recommendation stay on this documentation page? If it's in the API guidelines, it might not be seen by those that want to learn more about the trait. |
Perhaps it would be worth being able to derive the symmetry after having implemented one direction. I agree that it's better to have both if possible (and the inconsistency in the past has caused problems with generalising some of the existing library methods). |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
@bors r+ rollup |
📌 Commit 8758083 has been approved by |
…as-schievink Rollup of 18 pull requests Successful merges: - rust-lang#78044 (Implement io::Seek for io::Empty) - rust-lang#79285 (Stabilize Arc::{increment,decrement}_strong_count) - rust-lang#80053 (stabilise `cargo test -- --include-ignored`) - rust-lang#80279 (Implement missing `AsMut<str>` for `str`) - rust-lang#80470 (Stabilize by-value `[T; N]` iterator `core::array::IntoIter`) - rust-lang#80945 (Add Box::downcast() for dyn Any + Send + Sync) - rust-lang#81048 (Stabilize `core::slice::fill_with`) - rust-lang#81198 (Remove requirement that forces symmetric and transitive PartialEq impls to exist) - rust-lang#81422 (Account for existing `_` field pattern when suggesting `..`) - rust-lang#81472 (Clone entire `TokenCursor` when collecting tokens) - rust-lang#81484 (Optimize decimal formatting of 128-bit integers) - rust-lang#81491 (Balance sidebar `Deref` cycle check with main content) - rust-lang#81509 (Add a regression test for ICE of bad_placeholder_type) - rust-lang#81547 (Edit rustc_typeck top-level docs) - rust-lang#81550 (Replace predecessor with range in collections documentation) - rust-lang#81558 (Fix ascii art text wrapping in mobile) - rust-lang#81562 (Clarify that InPlaceIterable guarantees extend to all advancing iterator methods.) - rust-lang#81563 (Improve docblock readability on small screen) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
/// - **Symmetric**: if `A: PartialEq<B>` and `B: PartialEq<A>`, then **`a == b` | ||
/// implies `b == a`**; and | ||
/// | ||
/// - **Transitive**: if `A: PartialEq<B>` and `B: PartialEq<C>` and `A: |
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.
If this part is updated for styling then Eq part should also be updated. Let me send a pull request.
Counterexample of symmetry:
If you have an impl like:
then Rust will not even allow the symmetric impl to exist.
Counterexample of transitivity:
Consider these two existing impls from
regex
andclap
:It's nice to be able to add
PartialEq<proc_macro::Punct> for char
in libproc_macro (#80595), but it makes no sense to force animpl PartialEq<Punct> for Char
andimpl PartialEq<Punct> for KeyType
inregex
andclap
in code that otherwise has nothing to do with proc macros.@rust-lang/libs