Skip to content

Drop array elements in order after a partial move - #165037

Open
yashaggarwal85d wants to merge 1 commit into
rust-lang:mainfrom
yashaggarwal85d:fix-array-partial-move-drop-order
Open

yashaggarwal85d wants to merge 1 commit into
rust-lang:mainfrom
yashaggarwal85d:fix-array-partial-move-drop-order

Conversation

@yashaggarwal85d

@yashaggarwal85d yashaggarwal85d commented Oct 27, 2026 •

Copy link
Copy Markdown

When an array may have been partially moved out by an array pattern, drop elaboration splits it into
kept indices and dropped subslices, but then built the drop ladder over those pieces in reverse. So
let a = [D(1), D(2)]; if false { let [_x, _] = a; } dropped 2 before 1. The reversal came in with
#109008; before that the ladder went first to last, which is what the Reference says.

This removes the .rev() and adds a run-pass test. Two existing drop-order tests
(if-let-guards.rs, or-pattern-drop-order.rs) were asserting the reversed order, so I fixed their expectations.

Fixes #164809

AI was used to write tests for this. I reviewed the changes myself. Thanks

@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 27, 2026
@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@petrochenkov

Copy link
Copy Markdown
Contributor

r? mir

@rustbot rustbot assigned oli-obk and unassigned petrochenkov Oct 27, 2026
@oli-obk oli-obk closed this Oct 28, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 28, 2026
@oli-obk oli-obk reopened this Oct 29, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 29, 2026
@yashaggarwal85d

This comment was marked as resolved.

@oli-obk

This comment was marked as resolved.

@yashaggarwal85d

This comment was marked as resolved.

This branch has not been deployed

No deployments
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elements of an array that may have been moved out of with an array pattern are dropped in the wrong order

4 participants