Skip to content

Implement DoubleEndedIterator::next_chunk_back#156737

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
asder8215:double_ended_iterator_next_chunk_back
Jul 2, 2026
Merged

Implement DoubleEndedIterator::next_chunk_back#156737
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
asder8215:double_ended_iterator_next_chunk_back

Conversation

@asder8215

@asder8215 asder8215 commented May 19, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR builds off on @vinDelphini's PR on introducing DoubleEndedIterator::next_chunk_back (which will be used in a follow up PR to optimize ArrayChunks::try_rfold once merged). This was in the works since late Jan and I thought to pick it up and get this over the finish line as vinDelphini has been away from the PR for a couple of months. I've made sure to pull from vinDelphini's branch to keep him authored on the commits he made.

Other things introduced from this PR is specialization like done for Iterator::next_chunk, constifying some stuff, making a custom DoubleEndedIterator::next_chunk_back for IntoIter (since it also has a custom impl of Iterator::next_chunk), and a bunch of tests mirroring that of Iterator::next_chunk.

There's no tracking issue for this yet, but the ACP for this introduction is here. I'll create the tracking issue for this soon.


Actually, can we have DoubleEndedIterator::next_chunk_back underneath Iterator::next_chunk tracking issue?

@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 May 19, 2026
@rustbot

rustbot commented May 19, 2026

Copy link
Copy Markdown
Collaborator

r? @tgross35

rustbot has assigned @tgross35.
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 7 candidates
  • Random selection from Mark-Simulacrum, tgross35

@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 7cb34f0 to 210d0a1 Compare May 19, 2026 03:11
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 210d0a1 to 41f9ab9 Compare May 19, 2026 04:27
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 41f9ab9 to 0688940 Compare May 19, 2026 05:12
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 0688940 to 9d29265 Compare May 19, 2026 15:26
Comment thread library/alloc/src/vec/into_iter.rs
Comment thread library/alloc/src/vec/into_iter.rs Outdated
@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 9d29265 to db0f4cc Compare May 31, 2026 05:01
@asder8215

Copy link
Copy Markdown
Contributor Author

r? libs

@rustbot rustbot assigned aapoalas and unassigned tgross35 Jun 11, 2026

@aapoalas aapoalas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some minor nits to pick and one case of "I don't think that's what we want to indicate to the compiler".

I'm also a little worried about adding const stuff as this has recently been a topic of discussion - this is in line with the fn next_chunk and doesn't seem like a problem in that sense, but I figured it's best to mention it as well.

View changes since this review

Comment thread library/core/src/array/mod.rs Outdated
Comment thread library/alloc/src/vec/into_iter.rs Outdated
Comment thread library/alloc/src/vec/into_iter.rs Outdated
Comment thread library/alloc/src/vec/into_iter.rs Outdated
Comment thread library/alloc/src/vec/into_iter.rs Outdated
@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 Jun 13, 2026
@rustbot

rustbot commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

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

@asder8215

asder8215 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

I'm also a little worried about adding const stuff as #155816 - this is in line with the fn next_chunk and doesn't seem like a problem in that sense, but I figured it's best to mention it as well.

Yeah, I'm aware that the Rust libs team are cautious with constifying functions/methods. I figured in this case it was fine for consistency with Iterator::next_chunk, which seemed to have been constified from this PR.

@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from db0f4cc to 2ea9ac3 Compare June 13, 2026 18:14
@rust-log-analyzer

This comment has been minimized.

@asder8215

Copy link
Copy Markdown
Contributor Author

Did they change how tidy work on const impl trait blocks recently? My tidy --bless automatically puts the const right before the trait name rather than how it recommends me to put it here before the impl.

vinDelphini and others added 4 commits June 13, 2026 15:18
Clarify that GuardBack initializes arrays from the end.

Restore performance note for iter_next_chunk_erased regarding optimization issues.
I copied the impl block from Guard without noticing that Destruct was only there for const contexts. Consumed the suggestion, thanks.

