-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.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 team
Description
I'm not sure if this is a bug or not.
struct Thing;
impl Drop for Thing {
fn drop(&mut self) {
println!("drop");
}
}
const X: &Thing = &Thing;
fn main() {
let _a = X;
}The above code prints nothing. It seems that the Thing value is lifetime-extended into an implicit static.
I believe that the design intention of const is that replacing a const with its definition should not change its behavior. However, in the above code, replacing X with &Thing causes it to print drop. Therefore, I think this code should probably produce a compile error.
Meta
Reproducible on the playground with version 1.91.0-nightly (2025-08-25 54c581243c977c7662c9)
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-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.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 team