about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-21 11:53:49 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-21 11:53:49 -0800
commit886c6f3534e6f03916eeff2ea8b235e85dd04b42 (patch)
tree616ec48db83b768a4be84225bed9b0c0f730072d /src/libcollections
parent036d8c41897099b5822eafa40e3f1fd2cdc4a92a (diff)
parent537889aa78c984ee6484d16fec4a67f35778aec6 (diff)
downloadrust-886c6f3534e6f03916eeff2ea8b235e85dd04b42.tar.gz
rust-886c6f3534e6f03916eeff2ea8b235e85dd04b42.zip
rollup merge of #21258: aturon/stab-3-index
Conflicts:
	src/libcore/ops.rs
	src/librustc_typeck/astconv.rs
	src/libstd/io/mem.rs
	src/libsyntax/parse/lexer/mod.rs
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/btree/node.rs21
-rw-r--r--src/libcollections/ring_buf.rs2
-rw-r--r--src/libcollections/slice.rs64
-rw-r--r--src/libcollections/str.rs82
-rw-r--r--src/libcollections/string.rs4
-rw-r--r--src/libcollections/vec.rs12
6 files changed, 66 insertions, 119 deletions
diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs
index fa890643089..50857c78469 100644
--- a/src/libcollections/btree/node.rs
+++ b/src/libcollections/btree/node.rs
@@ -21,7 +21,7 @@ use core::prelude::*;
 use core::borrow::BorrowFrom;
 use core::cmp::Ordering::{Greater, Less, Equal};
 use core::iter::Zip;
-use core::ops::{Deref, DerefMut};
+use core::ops::{Deref, DerefMut, Index, IndexMut};
 use core::ptr::Unique;
 use core::{slice, mem, ptr, cmp, num, raw};
 use alloc::heap;
