-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-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.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamneeds-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'm not sure if this is a bug or not.
I expected the below code to produce a compile error, but instead it compiles fine.
struct Thing;
fn foo() -> &'static Thing {
let y;
match Thing {
x if { y = &x; true } => {
// This drop should invalidate y
drop(x);
y
}
_ => {
panic!();
}
}
}
It seems that the single Thing
constant is both moved and static-promoted. This seems very strange.
Related to #144939. Discovered in #141295 (comment).
@rustbot labels +A-patterns +A-const-eval
Meta
Reproduces on the playground with version 1.91.0-nightly (2025-08-09 ca77504943887037504c)
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-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.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamneeds-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.