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

unstable_sort_by vs panics #136665

Closed
mitsuhiko opened this issue Feb 6, 2025 · 0 comments · Fixed by #137484
Closed

unstable_sort_by vs panics #136665

mitsuhiko opened this issue Feb 6, 2025 · 0 comments · Fixed by #137484
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@mitsuhiko
Copy link
Contributor

Location

slice::sort_unstable_by

Summary

I ran into a bug with total sort order again which caused a panic. While looking for what others were doing in that situation I ran into a pull request where someone attempted to work around this with unstable sort (cantino/mcfly#454).

Reading the documentation implies in the first part that the worst that happens is not a sorted slice, whereas in the end it mentions that it can panic:

If the comparison function compare does not implement a total order the resulting order of elements in the slice is unspecified.

later

May panic if compare does not implement a total order.

The documentation on sort_by is clearer in that regard:

If the comparison function compare does not implement a total order, the function may panic; even if the function exits normally, the resulting order of elements in the slice is unspecified. See also the note on panicking below.

This should probably be aligned.

@mitsuhiko mitsuhiko added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Feb 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 6, 2025
@jieyouxu jieyouxu added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 10, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 24, 2025
…Noratrieb

Fix documentation for unstable sort on slice

Fixes rust-lang#136665
@bors bors closed this as completed in 8a8c0e2 Feb 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 24, 2025
Rollup merge of rust-lang#137484 - chenyukang:yukang-fix-sort-doc, r=Noratrieb

Fix documentation for unstable sort on slice

Fixes rust-lang#136665
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
…Noratrieb

Fix documentation for unstable sort on slice

Fixes rust-lang#136665
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
…Noratrieb

Fix documentation for unstable sort on slice

Fixes rust-lang#136665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants