-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What guarantees does core::iter::Repeat give around observing calls to clone? #81292
Labels
A-iterators
Area: Iterators
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Comments
camelid
added
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
A-iterators
Area: Iterators
labels
Jan 23, 2021
At the very least it would be a valid specialization for https://doc.rust-lang.org/std/clone/trait.Clone.html#how-can-i-implement-clone |
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
May 18, 2021
…gh-81292, r=joshtriplett Implement more Iterator methods on core::iter::Repeat `core::iter::Repeat` always returns the same element, which means we can do better than implementing most `Iterator` methods in terms of `Iterator::next`. Fixes rust-lang#81292. rust-lang#81292 raises the question of whether these changes violate the contract of `core::iter::Repeat`, but as far as I can tell `core::iter::repeat` doesn't make any guarantees around how it calls `Clone::clone`.
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
May 18, 2021
…gh-81292, r=joshtriplett Implement more Iterator methods on core::iter::Repeat `core::iter::Repeat` always returns the same element, which means we can do better than implementing most `Iterator` methods in terms of `Iterator::next`. Fixes rust-lang#81292. rust-lang#81292 raises the question of whether these changes violate the contract of `core::iter::Repeat`, but as far as I can tell `core::iter::repeat` doesn't make any guarantees around how it calls `Clone::clone`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-iterators
Area: Iterators
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Currently,
core::iter::Repeat::nth
callscore::iter::Repeat::next
n
times.This allows a struct with interior mutability or other global state and a custom clone implementation to observe the number of times it has been cloned.
Currently, this program outputs:
Would it be possible to override the implementations of some
Iterator
methods that have default implementations without breaking any documented contract?The text was updated successfully, but these errors were encountered: