From: Ryutaro Okada <1015ry...@gmail.com>

gcc/rust/ChangeLog:

        * checks/lints/rust-lint-unused-var.cc (check_decl):
        Do not warn about unused `self` parameter.

Signed-off-by: Ryutaro Okada <1015ry...@gmail.com>
---
 gcc/rust/checks/lints/rust-lint-unused-var.cc | 4 +++-
 1 file changed, 3 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 896eeb01c62..08596f1745a 100644
--- a/gcc/rust/checks/lints/rust-lint-unused-var.cc
+++ b/gcc/rust/checks/lints/rust-lint-unused-var.cc
@@ -31,6 +31,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 is_self = strcmp (var_name_ptr, "self") == 0;
 
   bool is_constant = TREE_CODE (*t) == CONST_DECL;
   // if (!is_constant)
@@ -43,7 +44,8 @@ check_decl (tree *t)
   //             starts_with_under_score ? "true" : "false", var_name_ptr);
   //   }
 
-  if (!TREE_USED (*t) && !DECL_ARTIFICIAL (*t) && !starts_with_under_score)
+  if (!TREE_USED (*t) && !DECL_ARTIFICIAL (*t) && !starts_with_under_score
+      && !is_self)
     {
       warning_at (DECL_SOURCE_LOCATION (*t),
                  is_constant ? OPT_Wunused_const_variable_
-- 
2.49.0

Reply via email to