[gcc r17-2235] gccrs: add unused visibilities lint

Arthur Cohen via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:1295b399622995da35979c9afde76e1237ce90c7

commit r17-2235-g1295b399622995da35979c9afde76e1237ce90c7
Author: Lucas Ly Ba <[email protected]>
Date:   Sat Jun 27 23:45:56 2026 +0200

    gccrs: add unused visibilities lint
    
    Warn on a visibility qualifier applied to a `const _` item, as it has no
    effect.
    
    gcc/rust/ChangeLog:
    
            * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
            Warn on a visibility qualifier on a `const _` item.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/unused-visibilities_0.rs: New test.
    
    Signed-off-by: Lucas Ly Ba <[email protected]>

Diff:
---
 gcc/rust/checks/lints/unused/rust-unused-checker.cc | 6 ++++++
 gcc/testsuite/rust/compile/unused-visibilities_0.rs | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.cc b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
index 571e31e430ae..6fd6c6efe1ca 100644
--- a/gcc/rust/checks/lints/unused/rust-unused-checker.cc
+++ b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
@@ -58,6 +58,12 @@ UnusedChecker::visit (HIR::ConstantItem &item)
     rust_warning_at (item.get_locus (), OPT_Wunused_variable,
 		     "unused variable %qs",
 		     item.get_identifier ().as_string ().c_str ());
+
+  // The unused_visibilities lint: a visibility qualifier on a `const _` item
+  // has no effect.
+  if (var_name == "_" && item.get_visibility ().is_public ())
+    rust_warning_at (item.get_locus (), OPT_Wunused_variable,
+		     "visibility qualifier on a %<const _%> item is unused");
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/unused-visibilities_0.rs b/gcc/testsuite/rust/compile/unused-visibilities_0.rs
new file mode 100644
index 000000000000..d158ab657b23
--- /dev/null
+++ b/gcc/testsuite/rust/compile/unused-visibilities_0.rs
@@ -0,0 +1,6 @@
+// { dg-additional-options "-frust-unused-check-2.0" }
+#![feature(no_core)]
+#![no_core]
+
+pub const _: i32 = 0;
+// { dg-warning "visibility qualifier on a .const _. item is unused" "" { target *-*-* } .-1 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.