Skip to content

Implement DoubleEndedIterator::next_chunk_back#156737

Open
asder8215 wants to merge 4 commits into
rust-lang:mainfrom
asder8215:double_ended_iterator_next_chunk_back
Open

Implement DoubleEndedIterator::next_chunk_back#156737
asder8215 wants to merge 4 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
@rustbot

rustbot commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

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.

@asder8215

Copy link
Copy Markdown
Contributor Author

Just rebased main onto this branch, so the tidy script works appropriately in where to put the const keyword now.

@asder8215 asder8215 requested a review from aapoalas June 13, 2026 20:13
@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 Jun 13, 2026
@asder8215

Copy link
Copy Markdown
Contributor Author

Just in case, I'm going to mark this as libs-api nominated on whether or not constifying certain functions here for DoubleEndedIterator::next_chunk_back is okay.

@rustbot label +I-libs-api-nominated

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jun 14, 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.

LGTM :) I'll let the nomination run its course.

View changes since this review

@nia-e

nia-e commented Jun 16, 2026

Copy link
Copy Markdown
Member

Per today's libs-api meeting, we'd rather keep this non-const for now unless there's a concrete usecase stronger than just consistency. Thanks ^^

@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.

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

Labels

I-libs-api-nominated Nominated for discussion during a libs-api team meeting. 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.

8 participants