Skip to content

Disallow accesses through an Index projection when a sibling ConstantIndex projection has been moved out of - #160780

Open
beepster4096 wants to merge 2 commits into
rust-lang:mainfrom
beepster4096:overlapping_move_paths
Open

Disallow accesses through an Index projection when a sibling ConstantIndex projection has been moved out of#160780
beepster4096 wants to merge 2 commits into
rust-lang:mainfrom
beepster4096:overlapping_move_paths

Conversation

@beepster4096

@beepster4096 beepster4096 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor
  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

Fixes #160525

  • Refactored the LookupResult enum returned by MovePathLookup::find:
    • The LookupResult::Parent(None) case is now a separate variant, LookupResult::None
    • LookupResult::Parent has an additional field containing the variant immediately following the parent move path.
  • Borrowck's check_if_full_path_is_moved now checks that new field and if it is PlaceElem::Index, it makes sure there are no uninit descendants of the indexed array's move path (which can only be ConstantIndex and descendants of those.)
    • move_path_closest_to is removed and inlined into check_if_full_path_is_moved.

@rustbot

rustbot commented Aug 8, 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 Aug 8, 2026
@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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: borrowck, compiler
  • borrowck, compiler expanded to 75 candidates
  • Random selection from 19 candidates

mpi: MovePathIndex,

/// The PlaceElem in the place immediately projecting from the parent move path.
next_elem: PlaceElem<'tcx>,

@cjgillot cjgillot Aug 9, 2026

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.

Should this be a ProjectionKind?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes more sense considering the variant is the only info used right now

Comment thread compiler/rustc_borrowck/src/lib.rs Outdated
// Subslice and ConstantIndex projections of slices also overlap siblings,
// but the parent slice will never have a move path
// Subslice projections of arrays are specifically checked in `check_if_subslice_element_is_moved`
LookupResult::Parent { mpi, next_elem: PlaceElem::Index(..) } => self

@cjgillot cjgillot Aug 9, 2026

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.

Could we match exhaustively on next_elem?

View changes since the review

@oli-obk oli-obk assigned cjgillot and oli-obk and unassigned oli-obk Aug 13, 2026
@oli-obk

oli-obk commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

While this is a soundness fix where we're def landing it, let's still crater it and inform any potentially broken crates.

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 13, 2026
Disallow accesses through an Index projection when a sibling ConstantIndex projection has been moved out of
@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 47574b8 (47574b82ff3fe9b0a45ff65a4fe189e295ecb748)
Base parent: ba28ff7 (ba28ff76f353a722f31c4f3dd2ac4e437d36411b)

@oli-obk

oli-obk commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@craterbot check

@oli-obk oli-obk added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 13, 2026
@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-160780 created and queued.
🤖 Automatically detected try build 47574b8
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-crater Status: Waiting on a crater run to be completed. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConstantIndex and Index not flagged as potential aliases

5 participants