-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-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.
Description
Consider the following code:
const _: &i32 = {
let x = &(5, false).0;
x
};
fn main() {
let _: &'static i32 = &(5, false).0;
}The borrow of the tuple field in main is promoted out along with the tuple itself in accordance with the rules for rvalue static promotion. However, in the const, the mechanism for promotion does not remove Drop/StorageDead for the tuple, causing x to dangle. On stable, this is only caught during const-evaluation and results in a const_err warning. If this warning is supressed, an ICE occurs.
error: internal compiler error: tried to intern dangling pointer
--> src/main.rs:2:1
|
2 | / const _: &i32 = {
3 | | let x = &(5, false).0;
4 | | x
5 | | };
| |__^
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:361:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
On nightly, the MIR borrow checker prevents this from happening, and this code is rejected instead. It should be accepted in all contexts.
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, ...)C-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.