Skip to content

Commit

Permalink
Auto merge of #43989 - circuitfox:sliceext-binary-search-sig, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Remove Borrow bound from SliceExt::binary_search

#37761 added a Borrow bound to `binary_search` and `binary_search_by_key` in `core::SliceExt`, but did not add it to the methods in `std::slice`. #41590 attempted to add this bound to `std::slice` but was not merged due to breakage. This PR removes the bound in `core::SliceExt`, so that these methods will have the same signature in `core` and `std`.

Fixes #41561
  • Loading branch information
bors committed Sep 16, 2017
2 parents 277476c + e15a07a commit b492405
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
// * The `raw` and `bytes` submodules.
// * Boilerplate trait implementations.

use borrow::Borrow;
use cmp::Ordering::{self, Less, Equal, Greater};
use cmp;
use fmt;
Expand Down Expand Up @@ -122,19 +121,17 @@ pub trait SliceExt {
fn as_ptr(&self) -> *const Self::Item;

#[stable(feature = "core", since = "1.6.0")]
fn binary_search<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
where Self::Item: Borrow<Q>,
Q: Ord;
fn binary_search(&self, x: &Self::Item) -> Result<usize, usize>
where Self::Item: Ord;

#[stable(feature = "core", since = "1.6.0")]
fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> Ordering;

#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, f: F) -> Result<usize, usize>
fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> B,
B: Borrow<Q>,
Q: Ord;
B: Ord;

#[stable(feature = "core", since = "1.6.0")]
fn len(&self) -> usize;
Expand Down Expand Up @@ -635,11 +632,10 @@ impl<T> SliceExt for [T] {
m >= n && needle == &self[m-n..]
}

fn binary_search<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
where T: Borrow<Q>,
Q: Ord
fn binary_search(&self, x: &T) -> Result<usize, usize>
where T: Ord
{
self.binary_search_by(|p| p.borrow().cmp(x))
self.binary_search_by(|p| p.cmp(x))
}

fn rotate(&mut self, mid: usize) {
Expand Down Expand Up @@ -687,12 +683,11 @@ impl<T> SliceExt for [T] {
}

#[inline]
fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, mut f: F) -> Result<usize, usize>
fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> B,
B: Borrow<Q>,
Q: Ord
B: Ord
{
self.binary_search_by(|k| f(k).borrow().cmp(b))
self.binary_search_by(|k| f(k).cmp(b))
}

#[inline]
Expand Down

0 comments on commit b492405

Please sign in to comment.