Skip to content

Commit 7cee082

Browse files
authoredSep 16, 2017
Rollup merge of rust-lang#43989 - circuitfox:sliceext-binary-search-sig, r=alexcrichton
Remove Borrow bound from SliceExt::binary_search rust-lang#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`. rust-lang#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 rust-lang#41561
2 parents eed781e + e15a07a commit 7cee082

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed
 

‎src/libcore/slice/mod.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
// * The `raw` and `bytes` submodules.
3636
// * Boilerplate trait implementations.
3737

38-
use borrow::Borrow;
3938
use cmp::Ordering::{self, Less, Equal, Greater};
4039
use cmp;
4140
use fmt;
@@ -122,19 +121,17 @@ pub trait SliceExt {
122121
fn as_ptr(&self) -> *const Self::Item;
123122

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

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

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

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

638-
fn binary_search<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
639-
where T: Borrow<Q>,
640-
Q: Ord
635+
fn binary_search(&self, x: &T) -> Result<usize, usize>
636+
where T: Ord
641637
{
642-
self.binary_search_by(|p| p.borrow().cmp(x))
638+
self.binary_search_by(|p| p.cmp(x))
643639
}
644640

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

689685
#[inline]
690-
fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, mut f: F) -> Result<usize, usize>
686+
fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
691687
where F: FnMut(&'a Self::Item) -> B,
692-
B: Borrow<Q>,
693-
Q: Ord
688+
B: Ord
694689
{
695-
self.binary_search_by(|k| f(k).borrow().cmp(b))
690+
self.binary_search_by(|k| f(k).cmp(b))
696691
}
697692

698693
#[inline]

0 commit comments

Comments
 (0)
Please sign in to comment.