diff options
| author | bors <bors@rust-lang.org> | 2015-02-17 05:57:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-17 05:57:55 +0000 |
| commit | f1bb6c2f46f08c1d7b6d695f5b3cf93142cb8860 (patch) | |
| tree | 98ca2711a34754a09d5eedaa32770aed248a7dce /src/libcore | |
| parent | 22224ca4499247e99e18fba8a18a4259f0e4d08b (diff) | |
| parent | 35ee89599cb50be74270e6475f4bbe182e769892 (diff) | |
| download | rust-f1bb6c2f46f08c1d7b6d695f5b3cf93142cb8860.tar.gz rust-f1bb6c2f46f08c1d7b6d695f5b3cf93142cb8860.zip | |
Auto merge of #22397 - Manishearth:rollup, r=huonw
None
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/array.rs | 24 | ||||
| -rw-r--r-- | src/libcore/finally.rs | 2 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 26 | ||||
| -rw-r--r-- | src/libcore/ops.rs | 26 | ||||
| -rw-r--r-- | src/libcore/option.rs | 56 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 40 | ||||
| -rw-r--r-- | src/libcore/result.rs | 96 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 24 |
8 files changed, 184 insertions, 110 deletions
diff --git a/src/libcore/array.rs b/src/libcore/array.rs index a596fe4a588..abaa7594d04 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -48,6 +48,8 @@ macro_rules! array_impls { } } + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T; $N] { type IntoIter = Iter<'a, T>; @@ -56,7 +58,29 @@ macro_rules! array_impls { } } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + impl<'a, T> IntoIterator for &'a [T; $N] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } + } + + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] + impl<'a, T> IntoIterator for &'a mut [T; $N] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } + } + + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T; $N] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs index 182851002d9..562a597cccf 100644 --- a/src/libcore/finally.rs +++ b/src/libcore/finally.rs @@ -72,7 +72,7 @@ impl<T, F> Finally<T> for F where F: FnMut() -> T { /// ``` /// use std::finally::try_finally; /// -/// struct State<'a> { buffer: &'a mut [u8], len: uint } +/// struct State<'a> { buffer: &'a mut [u8], len: usize } /// # let mut buf = []; /// let mut state = State { buffer: &mut buf, len: 0 }; /// try_finally( diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 06aba2cb08e..03c473ed967 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -118,6 +118,8 @@ pub trait FromIterator<A> { fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self; } +// NOTE(stage0): remove trait after a snapshot +#[cfg(stage0)] /// Conversion into an `Iterator` pub trait IntoIterator { type IntoIter: Iterator; @@ -127,6 +129,19 @@ pub trait IntoIterator { fn into_iter(self) -> Self::IntoIter; } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +/// Conversion into an `Iterator` +pub trait IntoIterator { + type Item; + type IntoIter: Iterator<Item=Self::Item>; + + /// Consumes `Self` and returns an iterator over it + #[stable(feature = "rust1", since = "1.0.0")] + fn into_iter(self) -> Self::IntoIter; +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<I> IntoIterator for I where I: Iterator { type IntoIter = I; @@ -135,6 +150,16 @@ impl<I> IntoIterator for I where I: Iterator { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<I: Iterator> IntoIterator for I { + type Item = I::Item; + type IntoIter = I; + + fn into_iter(self) -> I { + self + } +} + /// A type growable from an `Iterator` implementation #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend<A> { @@ -1055,6 +1080,7 @@ pub trait RandomAccessIterator: Iterator { #[stable(feature = "rust1", since = "1.0.0")] pub trait ExactSizeIterator: Iterator { #[inline] + #[stable(feature = "rust1", since = "1.0.0")] /// Return the exact length of the iterator. fn len(&self) -> usize { let (lower, upper) = self.size_hint(); diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index a46536e341e..fbd7f840da6 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -37,8 +37,8 @@ //! //! #[derive(Debug)] //! struct Point { -//! x: int, -//! y: int +//! x: i32, +//! y: i32 //! } //! //! impl Add for Point { @@ -206,7 +206,7 @@ macro_rules! add_impl { )*) } -add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Sub` trait is used to specify the functionality of `-`. /// @@ -259,7 +259,7 @@ macro_rules! sub_impl { )*) } -sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Mul` trait is used to specify the functionality of `*`. /// @@ -312,7 +312,7 @@ macro_rules! mul_impl { )*) } -mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Div` trait is used to specify the functionality of `/`. /// @@ -365,7 +365,7 @@ macro_rules! div_impl { )*) } -div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Rem` trait is used to specify the functionality of `%`. /// @@ -435,7 +435,7 @@ macro_rules! rem_float_impl { } } -rem_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } +rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 } rem_float_impl! { f32, fmodf } rem_float_impl! { f64, fmod } @@ -506,9 +506,9 @@ macro_rules! neg_uint_impl { } } -neg_impl! { int i8 i16 i32 i64 f32 f64 } +neg_impl! { isize i8 i16 i32 i64 f32 f64 } -neg_uint_impl! { uint, int } +neg_uint_impl! { usize, isize } neg_uint_impl! { u8, i8 } neg_uint_impl! { u16, i16 } neg_uint_impl! { u32, i32 } @@ -566,7 +566,7 @@ macro_rules! not_impl { )*) } -not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitAnd` trait is used to specify the functionality of `&`. /// @@ -619,7 +619,7 @@ macro_rules! bitand_impl { )*) } -bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitOr` trait is used to specify the functionality of `|`. /// @@ -672,7 +672,7 @@ macro_rules! bitor_impl { )*) } -bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitXor` trait is used to specify the functionality of `^`. /// @@ -725,7 +725,7 @@ macro_rules! bitxor_impl { )*) } -bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `Shl` trait is used to specify the functionality of `<<`. /// diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 081c895c317..3dc94ba555f 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -60,19 +60,19 @@ //! the optional owned box, `Option<Box<T>>`. //! //! The following example uses `Option` to create an optional box of -//! `int`. Notice that in order to use the inner `int` value first the +//! `i32`. Notice that in order to use the inner `i32` value first the //! `check_optional` function needs to use pattern matching to //! determine whether the box has a value (i.e. it is `Some(...)`) or //! not (`None`). //! //! ``` -//! let optional: Option<Box<int>> = None; +//! let optional: Option<Box<i32>> = None; //! check_optional(&optional); //! -//! let optional: Option<Box<int>> = Some(Box::new(9000)); +//! let optional: Option<Box<i32>> = Some(Box::new(9000)); //! check_optional(&optional); //! -//! fn check_optional(optional: &Option<Box<int>>) { +//! fn check_optional(optional: &Option<Box<i32>>) { //! match *optional { //! Some(ref p) => println!("have value {}", p), //! None => println!("have no value") @@ -108,7 +108,7 @@ //! Initialize a result to `None` before a loop: //! //! ``` -//! enum Kingdom { Plant(uint, &'static str), Animal(uint, &'static str) } +//! enum Kingdom { Plant(u32, &'static str), Animal(u32, &'static str) } //! //! // A list of data to search through. //! let all_the_big_things = [ @@ -188,10 +188,10 @@ impl<T> Option<T> { /// # Example /// /// ``` - /// let x: Option<uint> = Some(2); + /// let x: Option<u32> = Some(2); /// assert_eq!(x.is_some(), true); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// assert_eq!(x.is_some(), false); /// ``` #[inline] @@ -208,10 +208,10 @@ impl<T> Option<T> { /// # Example /// /// ``` - /// let x: Option<uint> = Some(2); + /// let x: Option<u32> = Some(2); /// assert_eq!(x.is_none(), false); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// assert_eq!(x.is_none(), true); /// ``` #[inline] @@ -228,7 +228,7 @@ impl<T> Option<T> { /// /// # Example /// - /// Convert an `Option<String>` into an `Option<int>`, preserving the original. + /// Convert an `Option<String>` into an `Option<usize>`, preserving the original. /// The `map` method takes the `self` argument by value, consuming the original, /// so this technique uses `as_ref` to first take an `Option` to a reference /// to the value inside the original. @@ -237,7 +237,7 @@ impl<T> Option<T> { /// let num_as_str: Option<String> = Some("10".to_string()); /// // First, cast `Option<String>` to `Option<&String>` with `as_ref`, /// // then consume *that* with `map`, leaving `num_as_str` on the stack. - /// let num_as_int: Option<uint> = num_as_str.as_ref().map(|n| n.len()); + /// let num_as_int: Option<usize> = num_as_str.as_ref().map(|n| n.len()); /// println!("still can print num_as_str: {:?}", num_as_str); /// ``` #[inline] @@ -406,12 +406,12 @@ impl<T> Option<T> { /// /// # Example /// - /// Convert an `Option<String>` into an `Option<uint>`, consuming the original: + /// Convert an `Option<String>` into an `Option<usize>`, consuming the original: /// /// ``` /// let num_as_str: Option<String> = Some("10".to_string()); /// // `Option::map` takes self *by value*, consuming `num_as_str` - /// let num_as_int: Option<uint> = num_as_str.map(|n| n.len()); + /// let num_as_int: Option<usize> = num_as_str.map(|n| n.len()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -518,7 +518,7 @@ impl<T> Option<T> { /// let x = Some(4); /// assert_eq!(x.iter().next(), Some(&4)); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// assert_eq!(x.iter().next(), None); /// ``` #[inline] @@ -539,7 +539,7 @@ impl<T> Option<T> { /// } /// assert_eq!(x, Some(42)); /// - /// let mut x: Option<uint> = None; + /// let mut x: Option<u32> = None; /// assert_eq!(x.iter_mut().next(), None); /// ``` #[inline] @@ -581,7 +581,7 @@ impl<T> Option<T> { /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// let y = Some("foo"); /// assert_eq!(x.and(y), None); /// @@ -589,7 +589,7 @@ impl<T> Option<T> { /// let y = Some("foo"); /// assert_eq!(x.and(y), Some("foo")); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// ``` @@ -608,8 +608,8 @@ impl<T> Option<T> { /// # Example /// /// ``` - /// fn sq(x: uint) -> Option<uint> { Some(x * x) } - /// fn nope(_: uint) -> Option<uint> { None } + /// fn sq(x: u32) -> Option<u32> { Some(x * x) } + /// fn nope(_: u32) -> Option<u32> { None } /// /// assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16)); /// assert_eq!(Some(2).and_then(sq).and_then(nope), None); @@ -642,7 +642,7 @@ impl<T> Option<T> { /// let y = Some(100); /// assert_eq!(x.or(y), Some(2)); /// - /// let x: Option<uint> = None; + /// let x: Option<u32> = None; /// let y = None; /// assert_eq!(x.or(y), None); /// ``` @@ -690,7 +690,7 @@ impl<T> Option<T> { /// x.take(); /// assert_eq!(x, None); /// - /// let mut x: Option<uint> = None; + /// let mut x: Option<u32> = None; /// x.take(); /// assert_eq!(x, None); /// ``` @@ -789,7 +789,7 @@ impl<A> Iterator for Item<A> { } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { + fn size_hint(&self) -> (usize, Option<usize>) { match self.opt { Some(_) => (1, Some(1)), None => (0, Some(0)), @@ -817,7 +817,7 @@ impl<'a, A> Iterator for Iter<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -847,7 +847,7 @@ impl<'a, A> Iterator for IterMut<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -870,7 +870,7 @@ impl<A> Iterator for IntoIter<A> { #[inline] fn next(&mut self) -> Option<A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -896,11 +896,11 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> { /// checking for overflow: /// /// ```rust - /// use std::uint; + /// use std::u16; /// /// let v = vec!(1, 2); - /// let res: Option<Vec<uint>> = v.iter().map(|&x: &uint| - /// if x == uint::MAX { None } + /// let res: Option<Vec<u16>> = v.iter().map(|&x: &u16| + /// if x == u16::MAX { None } /// else { Some(x + 1) } /// ).collect(); /// assert!(res == Some(vec!(2, 3))); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 1b8ec048f8d..072c60c7036 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -27,10 +27,10 @@ //! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`). //! //! ``` -//! let my_num: int = 10; -//! let my_num_ptr: *const int = &my_num; -//! let mut my_speed: int = 88; -//! let my_speed_ptr: *mut int = &mut my_speed; +//! let my_num: i32 = 10; +//! let my_num_ptr: *const i32 = &my_num; +//! let mut my_speed: i32 = 88; +//! let my_speed_ptr: *mut i32 = &mut my_speed; //! ``` //! //! This does not take ownership of the original allocation @@ -49,15 +49,15 @@ //! use std::mem; //! //! unsafe { -//! let my_num: Box<int> = Box::new(10); -//! let my_num: *const int = mem::transmute(my_num); -//! let my_speed: Box<int> = Box::new(88); -//! let my_speed: *mut int = mem::transmute(my_speed); +//! let my_num: Box<i32> = Box::new(10); +//! let my_num: *const i32 = mem::transmute(my_num); +//! let my_speed: Box<i32> = Box::new(88); +//! let my_speed: *mut i32 = mem::transmute(my_speed); //! //! // By taking ownership of the original `Box<T>` though //! // we are obligated to transmute it back later to be destroyed. -//! drop(mem::transmute::<_, Box<int>>(my_speed)); -//! drop(mem::transmute::<_, Box<int>>(my_num)); +//! drop(mem::transmute::<_, Box<i32>>(my_speed)); +//! drop(mem::transmute::<_, Box<i32>>(my_num)); //! } //! ``` //! @@ -73,7 +73,7 @@ //! //! fn main() { //! unsafe { -//! let my_num: *mut int = libc::malloc(mem::size_of::<int>() as libc::size_t) as *mut int; +//! let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>() as libc::size_t) as *mut i32; //! if my_num.is_null() { //! panic!("failed to allocate memory"); //! } @@ -117,7 +117,7 @@ pub use intrinsics::set_memory; /// ``` /// use std::ptr; /// -/// let p: *const int = ptr::null(); +/// let p: *const i32 = ptr::null(); /// assert!(p.is_null()); /// ``` #[inline] @@ -131,7 +131,7 @@ pub fn null<T>() -> *const T { 0 as *const T } /// ``` /// use std::ptr; /// -/// let p: *mut int = ptr::null_mut(); +/// let p: *mut i32 = ptr::null_mut(); /// assert!(p.is_null()); /// ``` #[inline] @@ -148,7 +148,7 @@ pub fn null_mut<T>() -> *mut T { 0 as *mut T } #[inline] #[unstable(feature = "core", reason = "may play a larger role in std::ptr future extensions")] -pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) { +pub unsafe fn zero_memory<T>(dst: *mut T, count: usize) { set_memory(dst, 0, count); } @@ -276,7 +276,7 @@ pub trait PtrExt: Sized { /// Otherwise `offset` invokes Undefined Behaviour, regardless of whether /// the pointer is used. #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> Self; + unsafe fn offset(self, count: isize) -> Self; } /// Methods on mutable raw pointers @@ -303,11 +303,11 @@ impl<T> PtrExt for *const T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as uint == 0 } + fn is_null(self) -> bool { self as usize == 0 } #[inline] #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> *const T { + unsafe fn offset(self, count: isize) -> *const T { intrinsics::offset(self, count) } @@ -330,11 +330,11 @@ impl<T> PtrExt for *mut T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as uint == 0 } + fn is_null(self) -> bool { self as usize == 0 } #[inline] #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> *mut T { + unsafe fn offset(self, count: isize) -> *mut T { intrinsics::offset(self, count) as *mut T } @@ -553,7 +553,7 @@ impl<T> Unique<T> { /// Return an (unsafe) pointer into the memory owned by `self`. #[unstable(feature = "core", reason = "recently added to this module")] - pub unsafe fn offset(self, offset: int) -> *mut T { + pub unsafe fn offset(self, offset: isize) -> *mut T { self.ptr.offset(offset) } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index d610962f862..1a874ee178b 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -311,10 +311,10 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// assert_eq!(x.ok(), Some(2)); /// - /// let x: Result<uint, &str> = Err("Nothing here"); + /// let x: Result<u32, &str> = Err("Nothing here"); /// assert_eq!(x.ok(), None); /// ``` #[inline] @@ -334,10 +334,10 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// assert_eq!(x.err(), None); /// - /// let x: Result<uint, &str> = Err("Nothing here"); + /// let x: Result<u32, &str> = Err("Nothing here"); /// assert_eq!(x.err(), Some("Nothing here")); /// ``` #[inline] @@ -359,10 +359,10 @@ impl<T, E> Result<T, E> { /// into the original, leaving the original in place. /// /// ``` - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// assert_eq!(x.as_ref(), Ok(&2)); /// - /// let x: Result<uint, &str> = Err("Error"); + /// let x: Result<u32, &str> = Err("Error"); /// assert_eq!(x.as_ref(), Err(&"Error")); /// ``` #[inline] @@ -404,7 +404,7 @@ impl<T, E> Result<T, E> { /// Convert from `Result<T, E>` to `&mut [T]` (without copying) /// /// ``` - /// let mut x: Result<&str, uint> = Ok("Gold"); + /// let mut x: Result<&str, u32> = Ok("Gold"); /// { /// let v = x.as_mut_slice(); /// assert!(v == ["Gold"]); @@ -413,7 +413,7 @@ impl<T, E> Result<T, E> { /// } /// assert_eq!(x, Ok("Silver")); /// - /// let mut x: Result<&str, uint> = Err(45); + /// let mut x: Result<&str, u32> = Err(45); /// assert!(x.as_mut_slice().is_empty()); /// ``` #[inline] @@ -481,12 +481,12 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// fn stringify(x: uint) -> String { format!("error code: {}", x) } + /// fn stringify(x: u32) -> String { format!("error code: {}", x) } /// - /// let x: Result<uint, uint> = Ok(2); + /// let x: Result<u32, u32> = Ok(2); /// assert_eq!(x.map_err(stringify), Ok(2)); /// - /// let x: Result<uint, uint> = Err(13); + /// let x: Result<u32, u32> = Err(13); /// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string())); /// ``` #[inline] @@ -507,10 +507,10 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(7); + /// let x: Result<u32, &str> = Ok(7); /// assert_eq!(x.iter().next(), Some(&7)); /// - /// let x: Result<uint, &str> = Err("nothing!"); + /// let x: Result<u32, &str> = Err("nothing!"); /// assert_eq!(x.iter().next(), None); /// ``` #[inline] @@ -524,14 +524,14 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let mut x: Result<uint, &str> = Ok(7); + /// let mut x: Result<u32, &str> = Ok(7); /// match x.iter_mut().next() { /// Some(&mut ref mut x) => *x = 40, /// None => {}, /// } /// assert_eq!(x, Ok(40)); /// - /// let mut x: Result<uint, &str> = Err("nothing!"); + /// let mut x: Result<u32, &str> = Err("nothing!"); /// assert_eq!(x.iter_mut().next(), None); /// ``` #[inline] @@ -545,12 +545,12 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(5); - /// let v: Vec<uint> = x.into_iter().collect(); + /// let x: Result<u32, &str> = Ok(5); + /// let v: Vec<u32> = x.into_iter().collect(); /// assert_eq!(v, vec![5]); /// - /// let x: Result<uint, &str> = Err("nothing!"); - /// let v: Vec<uint> = x.into_iter().collect(); + /// let x: Result<u32, &str> = Err("nothing!"); + /// let v: Vec<u32> = x.into_iter().collect(); /// assert_eq!(v, vec![]); /// ``` #[inline] @@ -568,19 +568,19 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// let y: Result<&str, &str> = Err("late error"); /// assert_eq!(x.and(y), Err("late error")); /// - /// let x: Result<uint, &str> = Err("early error"); + /// let x: Result<u32, &str> = Err("early error"); /// let y: Result<&str, &str> = Ok("foo"); /// assert_eq!(x.and(y), Err("early error")); /// - /// let x: Result<uint, &str> = Err("not a 2"); + /// let x: Result<u32, &str> = Err("not a 2"); /// let y: Result<&str, &str> = Err("late error"); /// assert_eq!(x.and(y), Err("not a 2")); /// - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// let y: Result<&str, &str> = Ok("different result type"); /// assert_eq!(x.and(y), Ok("different result type")); /// ``` @@ -600,8 +600,8 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// fn sq(x: uint) -> Result<uint, uint> { Ok(x * x) } - /// fn err(x: uint) -> Result<uint, uint> { Err(x) } + /// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) } + /// fn err(x: u32) -> Result<u32, u32> { Err(x) } /// /// assert_eq!(Ok(2).and_then(sq).and_then(sq), Ok(16)); /// assert_eq!(Ok(2).and_then(sq).and_then(err), Err(4)); @@ -622,20 +622,20 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(2); - /// let y: Result<uint, &str> = Err("late error"); + /// let x: Result<u32, &str> = Ok(2); + /// let y: Result<u32, &str> = Err("late error"); /// assert_eq!(x.or(y), Ok(2)); /// - /// let x: Result<uint, &str> = Err("early error"); - /// let y: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Err("early error"); + /// let y: Result<u32, &str> = Ok(2); /// assert_eq!(x.or(y), Ok(2)); /// - /// let x: Result<uint, &str> = Err("not a 2"); - /// let y: Result<uint, &str> = Err("late error"); + /// let x: Result<u32, &str> = Err("not a 2"); + /// let y: Result<u32, &str> = Err("late error"); /// assert_eq!(x.or(y), Err("late error")); /// - /// let x: Result<uint, &str> = Ok(2); - /// let y: Result<uint, &str> = Ok(100); + /// let x: Result<u32, &str> = Ok(2); + /// let y: Result<u32, &str> = Ok(100); /// assert_eq!(x.or(y), Ok(2)); /// ``` #[inline] @@ -654,8 +654,8 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// fn sq(x: uint) -> Result<uint, uint> { Ok(x * x) } - /// fn err(x: uint) -> Result<uint, uint> { Err(x) } + /// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) } + /// fn err(x: u32) -> Result<u32, u32> { Err(x) } /// /// assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); /// assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); @@ -678,10 +678,10 @@ impl<T, E> Result<T, E> { /// /// ``` /// let optb = 2; - /// let x: Result<uint, &str> = Ok(9); + /// let x: Result<u32, &str> = Ok(9); /// assert_eq!(x.unwrap_or(optb), 9); /// - /// let x: Result<uint, &str> = Err("error"); + /// let x: Result<u32, &str> = Err("error"); /// assert_eq!(x.unwrap_or(optb), optb); /// ``` #[inline] @@ -699,7 +699,7 @@ impl<T, E> Result<T, E> { /// # Example /// /// ``` - /// fn count(x: &str) -> uint { x.len() } + /// fn count(x: &str) -> usize { x.len() } /// /// assert_eq!(Ok(2).unwrap_or_else(count), 2); /// assert_eq!(Err("foo").unwrap_or_else(count), 3); @@ -726,12 +726,12 @@ impl<T, E: fmt::Debug> Result<T, E> { /// # Example /// /// ``` - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// assert_eq!(x.unwrap(), 2); /// ``` /// /// ```{.should_fail} - /// let x: Result<uint, &str> = Err("emergency failure"); + /// let x: Result<u32, &str> = Err("emergency failure"); /// x.unwrap(); // panics with `emergency failure` /// ``` #[inline] @@ -757,12 +757,12 @@ impl<T: fmt::Debug, E> Result<T, E> { /// # Example /// /// ```{.should_fail} - /// let x: Result<uint, &str> = Ok(2); + /// let x: Result<u32, &str> = Ok(2); /// x.unwrap_err(); // panics with `2` /// ``` /// /// ``` - /// let x: Result<uint, &str> = Err("emergency failure"); + /// let x: Result<u32, &str> = Err("emergency failure"); /// assert_eq!(x.unwrap_err(), "emergency failure"); /// ``` #[inline] @@ -811,7 +811,7 @@ impl<'a, T> Iterator for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { + fn size_hint(&self) -> (usize, Option<usize>) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -841,7 +841,7 @@ impl<'a, T> Iterator for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { + fn size_hint(&self) -> (usize, Option<usize>) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -867,7 +867,7 @@ impl<T> Iterator for IntoIter<T> { #[inline] fn next(&mut self) -> Option<T> { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option<uint>) { + fn size_hint(&self) -> (usize, Option<usize>) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -896,11 +896,11 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> { /// checking for overflow: /// /// ```rust - /// use std::uint; + /// use std::u32; /// /// let v = vec!(1, 2); - /// let res: Result<Vec<uint>, &'static str> = v.iter().map(|&x: &uint| - /// if x == uint::MAX { Err("Overflow!") } + /// let res: Result<Vec<u32>, &'static str> = v.iter().map(|&x: &u32| + /// if x == u32::MAX { Err("Overflow!") } /// else { Ok(x + 1) } /// ).collect(); /// assert!(res == Ok(vec!(2, 3))); diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 097633b7063..cd91843f359 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -626,6 +626,8 @@ impl<'a, T> Default for &'a [T] { // Iterators // +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T] { type IntoIter = Iter<'a, T>; @@ -634,7 +636,29 @@ impl<'a, T> IntoIterator for &'a [T] { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a [T] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut [T] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { |
