diff options
| author | bors <bors@rust-lang.org> | 2015-02-03 03:44:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-03 03:44:05 +0000 |
| commit | 7858cb432d3f2efc0374424cb2b51518f697c172 (patch) | |
| tree | bccd460a861e61f758d2d459cb9da02b1ad8792b /src/libcore | |
| parent | eaf4c5c784637f3df8bdebc6ec21dbd4bc69420a (diff) | |
| parent | 9ece22ee00033cdf0b6b418c451112c92c8ad922 (diff) | |
| download | rust-7858cb432d3f2efc0374424cb2b51518f697c172.tar.gz rust-7858cb432d3f2efc0374424cb2b51518f697c172.zip | |
Auto merge of #21872 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/array.rs | 3 | ||||
| -rw-r--r-- | src/libcore/atomic.rs | 20 | ||||
| -rw-r--r-- | src/libcore/cell.rs | 55 | ||||
| -rw-r--r-- | src/libcore/char.rs | 194 | ||||
| -rw-r--r-- | src/libcore/fmt/mod.rs | 67 | ||||
| -rw-r--r-- | src/libcore/fmt/rt/v1.rs | 13 | ||||
| -rw-r--r-- | src/libcore/hash/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 364 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/ops.rs | 17 | ||||
| -rw-r--r-- | src/libcore/prelude.rs | 3 | ||||
| -rw-r--r-- | src/libcore/result.rs | 2 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 13 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 14 |
14 files changed, 366 insertions, 402 deletions
diff --git a/src/libcore/array.rs b/src/libcore/array.rs index ec3d9783255..5c4567e567b 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -20,9 +20,6 @@ use fmt; use hash::{Hash, Hasher, self}; use iter::IntoIterator; use marker::Copy; -#[cfg(stage0)] -use ops::{Deref, FullRange}; -#[cfg(not(stage0))] use ops::Deref; use option::Option; use slice::{Iter, IterMut, SliceExt}; diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index cf2854be016..0f3823eb7a5 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -415,6 +415,7 @@ impl AtomicIsize { /// let atomic_forty_two = AtomicIsize::new(42); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn new(v: isize) -> AtomicIsize { AtomicIsize {v: UnsafeCell::new(v)} } @@ -437,6 +438,7 @@ impl AtomicIsize { /// let value = some_isize.load(Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn load(&self, order: Ordering) -> isize { unsafe { atomic_load(self.v.get(), order) } } @@ -459,6 +461,7 @@ impl AtomicIsize { /// /// Panics if `order` is `Acquire` or `AcqRel`. #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, val: isize, order: Ordering) { unsafe { atomic_store(self.v.get(), val, order); } } @@ -477,6 +480,7 @@ impl AtomicIsize { /// let value = some_isize.swap(10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn swap(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_swap(self.v.get(), val, order) } } @@ -498,6 +502,7 @@ impl AtomicIsize { /// let value = some_isize.compare_and_swap(5, 10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn compare_and_swap(&self, old: isize, new: isize, order: Ordering) -> isize { unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } } @@ -514,6 +519,7 @@ impl AtomicIsize { /// assert_eq!(10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_add(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_add(self.v.get(), val, order) } } @@ -530,6 +536,7 @@ impl AtomicIsize { /// assert_eq!(-10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_sub(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_sub(self.v.get(), val, order) } } @@ -545,6 +552,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_and(0b110011, Ordering::SeqCst)); /// assert_eq!(0b100001, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_and(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_and(self.v.get(), val, order) } } @@ -560,6 +568,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_or(0b110011, Ordering::SeqCst)); /// assert_eq!(0b111111, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_or(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_or(self.v.get(), val, order) } } @@ -575,6 +584,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_xor(0b110011, Ordering::SeqCst)); /// assert_eq!(0b011110, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_xor(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_xor(self.v.get(), val, order) } } @@ -592,6 +602,7 @@ impl AtomicUsize { /// let atomic_forty_two = AtomicUsize::new(42); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn new(v: usize) -> AtomicUsize { AtomicUsize { v: UnsafeCell::new(v) } } @@ -614,6 +625,7 @@ impl AtomicUsize { /// let value = some_usize.load(Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn load(&self, order: Ordering) -> usize { unsafe { atomic_load(self.v.get(), order) } } @@ -636,6 +648,7 @@ impl AtomicUsize { /// /// Panics if `order` is `Acquire` or `AcqRel`. #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, val: usize, order: Ordering) { unsafe { atomic_store(self.v.get(), val, order); } } @@ -654,6 +667,7 @@ impl AtomicUsize { /// let value = some_usize.swap(10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn swap(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_swap(self.v.get(), val, order) } } @@ -675,6 +689,7 @@ impl AtomicUsize { /// let value = some_usize.compare_and_swap(5, 10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn compare_and_swap(&self, old: usize, new: usize, order: Ordering) -> usize { unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } } @@ -691,6 +706,7 @@ impl AtomicUsize { /// assert_eq!(10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_add(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_add(self.v.get(), val, order) } } @@ -707,6 +723,7 @@ impl AtomicUsize { /// assert_eq!(0, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_sub(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_sub(self.v.get(), val, order) } } @@ -722,6 +739,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_and(0b110011, Ordering::SeqCst)); /// assert_eq!(0b100001, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_and(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_and(self.v.get(), val, order) } } @@ -737,6 +755,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_or(0b110011, Ordering::SeqCst)); /// assert_eq!(0b111111, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_or(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_or(self.v.get(), val, order) } } @@ -752,6 +771,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_xor(0b110011, Ordering::SeqCst)); /// assert_eq!(0b011110, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_xor(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_xor(self.v.get(), val, order) } } diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 65dccc8c244..c82d8c531d2 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -266,6 +266,18 @@ pub struct RefCell<T> { borrow: Cell<BorrowFlag>, } +/// An enumeration of values returned from the `state` method on a `RefCell<T>`. +#[derive(Copy, Clone, PartialEq, Debug)] +#[unstable(feature = "std_misc")] +pub enum BorrowState { + /// The cell is currently being read, there is at least one active `borrow`. + Reading, + /// The cell is currently being written to, there is an active `borrow_mut`. + Writing, + /// There are no outstanding borrows on this cell. + Unused, +} + // Values [1, MAX-1] represent the number of `Ref` active // (will not outgrow its range since `uint` is the size of the address space) type BorrowFlag = uint; @@ -310,6 +322,19 @@ impl<T> RefCell<T> { unsafe { self.value.into_inner() } } + /// Query the current state of this `RefCell` + /// + /// The returned value can be dispatched on to determine if a call to + /// `borrow` or `borrow_mut` would succeed. + #[unstable(feature = "std_misc")] + pub fn borrow_state(&self) -> BorrowState { + match self.borrow.get() { + WRITING => BorrowState::Writing, + UNUSED => BorrowState::Unused, + _ => BorrowState::Reading, + } + } + /// Attempts to immutably borrow the wrapped value. /// /// The borrow lasts until the returned `Ref` exits scope. Multiple @@ -317,6 +342,8 @@ impl<T> RefCell<T> { /// /// Returns `None` if the value is currently mutably borrowed. #[unstable(feature = "core", reason = "may be renamed or removed")] + #[deprecated(since = "1.0.0", + reason = "dispatch on `cell.borrow_state()` instead")] pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> { match BorrowRef::new(&self.borrow) { Some(b) => Some(Ref { _value: unsafe { &*self.value.get() }, _borrow: b }), @@ -326,8 +353,8 @@ impl<T> RefCell<T> { /// Immutably borrows the wrapped value. /// - /// The borrow lasts until the returned `Ref` exits scope. Multiple immutable borrows can be - /// taken out at the same time. + /// The borrow lasts until the returned `Ref` exits scope. Multiple + /// immutable borrows can be taken out at the same time. /// /// # Panics /// @@ -361,9 +388,12 @@ impl<T> RefCell<T> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn borrow<'a>(&'a self) -> Ref<'a, T> { - match self.try_borrow() { - Some(ptr) => ptr, - None => panic!("RefCell<T> already mutably borrowed") + match BorrowRef::new(&self.borrow) { + Some(b) => Ref { + _value: unsafe { &*self.value.get() }, + _borrow: b, + }, + None => panic!("RefCell<T> already mutably borrowed"), } } @@ -374,6 +404,8 @@ impl<T> RefCell<T> { /// /// Returns `None` if the value is currently borrowed. #[unstable(feature = "core", reason = "may be renamed or removed")] + #[deprecated(since = "1.0.0", + reason = "dispatch on `cell.borrow_state()` instead")] pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> { match BorrowRefMut::new(&self.borrow) { Some(b) => Some(RefMut { _value: unsafe { &mut *self.value.get() }, _borrow: b }), @@ -383,8 +415,8 @@ impl<T> RefCell<T> { /// Mutably borrows the wrapped value. /// - /// The borrow lasts until the returned `RefMut` exits scope. The value cannot be borrowed - /// while this borrow is active. + /// The borrow lasts until the returned `RefMut` exits scope. The value + /// cannot be borrowed while this borrow is active. /// /// # Panics /// @@ -417,9 +449,12 @@ impl<T> RefCell<T> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> { - match self.try_borrow_mut() { - Some(ptr) => ptr, - None => panic!("RefCell<T> already borrowed") + match BorrowRefMut::new(&self.borrow) { + Some(b) => RefMut { + _value: unsafe { &mut *self.value.get() }, + _borrow: b, + }, + None => panic!("RefCell<T> already borrowed"), } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 22bfd47893c..28e0247f00a 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -67,7 +67,25 @@ static MAX_THREE_B: u32 = 0x10000u32; #[stable(feature = "rust1", since = "1.0.0")] pub const MAX: char = '\u{10ffff}'; -/// Converts from `u32` to a `char` +/// Converts a `u32` to an `Option<char>`. +/// +/// # Examples +/// +/// ``` +/// use std::char; +/// +/// let c = char::from_u32(10084); // produces `Some(❤)` +/// assert_eq!(c, Some('❤')); +/// ``` +/// +/// An invalid character: +/// +/// ``` +/// use std::char; +/// +/// let none = char::from_u32(1114112); +/// assert_eq!(none, None); +/// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn from_u32(i: u32) -> Option<char> { @@ -79,8 +97,7 @@ pub fn from_u32(i: u32) -> Option<char> { } } -/// -/// Converts a number to the character representing it +/// Converts a number to the character representing it. /// /// # Return value /// @@ -91,6 +108,15 @@ pub fn from_u32(i: u32) -> Option<char> { /// /// Panics if given an `radix` > 36. /// +/// # Examples +/// +/// ``` +/// use std::char; +/// +/// let c = char::from_digit(4, 10); +/// +/// assert_eq!(c, Some('4')); +/// ``` #[inline] #[unstable(feature = "core", reason = "pending integer conventions")] pub fn from_digit(num: uint, radix: uint) -> Option<char> { @@ -126,6 +152,16 @@ pub trait CharExt { /// # Panics /// /// Panics if given a radix > 36. + /// + /// # Examples + /// + /// ``` + /// let c = '1'; + /// + /// assert!(c.is_digit(10)); + /// + /// assert!('f'.is_digit(16)); + /// ``` #[unstable(feature = "core", reason = "pending integer conventions")] fn is_digit(self, radix: uint) -> bool; @@ -141,16 +177,53 @@ pub trait CharExt { /// # Panics /// /// Panics if given a radix outside the range [0..36]. + /// + /// # Examples + /// + /// ``` + /// let c = '1'; + /// + /// assert_eq!(c.to_digit(10), Some(1)); + /// + /// assert_eq!('f'.to_digit(16), Some(15)); + /// ``` #[unstable(feature = "core", reason = "pending integer conventions")] fn to_digit(self, radix: uint) -> Option<uint>; - /// Returns an iterator that yields the hexadecimal Unicode escape - /// of a character, as `char`s. + /// Returns an iterator that yields the hexadecimal Unicode escape of a character, as `char`s. + /// + /// All characters are escaped with Rust syntax of the form `\\u{NNNN}` where `NNNN` is the + /// shortest hexadecimal representation of the code point. + /// + /// # Examples + /// + /// ``` + /// for i in '❤'.escape_unicode() { + /// println!("{}", i); + /// } + /// ``` /// - /// All characters are escaped with Rust syntax of the form `\\u{NNNN}` - /// where `NNNN` is the shortest hexadecimal representation of the code - /// point. + /// This prints: + /// + /// ```text + /// \ + /// u + /// { + /// 2 + /// 7 + /// 6 + /// 4 + /// } + /// ``` + /// + /// Collecting into a `String`: + /// + /// ``` + /// let heart: String = '❤'.escape_unicode().collect(); + /// + /// assert_eq!(heart, r"\u{2764}"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn escape_unicode(self) -> EscapeUnicode; @@ -166,32 +239,113 @@ pub trait CharExt { /// escaped. /// * Any other chars in the range [0x20,0x7e] are not escaped. /// * Any other chars are given hex Unicode escapes; see `escape_unicode`. + /// + /// # Examples + /// + /// ``` + /// for i in '"'.escape_default() { + /// println!("{}", i); + /// } + /// ``` + /// + /// This prints: + /// + /// ```text + /// \ + /// " + /// ``` + /// + /// Collecting into a `String`: + /// + /// ``` + /// let quote: String = '"'.escape_default().collect(); + /// + /// assert_eq!(quote, "\\\""); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn escape_default(self) -> EscapeDefault; - /// Returns the amount of bytes this character would need if encoded in - /// UTF-8. + /// Returns the number of bytes this character would need if encoded in UTF-8. + /// + /// # Examples + /// + /// ``` + /// let n = 'ß'.len_utf8(); + /// + /// assert_eq!(n, 2); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn len_utf8(self) -> uint; - /// Returns the amount of bytes this character would need if encoded in - /// UTF-16. + /// Returns the number of bytes this character would need if encoded in UTF-16. + /// + /// # Examples + /// + /// ``` + /// let n = 'ß'.len_utf16(); + /// + /// assert_eq!(n, 1); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn len_utf16(self) -> uint; - /// Encodes this character as UTF-8 into the provided byte buffer, - /// and then returns the number of bytes written. + /// Encodes this character as UTF-8 into the provided byte buffer, and then returns the number + /// of bytes written. + /// + /// If the buffer is not large enough, nothing will be written into it and a `None` will be + /// returned. + /// + /// # Examples + /// + /// In both of these examples, 'ß' takes two bytes to encode. + /// + /// ``` + /// let mut b = [0; 2]; /// - /// If the buffer is not large enough, nothing will be written into it - /// and a `None` will be returned. + /// let result = 'ß'.encode_utf8(&mut b); + /// + /// assert_eq!(result, Some(2)); + /// ``` + /// + /// A buffer that's too small: + /// + /// ``` + /// let mut b = [0; 1]; + /// + /// let result = 'ß'.encode_utf8(&mut b); + /// + /// assert_eq!(result, None); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>; - /// Encodes this character as UTF-16 into the provided `u16` buffer, - /// and then returns the number of `u16`s written. + /// Encodes this character as UTF-16 into the provided `u16` buffer, and then returns the + /// number of `u16`s written. + /// + /// If the buffer is not large enough, nothing will be written into it and a `None` will be + /// returned. + /// + /// # Examples + /// + /// In both of these examples, 'ß' takes one byte to encode. + /// + /// ``` + /// let mut b = [0; 1]; + /// + /// let result = 'ß'.encode_utf16(&mut b); + /// + /// assert_eq!(result, Some(1)); + /// ``` + /// + /// A buffer that's too small: + /// + /// ``` + /// let mut b = [0; 0]; + /// + /// let result = 'ß'.encode_utf8(&mut b); /// - /// If the buffer is not large enough, nothing will be written into it - /// and a `None` will be returned. + /// assert_eq!(result, None); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>; } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 2ff67ebd550..551277bae5c 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -13,7 +13,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use any; -use cell::{Cell, RefCell, Ref, RefMut}; +use cell::{Cell, RefCell, Ref, RefMut, BorrowState}; use char::CharExt; use iter::{Iterator, IteratorExt}; use marker::{Copy, Sized}; @@ -38,7 +38,6 @@ mod float; #[stable(feature = "rust1", since = "1.0.0")] #[doc(hidden)] pub mod rt { - #[cfg(stage0)] pub use self::v1::*; pub mod v1; } @@ -191,38 +190,6 @@ impl<'a> Arguments<'a> { } } - /// When using the format_args!() macro, this function is used to generate the - /// Arguments structure. - #[doc(hidden)] #[inline] - #[cfg(stage0)] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(pieces: &'a [&'a str], - args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { - Arguments { - pieces: pieces, - fmt: None, - args: args - } - } - - /// This function is used to specify nonstandard formatting parameters. - /// The `pieces` array must be at least as long as `fmt` to construct - /// a valid Arguments structure. Also, any `Count` within `fmt` that is - /// `CountIsParam` or `CountIsNextParam` has to point to an argument - /// created with `argumentuint`. However, failing to do so doesn't cause - /// unsafety, but will ignore invalid . - #[doc(hidden)] #[inline] - #[cfg(stage0)] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn with_placeholders(pieces: &'a [&'a str], - fmt: &'a [rt::v1::Argument], - args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { - Arguments { - pieces: pieces, - fmt: Some(fmt), - args: args - } - } /// This function is used to specify nonstandard formatting parameters. /// The `pieces` array must be at least as long as `fmt` to construct /// a valid Arguments structure. Also, any `Count` within `fmt` that is @@ -230,7 +197,6 @@ impl<'a> Arguments<'a> { /// created with `argumentuint`. However, failing to do so doesn't cause /// unsafety, but will ignore invalid . #[doc(hidden)] #[inline] - #[cfg(not(stage0))] pub fn new_v1_formatted(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>], fmt: &'a [rt::v1::Argument]) -> Arguments<'a> { @@ -516,7 +482,7 @@ impl<'a> Formatter<'a> { // Writes the sign if it exists, and then the prefix if it was requested let write_prefix = |&: f: &mut Formatter| { - for c in sign.into_iter() { + if let Some(c) = sign { let mut b = [0; 4]; let n = c.encode_utf8(&mut b).unwrap_or(0); let b = unsafe { str::from_utf8_unchecked(&b[..n]) }; @@ -684,25 +650,6 @@ impl Display for Error { } } -/// This is a function which calls are emitted to by the compiler itself to -/// create the Argument structures that are passed into the `format` function. -#[doc(hidden)] #[inline] -#[cfg(stage0)] -#[stable(feature = "rust1", since = "1.0.0")] -pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result, - t: &'a T) -> ArgumentV1<'a> { - ArgumentV1::new(t, f) -} - -/// When the compiler determines that the type of an argument *must* be a uint -/// (such as for width and precision), then it invokes this method. -#[doc(hidden)] #[inline] -#[cfg(stage0)] -#[stable(feature = "rust1", since = "1.0.0")] -pub fn argumentuint<'a>(s: &'a uint) -> ArgumentV1<'a> { - ArgumentV1::from_uint(s) -} - // Implementations of the core formatting traits macro_rules! fmt_refs { @@ -941,7 +888,7 @@ impl<T: Debug> Debug for [T] { try!(write!(f, "[")); } let mut is_first = true; - for x in self.iter() { + for x in self { if is_first { is_first = false; } else { @@ -973,9 +920,11 @@ impl<T: Copy + Debug> Debug for Cell<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: Debug> Debug for RefCell<T> { fn fmt(&self, f: &mut Formatter) -> Result { - match self.try_borrow() { - Some(val) => write!(f, "RefCell {{ value: {:?} }}", val), - None => write!(f, "RefCell {{ <borrowed> }}") + match self.borrow_state() { + BorrowState::Unused | BorrowState::Reading => { + write!(f, "RefCell {{ value: {:?} }}", self.borrow()) + } + BorrowState::Writing => write!(f, "RefCell {{ <borrowed> }}"), } } } diff --git a/src/libcore/fmt/rt/v1.rs b/src/libcore/fmt/rt/v1.rs index f0c82759b70..0c9bb6316e0 100644 --- a/src/libcore/fmt/rt/v1.rs +++ b/src/libcore/fmt/rt/v1.rs @@ -16,19 +16,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -#[cfg(stage0)] pub use self::Position::*; - -#[cfg(stage0)] pub use self::Alignment::Left as AlignLeft; -#[cfg(stage0)] pub use self::Alignment::Right as AlignRight; -#[cfg(stage0)] pub use self::Alignment::Center as AlignCenter; -#[cfg(stage0)] pub use self::Alignment::Unknown as AlignUnknown; -#[cfg(stage0)] pub use self::Count::Is as CountIs; -#[cfg(stage0)] pub use self::Count::Implied as CountImplied; -#[cfg(stage0)] pub use self::Count::Param as CountIsParam; -#[cfg(stage0)] pub use self::Count::NextParam as CountIsNextParam; -#[cfg(stage0)] pub use self::Position::Next as ArgumentNext; -#[cfg(stage0)] pub use self::Position::At as ArgumentIs; - #[derive(Copy)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Argument { diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 5a4d2fffade..d73e6ed589f 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -205,7 +205,7 @@ impl<S: Writer + Hasher, T: Hash<S>> Hash<S> for [T] { #[inline] fn hash(&self, state: &mut S) { self.len().hash(state); - for elt in self.iter() { + for elt in self { elt.hash(state); } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index c782452d4cf..d0734f9c039 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -174,7 +174,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn last(mut self) -> Option<Self::Item> { + fn last(self) -> Option<Self::Item> { let mut last = None; for x in self { last = Some(x); } last @@ -239,9 +239,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn zip<B, U>(self, other: U) -> Zip<Self, U> where - U: Iterator<Item=B>, - { + fn zip<U: Iterator>(self, other: U) -> Zip<Self, U> { Zip{a: self, b: other} } @@ -259,7 +257,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn map<B, F>(self, f: F) -> Map<Self::Item, B, Self, F> where + fn map<B, F>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Item) -> B, { Map{iter: self, f: f} @@ -279,7 +277,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter<P>(self, predicate: P) -> Filter<Self::Item, Self, P> where + fn filter<P>(self, predicate: P) -> Filter<Self, P> where P: FnMut(&Self::Item) -> bool, { Filter{iter: self, predicate: predicate} @@ -299,7 +297,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter_map<B, F>(self, f: F) -> FilterMap<Self::Item, B, Self, F> where + fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where F: FnMut(Self::Item) -> Option<B>, { FilterMap { iter: self, f: f } @@ -342,7 +340,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn peekable(self) -> Peekable<Self::Item, Self> { + fn peekable(self) -> Peekable<Self> { Peekable{iter: self, peeked: None} } @@ -362,7 +360,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn skip_while<P>(self, predicate: P) -> SkipWhile<Self::Item, Self, P> where + fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where P: FnMut(&Self::Item) -> bool, { SkipWhile{iter: self, flag: false, predicate: predicate} @@ -383,7 +381,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn take_while<P>(self, predicate: P) -> TakeWhile<Self::Item, Self, P> where + fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where P: FnMut(&Self::Item) -> bool, { TakeWhile{iter: self, flag: false, predicate: predicate} @@ -448,12 +446,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn scan<St, B, F>( - self, - initial_state: St, - f: F, - ) -> Scan<Self::Item, B, Self, St, F> where - F: FnMut(&mut St, Self::Item) -> Option<B>, + fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> + where F: FnMut(&mut St, Self::Item) -> Option<B>, { Scan{iter: self, f: f, state: initial_state} } @@ -474,9 +468,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn flat_map<B, U, F>(self, f: F) -> FlatMap<Self::Item, B, Self, U, F> where - U: Iterator<Item=B>, - F: FnMut(Self::Item) -> U, + fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> + where U: Iterator, F: FnMut(Self::Item) -> U, { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -534,7 +527,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn inspect<F>(self, f: F) -> Inspect<Self::Item, Self, F> where + fn inspect<F>(self, f: F) -> Inspect<Self, F> where F: FnMut(&Self::Item), { Inspect{iter: self, f: f} @@ -588,7 +581,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[unstable(feature = "core", reason = "recently added as part of collections reform")] - fn partition<B, F>(mut self, mut f: F) -> (B, B) where + fn partition<B, F>(self, mut f: F) -> (B, B) where B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool { @@ -617,7 +610,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn fold<B, F>(mut self, init: B, mut f: F) -> B where + fn fold<B, F>(self, init: B, mut f: F) -> B where F: FnMut(B, Self::Item) -> B, { let mut accum = init; @@ -638,7 +631,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn all<F>(mut self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool { + fn all<F>(self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool { for x in self { if !f(x) { return false; } } true } @@ -946,7 +939,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert_eq!([2, 4], right); /// ``` #[unstable(feature = "core", reason = "recent addition")] - fn unzip<A, B, FromA, FromB>(mut self) -> (FromA, FromB) where + fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Iterator<Item=(A, B)>, @@ -1077,16 +1070,14 @@ pub trait ExactSizeIterator: Iterator { #[stable(feature = "rust1", since = "1.0.0")] impl<I> ExactSizeIterator for Enumerate<I> where I: ExactSizeIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, F> ExactSizeIterator for Inspect<A, I, F> where - I: ExactSizeIterator<Item=A>, - F: FnMut(&A), +impl<I: ExactSizeIterator, F> ExactSizeIterator for Inspect<I, F> where + F: FnMut(&I::Item), {} #[stable(feature = "rust1", since = "1.0.0")] impl<I> ExactSizeIterator for Rev<I> where I: ExactSizeIterator + DoubleEndedIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> ExactSizeIterator for Map<A, B, I, F> where - I: ExactSizeIterator<Item=A>, - F: FnMut(A) -> B, +impl<B, I: ExactSizeIterator, F> ExactSizeIterator for Map<I, F> where + F: FnMut(I::Item) -> B, {} #[stable(feature = "rust1", since = "1.0.0")] impl<A, B> ExactSizeIterator for Zip<A, B> where A: ExactSizeIterator, B: ExactSizeIterator {} @@ -1561,28 +1552,15 @@ impl<T, U, A, B> RandomAccessIterator for Zip<A, B> where /// An iterator that maps the values of `iter` with `f` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Map<A, B, I: Iterator<Item=A>, F: FnMut(A) -> B> { +#[derive(Clone)] +pub struct Map<I, F> { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> Clone for Map<A, B, I, F> where - I: Clone + Iterator<Item=A>, - F: Clone + FnMut(A) -> B, -{ - fn clone(&self) -> Map<A, B, I, F> { - Map { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<Item=A>, F: FnMut(A) -> B { +impl<I: Iterator, F, B> Map<I, F> where F: FnMut(I::Item) -> B { #[inline] - fn do_map(&mut self, elt: Option<A>) -> Option<B> { + fn do_map(&mut self, elt: Option<I::Item>) -> Option<B> { match elt { Some(a) => Some((self.f)(a)), _ => None @@ -1591,7 +1569,7 @@ impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<Item=A>, F: FnMut(A) -> B { } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> Iterator for Map<A, B, I, F> where I: Iterator<Item=A>, F: FnMut(A) -> B { +impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B { type Item = B; #[inline] @@ -1607,9 +1585,8 @@ impl<A, B, I, F> Iterator for Map<A, B, I, F> where I: Iterator<Item=A>, F: FnMu } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> DoubleEndedIterator for Map<A, B, I, F> where - I: DoubleEndedIterator<Item=A>, - F: FnMut(A) -> B, +impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where + F: FnMut(I::Item) -> B, { #[inline] fn next_back(&mut self) -> Option<B> { @@ -1619,9 +1596,8 @@ impl<A, B, I, F> DoubleEndedIterator for Map<A, B, I, F> where } #[unstable(feature = "core", reason = "trait is experimental")] -impl<A, B, I, F> RandomAccessIterator for Map<A, B, I, F> where - I: RandomAccessIterator<Item=A>, - F: FnMut(A) -> B, +impl<B, I: RandomAccessIterator, F> RandomAccessIterator for Map<I, F> where + F: FnMut(I::Item) -> B, { #[inline] fn indexable(&self) -> usize { @@ -1638,31 +1614,18 @@ impl<A, B, I, F> RandomAccessIterator for Map<A, B, I, F> where /// An iterator that filters the elements of `iter` with `predicate` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Filter<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct Filter<I, P> { iter: I, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Clone for Filter<A, I, P> where - I: Clone + Iterator<Item=A>, - P: Clone + FnMut(&A) -> bool, -{ - fn clone(&self) -> Filter<A, I, P> { - Filter { - iter: self.iter.clone(), - predicate: self.predicate.clone(), - } - } -} - #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Iterator for Filter<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { - type Item = A; +impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option<A> { + fn next(&mut self) -> Option<I::Item> { for x in self.iter.by_ref() { if (self.predicate)(&x) { return Some(x); @@ -1681,12 +1644,11 @@ impl<A, I, P> Iterator for Filter<A, I, P> where I: Iterator<Item=A>, P: FnMut(& } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> DoubleEndedIterator for Filter<A, I, P> where - I: DoubleEndedIterator<Item=A>, - P: FnMut(&A) -> bool, +impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P> + where P: FnMut(&I::Item) -> bool, { #[inline] - fn next_back(&mut self) -> Option<A> { + fn next_back(&mut self) -> Option<I::Item> { for x in self.iter.by_ref().rev() { if (self.predicate)(&x) { return Some(x); @@ -1699,29 +1661,15 @@ impl<A, I, P> DoubleEndedIterator for Filter<A, I, P> where /// An iterator that uses `f` to both filter and map elements from `iter` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FilterMap<A, B, I, F> where I: Iterator<Item=A>, F: FnMut(A) -> Option<B> { +#[derive(Clone)] +pub struct FilterMap<I, F> { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> Clone for FilterMap<A, B, I, F> where - I: Clone + Iterator<Item=A>, - F: Clone + FnMut(A) -> Option<B>, -{ - fn clone(&self) -> FilterMap<A, B, I, F> { - FilterMap { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> Iterator for FilterMap<A, B, I, F> where - I: Iterator<Item=A>, - F: FnMut(A) -> Option<B>, +impl<B, I: Iterator, F> Iterator for FilterMap<I, F> + where F: FnMut(I::Item) -> Option<B>, { type Item = B; @@ -1744,9 +1692,8 @@ impl<A, B, I, F> Iterator for FilterMap<A, B, I, F> where } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, F> DoubleEndedIterator for FilterMap<A, B, I, F> where - I: DoubleEndedIterator<Item=A>, - F: FnMut(A) -> Option<B>, +impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F> + where F: FnMut(I::Item) -> Option<B>, { #[inline] fn next_back(&mut self) -> Option<B> { @@ -1824,20 +1771,28 @@ impl<I> RandomAccessIterator for Enumerate<I> where I: RandomAccessIterator { } /// An iterator with a `peek()` that returns an optional reference to the next element. -#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Peekable<T, I> where I: Iterator<Item=T> { +pub struct Peekable<I: Iterator> { iter: I, - peeked: Option<T>, + peeked: Option<I::Item>, +} + +impl<I: Iterator + Clone> Clone for Peekable<I> where I::Item: Clone { + fn clone(&self) -> Peekable<I> { + Peekable { + iter: self.iter.clone(), + peeked: self.peeked.clone(), + } + } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, I> Iterator for Peekable<T, I> where I: Iterator<Item=T> { - type Item = T; +impl<I: Iterator> Iterator for Peekable<I> { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option<T> { + fn next(&mut self) -> Option<I::Item> { if self.peeked.is_some() { self.peeked.take() } else { self.iter.next() } } @@ -1859,14 +1814,14 @@ impl<T, I> Iterator for Peekable<T, I> where I: Iterator<Item=T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, I> ExactSizeIterator for Peekable<T, I> where I: ExactSizeIterator<Item = T> {} +impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {} #[stable(feature = "rust1", since = "1.0.0")] -impl<T, I> Peekable<T, I> where I: Iterator<Item=T> { - /// Return a reference to the next element of the iterator with out advancing it, - /// or None if the iterator is exhausted. +impl<I: Iterator> Peekable<I> { + /// Return a reference to the next element of the iterator with out + /// advancing it, or None if the iterator is exhausted. #[inline] - pub fn peek(&mut self) -> Option<&T> { + pub fn peek(&mut self) -> Option<&I::Item> { if self.peeked.is_none() { self.peeked = self.iter.next(); } @@ -1886,33 +1841,21 @@ impl<T, I> Peekable<T, I> where I: Iterator<Item=T> { /// An iterator that rejects elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct SkipWhile<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct SkipWhile<I, P> { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Clone for SkipWhile<A, I, P> where - I: Clone + Iterator<Item=A>, - P: Clone + FnMut(&A) -> bool, +impl<I: Iterator, P> Iterator for SkipWhile<I, P> + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> SkipWhile<A, I, P> { - SkipWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Iterator for SkipWhile<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option<A> { + fn next(&mut self) -> Option<I::Item> { for x in self.iter.by_ref() { if self.flag || !(self.predicate)(&x) { self.flag = true; @@ -1932,33 +1875,21 @@ impl<A, I, P> Iterator for SkipWhile<A, I, P> where I: Iterator<Item=A>, P: FnMu /// An iterator that only accepts elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct TakeWhile<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct TakeWhile<I, P> { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Clone for TakeWhile<A, I, P> where - I: Clone + Iterator<Item=A>, - P: Clone + FnMut(&A) -> bool, +impl<I: Iterator, P> Iterator for TakeWhile<I, P> + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> TakeWhile<A, I, P> { - TakeWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, P> Iterator for TakeWhile<A, I, P> where I: Iterator<Item=A>, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option<A> { + fn next(&mut self) -> Option<I::Item> { if self.flag { None } else { @@ -2118,7 +2049,8 @@ impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {} /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Scan<A, B, I, St, F> where I: Iterator, F: FnMut(&mut St, A) -> Option<B> { +#[derive(Clone)] +pub struct Scan<I, St, F> { iter: I, f: F, @@ -2126,26 +2058,9 @@ pub struct Scan<A, B, I, St, F> where I: Iterator, F: FnMut(&mut St, A) -> Optio pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, St, F> Clone for Scan<A, B, I, St, F> where - I: Clone + Iterator<Item=A>, - St: Clone, - F: Clone + FnMut(&mut St, A) -> Option<B>, -{ - fn clone(&self) -> Scan<A, B, I, St, F> { - Scan { - iter: self.iter.clone(), - f: self.f.clone(), - state: self.state.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, St, F> Iterator for Scan<A, B, I, St, F> where - I: Iterator<Item=A>, - F: FnMut(&mut St, A) -> Option<B>, +impl<B, I: Iterator, St, F> Iterator for Scan<I, St, F> where + F: FnMut(&mut St, I::Item) -> Option<B>, { type Item = B; @@ -2166,46 +2081,24 @@ impl<A, B, I, St, F> Iterator for Scan<A, B, I, St, F> where /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FlatMap<A, B, I, U, F> where - I: Iterator<Item=A>, - U: Iterator<Item=B>, - F: FnMut(A) -> U, -{ +#[derive(Clone)] +pub struct FlatMap<I, U, F> { iter: I, f: F, frontiter: Option<U>, backiter: Option<U>, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, U, F> Clone for FlatMap<A, B, I, U, F> where - I: Clone + Iterator<Item=A>, - U: Clone + Iterator<Item=B>, - F: Clone + FnMut(A) -> U, -{ - fn clone(&self) -> FlatMap<A, B, I, U, F> { - FlatMap { - iter: self.iter.clone(), - f: self.f.clone(), - frontiter: self.frontiter.clone(), - backiter: self.backiter.clone(), - } - } -} - #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where - I: Iterator<Item=A>, - U: Iterator<Item=B>, - F: FnMut(A) -> U, +impl<I: Iterator, U: Iterator, F> Iterator for FlatMap<I, U, F> + where F: FnMut(I::Item) -> U, { - type Item = B; + type Item = U::Item; #[inline] - fn next(&mut self) -> Option<B> { + fn next(&mut self) -> Option<U::Item> { loop { - for inner in self.frontiter.iter_mut() { + if let Some(ref mut inner) = self.frontiter { for x in inner.by_ref() { return Some(x) } @@ -2230,15 +2123,14 @@ impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, B, I, U, F> DoubleEndedIterator for FlatMap<A, B, I, U, F> where - I: DoubleEndedIterator<Item=A>, - U: DoubleEndedIterator<Item=B>, - F: FnMut(A) -> U, +impl<I: DoubleEndedIterator, U: DoubleEndedIterator, F> DoubleEndedIterator + for FlatMap<I, U, F> + where F: FnMut(I::Item) -> U { #[inline] - fn next_back(&mut self) -> Option<B> { + fn next_back(&mut self) -> Option<U::Item> { loop { - for inner in self.backiter.iter_mut() { + if let Some(ref mut inner) = self.backiter { match inner.next_back() { None => (), y => return y @@ -2340,28 +2232,15 @@ impl<I> Fuse<I> { /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Inspect<A, I, F> where I: Iterator<Item=A>, F: FnMut(&A) { +#[derive(Clone)] +pub struct Inspect<I, F> { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, F> Clone for Inspect<A, I, F> where - I: Clone + Iterator<Item=A>, - F: Clone + FnMut(&A), -{ - fn clone(&self) -> Inspect<A, I, F> { - Inspect { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl<A, I, F> Inspect<A, I, F> where I: Iterator<Item=A>, F: FnMut(&A) { +impl<I: Iterator, F> Inspect<I, F> where F: FnMut(&I::Item) { #[inline] - fn do_inspect(&mut self, elt: Option<A>) -> Option<A> { + fn do_inspect(&mut self, elt: Option<I::Item>) -> Option<I::Item> { match elt { Some(ref a) => (self.f)(a), None => () @@ -2372,11 +2251,11 @@ impl<A, I, F> Inspect<A, I, F> where I: Iterator<Item=A>, F: FnMut(&A) { } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, F> Iterator for Inspect<A, I, F> where I: Iterator<Item=A>, F: FnMut(&A) { - type Item = A; +impl<I: Iterator, F> Iterator for Inspect<I, F> where F: FnMut(&I::Item) { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option<A> { + fn next(&mut self) -> Option<I::Item> { let next = self.iter.next(); self.do_inspect(next) } @@ -2388,21 +2267,19 @@ impl<A, I, F> Iterator for Inspect<A, I, F> where I: Iterator<Item=A>, F: FnMut( } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, I, F> DoubleEndedIterator for Inspect<A, I, F> where - I: DoubleEndedIterator<Item=A>, - F: FnMut(&A), +impl<I: DoubleEndedIterator, F> DoubleEndedIterator for Inspect<I, F> + where F: FnMut(&I::Item), { #[inline] - fn next_back(&mut self) -> Option<A> { + fn next_back(&mut self) -> Option<I::Item> { let next = self.iter.next_back(); self.do_inspect(next) } } #[unstable(feature = "core", reason = "trait is experimental")] -impl<A, I, F> RandomAccessIterator for Inspect<A, I, F> where - I: RandomAccessIterator<Item=A>, - F: FnMut(&A), +impl<I: RandomAccessIterator, F> RandomAccessIterator for Inspect<I, F> + where F: FnMut(&I::Item), { #[inline] fn indexable(&self) -> usize { @@ -2410,7 +2287,7 @@ impl<A, I, F> RandomAccessIterator for Inspect<A, I, F> where } #[inline] - fn idx(&mut self, index: usize) -> Option<A> { + fn idx(&mut self, index: usize) -> Option<I::Item> { let element = self.iter.idx(index); self.do_inspect(element) } @@ -2426,9 +2303,11 @@ impl<A, I, F> RandomAccessIterator for Inspect<A, I, F> where /// use std::iter::Unfold; /// use std::num::Int; // For `.checked_add()` /// -/// // This iterator will yield up to the last Fibonacci number before the max value of `u32`. -/// // You can simply change `u32` to `u64` in this line if you want higher values than that. -/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), |&mut (ref mut x2, ref mut x1)| { +/// // This iterator will yield up to the last Fibonacci number before the max +/// // value of `u32`. You can simply change `u32` to `u64` in this line if +/// // you want higher values than that. +/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), +/// |&mut (ref mut x2, ref mut x1)| { /// // Attempt to get the next Fibonacci number /// // `x1` will be `None` if previously overflowed. /// let next = match (*x2, *x1) { @@ -2449,32 +2328,19 @@ impl<A, I, F> RandomAccessIterator for Inspect<A, I, F> where /// } /// ``` #[unstable(feature = "core")] -pub struct Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> { +#[derive(Clone)] +pub struct Unfold<St, F> { f: F, /// Internal state that will be passed to the closure on the next iteration pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl<A, St, F> Clone for Unfold<A, St, F> where - F: Clone + FnMut(&mut St) -> Option<A>, - St: Clone, -{ - fn clone(&self) -> Unfold<A, St, F> { - Unfold { - f: self.f.clone(), - state: self.state.clone(), - } - } -} - #[unstable(feature = "core")] -impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> { +impl<A, St, F> Unfold<St, F> where F: FnMut(&mut St) -> Option<A> { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the closure #[inline] - pub fn new(initial_state: St, f: F) -> Unfold<A, St, F> { + pub fn new(initial_state: St, f: F) -> Unfold<St, F> { Unfold { f: f, state: initial_state @@ -2483,7 +2349,7 @@ impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<A, St, F> Iterator for Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> { +impl<A, St, F> Iterator for Unfold<St, F> where F: FnMut(&mut St) -> Option<A> { type Item = A; #[inline] @@ -2899,7 +2765,7 @@ type IterateState<T, F> = (F, Option<T>, bool); /// An iterator that repeatedly applies a given function, starting /// from a given seed value. #[unstable(feature = "core")] -pub type Iterate<T, F> = Unfold<T, IterateState<T, F>, fn(&mut IterateState<T, F>) -> Option<T>>; +pub type Iterate<T, F> = Unfold<IterateState<T, F>, fn(&mut IterateState<T, F>) -> Option<T>>; /// Create a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index d2bc30fa74a..5e9793f270d 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -59,7 +59,6 @@ #![no_std] #![allow(raw_pointer_derive)] #![deny(missing_docs)] -#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap #![feature(int_uint)] #![feature(intrinsics, lang_items)] diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index f656fd4b8b9..7af94c73f32 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -947,28 +947,11 @@ pub trait IndexMut<Index: ?Sized> { } /// An unbounded range. -#[cfg(stage0)] -#[derive(Copy, Clone, PartialEq, Eq)] -#[lang="full_range"] -#[unstable(feature = "core", reason = "may be renamed to RangeFull")] -pub struct FullRange; - -/// An unbounded range. -#[cfg(not(stage0))] #[derive(Copy, Clone, PartialEq, Eq)] #[lang="range_full"] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFull; -#[cfg(stage0)] -#[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for FullRange { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt("..", fmt) - } -} - -#[cfg(not(stage0))] #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for RangeFull { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 9d253178664..f4b1a0633de 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -26,9 +26,6 @@ // Reexported core operators pub use marker::{Copy, Send, Sized, Sync}; -#[cfg(stage0)] -pub use ops::{Drop, Fn, FnMut, FnOnce, FullRange}; -#[cfg(not(stage0))] pub use ops::{Drop, Fn, FnMut, FnOnce}; // Reexported functions diff --git a/src/libcore/result.rs b/src/libcore/result.rs index fc7d4e868f7..d610962f862 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -956,7 +956,7 @@ pub fn fold<T, E, F: FnMut(V, T) -> V, Iter: Iterator<Item=Result<T, E>>>( - mut iterator: Iter, + iterator: Iter, mut init: V, mut f: F) -> Result<V, E> { diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index a368ddba9bc..a750e81bf59 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -43,9 +43,6 @@ use default::Default; use iter::*; use num::Int; use ops::{FnMut, self, Index}; -#[cfg(stage0)] -use ops::FullRange as RangeFull; -#[cfg(not(stage0))] use ops::RangeFull; use option::Option; use option::Option::{None, Some}; @@ -769,16 +766,6 @@ impl<'a, T> ops::Index<ops::RangeFrom<uint>> for Iter<'a, T> { } } -#[cfg(stage0)] -#[unstable(feature = "core")] -impl<'a, T> ops::Index<ops::FullRange> for Iter<'a, T> { - type Output = [T]; - #[inline] - fn index(&self, _index: &ops::FullRange) -> &[T] { - self.as_slice() - } -} -#[cfg(not(stage0))] #[unstable(feature = "core")] impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> { type Output = [T]; diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index cb7af3b3d35..8c0c16bafc4 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -478,7 +478,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { /// Created with `StrExt::bytes` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] -pub struct Bytes<'a>(Map<&'a u8, u8, slice::Iter<'a, u8>, BytesDeref>); +pub struct Bytes<'a>(Map<slice::Iter<'a, u8>, BytesDeref>); delegate_iter!{exact u8 : Bytes<'a>} /// A temporary fn new type that ensures that the `Bytes` iterator @@ -526,7 +526,7 @@ pub struct Lines<'a> { /// An iterator over the lines of a string, separated by either `\n` or (`\r\n`). #[stable(feature = "rust1", since = "1.0.0")] pub struct LinesAny<'a> { - inner: Map<&'a str, &'a str, Lines<'a>, fn(&str) -> &str>, + inner: Map<Lines<'a>, fn(&str) -> &str>, } impl<'a, Sep> CharSplits<'a, Sep> { @@ -1266,16 +1266,6 @@ mod traits { } } - #[cfg(stage0)] - #[stable(feature = "rust1", since = "1.0.0")] - impl ops::Index<ops::FullRange> for str { - type Output = str; - #[inline] - fn index(&self, _index: &ops::FullRange) -> &str { - self - } - } - #[cfg(not(stage0))] #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::RangeFull> for str { type Output = str; |
