Skip to content

Commit

Permalink
Change Iterator::nth to use self.next() in a while loop.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed May 13, 2020
1 parent 5a0ac05 commit 3b10858
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3b10858

Please sign in to comment.