-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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 #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)
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.