Skip to content

Commit a8a1fa3

Browse files
lucasly-baP-E-P
authored andcommitted
gccrs: add non upper case globals lint
gcc/rust/ChangeLog: * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): Add warning for static variables. gcc/testsuite/ChangeLog: * rust/compile/non-upper-case-globals_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
1 parent f0558a0 commit a8a1fa3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

gcc/rust/checks/lints/unused/rust-unused-checker.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ UnusedChecker::visit (HIR::StaticItem &item)
5959
rust_warning_at (item.get_locus (), OPT_Wunused_variable,
6060
"unused variable %qs",
6161
item.get_identifier ().as_string ().c_str ());
62+
63+
if (!std::all_of (var_name.begin (), var_name.end (), [] (unsigned char c) {
64+
return ISUPPER (c) || ISDIGIT (c) || c == '_';
65+
}))
66+
rust_warning_at (item.get_locus (), OPT_Wunused_variable,
67+
"static variable %qs should have an upper case name",
68+
var_name.c_str ());
6269
}
6370

6471
void
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// { dg-additional-options "-frust-unused-check-2.0" }
2+
3+
static _my_static : i32 = 0;
4+
// { dg-warning "static variable ._my_static. should have an upper case name" "" { target *-*-* } .-1 }

0 commit comments

Comments
 (0)