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