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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/a8a1fa3bb691f9e362529bba8f39f62e4dcff0df
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4382
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 751306171..f8428c860 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 000000000..f44ae5b63
--- /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 }
base-commit: f0558a0f18bcca5819c44edef3949cc8d184d4ea
--
2.52.0