Uh oh!
There was an error while loading. Please reload this page.
Add unstable Iterator::copied() - #56534
Conversation
rust-highfive
commented
Dec 5, 2018
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
97efb25 to
0800e67CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| fn fold<Acc, F>(self, init: Acc, mut f: F) -> Acc | ||
| where F: FnMut(Acc, Self::Item) -> Acc, |
There was a problem hiding this comment.
the indentation style for where is different in these two methods, we need to use one (whatever this file prefers) 🙂
There was a problem hiding this comment.
It's consistently so in this file, with different indentation for try_fold and fold. It probably should be fixed, but it seems out of scope for this change.
There was a problem hiding this comment.
I was thinking that it might be good to (at some point) run rustfmt on the whole standard library
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Use inner iterator may_have_side_effect for Cloned Previous implementation wasn't correct, as an inner iterator could have had side effects. Noticed by @bluss in rust-lang#56534.
Use inner iterator may_have_side_effect for Cloned Previous implementation wasn't correct, as an inner iterator could have had side effects. Noticed by @bluss in rust-lang#56534.
Lucretiel
commented
Dec 6, 2018
Quick note: there's currently a clippy lint that suggests replacing |
SimonSapin
commented
Dec 9, 2018
For what it’s worth |
While true, a similar argument applies to That said, the intent of this feature isn't as much about performance, but rather making the invariants clear while refactoring to prevent accidentally cloning, which could be tricky to detect. |
shepmaster
commented
Dec 16, 2018
bors
commented
Dec 23, 2018
☔ The latest upstream changes (presumably #57063) made this pull request unmergeable. Please resolve the merge conflicts. |
bluss
commented
Dec 23, 2018
Technically the PR is fine. Thoughts on including this in std? |
Centril
commented
Dec 24, 2018
(My personal opinion is that this would be useful as a means of ensuring "cheapness") Randomly re-assigning to someone on T-libs for final triage. r? @SimonSapin |
SimonSapin
commented
Dec 25, 2018
Diff looks good. r=me with a tracking issue filed and referenced in I believe we tend to default to accepting new unstable APIs, and revisit them when stabilization is proposed. |
@SimonSapin Created tracking issues. |
Centril
commented
Dec 26, 2018
bors
commented
Dec 26, 2018
📌 Commit 315401d has been approved by |
bors
commented
Dec 26, 2018
🌲 The tree is currently closed for pull requests below priority 500, this pull request will be tested once the tree is reopened |
bors
commented
Dec 26, 2018
Add unstable Iterator::copied() Initially suggested at rust-itertools/itertools#289, however the maintainers of itertools suggested this may be better of in a standard library. The intent of `copied` is to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longer `Copy`. This is a relatively common pattern, as it can be seen by calling `rg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'` on Rust main repository. Additionally, many uses of `cloned` actually want to simply `Copy`, and changing something to be no longer copyable may introduce unnoticeable performance penalty. Also, this makes sense because the standard library includes `[T].copy_from_slice` to pair with `[T].clone_from_slice`. This also adds `Option::copied`, because it makes sense to pair it with `Iterator::copied`. I don't think this feature is particularly important, but it makes sense to update `Option` along with `Iterator` for consistency.
bors
commented
Dec 26, 2018
☀️ Test successful - status-appveyor, status-travis |
Initially suggested at rust-itertools/itertools#289, however the maintainers of itertools suggested this may be better of in a standard library.
The intent of
copiedis to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longerCopy. This is a relatively common pattern, as it can be seen by callingrg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'on Rust main repository. Additionally, many uses ofclonedactually want to simplyCopy, and changing something to be no longer copyable may introduce unnoticeable performance penalty.Also, this makes sense because the standard library includes
[T].copy_from_sliceto pair with[T].clone_from_slice.This also adds
Option::copied, because it makes sense to pair it withIterator::copied. I don't think this feature is particularly important, but it makes sense to updateOptionalong withIteratorfor consistency.