[COMMITTED 044/141] gccrs: scan-deadcode: Do not warn unused fields if they start with '_'

arthur.cohen@embecosm.com arthur.cohen@embecosm.com
Mon Mar 24 12:44:27 GMT 2025


From: Arthur Cohen <arthur.cohen@embecosm.com>

gcc/rust/ChangeLog:

	* checks/lints/rust-lint-scan-deadcode.h: Check if the field name starts with an
	underscore before warning.
---
 gcc/rust/checks/lints/rust-lint-scan-deadcode.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
index e6ef1392c89..0fc203b0318 100644
--- a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
+++ b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
@@ -93,7 +93,8 @@ public:
 	  {
 	    HirId field_hir_id = field.get_mappings ().get_hirid ();
 	    if (should_warn (field_hir_id)
-		&& !field.get_visibility ().is_public ())
+		&& !field.get_visibility ().is_public ()
+		&& field.get_field_name ().as_string ().at (0) != '_')
 	      {
 		rust_warning_at (field.get_locus (), 0,
 				 "field is never read: %qs",
-- 
2.45.2



More information about the Gcc-rust mailing list