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

select_nth documentation is insufficient #97982

Closed
TheIronBorn opened this issue Jun 11, 2022 · 2 comments · Fixed by #98111
Closed

select_nth documentation is insufficient #97982

TheIronBorn opened this issue Jun 11, 2022 · 2 comments · Fixed by #98111
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@TheIronBorn
Copy link

TheIronBorn commented Jun 11, 2022

The documentation's description of the return values is slightly incorrect.

/// element" in other libraries. It returns a triplet of the following values: all elements less
/// than the one at the given index, the value at the given index, and all elements greater than
/// the one at the given index.

The following code however, produces ([1, 1], 1, [1, 1]):

let mut v = [1i32; 5];
let (x, y, z) = v.select_nth_unstable(2);

(playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3c68d77916745c6442866324d675755d)

@TheIronBorn TheIronBorn added the C-bug Category: This is a bug. label Jun 11, 2022
asher-gh added a commit to asher-gh/rust that referenced this issue Jun 14, 2022
@GuillaumeGomez GuillaumeGomez added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed C-bug Category: This is a bug. labels Jun 17, 2022
@kartva
Copy link
Contributor

kartva commented Jul 8, 2022

@rustbot claim

@kartva
Copy link
Contributor

kartva commented Jul 8, 2022

Oh, it seems there's already an active PR for this. Sorry!

@kartva kartva removed their assignment Jul 8, 2022
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Sep 25, 2022
Clarify `[T]::select_nth_unstable*` return values

In cases where the nth element is not unique within the slice, it is not
correct to say that the values in the returned triplet include ones for
"all elements" less/greater than that at the given index: indeed one (or
more) such values would then also contain elements equal to that at
the given index.

The text proposed here clarifies exactly what is returned, but in so
doing it is also documenting an implementation detail that previously
wasn't detailed: namely that the returned slices are slices into the
reordered slice.  I don't think this can be contentious, because the
lifetimes of those returned slices are bound to that of the original
(now reordered) slice—so there really isn't any other reasonable
implementation that could have this behaviour; but nevertheless it's
probably best if `@rust-lang/libs-api` give it a nod?

Fixes rust-lang#97982
r? `@m-ou-se`

`@rustbot` label +A-docs +C-bug +T-libs-api -T-libs
@bors bors closed this as completed in 97bd49b Sep 25, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants