-
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
PartialOrd: transitivity and duality are required only if the corresponding impls exist #118108
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
801f4af
to
2c5dc64
Compare
…onding impls exist
2c5dc64
to
0eecc9e
Compare
r? libs-api |
/// - duality: `a < b` if and only if `b > a`. | ||
/// - **Transitivity**: if `A: PartialOrd<B>` and `B: PartialOrd<C>` and `A: | ||
/// PartialOrd<C>`, then `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. | ||
/// This must also work for longer chains, such as when `A: PartialOrd<B>`, `B: PartialOrd<C>`, |
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.
/// This must also work for longer chains, such as when `A: PartialOrd<B>`, `B: PartialOrd<C>`, | |
/// This should also work for longer chains, such as when `A: PartialOrd<B>`, `B: PartialOrd<C>`, |
(Acknowledging the current state of things here.)
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 current state is that this is a must, no? "The comparison must satisfy, for all [...]".
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.
(Consolidating this to the similar discussion on PartialEq
.)
I assume we want this to be consistent, despite the different starting points (one PR is relaxing the currently stable requirements/recommendations for I can also merge one PR into the other if you prefer. |
I've made this part of #115386. |
Fixes #87067. Currently, not even std itself upholds the requirements documented for
PartialOrd
.This is basically doing for
PartialOrd
what #81198 did forPartialEq
. However, #81198 (likely accidentally) significantly weakened the transitivity requirement, which we are avoiding here: as of today, it is the case that ifA: PartialOrd<B>
andB: PartialOrd<C>
andC: PartialOrd<D>
andA: PartialOrd<D>
all hold, then ifa < b < c < d
, we havea < d
. If we just did the same thing as #81198, we would lose that property. Therefore, we explicitly require transitivity for longer chains as well.Libs-api decided here that they are fine with applying #81198 to
PartialOrd
as well. I'm still nominating this for them again due to this change in how transitivity is handled.