@@ -29,12 +29,13 @@ namespace Rust {
2929namespace Analysis {
3030
3131// Scan item symbols and warn the symbol if it is not in the live_symbols set.
32- // There are three kinds of item we should handle in this pass.
32+ // There are four kinds of item we should handle in this pass.
3333// 1. Function item
3434// 2. The function item in the impl block without trait
3535// 3. StructStruct, e.g., `Struct Foo{one: 1, two: 2}`. Furthermore, the unused
3636// struct fields will be warned too.
3737// 4. TupleStruct, e.g., `Struct Foo(i32, i32)`
38+ // 5. Enum, e.g., `enum Foo { A, B }`
3839class ScanDeadcode : public MarkLiveBase
3940{
4041 using Rust::Analysis::MarkLiveBase::visit;
@@ -116,6 +117,19 @@ class ScanDeadcode : public MarkLiveBase
116117 }
117118 }
118119
120+ void visit (HIR::Enum &enm) override
121+ {
122+ HirId hirId = enm.get_mappings ().get_hirid ();
123+ if (should_warn (hirId) && !enm.get_visibility ().is_public ())
124+ {
125+ bool name_starts_underscore
126+ = enm.get_identifier ().as_string ().at (0 ) == ' _' ;
127+ if (!name_starts_underscore)
128+ rust_warning_at (enm.get_locus (), 0 , " enum is never used: %qs" ,
129+ enm.get_identifier ().as_string ().c_str ());
130+ }
131+ }
132+
119133 void visit (HIR::ImplBlock &blc) override
120134 {
121135 if (blc.has_impl_items ())
0 commit comments