From c184ab48c4f007f8700e9fefc7d7a143b1777753 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Mon, 18 Jul 2022 21:10:47 +0200 Subject: [PATCH] Fix `Skip::next` for non-fused inner iterators --- core/src/iter/adapters/skip.rs | 2 +- core/tests/iter/adapters/skip.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/iter/adapters/skip.rs b/core/src/iter/adapters/skip.rs index ea1da8ba4..2c283100f 100644 --- a/core/src/iter/adapters/skip.rs +++ b/core/src/iter/adapters/skip.rs @@ -33,7 +33,7 @@ where #[inline] fn next(&mut self) -> Option { if unlikely(self.n > 0) { - self.iter.nth(crate::mem::take(&mut self.n) - 1); + self.iter.nth(crate::mem::take(&mut self.n) - 1)?; } self.iter.next() } diff --git a/core/tests/iter/adapters/skip.rs b/core/tests/iter/adapters/skip.rs index 0c464bdd0..a73d9861d 100644 --- a/core/tests/iter/adapters/skip.rs +++ b/core/tests/iter/adapters/skip.rs @@ -1,5 +1,7 @@ use core::iter::*; +use super::Unfuse; + #[test] fn test_iterator_skip() { let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30]; @@ -190,3 +192,9 @@ fn test_skip_nth_back() { it.by_ref().skip(2).nth_back(10); assert_eq!(it.next_back(), Some(&1)); } + +#[test] +fn test_skip_non_fused() { + let non_fused = Unfuse::new(0..10); + let _ = non_fused.skip(20).next(); +}