You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Why are
'static
lifetimes required to be written explicitly inconst
andstatic
references?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
'static
s were relatively annoying before, with constant strings, but now they are even more annoying, because after introduction ofconst
(#398) constant arrays have to be written through references.The same snippets after the change:
The question was asked on discuss forum, but without success.
The text was updated successfully, but these errors were encountered: