]> git.lizzy.rs Git - rust.git/commitdiff
Rename slicing methods
authorNick Cameron <ncameron@mozilla.com>
Sat, 4 Oct 2014 22:59:10 +0000 (11:59 +1300)
committerNick Cameron <ncameron@mozilla.com>
Tue, 7 Oct 2014 02:49:53 +0000 (15:49 +1300)
src/libcollections/string.rs
src/libcollections/trie.rs
src/libcollections/vec.rs
src/libcore/ops.rs
src/libcore/prelude.rs
src/libcore/slice.rs
src/libcore/str.rs
src/libcoretest/iter.rs
src/librustc/middle/typeck/check/mod.rs
src/libstd/prelude.rs
src/test/run-pass/slice.rs

index 19edc1d2b007c19b100e17eb9e3b57a9afbd3f7b..0a460b642102c2872e6c6604211d923763eac8ee 100644 (file)
@@ -928,6 +928,7 @@ fn add(&self, other: &S) -> String {
     }
 }
 
+#[cfg(stage0)]
 impl ops::Slice<uint, str> for String {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a str {
@@ -949,6 +950,28 @@ fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
         self[][*from..*to]
     }
 }
+#[cfg(not(stage0))]
+impl ops::Slice<uint, str> for String {
+    #[inline]
+    fn as_slice_<'a>(&'a self) -> &'a str {
+        self.as_slice()
+    }
+
+    #[inline]
+    fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
+        self[][*from..]
+    }
+
+    #[inline]
+    fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
+        self[][..*to]
+    }
+
+    #[inline]
+    fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
+        self[][*from..*to]
+    }
+}
 
 /// Unsafe operations
 #[unstable = "waiting on raw module conventions"]
index 04175173febe6e8ba628351f87a35ca74f67e381..66f41d2ba1f32513823a4fdf24c0b6931a177577 100644 (file)
@@ -389,6 +389,7 @@ macro_rules! bound {
 
 impl<T> TrieMap<T> {
     // If `upper` is true then returns upper_bound else returns lower_bound.
+    #[cfg(stage0)]
     #[inline]
     fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
         bound!(Entries, self = self,
@@ -396,6 +397,14 @@ fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
                slice_from = slice_from_, iter = iter,
                mutability = )
     }
+    #[cfg(not(stage0))]
+    #[inline]
+    fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
+        bound!(Entries, self = self,
+               key = key, is_upper = upper,
+               slice_from = slice_from_or_fail, iter = iter,
+               mutability = )
+    }
 
     /// Gets an iterator pointing to the first key-value pair whose key is not less than `key`.
     /// If all keys in the map are less than `key` an empty iterator is returned.
@@ -431,6 +440,7 @@ pub fn upper_bound<'a>(&'a self, key: uint) -> Entries<'a, T> {
         self.bound(key, true)
     }
     // If `upper` is true then returns upper_bound else returns lower_bound.
+    #[cfg(stage0)]
     #[inline]
     fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
         bound!(MutEntries, self = self,
@@ -438,6 +448,14 @@ fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
                slice_from = slice_from_mut_, iter = iter_mut,
                mutability = mut)
     }
+    #[cfg(not(stage0))]
+    #[inline]
+    fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
+        bound!(MutEntries, self = self,
+               key = key, is_upper = upper,
+               slice_from = slice_from_or_fail_mut, iter = iter_mut,
+               mutability = mut)
+    }
 
     /// Deprecated: use `lower_bound_mut`.
     #[deprecated = "use lower_bound_mut"]
index b995af952f119ffc15e92f1ac9c0595091cb09d6..da88b5efa61fed5cb8edac762e656bb114a94f02 100644 (file)
@@ -460,6 +460,7 @@ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
     }
 }*/
 
+#[cfg(stage0)]
 impl<T> ops::Slice<uint, [T]> for Vec<T> {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a [T] {
@@ -480,7 +481,29 @@ fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
         self.as_slice().slice_(start, end)
     }
 }
