Skip to content

Commit dfcec28

Browse files
authored
Rollup merge of rust-lang#119481 - romanows:fix-doc-select-nth-unstable, r=Mark-Simulacrum
Clarify ambiguity in select_nth_unstable docs Original docs for `select_nth_unstable` family of functions were ambiguous as to whether "the element at `index`" was the element at `index` before the function reordered the elements or after the function reordered the elements. The most helpful change in this PR is to change the given examples to make this absolutely clear. Before, "the element at `index`" was the same value before and after the reordering, so it didn't help disambiguate the meaning. I've changed the example for `select_nth_unstable` and `select_nth_unstable_by` so that "the element at `index`" is different before and after the reordering, which clears up the ambiguity. The function `select_nth_unstable_by_key` already had an example that was unambiguous. In an attempt to clear up the ambiguity from the get-go, I've added a bit of redundancy to the text. Now the docs refer to "the element at `index` *after the reordering*".
2 parents 268dbbb + 7ac4515 commit dfcec28

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

library/core/src/slice/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2989,7 +2989,7 @@ impl<T> [T] {
29892989
sort::quicksort(self, |a, b| f(a).lt(&f(b)));
29902990
}
29912991

2992-
/// Reorder the slice such that the element at `index` is at its final sorted position.
2992+
/// Reorder the slice such that the element at `index` after the reordering is at its final sorted position.
29932993
///
29942994
/// This reordering has the additional property that any value at position `i < index` will be
29952995
/// less than or equal to any value at a position `j > index`. Additionally, this reordering is
@@ -3017,7 +3017,7 @@ impl<T> [T] {
30173017
/// # Examples
30183018
///
30193019
/// ```
3020-
/// let mut v = [-5i32, 4, 1, -3, 2];
3020+
/// let mut v = [-5i32, 4, 2, -3, 1];
30213021
///
30223022
/// // Find the median
30233023
/// v.select_nth_unstable(2);
@@ -3038,8 +3038,8 @@ impl<T> [T] {
30383038
select::partition_at_index(self, index, T::lt)
30393039
}
30403040

3041-
/// Reorder the slice with a comparator function such that the element at `index` is at its
3042-
/// final sorted position.
3041+
/// Reorder the slice with a comparator function such that the element at `index` after the reordering is at
3042+
/// its final sorted position.
30433043
///
30443044
/// This reordering has the additional property that any value at position `i < index` will be
30453045
/// less than or equal to any value at a position `j > index` using the comparator function.
@@ -3068,7 +3068,7 @@ impl<T> [T] {
30683068
/// # Examples
30693069
///
30703070
/// ```
3071-
/// let mut v = [-5i32, 4, 1, -3, 2];
3071+
/// let mut v = [-5i32, 4, 2, -3, 1];
30723072
///
30733073
/// // Find the median as if the slice were sorted in descending order.
30743074
/// v.select_nth_unstable_by(2, |a, b| b.cmp(a));
@@ -3093,8 +3093,8 @@ impl<T> [T] {
30933093
select::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less)
30943094
}
30953095

3096-
/// Reorder the slice with a key extraction function such that the element at `index` is at its
3097-
/// final sorted position.
3096+
/// Reorder the slice with a key extraction function such that the element at `index` after the reordering is
3097+
/// at its final sorted position.
30983098
///
30993099
/// This reordering has the additional property that any value at position `i < index` will be
31003100
/// less than or equal to any value at a position `j > index` using the key extraction function.

0 commit comments

Comments
 (0)