gccrs: Change variable underscore detection

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 <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
Pierre-Emmanuel Patry
2026-03-03 12:23:42 +01:00
committed by Arthur Cohen
parent 8feaf869ba
commit ea31a3fddb

View File

@@ -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;