-
-
Notifications
You must be signed in to change notification settings - Fork 14.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-constant-promotionArea: constant promotionArea: constant promotionA-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.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
This code:
const C: *const *const i32 = [
&{
let x: i32 = 0;
x
} as *const i32,
]
.as_ptr();fails to build with an error: error: encountered dangling pointer in final value of constant.
My belief is that the subexpression { let x: i32 = 0; x } should be promoted to a constant. It works if the final .as_ptr() is removed:
const C: [*const i32; 1] = [
&{
let x: i32 = 0;
x
} as *const i32,
];If the inner subexpression is replaced with zero, it works as well:
const C: *const *const i32 = [
&{
0
} as *const i32,
]
.as_ptr();Tested in Rust 1.95.0-nightly (2026-02-24 859951e).
Reactions are currently unavailable
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-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.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