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