aboutsummaryrefslogtreecommitdiff
path: root/libcore/slice.rs
diff options
context:
space:
mode:
Diffstat (limited to 'libcore/slice.rs')
-rw-r--r--libcore/slice.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/libcore/slice.rs b/libcore/slice.rs
index 07f76ac..b6ae6fd 100644
--- a/libcore/slice.rs
+++ b/libcore/slice.rs
@@ -106,6 +106,10 @@ pub trait SliceExt {
#[stable(feature = "core", since = "1.6.0")]
fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
where F: FnMut(&Self::Item) -> Ordering;
+ #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
+ fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
+ where F: FnMut(&Self::Item) -> B,
+ B: Ord;
#[stable(feature = "core", since = "1.6.0")]
fn len(&self) -> usize;
#[stable(feature = "core", since = "1.6.0")]
@@ -157,11 +161,6 @@ pub trait SliceExt {
fn clone_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Clone;
#[stable(feature = "copy_from_slice", since = "1.9.0")]
fn copy_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Copy;
-
- #[unstable(feature = "slice_binary_search_by_key", reason = "recently added", issue = "33018")]
- fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
- where F: FnMut(&Self::Item) -> B,
- B: Ord;
}
// Use macros to be generic over const/mut
@@ -523,6 +522,7 @@ impl<T> SliceExt for [T] {
}
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<usize> for [T] {
type Output = T;
@@ -533,6 +533,7 @@ impl<T> ops::Index<usize> for [T] {
}
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<usize> for [T] {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut T {
@@ -553,7 +554,6 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! {
panic!("slice index starts at {} but ends at {}", index, end);
}
-// FIXME implement indexing with inclusive ranges
/// Implements slicing with syntax `&self[begin .. end]`.
///
@@ -566,6 +566,7 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! {
/// Requires that `begin <= end` and `end <= self.len()`,
/// otherwise slicing will panic.
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<ops::Range<usize>> for [T] {
type Output = [T];
@@ -592,6 +593,7 @@ impl<T> ops::Index<ops::Range<usize>> for [T] {
///
/// Equivalent to `&self[0 .. end]`
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
type Output = [T];
@@ -607,6 +609,7 @@ impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
///
/// Equivalent to `&self[begin .. self.len()]`
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
type Output = [T];
@@ -618,7 +621,7 @@ impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
/// Implements slicing with syntax `&self[..]`.
///
-/// Returns a slice of the whole slice. This operation can not panic.
+/// Returns a slice of the whole slice. This operation cannot panic.
///
/// Equivalent to `&self[0 .. self.len()]`
#[stable(feature = "rust1", since = "1.0.0")]
@@ -632,6 +635,7 @@ impl<T> ops::Index<RangeFull> for [T] {
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<ops::RangeInclusive<usize>> for [T] {
type Output = [T];
@@ -647,6 +651,7 @@ impl<T> ops::Index<ops::RangeInclusive<usize>> for [T] {
}
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::Index<ops::RangeToInclusive<usize>> for [T] {
type Output = [T];
@@ -667,6 +672,7 @@ impl<T> ops::Index<ops::RangeToInclusive<usize>> for [T] {
/// Requires that `begin <= end` and `end <= self.len()`,
/// otherwise slicing will panic.
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
@@ -691,6 +697,7 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
///
/// Equivalent to `&mut self[0 .. end]`
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<ops::RangeTo<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
@@ -704,6 +711,7 @@ impl<T> ops::IndexMut<ops::RangeTo<usize>> for [T] {
///
/// Equivalent to `&mut self[begin .. self.len()]`
#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
@@ -726,6 +734,7 @@ impl<T> ops::IndexMut<RangeFull> for [T] {
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<ops::RangeInclusive<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut [T] {
@@ -739,6 +748,7 @@ impl<T> ops::IndexMut<ops::RangeInclusive<usize>> for [T] {
}
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+#[rustc_on_unimplemented = "slice indices are of type `usize`"]
impl<T> ops::IndexMut<ops::RangeToInclusive<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut [T] {
@@ -1820,6 +1830,9 @@ impl<A> SlicePartialEq<A> for [A]
if self.len() != other.len() {
return false;
}
+ if self.as_ptr() == other.as_ptr() {
+ return true;
+ }
unsafe {
let size = mem::size_of_val(self);
memcmp(self.as_ptr() as *const u8,
@@ -1929,4 +1942,3 @@ macro_rules! impl_marker_for {
impl_marker_for!(BytewiseEquality,
u8 i8 u16 i16 u32 i32 u64 i64 usize isize char bool);
-