Determine const type dynamically, remove capitalization requirement


#1

Hi,

I like the dynamic approach used in rust where types are determined dynamically, with the option to specify variable type if desired. I think applying that to const keyword to enable dynamic type determination would be great as well. I would be great as well to cancel the the capitalization rule required for const keyword.

Thank You,


#2

Types are never determined dynamically- they must always be knowable at compile time from the context they are used in. As far as actually applying that rule to consts, there is already a GitHub issue here: https://github.com/rust-lang/rfcs/issues/1349

You can get rid of the capitalization rule with #[allow(non_upper_case_globals)]- it’s just a lint.


#3

Ok, I would like const to get the type automatically same as let statement. Thank You


#4

Why do I get the feeling that the next thing to be suggested will be support for let statements outside of functions?

Seriously, as I said in the other thread, const is not let. It’s nothing like let. If anything, it’s closer to C preprocessor macros in purpose. (though C++ constexpr is a much better approximation)


#5

f anything, it’s closer to C preprocessor macros in purpose.

But C preprocessor macros don’t require type annotations


#6

Ok, I would like const to get the type automatically same as let statement

The fact that type inference does not happen for consts (and statics, and non-closure functions) is intentional. It makes the code clearer and more robust. (So, it’s basically not going to happen.)