From: Pierre-Emmanuel Patry <[email protected]>
The compiler should not emit any unused function warning on function name
prefixed with an underscore.
gcc/rust/ChangeLog:
* checks/lints/rust-lint-scan-deadcode.h: Add additional condition
to prevent warning emission. Check for underscore prefix.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3947.rs: Do not expect a warning on this
underscore prefixed function.
Signed-off-by: Pierre-Emmanuel Patry <[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/61fbdf23b43e65bb3ae7454bd99fd470a01ab946
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4450
gcc/rust/checks/lints/rust-lint-scan-deadcode.h | 5 ++++-
gcc/testsuite/rust/compile/issue-3947.rs | 1 -
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
index c79157986..ef43744a6 100644
--- a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
+++ b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
@@ -51,7 +51,10 @@ public:
void visit (HIR::Function &function) override
{
HirId hirId = function.get_mappings ().get_hirid ();
- if (should_warn (hirId) && !function.get_visibility ().is_public ())
+ auto starts_with_underscore
+ = function.get_function_name ().as_string ().rfind ('_', 0) == 0;
+ if (should_warn (hirId) && !function.get_visibility ().is_public ()
+ && !starts_with_underscore)
{
if (mappings.is_impl_item (hirId))
{
diff --git a/gcc/testsuite/rust/compile/issue-3947.rs
b/gcc/testsuite/rust/compile/issue-3947.rs
index 4d33c632c..b5219e760 100644
--- a/gcc/testsuite/rust/compile/issue-3947.rs
+++ b/gcc/testsuite/rust/compile/issue-3947.rs
@@ -7,7 +7,6 @@ enum _Enum {
type _E = _Enum;
-// { dg-warning "function is never used: '_a'" "" { target *-*-* } .+1 }
const fn _a() -> _Enum {
_E::A()
}
--
2.53.0