[gcc r16-6840] gccrs: add redudant semicolon lint
Arthur Cohen
cohenarthur@gcc.gnu.org
Fri Jan 16 16:30:23 GMT 2026
https://gcc.gnu.org/g:0655ee82b9938861d49f86ef3d5cb0a65fdc1d3e
commit r16-6840-g0655ee82b9938861d49f86ef3d5cb0a65fdc1d3e
Author: Lucas Ly Ba <lucas.ly-ba@outlook.com>
Date: Tue Jan 6 11:21:13 2026 +0000
gccrs: add redudant semicolon lint
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 <lucas.ly-ba@outlook.com>
Diff:
---
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(+)
diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.cc b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
index 45715dac43e7..235acd6a4065 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 ac7d2169781e..061d0c6f0029 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 000000000000..57d7c9ad3a06
--- /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
+}
+
+
More information about the Gcc-cvs
mailing list