Skip to content

Fix Cycle::size_hint for clones that differ from the original - #166593

Open
bardiharborow wants to merge 1 commit into
rust-lang:mainfrom
bardiharborow:fix-cycle-size-hint
Open

bardiharborow wants to merge 1 commit into
rust-lang:mainfrom
bardiharborow:fix-cycle-size-hint

Conversation

@bardiharborow

@bardiharborow bardiharborow commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Cycle::size_hint decided whether the cycle was empty or infinite based on orig.size_hint(), but orig is only a clone and Clone doesn't promise that clones yield the same items.

This commit bases the hint on the rest of the live iterator, with no upper bound.

Fixes #166145

@rustbot rustbot added A-iterators Area: Iterators S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, jhpratt, joboet

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

`Cycle::size_hint` decided whether the cycle was empty or infinite based on
`orig.size_hint()`, but `orig` is only a clone and `Clone` doesn't promise
that clones yield the same items.

This commit bases the hint on the rest of the live iterator, with no upper
bound.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-iterators Area: Iterators S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cycle::size_hint is wrong

4 participants