]> git.lizzy.rs Git - rust.git/commitdiff
Weaken guarantee around advancing underlying iterators in zip
authorThe8472 <git@infinite-source.de>
Fri, 2 Apr 2021 18:20:55 +0000 (20:20 +0200)
committerThe8472 <git@infinite-source.de>
Wed, 11 Aug 2021 19:09:00 +0000 (21:09 +0200)
The current guarantee is too strong as it would prevent adapters
from exploiting knowledge about the iterator length and using counted
loops for example because they would stop calling `next()` before
it ever returned `None`. Additionally several nested zip iterators
already fail to uphold this.

This doesn't remove any of the specialization code that tries
(and sometimes fails) to uphold the guarantee for `next()`
because removing it would also affect `next_back()`
in more surprising ways.

library/core/src/iter/traits/iterator.rs

index 6b24d33bebca39239d618a74f3cd0d23615eadbd..25135018a5572c4e78aff4912bfb6479a6f126cd 100644 (file)
@@ -457,8 +457,10 @@ fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>
     /// In other words, it zips two iterators together, into a single one.
     ///
     /// If either iterator returns [`None`], [`next`] from the zipped iterator
-    /// will return [`None`]. If the first iterator returns [`None`], `zip` will
-    /// short-circuit and `next` will not be called on the second iterator.
+    /// will return [`None`].
+    /// If the zipped iterator has no more elements to return then each further attempt to advance
+    /// it will first try to advance the first iterator at most one time and if it still yielded an item
+    /// try to advance the second iterator at most one time.
     ///
     /// # Examples
     ///