-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make is_sorted[_by_key]
require Ord
instead of PartialOrd
and remove Iterator::is_sorted_by_key
#81382
Make is_sorted[_by_key]
require Ord
instead of PartialOrd
and remove Iterator::is_sorted_by_key
#81382
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
Hm, which bound is more useful here is an interesting question.
And this also makes sense to me. Partially orderable values can also be sorted, as long as every two consecutive elements are in the right order:
Making the return type of the
|
Oh and I forgot to add: I don't think this new |
That's a good point. I totally forgot I also thought about whether const-generics and array can make an
I think I disagree and that there is no "correct" behavior here. There are useful behaviors, and the current way There was some very in-depth discussion back in the RFC thread about the exact semantics of As an alternative way to stabilization, what do you think about this?
|
Yeah, exactly. Maybe
Sounds like we should investigate this.
Yes, I agree that it's only one useful behaviour, and not necessarily the one you'd always want. But the point still stands that
That sounds reasonable. We should make sure that a potential |
cc @rust-lang/libs nominating for discussion at our next meeting if we haven't convinced ourselves that this is breaking or not by then. |
I think it should be non-breaking if all we're doing is simply "downgrading" a full |
543a41f
to
f57c719
Compare
I created a Zulip stream about this. I just force pushed so that this PR now removes If this PR is merged, I would create another PR stabilizing
As I said, I couldn't come up with a scenario where something could break. The "sneaky backwards-compatibility breaking things" I considered were: inference breaking and deref coercion breaking. Both of these seem to deal with specific types though. Consider: Finally, I tried what would happen for something like So yeah, I'm pretty sure by now that changing |
The job Click to see the possible cause of the failure (guessed by this bot)
|
This method can be trivially replaced by `iter.map(...).is_sorted()`. There has been some discussion about this, but the only reason for having that method that has been brought up is to have a more symmetry between the methods of `[T]` and `Iterator`. `[T]::is_sorted_by_key` is necessary, as there is not a simple replacement for it. But I don't think API symmetry is a strong enough argument for adding methods that are essentially superfluous or "a tiny bit convenient" at most. Finally, this method can always be added in the future. For the initial stabilization of the `is_sorted` API, it is not necessary.
…ialOrd` With `f32::total_cmp` and `f64::total_cmp`, the main reason for having an `PartialOrd` bound on these methods is mostly gone. By requiring `Ord`, we have no more edges cases with non-comparable values that need to be explained in the docs. These methods are now also in line with the `sort*` methods. Also note that `is_sorted` is mostly for convenience; if it is not powerful enough, there are more powerful tools that are only slightly less convenient. Finally, the trait bound can be relaxed in the future.
f57c719
to
324d5e9
Compare
is_sorted*
require Ord
instead of PartialOrd
is_sorted[_by_key]
require Ord
instead of PartialOrd
and remove Iterator::is_sorted_by_key
This was discussed in the library team meeting last week, in which we agreed that |
I see. So then I'd probably close this PR and open a PR that stabilizes |
In any case, this PR has become useless now basically, so I will close it. As far as I see it, the open question "Should |
See #53485 and the RFC thread for discussion about this. One of the last comments by @KodrAus:
And I agree. We should not longer block
is_sorted
in this discussion. It's better to have a stableis_sorted
that doesn't work withPartialOrd + !Ord
types than to have an forever unstable function. A few more arguments in favor ofOrd
:is_sorted_by
closure can now just returnOrdering
instead ofOption<Ordering>
.Ord
is more in line withsort*
methods.This PR does not stabilize anything yet, but I hope that with this PR we can stabilize these methods soon.