+#[cfg(not(stage0))]
+impl<T> ops::Slice<uint, [T]> for Vec<T> {
+    #[inline]
+    fn as_slice_<'a>(&'a self) -> &'a [T] {
+        self.as_slice()
+    }
+
+    #[inline]
+    fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
+        self.as_slice().slice_from_or_fail(start)
+    }
 
+    #[inline]
+    fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
+        self.as_slice().slice_to_or_fail(end)
+    }
+    #[inline]
+    fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
+        self.as_slice().slice_or_fail(start, end)
+    }
+}
+
+#[cfg(stage0)]
 impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
     #[inline]
     fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
@@ -501,6 +524,27 @@ fn slice_mut_<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
         self.as_mut_slice().slice_mut_(start, end)
     }
 }
+#[cfg(not(stage0))]
+impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
+    #[inline]
+    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
+        self.as_mut_slice()
+    }
+
+    #[inline]
+    fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
+        self.as_mut_slice().slice_from_or_fail_mut(start)
+    }
+
+    #[inline]
+    fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
+        self.as_mut_slice().slice_to_or_fail_mut(end)
+    }
+    #[inline]
+    fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
+        self.as_mut_slice().slice_or_fail_mut(start, end)
+    }
+}
 
 #[experimental = "waiting on FromIterator stability"]
 impl<T> FromIterator<T> for Vec<T> {
@@ -1181,7 +1225,7 @@ pub fn push_all_move(&mut self, other: Vec<T>) {
     }
 
     /// Deprecated: use `slice_mut`.
-    #[deprecated = "use slice_from"]
+    #[deprecated = "use slice_mut"]
     pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
                          -> &'a mut [T] {
         self[mut start..end]
index e7b62e020a3cd84c13f3127e22056f988ebbec45..b08432c773e61a48bcf0e060c58b136d37f6e2ed 100644 (file)
@@ -692,15 +692,15 @@ pub trait IndexMut<Index, Result> {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo {
+ *     fn slice_from_or_fail<'a>(&'a self, from: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo {
+ *     fn slice_to_or_fail<'a>(&'a self, to: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
+ *     fn slice_or_fail<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
@@ -711,7 +711,22 @@ pub trait IndexMut<Index, Result> {
  * }
  * ```
  */
-// FIXME(#17273) remove the postscript _s
+#[cfg(not(stage0))]
+#[lang="slice"]
+pub trait Slice<Idx, Sized? Result> for Sized? {
+    /// The method for the slicing operation foo[]
+    fn as_slice_<'a>(&'a self) -> &'a Result;
+    /// The method for the slicing operation foo[from..]
+    fn slice_from_or_fail<'a>(&'a self, from: &Idx) -> &'a Result;
+    /// The method for the slicing operation foo[..to]
+    fn slice_to_or_fail<'a>(&'a self, to: &Idx) -> &'a Result;
+    /// The method for the slicing operation foo[from..to]
+    fn slice_or_fail<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
+}
+#[cfg(stage0)]
+/**
+ *
+ */
 #[lang="slice"]
 pub trait Slice<Idx, Sized? Result> for Sized? {
     /// The method for the slicing operation foo[]
@@ -742,15 +757,15 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_from_mut_<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
+ *     fn slice_from_or_fail_mut<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_to_mut_<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
+ *     fn slice_to_or_fail_mut<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_mut_<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
+ *     fn slice_or_fail_mut<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
@@ -761,7 +776,22 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
  * }
  * ```
  */
-// FIXME(#17273) remove the postscript _s
+#[cfg(not(stage0))]
+#[lang="slice_mut"]
+pub trait SliceMut<Idx, Sized? Result> for Sized? {
+    /// The method for the slicing operation foo[]
+    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Result;
+    /// The method for the slicing operation foo[from..]
+    fn slice_from_or_fail_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
+    /// The method for the slicing operation foo[..to]
+    fn slice_to_or_fail_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
+    /// The method for the slicing operation foo[from..to]
+    fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
+}
+#[cfg(stage0)]
+/**
+ *
+ */
 #[lang="slice_mut"]
 pub trait SliceMut<Idx, Sized? Result> for Sized? {
     /// The method for the slicing operation foo[mut]
index da17b113bf48c80ff81407863b61c78a81277eeb..680f91945d103d50a8ff98aabf40c87d61de7a3f 100644 (file)
@@ -35,6 +35,7 @@
 pub use ops::{Drop, Deref, DerefMut};
 pub use ops::{Shl, Shr};
 pub use ops::{Index, IndexMut};
+pub use ops::{Slice, SliceMut};
 pub use ops::{Fn, FnMut, FnOnce};
 pub use option::{Option, Some, None};
 pub use result::{Result, Ok, Err};
index 675037517428cc559369f7830124a3f8618ffbcd..7246fc367f8c89ae209355f0eec93117aea492a3 100644 (file)
@@ -486,6 +486,37 @@ fn pop_ref(&mut self) -> Option<&'a T> {
     }
 }
 
+
+
+#[cfg(not(stage0))]
+impl<T> ops::Slice<uint, [T]> for [T] {
+    #[inline]
+    fn as_slice_<'a>(&'a self) -> &'a [T] {
+        self
+    }
+
+    #[inline]
+    fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
+        self.slice_or_fail(start, &self.len())
+    }
+
+    #[inline]
+    fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
+        self.slice_or_fail(&0, end)
+    }
+    #[inline]
+    fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
+        assert!(*start <= *end);
+        assert!(*end <= self.len());
+        unsafe {
+            transmute(RawSlice {
+                    data: self.as_ptr().offset(*start as int),
+                    len: (*end - *start)
+                })
+        }
+    }
+}
+#[cfg(stage0)]
 impl<T> ops::Slice<uint, [T]> for [T] {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a [T] {
@@ -514,6 +545,36 @@ fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
     }
 }
 