@@ -1487,7 +1487,7 @@ impl<K, V, E, Impl> AbsTraversal<Impl>
 
 macro_rules! node_slice_impl {
     ($NodeSlice:ident, $Traversal:ident,
-     $as_slices_internal:ident, $slice_from:ident, $slice_to:ident, $iter:ident) => {
+     $as_slices_internal:ident, $index:ident, $iter:ident) => {
         impl<'a, K: Ord + 'a, V: 'a> $NodeSlice<'a, K, V> {
             /// Performs linear search in a slice. Returns a tuple of (index, is_exact_match).
             fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool)
@@ -1521,10 +1521,10 @@ macro_rules! node_slice_impl {
                     edges: if !self.has_edges {
                         self.edges
                     } else {
-                        self.edges.$slice_from(pos)
+                        self.edges.$index(&(pos ..))
                     },
-                    keys: self.keys.slice_from(pos),
-                    vals: self.vals.$slice_from(pos),
+                    keys: &self.keys[pos ..],
+                    vals: self.vals.$index(&(pos ..)),
                     head_is_edge: !pos_is_kv,
                     tail_is_edge: self.tail_is_edge,
                 }
@@ -1550,10 +1550,10 @@ macro_rules! node_slice_impl {
                     edges: if !self.has_edges {
                         self.edges
                     } else {
-                        self.edges.$slice_to(pos + 1)
+                        self.edges.$index(&(.. (pos + 1)))
                     },
-                    keys: self.keys.slice_to(pos),
-                    vals: self.vals.$slice_to(pos),
+                    keys: &self.keys[..pos],
+                    vals: self.vals.$index(&(.. pos)),
                     head_is_edge: self.head_is_edge,
                     tail_is_edge: !pos_is_kv,
                 }
@@ -1583,6 +1583,5 @@ macro_rules! node_slice_impl {
     }
 }
 
-node_slice_impl!(NodeSlice, Traversal, as_slices_internal, slice_from, slice_to, iter);
-node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, slice_from_mut,
-                                                                     slice_to_mut, iter_mut);
+node_slice_impl!(NodeSlice, Traversal, as_slices_internal, index, iter);
+node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, index_mut, iter_mut);
diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs
index badd7a8d6cc..338166c2f0b 100644
--- a/src/libcollections/ring_buf.rs
+++ b/src/libcollections/ring_buf.rs
@@ -578,7 +578,7 @@ impl<T> RingBuf<T> {
 
             if contiguous {
                 let (empty, buf) = buf.split_at_mut(0);
-                (buf.slice_mut(tail, head), empty)
+                (&mut buf[tail .. head], empty)
             } else {
                 let (mid, right) = buf.split_at_mut(tail);
                 let (left, _) = mid.split_at_mut(head);
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs
index 6fdeea0deaf..8c7f79d4d78 100644
--- a/src/libcollections/slice.rs
+++ b/src/libcollections/slice.rs
@@ -169,29 +169,16 @@ pub trait SliceExt {
     #[unstable = "uncertain about this API approach"]
     fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
 
-    /// Returns a subslice spanning the interval [`start`, `end`).
-    ///
-    /// Panics when the end of the new slice lies beyond the end of the
-    /// original slice (i.e. when `end > self.len()`) or when `start > end`.
-    ///
-    /// Slicing with `start` equal to `end` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&s[start .. end]` notation instead.
+    #[deprecated = "use &s[start .. end] instead"]
     fn slice(&self, start: uint, end: uint) -> &[Self::Item];
 
-    /// Returns a subslice from `start` to the end of the slice.
-    ///
-    /// Panics when `start` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing from `self.len()` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&s[start..]` notation instead.
+    #[deprecated = "use &s[start..] isntead"]
     fn slice_from(&self, start: uint) -> &[Self::Item];
 
-    /// Returns a subslice from the start of the slice to `end`.
-    ///
-    /// Panics when `end` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing to `0` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&s[..end]` notation instead.
+    #[deprecated = "use &s[..end] instead"]
     fn slice_to(&self, end: uint) -> &[Self::Item];
 
     /// Divides one slice into two at an index.
@@ -378,29 +365,16 @@ pub trait SliceExt {
     #[stable]
     fn as_mut_slice(&mut self) -> &mut [Self::Item];
 
-    /// Returns a mutable subslice spanning the interval [`start`, `end`).
-    ///
-    /// Panics when the end of the new slice lies beyond the end of the
-    /// original slice (i.e. when `end > self.len()`) or when `start > end`.
-    ///
-    /// Slicing with `start` equal to `end` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&mut s[start .. end]` instead.
+    #[deprecated = "use &mut s[start .. end] instead"]
     fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
 
-    /// Returns a mutable subslice from `start` to the end of the slice.
-    ///
-    /// Panics when `start` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing from `self.len()` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&mut s[start ..]` instead.
+    #[deprecated = "use &mut s[start ..] instead"]
     fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
 
-    /// Returns a mutable subslice from the start of the slice to `end`.
-    ///
-    /// Panics when `end` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing to `0` yields an empty slice.
-    #[unstable = "will be replaced by slice syntax"]
+    /// Deprecated: use `&mut s[.. end]` instead.
+    #[deprecated = "use &mut s[.. end] instead"]
     fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
 
     /// Returns an iterator that allows modifying each value
@@ -712,7 +686,7 @@ impl<T> SliceExt for [T] {
 
     #[inline]
     fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
-        for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) {
+        for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) {
             mem::swap(a, b);
         }
         cmp::min(self.len(), end-start)
@@ -720,17 +694,17 @@ impl<T> SliceExt for [T] {
 
     #[inline]
     fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
-        core_slice::SliceExt::slice(self, start, end)
+        &self[start .. end]
     }
 
     #[inline]
     fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
-        core_slice::SliceExt::slice_from(self, start)
+        &self[start ..]
     }
 
     #[inline]
     fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
-        core_slice::SliceExt::slice_to(self, end)
+        &self[.. end]
     }
 
     #[inline]
@@ -834,17 +808,17 @@ impl<T> SliceExt for [T] {
 
     #[inline]
     fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
-        core_slice::SliceExt::slice_mut(self, start, end)
+        &mut self[start .. end]
     }
 
     #[inline]
     fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
-        core_slice::SliceExt::slice_from_mut(self, start)
+        &mut self[start ..]
     }
 
     #[inline]
     fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
-        core_slice::SliceExt::slice_to_mut(self, end)
+        &mut self[.. end]
     }
 
     #[inline]
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index f7668930660..6608d0ee9a7 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -750,67 +750,17 @@ pub trait StrExt: Index<FullRange, Output = str> {
         core_str::StrExt::lines_any(&self[])
     }
 
-    /// Returns a slice of the given string from the byte range
-    /// [`begin`..`end`).
-    ///
-    /// This operation is `O(1)`.
-    ///
-    /// Panics when `begin` and `end` do not point to valid characters
-    /// or point beyond the last character of the string.
-    ///
-    /// See also `slice_to` and `slice_from` for slicing prefixes and
-    /// suffixes of strings, and `slice_chars` for slicing based on
-    /// code point counts.
-    ///
-    /// # Example
-    ///
-    /// ```rust
-    /// let s = "Löwe 老虎 Léopard";
-    /// assert_eq!(s.slice(0, 1), "L");
-    ///
-    /// assert_eq!(s.slice(1, 9), "öwe 老");
-    ///
-    /// // these will panic:
-    /// // byte 2 lies within `ö`:
-    /// // s.slice(2, 3);
-    ///
-    /// // byte 8 lies within `老`
-    /// // s.slice(1, 8);
-    ///
-    /// // byte 100 is outside the string
-    /// // s.slice(3, 100);
-    /// ```
-    #[unstable = "use slice notation [a..b] instead"]
-    fn slice(&self, begin: uint, end: uint) -> &str {
-        core_str::StrExt::slice(&self[], begin, end)
-    }
+    /// Deprecated: use `s[a .. b]` instead.
+    #[deprecated = "use slice notation [a..b] instead"]
+    fn slice(&self, begin: uint, end: uint) -> &str;
 
