File tree Expand file tree Collapse file tree 5 files changed +26
-27
lines changed Expand file tree Collapse file tree 5 files changed +26
-27
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,28 @@ class ScanDeadcode : public MarkLiveBase
133133 item->accept_vis (*this );
134134 }
135135
136+ void visit (HIR::ConstantItem &item) override
137+ {
138+ std::string var_name = item.get_identifier ().as_string ();
139+ bool starts_with_under_score = var_name.at (0 ) == ' _' ;
140+ HirId hirId = item.get_mappings ().get_hirid ();
141+ if (should_warn (hirId) && !starts_with_under_score)
142+ rust_warning_at (item.get_locus (), OPT_Wunused_variable,
143+ " deadcode const item %qs" ,
144+ item.get_identifier ().as_string ().c_str ());
145+ }
146+
147+ void visit (HIR::StaticItem &item) override
148+ {
149+ std::string var_name = item.get_identifier ().as_string ();
150+ bool starts_with_under_score = var_name.at (0 ) == ' _' ;
151+ HirId hirId = item.get_mappings ().get_hirid ();
152+ if (should_warn (hirId) && !starts_with_under_score)
153+ rust_warning_at (item.get_locus (), OPT_Wunused_variable,
154+ " deadcode static item %qs" ,
155+ item.get_identifier ().as_string ().c_str ());
156+ }
157+
136158private:
137159 std::set<HirId> live_symbols;
138160 Resolver::Resolver *resolver;
Original file line number Diff line number Diff line change @@ -37,35 +37,13 @@ UnusedChecker::go (HIR::Crate &crate)
3737 for (auto &item : crate.get_items ())
3838 item->accept_vis (*this );
3939}
40- void
41- UnusedChecker::visit (HIR::ConstantItem &item)
42- {
43- std::string var_name = item.get_identifier ().as_string ();
44- bool starts_with_under_score = var_name.compare (0 , 1 , " _" ) == 0 ;
45- auto id = item.get_mappings ().get_hirid ();
46- if (!unused_context.is_variable_used (id) && !starts_with_under_score)
47- rust_warning_at (item.get_locus (), OPT_Wunused_variable,
48- " unused variable %qs" ,
49- item.get_identifier ().as_string ().c_str ());
50- }
51-
52- void
53- UnusedChecker::visit (HIR::StaticItem &item)
54- {
55- std::string var_name = item.get_identifier ().as_string ();
56- bool starts_with_under_score = var_name.compare (0 , 1 , " _" ) == 0 ;
57- auto id = item.get_mappings ().get_hirid ();
58- if (!unused_context.is_variable_used (id) && !starts_with_under_score)
59- rust_warning_at (item.get_locus (), OPT_Wunused_variable,
60- " unused variable %qs" ,
61- item.get_identifier ().as_string ().c_str ());
62- }
6340
6441void
6542UnusedChecker::visit (HIR::TraitItemFunc &item)
6643{
6744 // TODO: check trait item functions if they are not derived.
6845}
46+
6947void
7048UnusedChecker::visit (HIR::IdentifierPattern &pattern)
7149{
Original file line number Diff line number Diff line change @@ -38,8 +38,6 @@ class UnusedChecker : public HIR::DefaultHIRVisitor
3838
3939 using HIR::DefaultHIRVisitor::visit;
4040 virtual void visit (HIR::TraitItemFunc &decl) override ;
41- virtual void visit (HIR::ConstantItem &item) override ;
42- virtual void visit (HIR::StaticItem &item) override ;
4341 virtual void visit (HIR::IdentifierPattern &identifier) override ;
4442 virtual void visit (HIR::AssignmentExpr &identifier) override ;
4543 virtual void visit (HIR::StructPatternFieldIdent &identifier) override ;
Original file line number Diff line number Diff line change 1+ const TEST : usize = 1 ;
2+ // { dg-warning "deadcode const .TEST." "" { target *-*-* } .-1 }
Original file line number Diff line number Diff line change 1- // { dg-additional-options "-frust-unused-check-2.0" }
21static TEST : usize = 1 ;
3- // { dg-warning "unused variable .TEST." "" { target *-*-* } .-1 }
2+ // { dg-warning "deadcode static item .TEST." "" { target *-*-* } .-1 }
You can’t perform that action at this time.
0 commit comments