rust-lang / rust-lang/rust

indexing expressions can ignore fake borrows when an index diverges

Open
#161,852 1 comment 0 reactions 1 assignee View on GitHub

@dianne is already working on this.

Since Aug 27, 2026.

A-MIR A-slice C-bug I-unsound P-high T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently for chained-together indexing expressions, we emit fake reads for fake borrows only at the very end. This means that if control flow diverges within an index expression such that the fake reads are unreachable, they can't keep fake borrows on indexed-into slice references alive.

For example:

fn unsound() {
    let mut x: &[&[&[u32]]] = &[&[&[0]]];
    let y: &[&[&[u32]]] = &[];
    x[0][{ x = y; 0 }][{ return; 0 }];
}

This compiles successfully because the fake read on the fake borrow of x is unreachable, but Miri detects UB in x[0][{ x = y; 0 }]. This checks that 0 is within-bounds for y[0], but y[0] is itself out-of-bounds, so it's UB to read its length.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.