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.
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:
This compiles successfully because the fake read on the fake borrow of
xis unreachable, but Miri detects UB inx[0][{ x = y; 0 }]. This checks that0is within-bounds fory[0], buty[0]is itself out-of-bounds, so it's UB to read its length.