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

Allow omitting ‘static in const and static references #406

Closed
petrochenkov opened this issue Oct 23, 2014 · 2 comments
Closed

Allow omitting ‘static in const and static references #406

petrochenkov opened this issue Oct 23, 2014 · 2 comments

Comments

@petrochenkov
Copy link
Contributor

Why are 'static lifetimes required to be written explicitly in const and static references?

const MY_STRING: &'static str = "Hello world!";
const MY_ARRAY_REF: &'static [int, ..1000] = &[0, ..1000];

If I understand the motivation correctly, the types should be written there explicitly for the similar reasons as for function declarations - they represent interfaces and shouldn't change silently after changes to initializer or function body.
But the lifetimes for const/static references are always 'static and will not change, can't they be elided?

These explicit 'statics were relatively annoying before, with constant strings, but now they are even more annoying, because after introduction of const (#398) constant arrays have to be written through references.

const MY_ARRAY1: [int, ..1000] = [0, ..1000]; // Not OK, rvalue arrays are bad
static MY_ARRAY2: [int, ..1000] = [0, ..1000]; // Not OK, `static` arrays can't be used in constant expressions
const MY_ARRAY3: &'static [int, ..1000] = &[0, ..1000]; // OK, but more verbose than necessary

The same snippets after the change:

// The lifetimes are inferred
const MY_STRING: &str = "Hello world!";
const MY_ARRAY: &[int, ..1000] = &[0, ..1000];

The question was asked on discuss forum, but without success.

@petrochenkov
Copy link
Contributor Author

Closing in favor of #1623

@llogiq
Copy link
Contributor

llogiq commented May 20, 2016

I knew I wasn't the first to suggest this, but somehow your issue elided my search... 👍

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

2 participants