Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect promotion for projection in a const #65727

Closed
ecstatic-morse opened this issue Oct 23, 2019 · 0 comments · Fixed by #65728
Closed

Incorrect promotion for projection in a const #65727

ecstatic-morse opened this issue Oct 23, 2019 · 0 comments · Fixed by #65728
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Oct 23, 2019

Consider the following code:

Playground

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.

@ecstatic-morse ecstatic-morse added the A-const-eval Area: constant evaluation (mir interpretation) label Oct 23, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 23, 2019
@bors bors closed this as completed in 3804876 Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants