`&raw const` gets static-promoted in match guard
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
static X: &i32 = unsafe {
let wut = &*'a: {
match one() {
temp if { break 'a &raw const temp } => {}
_ => {}
}
loop {}
};
wut
};
const fn one() -> i32 {
1
}
fn main() {
println!("{X}");
}
I expected some kind of error, possibly UB. Instead, the code runs fine and prints 1.
It seems that the &raw const temp is somehow causing temp to be lifetime-extended. This seems wrong. Only non-raw referencing should cause lifetime extension or static promotion.
See also https://github.com/rust-lang/rust/issues/142229, where a similar weirdness causes an ICE. cc @RalfJung
This issue was discovered jointly with @danielhenrymantilla
@rustbot labels +A-const-eval +A-patterns
Meta
Reproducible on the rust playground with version 1.91.0-nightly (2025-08-03 f34ba774c78ea32b7c40)
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.
Research direction
Start with the standalone Rust reproducer and the compiler areas covered by the A-const-eval and A-patterns labels. Determine why the raw const reference in the match guard is lifetime-extended or statically promoted, then add a regression test showing the expected behavior and run the relevant compiler tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100