]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: add non upper case globals lint
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Wed, 14 Jan 2026 16:19:13 +0000 (16:19 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 27 Feb 2026 14:57:05 +0000 (15:57 +0100)
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>
gcc/rust/checks/lints/unused/rust-unused-checker.cc
gcc/testsuite/rust/compile/non-upper-case-globals_0.rs [new file with mode: 0644]

index 751306171debfb7e673fd5978c9840831f583d19..f8428c8605beb5a08a3bc007c0b63dbfebca0353 100644 (file)
@@ -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 (file)
index 0000000..f44ae5b
--- /dev/null
@@ -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 }