]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/dead.rs
d79e90690cac2fe24d07d97589067cd2a8409df5
[rust.git] / src / librustc / middle / dead.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // This implements the dead-code warning pass. It follows middle::reachable
12 // closely. The idea is that all reachable symbols are live, codes called
13 // from live codes are live, and everything else is dead.
14
15 use hir::map as hir_map;
16 use hir::{self, Item_, PatKind};
17 use hir::intravisit::{self, Visitor, NestedVisitorMap};
18 use hir::itemlikevisit::ItemLikeVisitor;
19
20 use hir::def::Def;
21 use hir::def_id::{DefId, LOCAL_CRATE};
22 use lint;
23 use middle::privacy;
24 use ty::{self, TyCtxt};
25 use util::nodemap::FxHashSet;
26
27 use syntax::{ast, codemap};
28 use syntax::attr;
29 use syntax_pos;
30
31 // Any local node that may call something in its body block should be
32 // explored. For example, if it's a live NodeItem that is a
33 // function, then we should explore its block to check for codes that
34 // may need to be marked as live.
35 fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
36                             node_id: ast::NodeId) -> bool {
37     match tcx.hir.find(node_id) {
38         Some(hir_map::NodeItem(..)) |
39         Some(hir_map::NodeImplItem(..)) |
40         Some(hir_map::NodeForeignItem(..)) |
41         Some(hir_map::NodeTraitItem(..)) =>
42             true,
43         _ =>
44             false
45     }
46 }
47
48 struct MarkSymbolVisitor<'a, 'tcx: 'a> {
49     worklist: Vec<ast::NodeId>,
50     tcx: TyCtxt<'a, 'tcx, 'tcx>,
51     tables: &'a ty::TypeckTables<'tcx>,
52     live_symbols: Box<FxHashSet<ast::NodeId>>,
53     struct_has_extern_repr: bool,
54     ignore_non_const_paths: bool,
55     inherited_pub_visibility: bool,
56     ignore_variant_stack: Vec<DefId>,
57 }
58
59 impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
60     fn check_def_id(&mut self, def_id: DefId) {
61         if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
62             if should_explore(self.tcx, node_id) {
63                 self.worklist.push(node_id);
64             }
65             self.live_symbols.insert(node_id);
66         }
67     }
68
69     fn insert_def_id(&mut self, def_id: DefId) {
70         if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
71             debug_assert!(!should_explore(self.tcx, node_id));
72             self.live_symbols.insert(node_id);
73         }
74     }
75
76     fn handle_definition(&mut self, def: Def) {
77         match def {
78             Def::Const(_) | Def::AssociatedConst(..) => {
79                 self.check_def_id(def.def_id());
80             }
81             _ if self.ignore_non_const_paths => (),
82             Def::PrimTy(..) | Def::SelfTy(..) => (),
83             Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
84                 if let Some(enum_id) = self.tcx.parent_def_id(variant_id) {
85                     self.check_def_id(enum_id);
86                 }
87                 if !self.ignore_variant_stack.contains(&variant_id) {
88                     self.check_def_id(variant_id);
89                 }
90             }
91             _ => {
92                 self.check_def_id(def.def_id());
93             }
94         }
95     }
96
97     fn lookup_and_handle_method(&mut self, id: hir::HirId) {
98         self.check_def_id(self.tables.type_dependent_defs()[id].def_id());
99     }
100
101     fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
102         match self.tables.expr_ty_adjusted(lhs).sty {
103             ty::TyAdt(def, _) => {
104                 self.insert_def_id(def.struct_variant().field_named(name).did);
105             }
106             _ => span_bug!(lhs.span, "named field access on non-ADT"),
107         }
108     }
109
110     fn handle_tup_field_access(&mut self, lhs: &hir::Expr, idx: usize) {
111         match self.tables.expr_ty_adjusted(lhs).sty {
112             ty::TyAdt(def, _) => {
113                 self.insert_def_id(def.struct_variant().fields[idx].did);
114             }
115             ty::TyTuple(..) => {}
116             _ => span_bug!(lhs.span, "numeric field access on non-ADT"),
117         }
118     }
119
120     fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def,
121                                   pats: &[codemap::Spanned<hir::FieldPat>]) {
122         let variant = match self.tables.node_id_to_type(lhs.hir_id).sty {
123             ty::TyAdt(adt, _) => adt.variant_of_def(def),
124             _ => span_bug!(lhs.span, "non-ADT in struct pattern")
125         };
126         for pat in pats {
127             if let PatKind::Wild = pat.node.pat.node {
128                 continue;
129             }
130             self.insert_def_id(variant.field_named(pat.node.name).did);
131         }
132     }
133
134     fn mark_live_symbols(&mut self) {
135         let mut scanned = FxHashSet();
136         while !self.worklist.is_empty() {
137             let id = self.worklist.pop().unwrap();
138             if scanned.contains(&id) {
139                 continue
140             }
141             scanned.insert(id);
142
143             if let Some(ref node) = self.tcx.hir.find(id) {
144                 self.live_symbols.insert(id);
145                 self.visit_node(node);
146             }
147         }
148     }
149
150     fn visit_node(&mut self, node: &hir_map::Node<'tcx>) {
151         let had_extern_repr = self.struct_has_extern_repr;
152         self.struct_has_extern_repr = false;
153         let had_inherited_pub_visibility = self.inherited_pub_visibility;
154         self.inherited_pub_visibility = false;
155         match *node {
156             hir_map::NodeItem(item) => {
157                 match item.node {
158                     hir::ItemStruct(..) | hir::ItemUnion(..) => {
159                         let def_id = self.tcx.hir.local_def_id(item.id);
160                         let def = self.tcx.adt_def(def_id);
161                         self.struct_has_extern_repr = def.repr.c();
162
163                         intravisit::walk_item(self, &item);
164                     }
165                     hir::ItemEnum(..) => {
166                         self.inherited_pub_visibility = item.vis == hir::Public;
167                         intravisit::walk_item(self, &item);
168                     }
169                     hir::ItemFn(..)
170                     | hir::ItemTy(..)
171                     | hir::ItemStatic(..)
172                     | hir::ItemConst(..) => {
173                         intravisit::walk_item(self, &item);
174                     }
175                     _ => ()
176                 }
177             }
178             hir_map::NodeTraitItem(trait_item) => {
179                 intravisit::walk_trait_item(self, trait_item);
180             }
181             hir_map::NodeImplItem(impl_item) => {
182                 intravisit::walk_impl_item(self, impl_item);
183             }
184             hir_map::NodeForeignItem(foreign_item) => {
185                 intravisit::walk_foreign_item(self, &foreign_item);
186             }
187             _ => ()
188         }
189         self.struct_has_extern_repr = had_extern_repr;
190         self.inherited_pub_visibility = had_inherited_pub_visibility;
191     }
192
193     fn mark_as_used_if_union(&mut self, did: DefId, fields: &hir::HirVec<hir::Field>) {
194         if let Some(node_id) = self.tcx.hir.as_local_node_id(did) {
195             if let Some(hir_map::NodeItem(item)) = self.tcx.hir.find(node_id) {
196                 if let Item_::ItemUnion(ref variant, _) = item.node {
197                     if variant.fields().len() > 1 {
198                         for field in variant.fields() {
199                             if fields.iter().find(|x| x.name.node == field.name).is_some() {
200                                 self.live_symbols.insert(field.id);
201                             }
202                         }
203                     }
204                 }
205             }
206         }
207     }
208 }
209
210 impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
211     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
212         NestedVisitorMap::None
213     }
214
215     fn visit_nested_body(&mut self, body: hir::BodyId) {
216         let old_tables = self.tables;
217         self.tables = self.tcx.body_tables(body);
218         let body = self.tcx.hir.body(body);
219         self.visit_body(body);
220         self.tables = old_tables;
221     }
222
223     fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name,
224                         _: &hir::Generics, _: ast::NodeId, _: syntax_pos::Span) {
225         let has_extern_repr = self.struct_has_extern_repr;
226         let inherited_pub_visibility = self.inherited_pub_visibility;
227         let live_fields = def.fields().iter().filter(|f| {
228             has_extern_repr || inherited_pub_visibility || f.vis == hir::Public
229         });
230         self.live_symbols.extend(live_fields.map(|f| f.id));
231
232         intravisit::walk_struct_def(self, def);
233     }
234
235     fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
236         match expr.node {
237             hir::ExprPath(ref qpath @ hir::QPath::TypeRelative(..)) => {
238                 let def = self.tables.qpath_def(qpath, expr.hir_id);
239                 self.handle_definition(def);
240             }
241             hir::ExprMethodCall(..) => {
242                 self.lookup_and_handle_method(expr.hir_id);
243             }
244             hir::ExprField(ref lhs, ref name) => {
245                 self.handle_field_access(&lhs, name.node);
246             }
247             hir::ExprTupField(ref lhs, idx) => {
248                 self.handle_tup_field_access(&lhs, idx.node);
249             }
250             hir::ExprStruct(_, ref fields, _) => {
251                 if let ty::TypeVariants::TyAdt(ref def, _) = self.tables.expr_ty(expr).sty {
252                     if def.is_union() {
253                         self.mark_as_used_if_union(def.did, fields);
254                     }
255                 }
256             }
257             _ => ()
258         }
259
260         intravisit::walk_expr(self, expr);
261     }
262
263     fn visit_arm(&mut self, arm: &'tcx hir::Arm) {
264         if arm.pats.len() == 1 {
265             let variants = arm.pats[0].necessary_variants();
266
267             // Inside the body, ignore constructions of variants
268             // necessary for the pattern to match. Those construction sites
269             // can't be reached unless the variant is constructed elsewhere.
270             let len = self.ignore_variant_stack.len();
271             self.ignore_variant_stack.extend_from_slice(&variants);
272             intravisit::walk_arm(self, arm);
273             self.ignore_variant_stack.truncate(len);
274         } else {
275             intravisit::walk_arm(self, arm);
276         }
277     }
278
279     fn visit_pat(&mut self, pat: &'tcx hir::Pat) {
280         match pat.node {
281             PatKind::Struct(hir::QPath::Resolved(_, ref path), ref fields, _) => {
282                 self.handle_field_pattern_match(pat, path.def, fields);
283             }
284             PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
285                 let def = self.tables.qpath_def(qpath, pat.hir_id);
286                 self.handle_definition(def);
287             }
288             _ => ()
289         }
290
291         self.ignore_non_const_paths = true;
292         intravisit::walk_pat(self, pat);
293         self.ignore_non_const_paths = false;
294     }
295
296     fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
297         self.handle_definition(path.def);
298         intravisit::walk_path(self, path);
299     }
300 }
301
302 fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt,
303                                     id: ast::NodeId,
304                                     attrs: &[ast::Attribute]) -> bool {
305     if attr::contains_name(attrs, "lang") {
306         return true;
307     }
308
309     // #[used] also keeps the item alive forcefully,
310     // e.g. for placing it in a specific section.
311     if attr::contains_name(attrs, "used") {
312         return true;
313     }
314
315     // Don't lint about global allocators
316     if attr::contains_name(attrs, "global_allocator") {
317         return true;
318     }
319
320     tcx.lint_level_at_node(lint::builtin::DEAD_CODE, id).0 == lint::Allow
321 }
322
323 // This visitor seeds items that
324 //   1) We want to explicitly consider as live:
325 //     * Item annotated with #[allow(dead_code)]
326 //         - This is done so that if we want to suppress warnings for a
327 //           group of dead functions, we only have to annotate the "root".
328 //           For example, if both `f` and `g` are dead and `f` calls `g`,
329 //           then annotating `f` with `#[allow(dead_code)]` will suppress
330 //           warning for both `f` and `g`.
331 //     * Item annotated with #[lang=".."]
332 //         - This is because lang items are always callable from elsewhere.
333 //   or
334 //   2) We are not sure to be live or not
335 //     * Implementation of a trait method
336 struct LifeSeeder<'k, 'tcx: 'k> {
337     worklist: Vec<ast::NodeId>,
338     krate: &'k hir::Crate,
339     tcx: TyCtxt<'k, 'tcx, 'tcx>,
340 }
341
342 impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
343     fn visit_item(&mut self, item: &hir::Item) {
344         let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx,
345                                                                item.id,
346                                                                &item.attrs);
347         if allow_dead_code {
348             self.worklist.push(item.id);
349         }
350         match item.node {
351             hir::ItemEnum(ref enum_def, _) if allow_dead_code => {
352                 self.worklist.extend(enum_def.variants.iter()
353                                                       .map(|variant| variant.node.data.id()));
354             }
355             hir::ItemTrait(.., ref trait_item_refs) => {
356                 for trait_item_ref in trait_item_refs {
357                     let trait_item = self.krate.trait_item(trait_item_ref.id);
358                     match trait_item.node {
359                         hir::TraitItemKind::Const(_, Some(_)) |
360                         hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => {
361                             if has_allow_dead_code_or_lang_attr(self.tcx,
362                                                                 trait_item.id,
363                                                                 &trait_item.attrs) {
364                                 self.worklist.push(trait_item.id);
365                             }
366                         }
367                         _ => {}
368                     }
369                 }
370             }
371             hir::ItemImpl(.., ref opt_trait, _, ref impl_item_refs) => {
372                 for impl_item_ref in impl_item_refs {
373                     let impl_item = self.krate.impl_item(impl_item_ref.id);
374                     if opt_trait.is_some() ||
375                             has_allow_dead_code_or_lang_attr(self.tcx,
376                                                              impl_item.id,
377                                                              &impl_item.attrs) {
378                         self.worklist.push(impl_item_ref.id.node_id);
379                     }
380                 }
381             }
382             _ => ()
383         }
384     }
385
386     fn visit_trait_item(&mut self, _item: &hir::TraitItem) {
387         // ignore: we are handling this in `visit_item` above
388     }
389
390     fn visit_impl_item(&mut self, _item: &hir::ImplItem) {
391         // ignore: we are handling this in `visit_item` above
392     }
393 }
394
395 fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
396                                       access_levels: &privacy::AccessLevels,
397                                       krate: &hir::Crate)
398                                       -> Vec<ast::NodeId> {
399     let mut worklist = Vec::new();
400     for (id, _) in &access_levels.map {
401         worklist.push(*id);
402     }
403
404     // Seed entry point
405     if let Some((id, _)) = *tcx.sess.entry_fn.borrow() {
406         worklist.push(id);
407     }
408
409     // Seed implemented trait items
410     let mut life_seeder = LifeSeeder {
411         worklist,
412         krate,
413         tcx,
414     };
415     krate.visit_all_item_likes(&mut life_seeder);
416
417     return life_seeder.worklist;
418 }
419
420 fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
421                        access_levels: &privacy::AccessLevels,
422                        krate: &hir::Crate)
423                        -> Box<FxHashSet<ast::NodeId>> {
424     let worklist = create_and_seed_worklist(tcx, access_levels, krate);
425     let mut symbol_visitor = MarkSymbolVisitor {
426         worklist,
427         tcx,
428         tables: &ty::TypeckTables::empty(None),
429         live_symbols: box FxHashSet(),
430         struct_has_extern_repr: false,
431         ignore_non_const_paths: false,
432         inherited_pub_visibility: false,
433         ignore_variant_stack: vec![],
434     };
435     symbol_visitor.mark_live_symbols();
436     symbol_visitor.live_symbols
437 }
438
439 fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {
440     match item.node {
441         hir::ItemStruct(ref struct_def, _) if !struct_def.is_struct() => {
442             Some(struct_def.id())
443         }
444         _ => None
445     }
446 }
447
448 struct DeadVisitor<'a, 'tcx: 'a> {
449     tcx: TyCtxt<'a, 'tcx, 'tcx>,
450     live_symbols: Box<FxHashSet<ast::NodeId>>,
451 }
452
453 impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
454     fn should_warn_about_item(&mut self, item: &hir::Item) -> bool {
455         let should_warn = match item.node {
456             hir::ItemStatic(..)
457             | hir::ItemConst(..)
458             | hir::ItemFn(..)
459             | hir::ItemTy(..)
460             | hir::ItemEnum(..)
461             | hir::ItemStruct(..)
462             | hir::ItemUnion(..) => true,
463             _ => false
464         };
465         let ctor_id = get_struct_ctor_id(item);
466         should_warn && !self.symbol_is_live(item.id, ctor_id)
467     }
468
469     fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
470         let field_type = self.tcx.type_of(self.tcx.hir.local_def_id(field.id));
471         let is_marker_field = match field_type.ty_to_def_id() {
472             Some(def_id) => self.tcx.lang_items().items().iter().any(|item| *item == Some(def_id)),
473             _ => false
474         };
475         !field.is_positional()
476             && !self.symbol_is_live(field.id, None)
477             && !is_marker_field
478             && !has_allow_dead_code_or_lang_attr(self.tcx, field.id, &field.attrs)
479     }
480
481     fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool {
482         !self.symbol_is_live(variant.data.id(), None)
483             && !has_allow_dead_code_or_lang_attr(self.tcx,
484                                                  variant.data.id(),
485                                                  &variant.attrs)
486     }
487
488     fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem) -> bool {
489         !self.symbol_is_live(fi.id, None)
490             && !has_allow_dead_code_or_lang_attr(self.tcx, fi.id, &fi.attrs)
491     }
492
493     // id := node id of an item's definition.
494     // ctor_id := `Some` if the item is a struct_ctor (tuple struct),
495     //            `None` otherwise.
496     // If the item is a struct_ctor, then either its `id` or
497     // `ctor_id` (unwrapped) is in the live_symbols set. More specifically,
498     // DefMap maps the ExprPath of a struct_ctor to the node referred by
499     // `ctor_id`. On the other hand, in a statement like
500     // `type <ident> <generics> = <ty>;` where <ty> refers to a struct_ctor,
501     // DefMap maps <ty> to `id` instead.
502     fn symbol_is_live(&mut self,
503                       id: ast::NodeId,
504                       ctor_id: Option<ast::NodeId>)
505                       -> bool {
506         if self.live_symbols.contains(&id)
507            || ctor_id.map_or(false,
508                              |ctor| self.live_symbols.contains(&ctor)) {
509             return true;
510         }
511         // If it's a type whose items are live, then it's live, too.
512         // This is done to handle the case where, for example, the static
513         // method of a private type is used, but the type itself is never
514         // called directly.
515         let def_id = self.tcx.hir.local_def_id(id);
516         let inherent_impls = self.tcx.inherent_impls(def_id);
517         for &impl_did in inherent_impls.iter() {
518             for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
519                 if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
520                     if self.live_symbols.contains(&item_node_id) {
521                         return true;
522                     }
523                 }
524             }
525         }
526         false
527     }
528
529     fn warn_dead_code(&mut self,
530                       id: ast::NodeId,
531                       span: syntax_pos::Span,
532                       name: ast::Name,
533                       node_type: &str) {
534         if !name.as_str().starts_with("_") {
535             self.tcx
536                 .lint_node(lint::builtin::DEAD_CODE,
537                            id,
538                            span,
539                            &format!("{} is never used: `{}`", node_type, name));
540         }
541     }
542 }
543
544 impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
545     /// Walk nested items in place so that we don't report dead-code
546     /// on inner functions when the outer function is already getting
547     /// an error. We could do this also by checking the parents, but
548     /// this is how the code is setup and it seems harmless enough.
549     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
550         NestedVisitorMap::All(&self.tcx.hir)
551     }
552
553     fn visit_item(&mut self, item: &'tcx hir::Item) {
554         if self.should_warn_about_item(item) {
555             self.warn_dead_code(
556                 item.id,
557                 item.span,
558                 item.name,
559                 item.node.descriptive_variant()
560             );
561         } else {
562             // Only continue if we didn't warn
563             intravisit::walk_item(self, item);
564         }
565     }
566
567     fn visit_variant(&mut self,
568                      variant: &'tcx hir::Variant,
569                      g: &'tcx hir::Generics,
570                      id: ast::NodeId) {
571         if self.should_warn_about_variant(&variant.node) {
572             self.warn_dead_code(variant.node.data.id(), variant.span,
573                                 variant.node.name, "variant");
574         } else {
575             intravisit::walk_variant(self, variant, g, id);
576         }
577     }
578
579     fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) {
580         if self.should_warn_about_foreign_item(fi) {
581             self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant());
582         }
583         intravisit::walk_foreign_item(self, fi);
584     }
585
586     fn visit_struct_field(&mut self, field: &'tcx hir::StructField) {
587         if self.should_warn_about_field(&field) {
588             self.warn_dead_code(field.id, field.span,
589                                 field.name, "field");
590         }
591         intravisit::walk_struct_field(self, field);
592     }
593
594     fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
595         match impl_item.node {
596             hir::ImplItemKind::Const(_, body_id) => {
597                 if !self.symbol_is_live(impl_item.id, None) {
598                     self.warn_dead_code(impl_item.id, impl_item.span,
599                                         impl_item.name, "associated const");
600                 }
601                 self.visit_nested_body(body_id)
602             }
603             hir::ImplItemKind::Method(_, body_id) => {
604                 if !self.symbol_is_live(impl_item.id, None) {
605                     self.warn_dead_code(impl_item.id, impl_item.span,
606                                         impl_item.name, "method");
607                 }
608                 self.visit_nested_body(body_id)
609             }
610             hir::ImplItemKind::Type(..) => {}
611         }
612     }
613
614     // Overwrite so that we don't warn the trait item itself.
615     fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
616         match trait_item.node {
617             hir::TraitItemKind::Const(_, Some(body_id)) |
618             hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => {
619                 self.visit_nested_body(body_id)
620             }
621             hir::TraitItemKind::Const(_, None) |
622             hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) |
623             hir::TraitItemKind::Type(..) => {}
624         }
625     }
626 }
627
628 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
629     let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
630     let krate = tcx.hir.krate();
631     let live_symbols = find_live(tcx, access_levels, krate);
632     let mut visitor = DeadVisitor {
633         tcx,
634         live_symbols,
635     };
636     intravisit::walk_crate(&mut visitor, krate);
637 }