about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-30 00:42:13 +0000
committerbors <bors@rust-lang.org>2014-12-30 00:42:13 +0000
commitfea5aa656ff4349f4d3e1fea1447d26986762ae1 (patch)
tree3736614e84499fcde1623619b6e1336f2b2221d6 /src/libcore
parent71123902e17ad339649f33423995eac78da40e3c (diff)
parent113f8aa86b64c0be1981a69d110e42d22460b33c (diff)
downloadrust-fea5aa656ff4349f4d3e1fea1447d26986762ae1.tar.gz
rust-fea5aa656ff4349f4d3e1fea1447d26986762ae1.zip
auto merge of #20160 : nick29581/rust/ranges2, r=nikomatsakis
The first six commits are from an earlier PR (#19858) and have already been reviewed. This PR makes an awful hack in the compiler to accommodate slices both natively and in the index a range form. After a snapshot we can hopefully add the new Index impls and then we can remove these awful hacks.

r? @nikomatsakis (or anyone who knows the compiler, really)
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/fmt/float.rs4
-rw-r--r--src/libcore/ops.rs8
-rw-r--r--src/libcore/slice.rs23
-rw-r--r--src/libcore/str/mod.rs1
4 files changed, 23 insertions, 13 deletions
diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs
index 47701ab8ffd..329fe7c7b49 100644
--- a/src/libcore/fmt/float.rs
+++ b/src/libcore/fmt/float.rs
@@ -179,7 +179,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
         _ => ()
     }
 
-    buf[mut ..end].reverse();
+    buf.slice_to_mut(end).reverse();
 
     // Remember start of the fractional digits.
     // Points one beyond end of buf if none get generated,
@@ -316,7 +316,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
 
             impl<'a> fmt::FormatWriter for Filler<'a> {
                 fn write(&mut self, bytes: &[u8]) -> fmt::Result {
-                    slice::bytes::copy_memory(self.buf[mut *self.end..],
+                    slice::bytes::copy_memory(self.buf.slice_from_mut(*self.end),
                                               bytes);
                     *self.end += bytes.len();
                     Ok(())
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index 0cd8c1d69d1..f6b79ccc42b 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -908,6 +908,14 @@ impl<Idx: Clone + Step> Iterator<Idx> for RangeFrom<Idx> {
     }
 }
 
+/// A range which is only bounded above.
+#[deriving(Copy)]
+#[lang="range_to"]
+pub struct RangeTo<Idx> {
+    /// The upper bound of the range (exclusive).
+    pub end: Idx,
+}
+
 
 /// The `Deref` trait is used to specify the functionality of dereferencing
 /// operations like `*v`.
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index 26684864c4c..d25f96ac15f 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -264,24 +264,26 @@ impl<T> SliceExt<T> for [T] {
     fn as_mut_slice(&mut self) -> &mut [T] { self }
 
     fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
-        self[mut start..end]
+        ops::SliceMut::slice_or_fail_mut(self, &start, &end)
     }
 
     #[inline]
     fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
-        self[mut start..]
+        ops::SliceMut::slice_from_or_fail_mut(self, &start)
     }
 
     #[inline]
     fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
-        self[mut ..end]
+        ops::SliceMut::slice_to_or_fail_mut(self, &end)
     }
 
     #[inline]
     fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
         unsafe {
             let self2: &mut [T] = mem::transmute_copy(&self);
-            (self[mut ..mid], self2[mut mid..])
+
+            (ops::SliceMut::slice_to_or_fail_mut(self, &mid),
+             ops::SliceMut::slice_from_or_fail_mut(self2, &mid))
         }
     }
 
@@ -315,14 +317,13 @@ impl<T> SliceExt<T> for [T] {
 
     #[inline]
     fn tail_mut(&mut self) -> &mut [T] {
-        let len = self.len();
-        self[mut 1..len]
+        self.slice_from_mut(1)
     }
 
     #[inline]
     fn init_mut(&mut self) -> &mut [T] {
         let len = self.len();
-        self[mut 0..len - 1]
+        self.slice_to_mut(len-1)
     }
 
     #[inline]
@@ -560,7 +561,7 @@ impl<T: Ord> OrdSliceExt<T> for [T] {
         self.swap(j, i-1);
 
         // Step 4: Reverse the (previously) weakly decreasing part
-        self[mut i..].reverse();
+        self.slice_from_mut(i).reverse();
 
         true
     }
@@ -582,7 +583,7 @@ impl<T: Ord> OrdSliceExt<T> for [T] {
         }
 
         // Step 2: Reverse the weakly increasing part
-        self[mut i..].reverse();
+        self.slice_from_mut(i).reverse();
 
         // Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
         let mut j = self.len() - 1;
@@ -990,7 +991,7 @@ impl<'a, T, P> Iterator<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T)
             Some(idx) => {
                 let tmp = mem::replace(&mut self.v, &mut []);
                 let (head, tail) = tmp.split_at_mut(idx);
-                self.v = tail[mut 1..];
+                self.v = tail.slice_from_mut(1);
                 Some(head)
             }
         }
@@ -1026,7 +1027,7 @@ impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T, P> where
                 let tmp = mem::replace(&mut self.v, &mut []);
                 let (head, tail) = tmp.split_at_mut(idx);
                 self.v = head;
-                Some(tail[mut 1..])
+                Some(tail.slice_from_mut(1))
             }
         }
     }
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 1e7fe8f060c..1fc5f90028d 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -897,6 +897,7 @@ impl<'a> Iterator<&'a str> for SplitStr<'a> {
     }
 }
 
+
 /*
 Section: Comparing strings
 */