about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-08 03:04:50 +0000
committerbors <bors@rust-lang.org>2018-10-08 03:04:50 +0000
commitef5c00d0ca027f8ef4b41fecd53177e105daa6a8 (patch)
tree1ae9854de132033135c507abdc48cc2f5f84acc3
parentaefe9b099ab9ce41f2138dca79e4b3d75cc784a4 (diff)
parentb5c64e2e261ab2d3a009ccf1630d532202400009 (diff)
downloadrust-ef5c00d0ca027f8ef4b41fecd53177e105daa6a8.tar.gz
rust-ef5c00d0ca027f8ef4b41fecd53177e105daa6a8.zip
Auto merge of #54700 - frewsxcv:frewsxcv-binary-search, r=GuillaumeGomez
Clarify docs for when binary_search has many matches.

Fixes https://github.com/rust-lang/rust/issues/51817.
-rw-r--r--src/libcore/slice/mod.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index a50426ba886..76dcca02578 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -1175,9 +1175,10 @@ impl<T> [T] {
 
     /// Binary searches this sorted slice for a given element.
     ///
-    /// If the value is found then `Ok` is returned, containing the
-    /// index of the matching element; if the value is not found then
-    /// `Err` is returned, containing the index where a matching
+    /// If the value is found then [`Result::Ok`] is returned, containing the
+    /// index of the matching element. If there are multiple matches, then any
+    /// one of the matches could be returned. If the value is not found then
+    /// [`Result::Err`] is returned, containing the index where a matching
     /// element could be inserted while maintaining sorted order.
     ///
     /// # Examples
@@ -1209,9 +1210,10 @@ impl<T> [T] {
     /// order code that indicates whether its argument is `Less`,
     /// `Equal` or `Greater` the desired target.
     ///
-    /// If a matching value is found then returns `Ok`, containing
-    /// the index for the matched element; if no match is found then
-    /// `Err` is returned, containing the index where a matching
+    /// If the value is found then [`Result::Ok`] is returned, containing the
+    /// index of the matching element. If there are multiple matches, then any
+    /// one of the matches could be returned. If the value is not found then
+    /// [`Result::Err`] is returned, containing the index where a matching
     /// element could be inserted while maintaining sorted order.
     ///
     /// # Examples
@@ -1265,10 +1267,11 @@ impl<T> [T] {
     /// Assumes that the slice is sorted by the key, for instance with
     /// [`sort_by_key`] using the same key extraction function.
     ///
-    /// If a matching value is found then returns `Ok`, containing the
-    /// index for the matched element; if no match is found then `Err`
-    /// is returned, containing the index where a matching element could
-    /// be inserted while maintaining sorted order.
+    /// If the value is found then [`Result::Ok`] is returned, containing the
+    /// index of the matching element. If there are multiple matches, then any
+    /// one of the matches could be returned. If the value is not found then
+    /// [`Result::Err`] is returned, containing the index where a matching
+    /// element could be inserted while maintaining sorted order.
     ///
     /// [`sort_by_key`]: #method.sort_by_key
     ///