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

Literals don't have static lifetime #40405

Closed
jethrogb opened this issue Mar 10, 2017 · 5 comments
Closed

Literals don't have static lifetime #40405

jethrogb opened this issue Mar 10, 2017 · 5 comments

Comments

@jethrogb
Copy link
Contributor

jethrogb commented Mar 10, 2017

OK:

fn get_slice_ok() -> &'static [u8] {
    const CONST: &'static [u8] = &[0];
    CONST
}

Borrowck error:

fn get_slice_error() -> &'static [u8] {
    &[0]
}

But consts and literals are basically the same thing, so I'd expect this to work.

@durka
Copy link
Contributor

durka commented Mar 10, 2017

It's not about slices: let _: &'static u8 = &42; doesn't work either.

@jethrogb jethrogb changed the title Slice literal does not have static lifetime Literals don't have static lifetime Mar 10, 2017
@jethrogb
Copy link
Contributor Author

Related #18852

@cramertj
Copy link
Member

cramertj commented Mar 10, 2017

IIUC #38865 should fix this.

@jethrogb
Copy link
Contributor Author

Huzzah!

From RFC 1414:

Summary

Promote constexpr rvalues to values in static memory instead of stack slots, and expose those in the language by being able to directly create 'static references to them. This would allow code like let x: &'static u32 = &42 to work.

@jethrogb
Copy link
Contributor Author

I'm going to close this in favor of the tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants