- Notifications
You must be signed in to change notification settings - Fork 13.9k
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-constant-promotionArea: constant promotionArea: constant promotionA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language team
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)
oli-obk
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-constant-promotionArea: constant promotionArea: constant promotionA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language team