diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-03-04 13:54:31 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-03-07 12:06:20 +0000 |
commit | e00311aa9aabf447f27031cc5ffc114c5fbd8551 (patch) | |
tree | 91308f48704849bfbd5b6c170749bcd3b686e687 /gcc | |
parent | be94ef6e2d7ce29896c3e2861a8506479dfd55b5 (diff) | |
download | gcc-e00311aa9aabf447f27031cc5ffc114c5fbd8551.zip gcc-e00311aa9aabf447f27031cc5ffc114c5fbd8551.tar.gz gcc-e00311aa9aabf447f27031cc5ffc114c5fbd8551.tar.bz2 |
Update the deadcode pass to scan into modules and respect underscores on type names
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.h | 6 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-scan-deadcode.h | 14 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/mod-nameresolve.rs | 5 |
3 files changed, 20 insertions, 5 deletions
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h index 8a77661..d0ab2b4 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -262,6 +262,12 @@ public: stct.get_struct_base ()->base_struct->accept_vis (*this); } + void visit (HIR::Module &module) override + { + for (auto &item : module.get_items ()) + item->accept_vis (*this); + } + private: std::vector<HirId> worklist; std::set<HirId> liveSymbols; diff --git a/gcc/rust/lint/rust-lint-scan-deadcode.h b/gcc/rust/lint/rust-lint-scan-deadcode.h index 7bb166a..00114f2 100644 --- a/gcc/rust/lint/rust-lint-scan-deadcode.h +++ b/gcc/rust/lint/rust-lint-scan-deadcode.h @@ -81,9 +81,11 @@ public: HirId hirId = stct.get_mappings ().get_hirid (); if (should_warn (hirId)) { - rust_warning_at (stct.get_locus (), 0, - "struct is never constructed: %<%s%>", - stct.get_identifier ().c_str ()); + bool name_starts_underscore = stct.get_identifier ().at (0) == '_'; + if (!name_starts_underscore) + rust_warning_at (stct.get_locus (), 0, + "struct is never constructed: %<%s%>", + stct.get_identifier ().c_str ()); } else { @@ -124,6 +126,12 @@ public: } } + void visit (HIR::Module &mod) override + { + for (auto &item : mod.get_items ()) + item->accept_vis (*this); + } + private: std::set<HirId> live_symbols; Resolver::Resolver *resolver; diff --git a/gcc/testsuite/rust/compile/torture/mod-nameresolve.rs b/gcc/testsuite/rust/compile/torture/mod-nameresolve.rs index 218095c..a5e214b 100644 --- a/gcc/testsuite/rust/compile/torture/mod-nameresolve.rs +++ b/gcc/testsuite/rust/compile/torture/mod-nameresolve.rs @@ -1,5 +1,6 @@ -mod foo { // { dg-warning "unused name" } - struct A; // { dg-warning "unused name" } +// { dg-additional-options "-w" } +mod foo { + struct A; } fn main() {} |