mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 17:26:12 +00:00
Fix an edge case with `StepBy::nth` on non-fused iterators Fixes rust-lang/rust#159965. From the `nth` documentation as pointed out by theemathas: > `nth()` will return `None` if `n` is greater than or equal to the length of the iterator. Currently, there is an edge case for non-fused iterator where it's able to return `Some` through `StepBy::nth` iterator even though the first item from the non-fused iterator returns `None` (it is logically an empty iterator). The issue came from how in the first take block it advances the underlying iterator forward using `.next()` and does not check if what it returns is a `None` value or not. This wouldn't be a problem for fused iterators because all the values that it would return after reaching the `None` point will also be `None`. However since non-fused iterators do not have to abide by continuously yielding `None` after reaching a `None`, it allows for a case, where after falling down from `first_take` block it can return `Some(_)` from a `self.iter.nth()` call in there. In the `first_take` block we should definitely check if the first item we got from `self.iter.next()` is `None` item, and return `None` if it is so.