-    /// Returns a slice of the string from `begin` to its end.
-    ///
-    /// Equivalent to `self.slice(begin, self.len())`.
-    ///
-    /// Panics when `begin` does not point to a valid character, or is
-    /// out of bounds.
-    ///
-    /// See also `slice`, `slice_to` and `slice_chars`.
-    #[unstable = "use slice notation [a..] instead"]
-    fn slice_from(&self, begin: uint) -> &str {
-        core_str::StrExt::slice_from(&self[], begin)
-    }
+    /// Deprecated: use `s[a..]` instead.
+    #[deprecated = "use slice notation [a..] instead"]
+    fn slice_from(&self, begin: uint) -> &str;
 
-    /// Returns a slice of the string from the beginning to byte
-    /// `end`.
-    ///
-    /// Equivalent to `self.slice(0, end)`.
-    ///
-    /// Panics when `end` does not point to a valid character, or is
-    /// out of bounds.
-    ///
-    /// See also `slice`, `slice_from` and `slice_chars`.
-    #[unstable = "use slice notation [..a] instead"]
-    fn slice_to(&self, end: uint) -> &str {
-        core_str::StrExt::slice_to(&self[], end)
-    }
+    /// Deprecated: use `s[..a]` instead.
+    #[deprecated = "use slice notation [..a] instead"]
+    fn slice_to(&self, end: uint) -> &str;
 
     /// Returns a slice of the string from the character range
     /// [`begin`..`end`).
@@ -1348,7 +1298,19 @@ pub trait StrExt: Index<FullRange, Output = str> {
 }
 
 #[stable]
-impl StrExt for str {}
+impl StrExt for str {
+    fn slice(&self, begin: uint, end: uint) -> &str {
+        &self[begin..end]
+    }
+
+    fn slice_from(&self, begin: uint) -> &str {
+        &self[begin..]
+    }
+
+    fn slice_to(&self, end: uint) -> &str {
+        &self[..end]
+    }
+}
 
 #[cfg(test)]
 mod tests {
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index e6f438ecded..c965aedbc5d 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -849,6 +849,7 @@ impl<'a> Add<&'a str> for String {
     }
 }
 
+#[stable]
 impl ops::Index<ops::Range<uint>> for String {
     type Output = str;
     #[inline]
@@ -856,6 +857,7 @@ impl ops::Index<ops::Range<uint>> for String {
         &self[][*index]
     }
 }
+#[stable]
 impl ops::Index<ops::RangeTo<uint>> for String {
     type Output = str;
     #[inline]
@@ -863,6 +865,7 @@ impl ops::Index<ops::RangeTo<uint>> for String {
         &self[][*index]
     }
 }
+#[stable]
 impl ops::Index<ops::RangeFrom<uint>> for String {
     type Output = str;
     #[inline]
@@ -870,6 +873,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String {
         &self[][*index]
     }
 }
+#[stable]
 impl ops::Index<ops::FullRange> for String {
     type Output = str;
     #[inline]
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index bc90a5ab846..52590297a6a 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -1229,7 +1229,7 @@ impl<S: hash::Writer + hash::Hasher, T: Hash<S>> Hash<S> for Vec<T> {
     }
 }
 
-#[unstable = "waiting on Index stability"]
+#[stable]
 impl<T> Index<uint> for Vec<T> {
     type Output = T;
 
@@ -1239,6 +1239,7 @@ impl<T> Index<uint> for Vec<T> {
     }
 }
 
+#[stable]
 impl<T> IndexMut<uint> for Vec<T> {
     type Output = T;
 
@@ -1249,6 +1250,7 @@ impl<T> IndexMut<uint> for Vec<T> {
 }
 
 
+#[stable]
 impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1256,6 +1258,7 @@ impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
         self.as_slice().index(index)
     }
 }
+#[stable]
 impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1263,6 +1266,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
         self.as_slice().index(index)
     }
 }
+#[stable]
 impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1270,6 +1274,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
         self.as_slice().index(index)
     }
 }
+#[stable]
 impl<T> ops::Index<ops::FullRange> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1278,6 +1283,7 @@ impl<T> ops::Index<ops::FullRange> for Vec<T> {
     }
 }
 
+#[stable]
 impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1285,6 +1291,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
         self.as_mut_slice().index_mut(index)
     }
 }
+#[stable]
 impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1292,6 +1299,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
         self.as_mut_slice().index_mut(index)
     }
 }
+#[stable]
 impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1299,6 +1307,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
         self.as_mut_slice().index_mut(index)
     }
 }
+#[stable]
 impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
     type Output = [T];
     #[inline]
@@ -1307,7 +1316,6 @@ impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
     }
 }
 
-
 #[stable]
 impl<T> ops::Deref for Vec<T> {
     type Target = [T];