Closed
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.