From c0c6c895890770d7029324fd9b592f42e0564e8b Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 2 Oct 2014 11:47:58 -0700 Subject: [PATCH] Revert "Remove the `_` suffix from slice methods." This reverts commit df2f1fa7680a86ba228f004e7de731e91a1df1fe. --- src/libcollections/trie.rs | 18 ---- src/libcollections/vec.rs | 53 ---------- src/libcore/ops.rs | 51 ++-------- src/libcore/slice.rs | 127 +++++++++++++----------- src/libcoretest/iter.rs | 4 +- src/librustc/middle/typeck/check/mod.rs | 16 +-- src/test/run-pass/slice.rs | 16 +-- 7 files changed, 97 insertions(+), 188 deletions(-) diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 9bfc8e08d8d..04175173feb 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -389,7 +389,6 @@ pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, T> { impl TrieMap { // 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, @@ -397,14 +396,6 @@ 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, 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. @@ -440,7 +431,6 @@ 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, @@ -448,14 +438,6 @@ 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_mut, iter = iter_mut, - mutability = mut) - } /// Deprecated: use `lower_bound_mut`. #[deprecated = "use lower_bound_mut"] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index f9bc5ac743c..dc48c85e0f4 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -24,7 +24,6 @@ use core::ops; use core::ptr; use core::raw::Slice as RawSlice; -use core::slice::Slice as SliceSlice; use core::uint; use {Mutable, MutableSeq}; @@ -461,36 +460,6 @@ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { } }*/ -// Annoying helper function because there are two Slice::as_slice functions in -// scope. -#[inline] -fn slice_to_slice<'a, T, U: Slice>(this: &'a U) -> &'a [T] { - this.as_slice() -} - - -#[cfg(not(stage0))] -impl ops::Slice for Vec { - #[inline] - fn as_slice<'a>(&'a self) -> &'a [T] { - slice_to_slice(self) - } - - #[inline] - fn slice_from<'a>(&'a self, start: &uint) -> &'a [T] { - slice_to_slice(self).slice_from(start) - } - - #[inline] - fn slice_to<'a>(&'a self, end: &uint) -> &'a [T] { - slice_to_slice(self).slice_to(end) - } - #[inline] - fn slice<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { - slice_to_slice(self).slice(start, end) - } -} -#[cfg(stage0)] impl ops::Slice for Vec { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -512,28 +481,6 @@ fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { } } -#[cfg(not(stage0))] -impl ops::SliceMut for Vec { - #[inline] - fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { - self.as_mut_slice() - } - - #[inline] - fn slice_from_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_from_mut(start) - } - - #[inline] - fn slice_to_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_to_mut(end) - } - #[inline] - fn slice_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_mut(start, end) - } -} -#[cfg(stage0)] impl ops::SliceMut for Vec { #[inline] fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 77cee2b9863..ad0f128a02e 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -688,19 +688,19 @@ pub trait IndexMut { * struct Foo; * * impl ::core::ops::Slice for Foo { - * fn as_slice<'a>(&'a self) -> &'a Foo { + * fn as_slice_<'a>(&'a self) -> &'a Foo { * println!("Slicing!"); * self * } - * fn slice_from<'a>(&'a self, from: &Foo) -> &'a Foo { + * fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo { * println!("Slicing!"); * self * } - * fn slice_to<'a>(&'a self, to: &Foo) -> &'a Foo { + * fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo { * println!("Slicing!"); * self * } - * fn slice<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo { + * fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo { * println!("Slicing!"); * self * } @@ -711,22 +711,7 @@ pub trait IndexMut { * } * ``` */ -#[cfg(not(stage0))] -#[lang="slice"] -pub trait Slice 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<'a>(&'a self, from: &Idx) -> &'a Result; - /// The method for the slicing operation foo[..to] - fn slice_to<'a>(&'a self, to: &Idx) -> &'a Result; - /// The method for the slicing operation foo[from..to] - fn slice<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result; -} -/** - * - */ -#[cfg(stage0)] +// FIXME(#17273) remove the postscript _s #[lang="slice"] pub trait Slice for Sized? { /// The method for the slicing operation foo[] @@ -753,19 +738,19 @@ pub trait Slice for Sized? { * struct Foo; * * impl ::core::ops::SliceMut for Foo { - * fn as_mut_slice<'a>(&'a mut self) -> &'a mut Foo { + * fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo { * println!("Slicing!"); * self * } - * fn slice_from_mut<'a>(&'a mut self, from: &Foo) -> &'a mut Foo { + * fn slice_from_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_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_mut_<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo { * println!("Slicing!"); * self * } @@ -776,22 +761,7 @@ pub trait Slice for Sized? { * } * ``` */ -#[cfg(not(stage0))] -#[lang="slice_mut"] -pub trait SliceMut 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_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result; - /// The method for the slicing operation foo[..to] - fn slice_to_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result; - /// The method for the slicing operation foo[from..to] - fn slice_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result; -} -/** - * - */ -#[cfg(stage0)] +// FIXME(#17273) remove the postscript _s #[lang="slice_mut"] pub trait SliceMut for Sized? { /// The method for the slicing operation foo[mut] @@ -803,7 +773,6 @@ pub trait SliceMut for Sized? { /// The method for the slicing operation foo[mut from..to] fn slice_mut_<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result; } - /** * * The `Deref` trait is used to specify the functionality of dereferencing diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 68b3a3199df..b8828d310f0 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -61,6 +61,32 @@ /// Extension methods for immutable slices. #[unstable = "may merge with other traits; region parameter may disappear"] pub trait ImmutableSlice<'a, T> { + /// Returns a subslice spanning the interval [`start`, `end`). + /// + /// Fails 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 = "waiting on final error conventions"] + //fn slice(&self, start: uint, end: uint) -> &'a [T]; + + /// Returns a subslice from `start` to the end of the slice. + /// + /// Fails when `start` is strictly greater than the length of the original slice. + /// + /// Slicing from `self.len()` yields an empty slice. + #[unstable = "waiting on final error conventions"] + // TODO + //fn slice_from(&self, start: uint) -> &'a [T]; + + /// Returns a subslice from the start of the slice to `end`. + /// + /// Fails when `end` is strictly greater than the length of the original slice. + /// + /// Slicing to `0` yields an empty slice. + #[unstable = "waiting on final error conventions"] + //fn slice_to(&self, end: uint) -> &'a [T]; + /// Divides one slice into two at an index. /// /// The first will contain all indices from `[0, mid)` (excluding @@ -418,35 +444,6 @@ fn pop_ref(&mut self) -> Option<&'a T> { } } -#[cfg(not(stage0))] -impl ops::Slice for [T] { - #[inline] - fn as_slice<'a>(&'a self) -> &'a [T] { - self - } - - #[inline] - fn slice_from<'a>(&'a self, start: &uint) -> &'a [T] { - self.slice(start, &self.len()) - } - - #[inline] - fn slice_to<'a>(&'a self, end: &uint) -> &'a [T] { - self.slice(&0, end) - } - #[inline] - fn slice<'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 ops::Slice for [T] { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -474,36 +471,7 @@ fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { } } } -#[cfg(not(stage0))] -impl ops::SliceMut for [T] { - #[inline] - fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { - self - } - - #[inline] - fn slice_from_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] { - let len = &self.len(); - self.slice_mut(start, len) - } - #[inline] - fn slice_to_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] { - self.slice_mut(&0, end) - } - #[inline] - fn slice_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 ops::SliceMut for [T] { #[inline] fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { @@ -546,6 +514,49 @@ pub trait MutableSlice<'a, T> { #[deprecated = "use slicing syntax"] fn as_mut_slice(self) -> &'a mut [T]; + /// Deprecated: use `slice_mut`. + #[deprecated = "use slicing syntax"] + //fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { + // self[mut start..end] + //} + + /// Returns a mutable subslice spanning the interval [`start`, `end`). + /// + /// Fails 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 = "waiting on final error conventions"] + //fn slice_mut(self, start: uint, end: uint) -> &'a mut [T]; + + /// Deprecated: use `slicing syntax`. + #[deprecated = "use slicing syntax"] + //fn mut_slice_from(self, start: uint) -> &'a mut [T] { + // self[mut start..] + //} + + /// Returns a mutable subslice from `start` to the end of the slice. + /// + /// Fails when `start` is strictly greater than the length of the original slice. + /// + /// Slicing from `self.len()` yields an empty slice. + #[unstable = "waiting on final error conventions"] + //fn slice_from_mut(self, start: uint) -> &'a mut [T]; + + /// Deprecated: use `slicing syntax`. + #[deprecated = "use slicing syntax"] + //fn mut_slice_to(self, end: uint) -> &'a mut [T] { + // self[mut ..end] + //} + + /// Returns a mutable subslice from the start of the slice to `end`. + /// + /// Fails when `end` is strictly greater than the length of the original slice. + /// + /// Slicing to `0` yields an empty slice. + #[unstable = "waiting on final error conventions"] + //fn slice_to_mut(self, end: uint) -> &'a mut [T]; + /// Deprecated: use `iter_mut`. #[deprecated = "use iter_mut"] fn mut_iter(self) -> MutItems<'a, T> { diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index e84c8947967..f2410745e4a 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -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_(&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_(&0, &0).iter().any(|_| fail!())); } #[test] diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 5f7f77ea7da..d0e8bcf2d2e 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2271,10 +2271,10 @@ 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", - (&None, &None) => "as_mut_slice", + (&Some(_), &Some(_)) => "slice_mut_", + (&Some(_), &None) => "slice_from_mut_", + (&None, &Some(_)) => "slice_to_mut_", + (&None, &None) => "as_mut_slice_", }; method::lookup_in_trait(fcx, @@ -2296,10 +2296,10 @@ 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", - (&None, &None) => "as_slice", + (&Some(_), &Some(_)) => "slice_", + (&Some(_), &None) => "slice_from_", + (&None, &Some(_)) => "slice_to_", + (&None, &None) => "as_slice_", }; method::lookup_in_trait(fcx, diff --git a/src/test/run-pass/slice.rs b/src/test/run-pass/slice.rs index 661ff055dc2..39feb075add 100644 --- a/src/test/run-pass/slice.rs +++ b/src/test/run-pass/slice.rs @@ -18,38 +18,38 @@ struct Foo; impl Slice for Foo { - fn as_slice<'a>(&'a self) -> &'a Foo { + 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_<'a>(&'a self, _from: &Foo) -> &'a Foo { unsafe { COUNT += 1; } self } - fn slice_to<'a>(&'a self, _to: &Foo) -> &'a Foo { + fn slice_to_<'a>(&'a self, _to: &Foo) -> &'a Foo { unsafe { COUNT += 1; } self } - fn slice<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo { + fn slice_<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo { unsafe { COUNT += 1; } self } } impl SliceMut for Foo { - fn as_mut_slice<'a>(&'a mut self) -> &'a mut Foo { + 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_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_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_mut_<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo { unsafe { COUNT += 1; } self } -- GitLab