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:
pub static STANDARD: Config =
Config {char_set: Standard, pad: true, line_length: None};
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:
pub static STANDARD =
Config {char_set: Standard, pad: true, line_length: None};
pub static HELLO = "hello, world!";
pub static HELLO_BYTES = bytes!("hello, world!");
pub static BAR = 18u8;
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.
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.