From: Lucas Ly Ba <[email protected]>

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 <[email protected]>
---
 gcc/rust/checks/lints/unused/rust-unused-checker.cc    | 7 +++++++
 gcc/testsuite/rust/compile/non-upper-case-globals_0.rs | 4 ++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/non-upper-case-globals_0.rs

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 }
-- 
2.50.1

Reply via email to