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]>
---
 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 85915dd2d11..0b2442f210e 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.50.1

Reply via email to