Skip to content

impl Default for RepeatN#139690

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
cuviper:iter_repeat_n_default
Apr 18, 2026
Merged

impl Default for RepeatN#139690
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
cuviper:iter_repeat_n_default

Conversation

@cuviper
Copy link
Copy Markdown
Member

@cuviper cuviper commented Apr 11, 2025

This creates an empty iterator, like repeat_n(value, 0) but without
needing any such value at hand. There's precedent in many other
iterators that the Default is empty, like slice::Iter.

I found myself wanting this for rayon's RepeatN as it lowers to a
sequential iterator here. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling std::iter::repeat_n(x, 0) just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty Default.

r? libs-api (insta-stable)

@rustbot rustbot added 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 Apr 11, 2025
@cuviper cuviper added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Apr 11, 2025
@tgross35 tgross35 added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Apr 27, 2025
@cuviper
Copy link
Copy Markdown
Member Author

cuviper commented Mar 13, 2026

r? libs-api

@rustbot rustbot assigned BurntSushi and unassigned joshtriplett Mar 13, 2026
@tgross35 tgross35 added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 14, 2026
@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 17, 2026
@Amanieu
Copy link
Copy Markdown
Member

Amanieu commented Mar 17, 2026

@rfcbot merge libs-api

@rust-rfcbot
Copy link
Copy Markdown
Collaborator

rust-rfcbot commented Mar 17, 2026

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 17, 2026
@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 7, 2026
@rust-rfcbot
Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@theemathas
Copy link
Copy Markdown
Contributor

This PR needs to be updated, since it conflicts with the already-merged #130887

@cuviper cuviper force-pushed the iter_repeat_n_default branch from 4a9f43f to ed79787 Compare April 16, 2026 23:48
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@cuviper
Copy link
Copy Markdown
Member Author

cuviper commented Apr 16, 2026

Updated, thanks for pointing out that conflict.

This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202
@cuviper cuviper force-pushed the iter_repeat_n_default branch from ed79787 to a66b781 Compare April 16, 2026 23:49
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 17, 2026
@rust-rfcbot
Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@cuviper
Copy link
Copy Markdown
Member Author

cuviper commented Apr 17, 2026

r? libs

Copy link
Copy Markdown
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r? tgross35
@bors r+ rollup

View changes since this review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 17, 2026

📌 Commit a66b781 has been approved by tgross35

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 17, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 17, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 18, 2026
…gross35

`impl Default for RepeatN`

This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202

r? libs-api (insta-stable)
rust-bors Bot pushed a commit that referenced this pull request Apr 18, 2026
Rollup of 12 pull requests

Successful merges:

 - #147811 (naked functions: respect `function-sections`)
 - #154935 (Add Sized supertrait for CoerceUnsized and DispatchFromDyn)
 - #139690 (`impl Default for RepeatN`)
 - #153511 (`std::any::TypeId`: remove misplaced "and" in `Unique<T>` example)
 - #154943 (Move recursion out of `MatchPairTree::for_pattern` helpers )
 - #155295 (Fix misleading "borrowed data escapes outside of function" diagnostic)
 - #155427 (ptr: update text in intro text to one in with_addr doc)
 - #155428 (Fix ICE in borrowck mutability suggestion with multi-byte ref sigil)
 - #155435 (rustdoc: Fix `redundant_explicit_links` incorrectly firing (or not firing) under certain scenarios)
 - #155450 (Remove unnecessary safety conditions related to unchecked uint arithmetic)
 - #155454 (docs: Fix typo in std/src/thready/scoped.rs)
 - #155467 (`std::error::Request`: clean up documentation)
@rust-bors rust-bors Bot merged commit 221dab8 into rust-lang:main Apr 18, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 18, 2026
rust-timer added a commit that referenced this pull request Apr 18, 2026
Rollup merge of #139690 - cuviper:iter_repeat_n_default, r=tgross35

`impl Default for RepeatN`

This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202

r? libs-api (insta-stable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants