Skip to content

Commit 033f93f

Browse files
authored
Rollup merge of #98111 - eggyal:issue-97982, r=GuillaumeGomez
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 #97982 r? `@m-ou-se` `@rustbot` label +A-docs +C-bug +T-libs-api -T-libs
2 parents 6f6010b + 97bd49b commit 033f93f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

library/core/src/slice/mod.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -2643,9 +2643,10 @@ impl<T> [T] {
26432643
/// less than or equal to any value at a position `j > index`. Additionally, this reordering is
26442644
/// unstable (i.e. any number of equal elements may end up at position `index`), in-place
26452645
/// (i.e. does not allocate), and *O*(*n*) worst-case. This function is also/ known as "kth
2646-
/// element" in other libraries. It returns a triplet of the following values: all elements less
2647-
/// than the one at the given index, the value at the given index, and all elements greater than
2648-
/// the one at the given index.
2646+
/// element" in other libraries. It returns a triplet of the following from the reordered slice:
2647+
/// the subslice prior to `index`, the element at `index`, and the subslice after `index`;
2648+
/// accordingly, the values in those two subslices will respectively all be less-than-or-equal-to
2649+
/// and greater-than-or-equal-to the value of the element at `index`.
26492650
///
26502651
/// # Current implementation
26512652
///
@@ -2689,10 +2690,11 @@ impl<T> [T] {
26892690
/// less than or equal to any value at a position `j > index` using the comparator function.
26902691
/// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
26912692
/// position `index`), in-place (i.e. does not allocate), and *O*(*n*) worst-case. This function
2692-
/// is also known as "kth element" in other libraries. It returns a triplet of the following
2693-
/// values: all elements less than the one at the given index, the value at the given index,
2694-
/// and all elements greater than the one at the given index, using the provided comparator
2695-
/// function.
2693+
/// is also known as "kth element" in other libraries. It returns a triplet of the following from
2694+
/// the slice reordered according to the provided comparator function: the subslice prior to
2695+
/// `index`, the element at `index`, and the subslice after `index`; accordingly, the values in
2696+
/// those two subslices will respectively all be less-than-or-equal-to and greater-than-or-equal-to
2697+
/// the value of the element at `index`.
26962698
///
26972699
/// # Current implementation
26982700
///
@@ -2740,10 +2742,11 @@ impl<T> [T] {
27402742
/// less than or equal to any value at a position `j > index` using the key extraction function.
27412743
/// Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
27422744
/// position `index`), in-place (i.e. does not allocate), and *O*(*n*) worst-case. This function
2743-
/// is also known as "kth element" in other libraries. It returns a triplet of the following
2744-
/// values: all elements less than the one at the given index, the value at the given index, and
2745-
/// all elements greater than the one at the given index, using the provided key extraction
2746-
/// function.
2745+
/// is also known as "kth element" in other libraries. It returns a triplet of the following from
2746+
/// the slice reordered according to the provided key extraction function: the subslice prior to
2747+
/// `index`, the element at `index`, and the subslice after `index`; accordingly, the values in
2748+
/// those two subslices will respectively all be less-than-or-equal-to and greater-than-or-equal-to
2749+
/// the value of the element at `index`.
27472750
///
27482751
/// # Current implementation
27492752
///

0 commit comments

Comments
 (0)