Skip to content

Commit 2a23af6

Browse files
authored
Rollup merge of #85985 - Lionelf329:master, r=joshtriplett
Clarify documentation of slice sorting methods After reading about [this](https://polkadot.network/a-polkadot-postmortem-24-05-2021/), I realized that although the documentation of these methods is not ambiguous in its current state, it is very easy to read it and erroneously assume that their exact behaviour can be relied upon to be deterministic. Although the docs make no guarantees about which index is returned when there are multiple matches, being more explicit about when and how their determinism can be relied upon should help prevent people from making this mistake in the future. r? ``@steveklabnik``
2 parents 3502bff + fddf012 commit 2a23af6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

library/core/src/slice/mod.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -2100,9 +2100,11 @@ impl<T> [T] {
21002100
///
21012101
/// If the value is found then [`Result::Ok`] is returned, containing the
21022102
/// index of the matching element. If there are multiple matches, then any
2103-
/// one of the matches could be returned. If the value is not found then
2104-
/// [`Result::Err`] is returned, containing the index where a matching
2105-
/// element could be inserted while maintaining sorted order.
2103+
/// one of the matches could be returned. The index is chosen
2104+
/// deterministically, but is subject to change in future versions of Rust.
2105+
/// If the value is not found then [`Result::Err`] is returned, containing
2106+
/// the index where a matching element could be inserted while maintaining
2107+
/// sorted order.
21062108
///
21072109
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
21082110
///
@@ -2153,9 +2155,11 @@ impl<T> [T] {
21532155
///
21542156
/// If the value is found then [`Result::Ok`] is returned, containing the
21552157
/// index of the matching element. If there are multiple matches, then any
2156-
/// one of the matches could be returned. If the value is not found then
2157-
/// [`Result::Err`] is returned, containing the index where a matching
2158-
/// element could be inserted while maintaining sorted order.
2158+
/// one of the matches could be returned. The index is chosen
2159+
/// deterministically, but is subject to change in future versions of Rust.
2160+
/// If the value is not found then [`Result::Err`] is returned, containing
2161+
/// the index where a matching element could be inserted while maintaining
2162+
/// sorted order.
21592163
///
21602164
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
21612165
///
@@ -2224,9 +2228,11 @@ impl<T> [T] {
22242228
///
22252229
/// If the value is found then [`Result::Ok`] is returned, containing the
22262230
/// index of the matching element. If there are multiple matches, then any
2227-
/// one of the matches could be returned. If the value is not found then
2228-
/// [`Result::Err`] is returned, containing the index where a matching
2229-
/// element could be inserted while maintaining sorted order.
2231+
/// one of the matches could be returned. The index is chosen
2232+
/// deterministically, but is subject to change in future versions of Rust.
2233+
/// If the value is not found then [`Result::Err`] is returned, containing
2234+
/// the index where a matching element could be inserted while maintaining
2235+
/// sorted order.
22302236
///
22312237
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
22322238
///

0 commit comments

Comments
 (0)