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
Rust should support omitting the types of constants and static variables, and allow inferring them.
Often the types are long to write, involving many &'static str etc. and for static arrays one has to count the number of elements (or wait for the error message to show the number).
Also, this problem will get worse as more functions become evaluatable at compile-time which could lead to large nested types for constants/static vars.
Allowing omitting the type encourages making more things const/static (also function-locally, where often a let binding gets used for values that should really be constants out of convenience of omitting the type..).
It would also make Rust more ergonomic, because more of the same rules that apply to let bindings will also apply to const/static vars.
So the syntax would mirror that of let bindings:
staticLOOKUP_TABLE = ["foo","bar"];
instead of having to spell out the types like this:
This would also be useful for later when more complex computations are allowed for initializing constants, which has spawned suggestions to allow impl Trait existential types in const/static definitions, but which wouldn't even be necessary if the types were allowed to be omitted.
What do you think?
The text was updated successfully, but these errors were encountered:
Rust should support omitting the types of constants and static variables, and allow inferring them.
Often the types are long to write, involving many
&'static str
etc. and for static arrays one has to count the number of elements (or wait for the error message to show the number).Also, this problem will get worse as more functions become evaluatable at compile-time which could lead to large nested types for constants/static vars.
Allowing omitting the type encourages making more things
const
/static
(also function-locally, where often alet
binding gets used for values that should really be constants out of convenience of omitting the type..).It would also make Rust more ergonomic, because more of the same rules that apply to
let
bindings will also apply toconst
/static
vars.So the syntax would mirror that of
let
bindings:instead of having to spell out the types like this:
This would also be useful for later when more complex computations are allowed for initializing constants, which has spawned suggestions to allow
impl Trait
existential types inconst
/static
definitions, but which wouldn't even be necessary if the types were allowed to be omitted.What do you think?
The text was updated successfully, but these errors were encountered: