Skip to content

Commit e00311a

Browse files
committed
Update the deadcode pass to scan into modules and respect underscores on type names
1 parent be94ef6 commit e00311a

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

gcc/rust/lint/rust-lint-marklive.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ class MarkLive : public MarkLiveBase
262262
stct.get_struct_base ()->base_struct->accept_vis (*this);
263263
}
264264

265+
void visit (HIR::Module &module) override
266+
{
267+
for (auto &item : module.get_items ())
268+
item->accept_vis (*this);
269+
}
270+
265271
private:
266272
std::vector<HirId> worklist;
267273
std::set<HirId> liveSymbols;

gcc/rust/lint/rust-lint-scan-deadcode.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ class ScanDeadcode : public MarkLiveBase
8181
HirId hirId = stct.get_mappings ().get_hirid ();
8282
if (should_warn (hirId))
8383
{
84-
rust_warning_at (stct.get_locus (), 0,
85-
"struct is never constructed: %<%s%>",
86-
stct.get_identifier ().c_str ());
84+
bool name_starts_underscore = stct.get_identifier ().at (0) == '_';
85+
if (!name_starts_underscore)
86+
rust_warning_at (stct.get_locus (), 0,
87+
"struct is never constructed: %<%s%>",
88+
stct.get_identifier ().c_str ());
8789
}
8890
else
8991
{
@@ -124,6 +126,12 @@ class ScanDeadcode : public MarkLiveBase
124126
}
125127
}
126128

129+
void visit (HIR::Module &mod) override
130+
{
131+
for (auto &item : mod.get_items ())
132+
item->accept_vis (*this);
133+
}
134+
127135
private:
128136
std::set<HirId> live_symbols;
129137
Resolver::Resolver *resolver;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
mod foo { // { dg-warning "unused name" }
2-
struct A; // { dg-warning "unused name" }
1+
// { dg-additional-options "-w" }
2+
mod foo {
3+
struct A;
34
}
45

56
fn main() {}

0 commit comments

Comments
 (0)