Skip to content

Commit 14ef447

Browse files
authored
Rollup merge of #83791 - the8472:relax-zip-side-effect-guarantee, r=dtolnay
Weaken guarantee around advancing underlying iterators in zip The current guarantee (introduced in #52279) is too strong as it prevents 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 does not yet 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. The intent is to be able to remove for example this branch https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/src/iter/adapters/zip.rs#L234-L243 or this test https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/tests/iter/adapters/zip.rs#L177-L188 Solves #82303 by declaring it a non-issue.
2 parents 84826fe + 2ff677d commit 14ef447

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,10 @@ pub trait Iterator {
461461
/// In other words, it zips two iterators together, into a single one.
462462
///
463463
/// If either iterator returns [`None`], [`next`] from the zipped iterator
464-
/// will return [`None`]. If the first iterator returns [`None`], `zip` will
465-
/// short-circuit and `next` will not be called on the second iterator.
464+
/// will return [`None`].
465+
/// If the zipped iterator has no more elements to return then each further attempt to advance
466+
/// it will first try to advance the first iterator at most one time and if it still yielded an item
467+
/// try to advance the second iterator at most one time.
466468
///
467469
/// # Examples
468470
///

0 commit comments

Comments
 (0)