Co-authored-by: Chayim Refael Friedman <chayimfr@gmail.com>
…troduced next_chunk_back implementation in IntoIter, updated documentation, and added test cases for DoubleEndedIterator::next_chunk_back
@asder8215 asder8215 force-pushed the double_ended_iterator_next_chunk_back branch from 2ea9ac3 to bfd1ba6 Compare June 13, 2026 19:21
@asder8215

asder8215 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@aapoalas @nia-e actually, these functions need const implementations. I just noticed that the DoubleEndedIterator trait has been marked const from this PR 4 months ago.

When @vinDelphini started working on this, that DoubleEndedIterator wasn't marked as a const trait, which I can see why his implementation didn't have const markings.

I think there's no other changes I can make to this PR.

Edit: Actually nevermind. We can use the #[rustc_non_const_trait_method] to create a non-const trait method within a const trait. However, I also feel like making DoubleEndedIterator::next_chunk_back non-const defeats the purpose with the DoubleEndedIterator trait being marked const and the implementation for this method is already possible to be made const.

@nia-e nia-e removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jun 23, 2026
@asder8215

Copy link
Copy Markdown
Contributor Author

@aapoalas I non-constified the DoubleEndedIterator::next_chunk_back. I put it in a separate commit for commit history in case we want to come back to constifying this in a future commit (let me know if you want me to remove it from history/squash it out).

@asder8215 asder8215 requested a review from aapoalas June 24, 2026 19:09
@aapoalas

aapoalas commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Looks good to me, thank you and great work <3

@bors r+

@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ae8f56d has been approved by aapoalas

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 1, 2026
…xt_chunk_back, r=aapoalas

Implement `DoubleEndedIterator::next_chunk_back`

This PR builds off on @vinDelphini's [PR](rust-lang#151668) on introducing `DoubleEndedIterator::next_chunk_back` (which will be used in a follow up PR to optimize `ArrayChunks::try_rfold` once merged). This was in the works since late Jan and I thought to pick it up and get this over the finish line as vinDelphini has been away from the PR for a couple of months. I've made sure to pull from vinDelphini's branch to keep him authored on the commits he made.

Other things introduced from this PR is specialization like done for `Iterator::next_chunk`, constifying some stuff, making a custom `DoubleEndedIterator::next_chunk_back` for `IntoIter` (since it also has a custom impl of `Iterator::next_chunk`), and a bunch of tests mirroring that of `Iterator::next_chunk`.

There's no tracking issue for this yet, but the ACP for this introduction is [here](rust-lang/libs-team#734). I'll create the tracking issue for this soon.

----

