From: Lucas Ly Ba Date: Wed, 14 Jan 2026 16:19:13 +0000 (+0000) Subject: gccrs: add non upper case globals lint X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77ebf01df7bdb30bfec4539b2a9050a7fdf09209;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.cc b/gcc/rust/checks/lints/unused/rust-unused-checker.cc index 751306171de..f8428c8605b 100644 --- a/gcc/rust/checks/lints/unused/rust-unused-checker.cc +++ b/gcc/rust/checks/lints/unused/rust-unused-checker.cc @@ -59,6 +59,13 @@ UnusedChecker::visit (HIR::StaticItem &item) rust_warning_at (item.get_locus (), OPT_Wunused_variable, "unused variable %qs", item.get_identifier ().as_string ().c_str ()); + + if (!std::all_of (var_name.begin (), var_name.end (), [] (unsigned char c) { + return ISUPPER (c) || ISDIGIT (c) || c == '_'; + })) + rust_warning_at (item.get_locus (), OPT_Wunused_variable, + "static variable %qs should have an upper case name", + var_name.c_str ()); } void diff --git a/gcc/testsuite/rust/compile/non-upper-case-globals_0.rs b/gcc/testsuite/rust/compile/non-upper-case-globals_0.rs new file mode 100644 index 00000000000..f44ae5b634c --- /dev/null +++ b/gcc/testsuite/rust/compile/non-upper-case-globals_0.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-frust-unused-check-2.0" } + +static _my_static : i32 = 0; +// { dg-warning "static variable ._my_static. should have an upper case name" "" { target *-*-* } .-1 }