From: Lucas Ly Ba <[email protected]>

gcc/rust/ChangeLog:

        * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
        Emit warning in empty statement visitor.
        * checks/lints/unused/rust-unused-checker.h:
        Likewise.

gcc/testsuite/ChangeLog:

        * rust/compile/redundant-semicolons_0.rs: New test.

Signed-off-by: Lucas Ly Ba <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/09ba4843b369530371487e1c84372299adecc17e

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4360

 gcc/rust/checks/lints/unused/rust-unused-checker.cc  |  7 +++++++
 gcc/rust/checks/lints/unused/rust-unused-checker.h   |  1 +
 gcc/testsuite/rust/compile/redundant-semicolons_0.rs | 10 ++++++++++
 3 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/redundant-semicolons_0.rs

diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.cc 
b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
index 45715dac4..235acd6a4 100644
--- a/gcc/rust/checks/lints/unused/rust-unused-checker.cc
+++ b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
@@ -117,5 +117,12 @@ UnusedChecker::visit (HIR::StructPatternFieldIdent 
&pattern)
                     pattern.get_identifier ().as_string ().c_str ());
 }
 
+void
+UnusedChecker::visit (HIR::EmptyStmt &stmt)
+{
+  rust_warning_at (stmt.get_locus (), OPT_Wunused_variable,
+                  "unnecessary trailing semicolons");
+}
+
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.h 
b/gcc/rust/checks/lints/unused/rust-unused-checker.h
index ac7d21697..061d0c6f0 100644
--- a/gcc/rust/checks/lints/unused/rust-unused-checker.h
+++ b/gcc/rust/checks/lints/unused/rust-unused-checker.h
@@ -43,6 +43,7 @@ private:
   virtual void visit (HIR::IdentifierPattern &identifier) override;
   virtual void visit (HIR::AssignmentExpr &identifier) override;
   virtual void visit (HIR::StructPatternFieldIdent &identifier) override;
+  virtual void visit (HIR::EmptyStmt &stmt) override;
 };
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/testsuite/rust/compile/redundant-semicolons_0.rs 
b/gcc/testsuite/rust/compile/redundant-semicolons_0.rs
new file mode 100644
index 000000000..57d7c9ad3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/redundant-semicolons_0.rs
@@ -0,0 +1,10 @@
+// { dg-additional-options "-frust-unused-check-2.0" }
+
+pub fn foo() -> i32 
+{
+    let a = 32;;
+// { dg-warning "unnecessary trailing semicolons" "" { target *-*-* } .-1 }
+    return a
+}
+
+

base-commit: c4d2abe33d8ef1a74ae44011f322a1721faaadb9
-- 
2.52.0

Reply via email to