Files
rust/library/coretests/tests/iter
Jonathan Brouwer 2825c037bc Rollup merge of #160025 - asder8215:step_by_nth_one, r=clarfonthey
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.
2026-08-01 19:16:28 +02:00
..
2026-01-30 15:52:40 +00:00
2026-04-16 16:49:11 -07:00