Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider allowing limited type inference in static declarations #296
Comments
rust-highfive
referenced this issue
Sep 24, 2014
Closed
Consider allowing limited type inference in static declarations #9346
nrc
added
the
T-lang
label
Aug 17, 2016
This comment has been minimized.
This comment has been minimized.
|
Closing in favor of #1349. |
Centril
closed this
Oct 7, 2018
wycats
pushed a commit
to wycats/rust-rfcs
that referenced
this issue
Mar 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rust-highfive commentedSep 24, 2014
Thursday Sep 19, 2013 at 23:23 GMT
For earlier discussion, see rust-lang/rust#9346
This issue was labelled with: A-typesystem, B-RFC in the Rust repository
Currently, statics must have a type annotation as doing global type inference to resolve the type is a bad idea. However, this leads to some annoying duplication, especially when defining a static struct instance. For example, from
extra::base64:There's no ambiguity in the type of the RHS, but the LHS must repeat the type anyways.
Would it be possible/reasonable to infer the type of statics from the RHS of the assignment where possible? Things like this would be work:
but
would not since the type isn't specified (or maybe it would resolve to
int?). Untyped integer literals and generic types containing them are actually the only things I can think of that would require a type annotation.