indexing expressions can ignore fake borrows when an index diverges
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.