+#[cfg(not(stage0))]
+impl<T> ops::SliceMut<uint, [T]> for [T] {
+    #[inline]
+    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
+        self
+    }
+
+    #[inline]
+    fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
+        let len = &self.len();
+        self.slice_or_fail_mut(start, len)
+    }
+
+    #[inline]
+    fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
+        self.slice_or_fail_mut(&0, end)
+    }
+    #[inline]
+    fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
+        assert!(*start <= *end);
+        assert!(*end <= self.len());
+        unsafe {
+            transmute(RawSlice {
+                    data: self.as_ptr().offset(*start as int),
+                    len: (*end - *start)
+                })
+        }
+    }
+}
+#[cfg(stage0)]
 impl<T> ops::SliceMut<uint, [T]> for [T] {
     #[inline]
     fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
@@ -556,7 +617,7 @@ pub trait MutableSlice<'a, T> {
     fn as_mut_slice(self) -> &'a mut [T];
 
     /// Deprecated: use `slice_mut`.
-    #[deprecated = "slice_mut"]
+    #[deprecated = "use slice_mut"]
     fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
         self.slice_mut(start, end)
     }
index f3a10a0a3ae908edd663a5f8bdf513749cbf3abc..6099af0e78fb6293fb2b1d5c80162664aa44d875 100644 (file)
@@ -1164,6 +1164,7 @@ impl<'a, S: Str> Equiv<S> for &'a str {
         fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
     }
 
+    #[cfg(stage0)]
     impl ops::Slice<uint, str> for str {
         #[inline]
         fn as_slice_<'a>(&'a self) -> &'a str {
@@ -1185,6 +1186,28 @@ fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
             self.slice(*from, *to)
         }
     }
+    #[cfg(not(stage0))]
+    impl ops::Slice<uint, str> for str {
+        #[inline]
+        fn as_slice_<'a>(&'a self) -> &'a str {
+            self
+        }
+
+        #[inline]
+        fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
+            self.slice_from(*from)
+        }
+
+        #[inline]
+        fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
+            self.slice_to(*to)
+        }
+
+        #[inline]
+        fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
+            self.slice(*from, *to)
+        }
+    }
 }
 
 /// Any string that can be represented as a slice
index e937d58ca2099234a305acd48757a7e5a6442cde..4135a02cc618e471959b9b7a07bee930c31339c7 100644 (file)
@@ -373,7 +373,7 @@ fn test_all() {
     assert!(v.iter().all(|&x| x < 10));
     assert!(!v.iter().all(|&x| x % 2 == 0));
     assert!(!v.iter().all(|&x| x > 100));
-    assert!(v.slice_(&0, &0).iter().all(|_| fail!()));
+    assert!(v.slice_or_fail(&0, &0).iter().all(|_| fail!()));
 }
 
 #[test]
@@ -382,7 +382,7 @@ fn test_any() {
     assert!(v.iter().any(|&x| x < 10));
     assert!(v.iter().any(|&x| x % 2 == 0));
     assert!(!v.iter().any(|&x| x > 100));
-    assert!(!v.slice_(&0, &0).iter().any(|_| fail!()));
+    assert!(!v.slice_or_fail(&0, &0).iter().any(|_| fail!()));
 }
 
 #[test]
index cdc375b258da7fef3bc2dcb27140b8cf396c88b5..4af71bfda8b35a27a3c659e120b189beaef66935 100644 (file)
@@ -2272,9 +2272,9 @@ fn try_overloaded_slice(fcx: &FnCtxt,
         match fcx.tcx().lang_items.slice_mut_trait() {
             Some(trait_did) => {
                 let method_name = match (start_expr, end_expr) {
-                    (&Some(_), &Some(_)) => "slice_mut_",
-                    (&Some(_), &None) => "slice_from_mut_",
-                    (&None, &Some(_)) => "slice_to_mut_",
+                    (&Some(_), &Some(_)) => "slice_or_fail_mut",
+                    (&Some(_), &None) => "slice_from_or_fail_mut",
+                    (&None, &Some(_)) => "slice_to_or_fail_mut",
                     (&None, &None) => "as_mut_slice_",
                 };
 
@@ -2297,9 +2297,9 @@ fn try_overloaded_slice(fcx: &FnCtxt,
         match fcx.tcx().lang_items.slice_trait() {
             Some(trait_did) => {
                 let method_name = match (start_expr, end_expr) {
-                    (&Some(_), &Some(_)) => "slice_",
-                    (&Some(_), &None) => "slice_from_",
-                    (&None, &Some(_)) => "slice_to_",
+                    (&Some(_), &Some(_)) => "slice_or_fail",
+                    (&Some(_), &None) => "slice_from_or_fail",
+                    (&None, &Some(_)) => "slice_to_or_fail",
                     (&None, &None) => "as_slice_",
                 };
 
index a1e74c7254e5a5a64b7db5ab5ea741b942b917ce..abfb2de13c5badca1b52c51263271afa9436fc9b 100644 (file)
@@ -46,6 +46,7 @@
 #[doc(no_inline)] pub use ops::{Drop, Deref, DerefMut};
 #[doc(no_inline)] pub use ops::{Shl, Shr};
 #[doc(no_inline)] pub use ops::{Index, IndexMut};
+#[doc(no_inline)] pub use ops::{Slice, SliceMut};
 #[doc(no_inline)] pub use ops::{Fn, FnMut, FnOnce};
 #[doc(no_inline)] pub use option::{Option, Some, None};
 #[doc(no_inline)] pub use result::{Result, Ok, Err};
index 7d969a0864ee900eda3ccc853b695f5dcec342b0..f863c4d330fbfa54346d406a64285367fd344197 100644 (file)
@@ -24,15 +24,15 @@ fn as_slice_<'a>(&'a self) -> &'a Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_from_<'a>(&'a self, _from: &Foo) -> &'a Foo {
+    fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_to_<'a>(&'a self, _to: &Foo) -> &'a Foo {
+    fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
+    fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
         unsafe { COUNT += 1; }
         self
     }
@@ -43,15 +43,15 @@ fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_from_mut_<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
+    fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_to_mut_<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
+    fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
         unsafe { COUNT += 1; }
         self
     }
-    fn slice_mut_<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
+    fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
         unsafe { COUNT += 1; }
         self
     }