[gccrs,COMMIT] gccrs: add unused braces lint
Checks
Commit Message
From: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/ChangeLog:
* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
Warn on unnecessary braces around an assigned value.
* rust-lang.cc (grs_langhook_init_options_struct): Enable warn_unused.
gcc/testsuite/ChangeLog:
* rust/compile/unused-braces_0.rs: New test.
Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
---
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/414c389f8094a888a30966485489e3680149cbb7
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4625
gcc/rust/checks/lints/unused/rust-unused-checker.cc | 9 +++++++++
gcc/testsuite/rust/compile/unused-braces_0.rs | 8 ++++++++
2 files changed, 17 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/unused-braces_0.rs
base-commit: ff0229b955bcb49716cd4fb48bec584f4cfbd53f
@@ -330,6 +330,15 @@ UnusedChecker::visit (HIR::LetStmt &stmt)
"unused doc comment");
break;
}
+ if (stmt.has_init_expr ()
+ && stmt.get_init_expr ().get_expression_type ()
+ == HIR::Expr::ExprType::Block)
+ {
+ auto &block = static_cast<HIR::BlockExpr &> (stmt.get_init_expr ());
+ if (block.get_statements ().empty () && block.has_expr ())
+ rust_warning_at (block.get_locus (), OPT_Wunused,
+ "unnecessary braces around assigned value");
+ }
walk (stmt);
}
new file mode 100644
@@ -0,0 +1,8 @@
+// { dg-additional-options "-frust-unused-check-2.0" }
+#![feature(no_core)]
+#![no_core]
+
+pub fn foo() {
+ let _x = { 5 };
+// { dg-warning "unnecessary braces around assigned value" "" { target *-*-* } .-1 }
+}