Also emit suggestions for usages in the non_upper_case_globals lint
This commit is contained in:
parent
994794a50b
commit
42bb66add3
5 changed files with 211 additions and 12 deletions
39
tests/ui/lint/lint-non-uppercase-usages.fixed
Normal file
39
tests/ui/lint/lint-non-uppercase-usages.fixed
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Checks that the `non_upper_case_globals` emits suggestions for usages as well
|
||||
// <https://github.com/rust-lang/rust/issues/124061>
|
||||
|
||||
//@ check-pass
|
||||
//@ run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
const MY_STATIC: u32 = 0;
|
||||
//~^ WARN constant `my_static` should have an upper case name
|
||||
//~| SUGGESTION MY_STATIC
|
||||
|
||||
const LOL: u32 = MY_STATIC + 0;
|
||||
//~^ SUGGESTION MY_STATIC
|
||||
|
||||
thread_local! {
|
||||
static FOO_FOO: Cell<usize> = unreachable!();
|
||||
//~^ WARN constant `fooFOO` should have an upper case name
|
||||
//~| SUGGESTION FOO_FOO
|
||||
}
|
||||
|
||||
fn foo<const FOO: u32>() {
|
||||
//~^ WARN const parameter `foo` should have an upper case name
|
||||
//~| SUGGESTION FOO
|
||||
let _a = FOO + 1;
|
||||
//~^ SUGGESTION FOO
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _a = crate::MY_STATIC;
|
||||
//~^ SUGGESTION MY_STATIC
|
||||
|
||||
FOO_FOO.set(9);
|
||||
//~^ SUGGESTION FOO_FOO
|
||||
println!("{}", FOO_FOO.get());
|
||||
//~^ SUGGESTION FOO_FOO
|
||||
}
|
||||
39
tests/ui/lint/lint-non-uppercase-usages.rs
Normal file
39
tests/ui/lint/lint-non-uppercase-usages.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Checks that the `non_upper_case_globals` emits suggestions for usages as well
|
||||
// <https://github.com/rust-lang/rust/issues/124061>
|
||||
|
||||
//@ check-pass
|
||||
//@ run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
const my_static: u32 = 0;
|
||||
//~^ WARN constant `my_static` should have an upper case name
|
||||
//~| SUGGESTION MY_STATIC
|
||||
|
||||
const LOL: u32 = my_static + 0;
|
||||
//~^ SUGGESTION MY_STATIC
|
||||
|
||||
thread_local! {
|
||||
static fooFOO: Cell<usize> = unreachable!();
|
||||
//~^ WARN constant `fooFOO` should have an upper case name
|
||||
//~| SUGGESTION FOO_FOO
|
||||
}
|
||||
|
||||
fn foo<const foo: u32>() {
|
||||
//~^ WARN const parameter `foo` should have an upper case name
|
||||
//~| SUGGESTION FOO
|
||||
let _a = foo + 1;
|
||||
//~^ SUGGESTION FOO
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _a = crate::my_static;
|
||||
//~^ SUGGESTION MY_STATIC
|
||||
|
||||
fooFOO.set(9);
|
||||
//~^ SUGGESTION FOO_FOO
|
||||
println!("{}", fooFOO.get());
|
||||
//~^ SUGGESTION FOO_FOO
|
||||
}
|
||||
64
tests/ui/lint/lint-non-uppercase-usages.stderr
Normal file
64
tests/ui/lint/lint-non-uppercase-usages.stderr
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
warning: constant `my_static` should have an upper case name
|
||||
--> $DIR/lint-non-uppercase-usages.rs:11:7
|
||||
|
|
||||
LL | const my_static: u32 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(non_upper_case_globals)]` on by default
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - const my_static: u32 = 0;
|
||||
LL + const MY_STATIC: u32 = 0;
|
||||
|
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - const LOL: u32 = my_static + 0;
|
||||
LL + const LOL: u32 = MY_STATIC + 0;
|
||||
|
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - let _a = crate::my_static;
|
||||
LL + let _a = crate::MY_STATIC;
|
||||
|
|
||||
|
||||
warning: constant `fooFOO` should have an upper case name
|
||||
--> $DIR/lint-non-uppercase-usages.rs:19:12
|
||||
|
|
||||
LL | static fooFOO: Cell<usize> = unreachable!();
|
||||
| ^^^^^^
|
||||
|
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - static fooFOO: Cell<usize> = unreachable!();
|
||||
LL + static FOO_FOO: Cell<usize> = unreachable!();
|
||||
|
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - fooFOO.set(9);
|
||||
LL + FOO_FOO.set(9);
|
||||
|
|
||||
help: convert the identifier to upper case
|
||||
|
|
||||
LL - println!("{}", fooFOO.get());
|
||||
LL + println!("{}", FOO_FOO.get());
|
||||
|
|
||||
|
||||
warning: const parameter `foo` should have an upper case name
|
||||
--> $DIR/lint-non-uppercase-usages.rs:24:14
|
||||
|
|
||||
LL | fn foo<const foo: u32>() {
|
||||
| ^^^
|
||||
|
|
||||
help: convert the identifier to upper case (notice the capitalization difference)
|
||||
|
|
||||
LL - fn foo<const foo: u32>() {
|
||||
LL + fn foo<const FOO: u32>() {
|
||||
|
|
||||
help: convert the identifier to upper case (notice the capitalization difference)
|
||||
|
|
||||
LL - let _a = foo + 1;
|
||||
LL + let _a = FOO + 1;
|
||||
|
|
||||
|
||||
warning: 3 warnings emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue