The warning "non_uppercase_globals" occurs for all uses of const, even ones in local scope. This should be renamed to "non_uppercase_const", instead.
I have some code like:
fn main() {
fn shadow1(f: u32) {
println!("f is {}", f)
const s: u32 = 1;
println!("s is {}", s);
fn shadow2(f: u32) {
println!("f is {}", f);
const s: u32 = 2;
println!("s is {}", s);
}
shadow2(s);
}
shadow1(8)
}
If I compile I get:
ƒ cargo run
Compiling tp v0.1.0 (/home/chris/Downloads/tp)
warning: constant `s` should have an upper case name
--> src/main.rs:5:11
|
5 | const s: u32 = 1;
| ^ help: convert the identifier to upper case: `S`
|
= note: `#[warn(non_upper_case_globals)]` on by default
warning: constant `s` should have an upper case name
--> src/main.rs:10:13
|
10 | const s: u32 = 2;
| ^ help: convert the identifier to upper case: `S`
Finished dev [unoptimized + debuginfo] target(s) in 0.19s
Running `target/debug/tp`
f is 8
s is 1
f is 1
s is 2
You'll notice that const was never used directly within main(), or in any global context.
Using const within local scope is useful for decoupling implicit sequential control flow from variable assignment within that scope. This is useful for writing concurrent code, and communicating intent to the compiler so it can catch errors.
It would be great if the error non_uppercase_globals was renamed to non_uppercase_const, and non_uppercase_globals would only warn on usage of const in the global scope!
The warning "non_uppercase_globals" occurs for all uses of const, even ones in local scope. This should be renamed to "non_uppercase_const", instead.
I have some code like:
If I compile I get:
You'll notice that const was never used directly within main(), or in any global context.
Using const within local scope is useful for decoupling implicit sequential control flow from variable assignment within that scope. This is useful for writing concurrent code, and communicating intent to the compiler so it can catch errors.
It would be great if the error non_uppercase_globals was renamed to non_uppercase_const, and non_uppercase_globals would only warn on usage of const in the global scope!