Skip to content

Commit

Permalink
Rollup merge of #59486 - varkor:dead-code-impl, r=sanxiyn
Browse files Browse the repository at this point in the history
Visit `ImplItem` in `dead_code` lint

Fixes #47131.
  • Loading branch information
Centril authored Mar 29, 2019
2 parents ee17267 + 8cdfad9 commit 4aacc49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
self.check_def_id(def.def_id());
}
_ if self.in_pat => (),
_ if self.in_pat => {},
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {}
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
Expand All @@ -91,6 +91,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
self.check_def_id(variant_id);
}
}
Def::ToolMod | Def::NonMacroAttr(..) | Def::Err => {}
_ => {
self.check_def_id(def.def_id());
}
Expand Down Expand Up @@ -166,16 +167,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
hir::ItemKind::Enum(..) => {
self.inherited_pub_visibility = item.vis.node.is_pub();

intravisit::walk_item(self, &item);
}
hir::ItemKind::Fn(..)
| hir::ItemKind::Ty(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Existential(..)
| hir::ItemKind::Const(..) => {
hir::ItemKind::ForeignMod(..) => {}
_ => {
intravisit::walk_item(self, &item);
}
_ => ()
}
}
Node::TraitItem(trait_item) => {
Expand All @@ -187,7 +185,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Node::ForeignItem(foreign_item) => {
intravisit::walk_foreign_item(self, &foreign_item);
}
_ => ()
_ => {}
}
self.repr_has_repr_c = had_repr_c;
self.inherited_pub_visibility = had_inherited_pub_visibility;
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/dead-code-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass

#![deny(dead_code)]

pub struct GenericFoo<T>(T);

type Foo = GenericFoo<u32>;

impl Foo {
fn bar(self) -> u8 {
0
}
}

fn main() {
println!("{}", GenericFoo(0).bar());
}

0 comments on commit 4aacc49

Please sign in to comment.