Change Iterator::nth to use self.next() in a while loop.

Currently it uses `for x in self`, which seems dubious within an
iterator method. Furthermore, `self.next()` is used in all the other
iterator methods.
This commit is contained in:
Nicholas Nethercote 2020-05-13 15:48:08 +10:00
parent 5a0ac0552e
commit 3b108588d1

View file

@ -333,7 +333,7 @@ pub trait Iterator {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
for x in self {
while let Some(x) = self.next() {
if n == 0 {
return Some(x);
}