From: Pierre-Emmanuel Patry <[email protected]>

gcc/rust/ChangeLog:

        * checks/lints/rust-lint-unused-var.cc (starts_with_underscore): Add
        function to detect underscore within symbol name.
        (check_decl): Call new function for underscore checking.

Signed-off-by: Pierre-Emmanuel Patry <[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/9f9752e9974fab4581c2ce6467b0838d7315d174

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4450

 gcc/rust/checks/lints/rust-lint-unused-var.cc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/lints/rust-lint-unused-var.cc 
b/gcc/rust/checks/lints/rust-lint-unused-var.cc
index 85915dd2d..0b2442f21 100644
--- a/gcc/rust/checks/lints/rust-lint-unused-var.cc
+++ b/gcc/rust/checks/lints/rust-lint-unused-var.cc
@@ -22,6 +22,15 @@
 namespace Rust {
 namespace Analysis {
 
+static bool
+starts_with_underscore (const char *var_name)
+{
+  auto pos = std::string (var_name).find_last_of (':');
+  if (pos == std::string::npos)
+    return strncmp (var_name, "_", 1) == 0;
+  return strncmp (var_name + pos + 1, "_", 1) == 0;
+}
+
 static void
 check_decl (tree *t)
 {
@@ -30,7 +39,7 @@ check_decl (tree *t)
 
   tree var_name = DECL_NAME (*t);
   const char *var_name_ptr = IDENTIFIER_POINTER (var_name);
-  bool starts_with_under_score = strncmp (var_name_ptr, "_", 1) == 0;
+  bool starts_with_under_score = starts_with_underscore (var_name_ptr);
   bool is_self = strcmp (var_name_ptr, "self") == 0;
 
   bool is_constant = TREE_CODE (*t) == CONST_DECL;
-- 
2.53.0

Reply via email to