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

Rust should support omitting types of constants and static variables #50242

Closed
Boscop opened this issue Apr 26, 2018 · 2 comments
Closed

Rust should support omitting types of constants and static variables #50242

Boscop opened this issue Apr 26, 2018 · 2 comments

Comments

@Boscop
Copy link

Boscop commented Apr 26, 2018

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:

static LOOKUP_TABLE = ["foo", "bar"];

instead of having to spell out the types like this:

static LOOKUP_TABLE: [&'static str; 2] = ["foo", "bar"];

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?

@hellow554
Copy link
Contributor

hellow554 commented Apr 26, 2018

rust-lang/rfcs#1349?
https:/rust-lang/rfcs/blob/master/text/1623-static.md as well (but more as a side note)

@pietroalbini
Copy link
Member

Closing this as a duplicate, continue on the rfcs 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