Rollup merge of #59486 - varkor:dead-code-impl, r=sanxiyn

Visit `ImplItem` in `dead_code` lint

Fixes https://github.com/rust-lang/rust/issues/47131.
This commit is contained in:
Mazdak Farrokhzad 2019-03-29 12:32:30 +01:00 committed by GitHub
commit 4aacc49ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -73,7 +73,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => { Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
self.check_def_id(def.def_id()); self.check_def_id(def.def_id());
} }
_ if self.in_pat => (), _ if self.in_pat => {},
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {} Def::Local(..) | Def::Upvar(..) => {}
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => { Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
@ -91,6 +91,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
self.check_def_id(variant_id); self.check_def_id(variant_id);
} }
} }
Def::ToolMod | Def::NonMacroAttr(..) | Def::Err => {}
_ => { _ => {
self.check_def_id(def.def_id()); self.check_def_id(def.def_id());
} }
@ -166,16 +167,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
} }
hir::ItemKind::Enum(..) => { hir::ItemKind::Enum(..) => {
self.inherited_pub_visibility = item.vis.node.is_pub(); self.inherited_pub_visibility = item.vis.node.is_pub();
intravisit::walk_item(self, &item); intravisit::walk_item(self, &item);
} }
hir::ItemKind::Fn(..) hir::ItemKind::ForeignMod(..) => {}
| hir::ItemKind::Ty(..) _ => {
| hir::ItemKind::Static(..)
| hir::ItemKind::Existential(..)
| hir::ItemKind::Const(..) => {
intravisit::walk_item(self, &item); intravisit::walk_item(self, &item);
} }
_ => ()
} }
} }
Node::TraitItem(trait_item) => { Node::TraitItem(trait_item) => {
@ -187,7 +185,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Node::ForeignItem(foreign_item) => { Node::ForeignItem(foreign_item) => {
intravisit::walk_foreign_item(self, &foreign_item); intravisit::walk_foreign_item(self, &foreign_item);
} }
_ => () _ => {}
} }
self.repr_has_repr_c = had_repr_c; self.repr_has_repr_c = had_repr_c;
self.inherited_pub_visibility = had_inherited_pub_visibility; self.inherited_pub_visibility = had_inherited_pub_visibility;

View File

@ -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());
}