From: Lucas Ly Ba <[email protected]>
gcc/rust/ChangeLog:
* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
New.
* checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit):
New.
gcc/testsuite/ChangeLog:
* rust/compile/unused-doc-comment_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/25ab7ba2877cec8bb831ddfeea9ecb72ef23c9d5
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/4627
.../checks/lints/unused/rust-unused-checker.cc | 14 ++++++++++++++
gcc/rust/checks/lints/unused/rust-unused-checker.h | 1 +
gcc/testsuite/rust/compile/unused-doc-comment_0.rs | 10 ++++++++++
3 files changed, 25 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/unused-doc-comment_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 643d262d2..0d091e647 100644
--- a/gcc/rust/checks/lints/unused/rust-unused-checker.cc
+++ b/gcc/rust/checks/lints/unused/rust-unused-checker.cc
@@ -24,6 +24,7 @@
#include "options.h"
#include "rust-keyword-values.h"
+#include "rust-attribute-values.h"
#include "rust-rib.h"
namespace Rust {
@@ -333,5 +334,18 @@ UnusedChecker::visit (HIR::MatchExpr &expr)
walk (expr);
}
+void
+UnusedChecker::visit (HIR::LetStmt &stmt)
+{
+ for (auto &attr : stmt.get_outer_attrs ())
+ if (attr.get_path ().as_string () == Values::Attributes::DOC)
+ {
+ rust_warning_at (stmt.get_locus (), OPT_Wunused_variable,
+ "unused doc comment");
+ break;
+ }
+ walk (stmt);
+}
+
} // 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 2f2557ce3..46e012e79 100644
--- a/gcc/rust/checks/lints/unused/rust-unused-checker.h
+++ b/gcc/rust/checks/lints/unused/rust-unused-checker.h
@@ -51,6 +51,7 @@ private:
virtual void visit (HIR::StructPatternFieldIdentPat &field) override;
virtual void visit (HIR::MatchExpr &expr) override;
virtual void visit (HIR::ExternBlock &block) override;
+ virtual void visit (HIR::LetStmt &stmt) override;
virtual void visit_loop_label (HIR::LoopLabel &label) override;
};
} // namespace Analysis
diff --git a/gcc/testsuite/rust/compile/unused-doc-comment_0.rs
b/gcc/testsuite/rust/compile/unused-doc-comment_0.rs
new file mode 100644
index 000000000..5556563f3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/unused-doc-comment_0.rs
@@ -0,0 +1,10 @@
+// { dg-additional-options "-frust-unused-check-2.0" }
+#![feature(no_core)]
+#![no_core]
+
+pub fn foo() {
+ /// useless
+ let _x = 5;
+// { dg-warning "unused doc comment" "" { target *-*-* } .-1 }
+ let _y = _x;
+}
base-commit: 864defecb6c0faf055005b48a24914651ef5c727
--
2.54.0