From ddc401e0bf4f972bc2916601797d12bb97c5f1dc Mon Sep 17 00:00:00 2001 From: pravic Date: Mon, 6 Jun 2016 23:05:39 +0300 Subject: update to 2016-06-06 --- libcore/iter/iterator.rs | 5 +++-- libcore/iter/mod.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'libcore/iter') diff --git a/libcore/iter/iterator.rs b/libcore/iter/iterator.rs index 2033ae5..71ca5cc 100644 --- a/libcore/iter/iterator.rs +++ b/libcore/iter/iterator.rs @@ -172,6 +172,7 @@ pub trait Iterator { /// assert_eq!(a.iter().count(), 5); /// ``` #[inline] + #[rustc_inherit_overflow_checks] #[stable(feature = "rust1", since = "1.0.0")] fn count(self) -> usize where Self: Sized { // Might overflow. @@ -214,7 +215,7 @@ pub trait Iterator { /// Like most indexing operations, the count starts from zero, so `nth(0)` /// returns the first value, `nth(1)` the second, and so on. /// - /// `nth()` will return `None` if `n` is larger than the length of the + /// `nth()` will return `None` if `n` is greater than or equal to the length of the /// iterator. /// /// # Examples @@ -237,7 +238,7 @@ pub trait Iterator { /// assert_eq!(iter.nth(1), None); /// ``` /// - /// Returning `None` if there are less than `n` elements: + /// Returning `None` if there are less than `n + 1` elements: /// /// ``` /// let a = [1, 2, 3]; diff --git a/libcore/iter/mod.rs b/libcore/iter/mod.rs index abc199c..ae1e311 100644 --- a/libcore/iter/mod.rs +++ b/libcore/iter/mod.rs @@ -510,6 +510,7 @@ impl Iterator for Chain where } #[inline] + #[rustc_inherit_overflow_checks] fn count(self) -> usize { match self.state { ChainState::Both => self.a.count() + self.b.count(), @@ -541,6 +542,23 @@ impl Iterator for Chain where } } + #[inline] + fn find

(&mut self, mut predicate: P) -> Option where + P: FnMut(&Self::Item) -> bool, + { + match self.state { + ChainState::Both => match self.a.find(&mut predicate) { + None => { + self.state = ChainState::Back; + self.b.find(predicate) + } + v => v + }, + ChainState::Front => self.a.find(predicate), + ChainState::Back => self.b.find(predicate), + } + } + #[inline] fn last(self) -> Option { match self.state { @@ -915,6 +933,7 @@ impl Iterator for Enumerate where I: Iterator { /// /// Might panic if the index of the element overflows a `usize`. #[inline] + #[rustc_inherit_overflow_checks] fn next(&mut self) -> Option<(usize, ::Item)> { self.iter.next().map(|a| { let ret = (self.count, a); @@ -930,6 +949,7 @@ impl Iterator for Enumerate where I: Iterator { } #[inline] + #[rustc_inherit_overflow_checks] fn nth(&mut self, n: usize) -> Option<(usize, I::Item)> { self.iter.nth(n).map(|a| { let i = self.count + n; @@ -991,6 +1011,7 @@ impl Iterator for Peekable { } #[inline] + #[rustc_inherit_overflow_checks] fn count(self) -> usize { (if self.peeked.is_some() { 1 } else { 0 }) + self.iter.count() } @@ -1108,6 +1129,7 @@ impl Peekable { /// ``` #[unstable(feature = "peekable_is_empty", issue = "32111")] #[inline] + #[rustc_deprecated(since = "1.10.0", reason = "replaced by .peek().is_none()")] pub fn is_empty(&mut self) -> bool { self.peek().is_none() } -- cgit v1.2.3