Skip to content

lib: specialize Clone of array IntoIter#156634

Open
Paladynee wants to merge 1 commit into
rust-lang:mainfrom
Paladynee:lib/array-intoiter-spec-clone
Open

lib: specialize Clone of array IntoIter#156634
Paladynee wants to merge 1 commit into
rust-lang:mainfrom
Paladynee:lib/array-intoiter-spec-clone

Conversation

@Paladynee
Copy link
Copy Markdown
Contributor

@Paladynee Paladynee commented May 16, 2026

This PR adds the TrivialClone specialization to the PolymorphicIter type, which array::IntoIter uses. I also added another coretest for the default case (already existing test catches the specialized one).

There are no unwinding concerns since TrivialClone means cloning = copying and we never call Clone::clone.

array:IntoIter is being used on a lot of places in both core and in user code, and array::IntoIter (nor does its users) override Clone often and just delegate to the inner type PolymorphicIter which does not yet do the TrivialClone specialization and is burdened by the iterator and unwind safety shenanigans for all types, so this PR should address some of that. This should in turn slightly reduce both stack usage and remove unwinding prologue/epilogue etc. from such functions and improve our -Cno-prepopulate-passes codegen too.

perf: https://godbolt.org/z/eTPjj3hP3

@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 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 16, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates

@Paladynee Paladynee force-pushed the lib/array-intoiter-spec-clone branch from 1ef1a4b to 5cec957 Compare May 16, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants