Revert "Remove the `_` suffix from slice methods."

This reverts commit df2f1fa768.
This commit is contained in:
Aaron Turon 2014-10-02 11:47:58 -07:00
parent 7bf56df4c8
commit c0c6c89589
7 changed files with 97 additions and 188 deletions

View File

@ -389,7 +389,6 @@ 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,
@ -397,14 +396,6 @@ impl<T> TrieMap<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 @@ impl<T> TrieMap<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 @@ impl<T> TrieMap<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"]

View File

@ -24,7 +24,6 @@ use core::num;
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 @@ impl<T> Index<uint,T> for Vec<T> {
}
}*/
// Annoying helper function because there are two Slice::as_slice functions in
// scope.
#[inline]
fn slice_to_slice<'a, T, U: Slice<T>>(this: &'a U) -> &'a [T] {
this.as_slice()
}
#[cfg(not(stage0))]
impl<T> ops::Slice<uint, [T]> for Vec<T> {
#[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<T> ops::Slice<uint, [T]> for Vec<T> {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
@ -512,28 +481,6 @@ impl<T> ops::Slice<uint, [T]> for Vec<T> {
}
}
#[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_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<T> ops::SliceMut<uint, [T]> for Vec<T> {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {

View File

@ -688,19 +688,19 @@ pub trait IndexMut<Index, Result> {
* struct Foo;
*
* impl ::core::ops::Slice<Foo, Foo> 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<Index, Result> {
* }
* ```
*/
#[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<'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<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[]
@ -753,19 +738,19 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
* struct Foo;
*
* impl ::core::ops::SliceMut<Foo, Foo> 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<Idx, Sized? Result> for Sized? {
* }
* ```
*/
#[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_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<Idx, Sized? Result> for Sized? {
/// The method for the slicing operation foo[mut]
@ -803,7 +773,6 @@ pub trait SliceMut<Idx, Sized? Result> 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

View File

@ -61,6 +61,32 @@ use raw::Slice as RawSlice;
/// 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 @@ impl<'a,T> ImmutableSlice<'a, T> for &'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<'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<T> ops::Slice<uint, [T]> for [T] {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
@ -474,36 +471,7 @@ impl<T> ops::Slice<uint, [T]> for [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_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<T> ops::SliceMut<uint, [T]> 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> {

View 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_(&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]

View File

@ -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,

View File

@ -18,38 +18,38 @@ static mut COUNT: uint = 0;
struct Foo;
impl Slice<Foo, Foo> 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<Foo, Foo> 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
}