Skip to content

docs: Specify that common sort functions sort in an ascending direction #140526

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

Merged
merged 1 commit into from
May 22, 2025

Conversation

Natr1x
Copy link
Contributor

@Natr1x Natr1x commented Apr 30, 2025

From forum discussion it seems like the sorting direction can be expected to always be ascending (in terms of cmp::Ordering).

If this is the case then it would be nice to have this stated in the documentation.

@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 30, 2025
@workingjubilee
Copy link
Member

workingjubilee commented Apr 30, 2025

@Natr1x As long as we're being excruciatingly explicit, should we note that "ascending" here causes slice::first to be the least and slice::last to be the greatest according to the Ordering? Or that the index order of values also compares like their comparison order, if you prefer (the least index, 0, is now the least value, et cetera).

...I say this because I have gotten confused before when "ascending" and "descending" flew around in a conversation that involved multi-part or "reversed" keys such that both "directions" lacked an obvious meaning. For bonus fun, at that point in a conversation, sometimes people will talk about the sorted ordering being "descending" when they have used such a sorting function to sort things into the ascending order of a reversed key.

@Natr1x
Copy link
Contributor Author

Natr1x commented May 1, 2025

@workingjubilee

I considered it. But I think the examples already explain this, and the extra clutter may just make it harder to read and thus more confusing.

The biggest reason I wanted to add this was to clarify that the order direction is consistent and expected to stay the same.

@workingjubilee
Copy link
Member

cool! yeah, "the examples already cover that" seems like a good reason for allowing the code to be the extra explanation since the code is... extra explanation. I still wonder if we should talk more about it, but we can explore that in other ways another day.

seems fine to me then.

@joboet
Copy link
Member

joboet commented May 15, 2025

r? libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 15, 2025
@rustbot rustbot assigned joshtriplett and unassigned joboet May 15, 2025
@joshtriplett
Copy link
Member

r? libs-api

@rustbot rustbot assigned dtolnay and unassigned joshtriplett May 21, 2025
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dtolnay
Copy link
Member

dtolnay commented May 21, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 21, 2025

📌 Commit b735dce has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 21, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#140526 (docs: Specify that common sort functions sort in an ascending direction)
 - rust-lang#141230 (std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`)
 - rust-lang#141341 (limit impls of `VaArgSafe` to just types that are actually safe)
 - rust-lang#141347 (incorrectly prefer builtin `dyn` impls :3)
 - rust-lang#141351 (Move -Zcrate-attr injection to just after crate root parsing)
 - rust-lang#141356 (lower bodies' params to thir before the body's value)
 - rust-lang#141357 (`unpretty=thir-tree`: don't require the final expr to be the body's value)
 - rust-lang#141363 (Document why we allow escaping bound vars in LTA norm)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d4b7915 into rust-lang:master May 22, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 22, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2025
Rollup merge of rust-lang#140526 - Natr1x:sort-direction-documentation, r=dtolnay

docs: Specify that common sort functions sort in an ascending direction

From [forum discussion](https://users.rust-lang.org/t/is-there-a-way-to-sort-a-slice-in-specifically-ascending-or-descending-order/128998?u=natr1x) it seems like the sorting direction can be expected to always be ascending (in terms of `cmp::Ordering`).

If this is the case then it would be nice to have this stated in the documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants