Skip to content

indexing expressions can ignore fake borrows when an index diverges #161852

Description

@dianne

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.

Activity

  1. self-assigned this
    on Aug 27, 2026
  2. added
    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    C-bugCategory: This is a bug.
    on Aug 27, 2026
  3. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 27, 2026
  4. rustbot commented on Aug 27, 2026

    @rustbot
    Collaborator

    Assigning P-high (discussion on Zulip).

  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 27, 2026
  6. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    P-highHigh priority
    and removed
    P-highHigh priority
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-sliceArea: `[T]`C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions