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

NLL: cast causes failure to promote to static #55288

Closed
pnkfelix opened this issue Oct 23, 2018 · 5 comments
Closed

NLL: cast causes failure to promote to static #55288

pnkfelix opened this issue Oct 23, 2018 · 5 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Oct 23, 2018

spawned off of #55223 (comment)

This example is causing an error in NLL:

play

struct Slice(&'static [&'static [u8]]);
static MAP: Slice = Slice(&[
    b"CloseEvent" as &'static [u8],
]);

but this one does not cause an error:

play

struct Slice(&'static [&'static [u8]]);
static MAP: Slice = Slice(&[
    b"CloseEvent",
]);
@pnkfelix pnkfelix changed the title NLL: temporary value dropped while borrowed NLL: cast causes failure to promote to static Oct 23, 2018
@estebank
Copy link
Contributor

And it causes an ICE without nll enabled.

@estebank estebank added A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-NLL Area: Non-lexical lifetimes (NLL) regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Oct 23, 2018
@nikomatsakis nikomatsakis added this to the Rust 2018 Release milestone Oct 23, 2018
@RalfJung
Copy link
Member

And it causes an ICE without nll enabled.

A fix for that is on its way: #55262

@oli-obk
Copy link
Contributor

oli-obk commented Oct 24, 2018

@davidtwco and I have worked out a theory on zulip:

Promotion is happening successfully, but the AscribeUserTy still refers to the old value after promotion is done, because https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/promote_consts.rs#L306 only modifies the assignment, leaving the AscribeUserTy in place. We need to find potential corresponding AscribeUserTys and update them.

@davidtwco
Copy link
Member

For an update on what the root cause of this and the approach being taken to fixing it, there's a breakdown on Zulip.

@SimonSapin
Copy link
Contributor

but this one does not cause an error:

Casting is typically required for byte string literals because their type is a thin reference to a fixed-size array like &'static [u8; 10]. In an array literal of byte strings, we can get type errors because for example the type inferred for the second item is not the same as the type inferred for the first item. (They’re references to byte arrays of different size.) This is even if the outer array ends up type-annotated as a slice of byte slices &'static [&'static [u8]].

(Perhaps this somewhere type inference could improve?)

Another way to "cast" is slicing with RangeFull, for example [&b"CloseEvent"[..], &b"foo"[..]].

bors added a commit that referenced this issue Oct 27, 2018
NLL: cast causes failure to promote to static

Fixes #55288. See commit messages for more details.

r? @oli-obk
cc @nikomatsakis
cc @pnkfelix
cc @RalfJung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

7 participants