You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chain::nth(0) and next() disagree on a non-fused iterator: Skip::advance_by keeps its skip count #164480
I think Chain is not to blame here, because you can reproduce the same error by using manual advance_by(0); next() -- although that requires nightly since it's unstable.
#![feature(iter_advance_by)]/// A legal non-fused iterator: `None` once, then `Some(1)`, `Some(2)`, ...structGap(u32);implIteratorforGap{typeItem = u32;fnnext(&mutself) -> Option<u32>{self.0 += 1;ifself.0 == 1{None}else{Some(self.0 - 1)}}}fnmain(){let next = Gap(0).skip(1).next();letmut iter = Gap(0).skip(1);
iter.advance_by(0).unwrap();let nth0 = iter.next();println!("{:?} {:?}", next, nth0);}
Right, this is the problem. In this scenario, Skip::advance_by(0) calls Gap::advance_by(1) and gets Err(1). It then counts advanced_inner as 0, so self.n stays the same, and it can only return Ok(()) itself for advance_by(0).
In contrast, Skip::next and Skip::nthalways clear self.n.
Or maybe this is evidence that advance_by(0) is generally nonsense.
I mean I would agree that is nonsense in any case. But this feels like ZSTs in the sense that we have to decide what's sensible to do in "nonsense" situations.
I think making it no-op is the least bad option but I don't know if I'm missing a reason not to.
Activity
cuviper commentedon Oct 17, 2026
I think
Chainis not to blame here, because you can reproduce the same error by using manualadvance_by(0); next()-- although that requires nightly since it's unstable.playground
Right, this is the problem. In this scenario,
Skip::advance_by(0)callsGap::advance_by(1)and getsErr(1). It then countsadvanced_inneras 0, soself.nstays the same, and it can only returnOk(())itself foradvance_by(0).In contrast,
Skip::nextandSkip::nthalways clearself.n.cuviper commentedon Oct 17, 2026
Actually, even if
Skip::advance_by(0)did clearself.n, it would instead returnSome(1)on the followingnext(), still wrong.Maybe it needs to avoid doing anything in this case? Or maybe this is evidence that
advance_by(0)is generally nonsense.ChrisDenton commentedon Oct 17, 2026
I mean I would agree that is nonsense in any case. But this feels like ZSTs in the sense that we have to decide what's sensible to do in "nonsense" situations.
I think making it no-op is the least bad option but I don't know if I'm missing a reason not to.
the8472 commentedon Oct 18, 2026
This seems like a good reason to make the
na NonZeroUsize then.Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Rollup merge of rust-lang#164488 - cuviper:skip0, r=JohnTitor
Unrolled build for #164488 in rollup 164662
Rollup merge of #164488 - cuviper:skip0, r=JohnTitor
Rollup merge of #164488 - cuviper:skip0, r=JohnTitor
Rollup merge of #164488 - cuviper:skip0, r=JohnTitor