match guards with unreachable success blocks ignore fake borrows
Open
@dianne is already working on this.
Since Aug 23, 2026.
A-MIR
A-patterns
C-bug
I-unsound
needs-triage
P-high
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Another variant of this, discovered at #t-compiler > Reporting a number of soundness issues in rustc @ 💬
#![forbid(unsafe_code)] #[inline(never)] fn read(b: &Box<Box<u64>>) -> u64 { ***b } fn main() { let mut x: Option<Box<Box<u64>>> = Some(Box::new(Box::new(7))); match x { Some(_) if { x = None; false } && panic!() => {} Some(ref b) => println!("{}", read(b)), None => println!("none"), } }
Originally posted by @theemathas in #160599
My reading of the problem here is that we insert fake reads for fake borrows into guards' success blocks (just before creating by-value bindings) instead of their failure blocks (before trying more arms, where we need fake borrows for soundness). The guard's success block is unreachable due to the panic, so the fake borrow on x isn't kept live and can't prevent x from being overwritten.
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.