ConstantIndex and Index not flagged as potential aliases
Open
@beepster4096 is already working on this.
Since Aug 8, 2026.
A-array
A-borrow-checker
A-NLL
C-bug
I-unsound
P-high
T-compiler
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code (playpen):
fn main() {
let mut arr = [[Box::new(42)]];
let alias = &mut arr[0][{ let [row] = arr; drop(row); 0 }];
println!("{}", **alias); // use-after-free of arr's dead stack slot
}
I expected to see this happen: Compiler rejects code as unsound.
Instead, this happened: Compiler accepts code and prints a garbage number.
When run under Miri, we see this output:
error: Undefined Behavior: constructing invalid value of type std::boxed::Box<i32>: encountered a dangling box (use-after-free)
--> src/main.rs:4:20
|
4 | println!("{}", **alias); // use-after-free of arr's dead stack slot
| ^^^^^^^ Undefined Behavior occurred here
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Hypothesis: after a move _1[ConstantIndex{0 of 1}], a subsequent use of _1[Index(_6)] is not flagged as a use-of-partially-moved. The "any subpath moved" check of borrowck treats ConstantIndex as a sibling of a runtime Index projection, rather than a potential alias.
Meta
Nightly channel
Build using the Nightly version: 1.99.0-nightly
(2026-08-03 504869653f510b279c54)
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.