Skip to content

Commit 2963a6f

Browse files
committed
Fix Take::nth logic.
1 parent eaf4a6c commit 2963a6f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/libcore/iter.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,12 +2126,15 @@ impl<I> Iterator for Take<I> where I: Iterator{
21262126

21272127
#[inline]
21282128
fn nth(&mut self, n: usize) -> Option<I::Item> {
2129-
if self.n == 0 {
2130-
None
2131-
} else {
2132-
let n = cmp::min(self.n-1, n);
2129+
if self.n > n {
21332130
self.n -= n + 1;
21342131
self.iter.nth(n)
2132+
} else {
2133+
if self.n > 0 {
2134+
self.iter.nth(self.n - 1);
2135+
self.n = 0;
2136+
}
2137+
None
21352138
}
21362139
}
21372140

0 commit comments

Comments
 (0)