Actually, can we have `DoubleEndedIterator::next_chunk_back` underneath [`Iterator::next_chunk` tracking issue](rust-lang#98326)?
rust-bors Bot pushed a commit that referenced this pull request Jul 1, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #156737 (Implement `DoubleEndedIterator::next_chunk_back`)
 - #158147 (std: fix stack buffer overflow in Windows junction_point)
 - #158180 (std: use `OnceLock` for SGX environment variable storage)
 - #158427 (Implement `ptr::{read,write}_unaligned` via `repr(packed)`)
 - #158531 (Change `adjust_ident_and_get_scope` arg to `LocalDefId`)
 - #158364 (rustc_target/asm: add LoongArch LSX/LASX inline asm register support)
@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit ae8f56d with merge 33e0f9b...

Workflow: https://github.com/rust-lang/rust/actions/runs/28548849803

rust-bors Bot pushed a commit that referenced this pull request Jul 1, 2026
…ck, r=aapoalas

Implement `DoubleEndedIterator::next_chunk_back`





This PR builds off on @vinDelphini's [PR](#151668) on introducing `DoubleEndedIterator::next_chunk_back` (which will be used in a follow up PR to optimize `ArrayChunks::try_rfold` once merged). This was in the works since late Jan and I thought to pick it up and get this over the finish line as vinDelphini has been away from the PR for a couple of months. I've made sure to pull from vinDelphini's branch to keep him authored on the commits he made.

Other things introduced from this PR is specialization like done for `Iterator::next_chunk`, constifying some stuff, making a custom `DoubleEndedIterator::next_chunk_back` for `IntoIter` (since it also has a custom impl of `Iterator::next_chunk`), and a bunch of tests mirroring that of `Iterator::next_chunk`.

There's no tracking issue for this yet, but the ACP for this introduction is [here](rust-lang/libs-team#734). I'll create the tracking issue for this soon.

----

Actually, can we have `DoubleEndedIterator::next_chunk_back` underneath [`Iterator::next_chunk` tracking issue](#98326)?
@jhpratt

jhpratt commented Jul 1, 2026

Copy link
Copy Markdown
Member

yielding to encompassing rollup

@bors yield

@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #158676.

rust-bors Bot pushed a commit that referenced this pull request Jul 1, 2026
Rollup of 8 pull requests

Successful merges:

 - #156737 (Implement `DoubleEndedIterator::next_chunk_back`)
 - #158180 (std: use `OnceLock` for SGX environment variable storage)
 - #158427 (Implement `ptr::{read,write}_unaligned` via `repr(packed)`)
 - #158531 (Change `adjust_ident_and_get_scope` arg to `LocalDefId`)
 - #158574 (Clarify ExitStatusExt documentation)
 - #158334 (rustdoc: Show use-site paths for unevaluated const array lengths)
 - #158364 (rustc_target/asm: add LoongArch LSX/LASX inline asm register support)
 - #158667 (rustc_sanitizers: use twox-hash without default features)
@rust-bors rust-bors Bot merged commit 666e69e into rust-lang:main Jul 2, 2026
13 of 14 checks passed
rust-timer added a commit that referenced this pull request Jul 2, 2026
Rollup merge of #156737 - asder8215:double_ended_iterator_next_chunk_back, r=aapoalas

Implement `DoubleEndedIterator::next_chunk_back`

This PR builds off on @vinDelphini's [PR](#151668) on introducing `DoubleEndedIterator::next_chunk_back` (which will be used in a follow up PR to optimize `ArrayChunks::try_rfold` once merged). This was in the works since late Jan and I thought to pick it up and get this over the finish line as vinDelphini has been away from the PR for a couple of months. I've made sure to pull from vinDelphini's branch to keep him authored on the commits he made.

Other things introduced from this PR is specialization like done for `Iterator::next_chunk`, constifying some stuff, making a custom `DoubleEndedIterator::next_chunk_back` for `IntoIter` (since it also has a custom impl of `Iterator::next_chunk`), and a bunch of tests mirroring that of `Iterator::next_chunk`.

There's no tracking issue for this yet, but the ACP for this introduction is [here](rust-lang/libs-team#734). I'll create the tracking issue for this soon.

----

Actually, can we have `DoubleEndedIterator::next_chunk_back` underneath [`Iterator::next_chunk` tracking issue](#98326)?
@rustbot rustbot added this to the 1.98.0 milestone Jul 2, 2026
@tgross35

tgross35 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Note that this could have used a squash before merge, the commit history has a lot of back-and-forth (for future reference).

@aapoalas

aapoalas commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Note that this could have used a squash before merge, the commit history has a lot of back-and-forth (for future reference).

Oof, my bad :(

@tgross35

tgross35 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

No worries, just another thing for the checklist :)

jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 3, 2026
…=aapoalas

Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`

Since `DoubleEndedIterator::next_chunk_back` got merged in rust-lang#156737, we can apply this method to optimize `ArrayChunk::try_rfold`.

I added @vinDelphini as a co-author because he was the one who originally made this change in his original PR on introducing [`DoubleEndedIterator::next_chunk_back`](rust-lang#151668).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 5, 2026
…=aapoalas

Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`

Since `DoubleEndedIterator::next_chunk_back` got merged in rust-lang#156737, we can apply this method to optimize `ArrayChunk::try_rfold`.

I added @vinDelphini as a co-author because he was the one who originally made this change in his original PR on introducing [`DoubleEndedIterator::next_chunk_back`](rust-lang#151668).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 5, 2026
…=aapoalas

Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`

Since `DoubleEndedIterator::next_chunk_back` got merged in rust-lang#156737, we can apply this method to optimize `ArrayChunk::try_rfold`.

I added @vinDelphini as a co-author because he was the one who originally made this change in his original PR on introducing [`DoubleEndedIterator::next_chunk_back`](rust-lang#151668).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants