Skip to content

Commit 4aacc49

Browse files
authored
Rollup merge of rust-lang#59486 - varkor:dead-code-impl, r=sanxiyn
Visit `ImplItem` in `dead_code` lint Fixes rust-lang#47131.
2 parents ee17267 + 8cdfad9 commit 4aacc49

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/librustc/middle/dead.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7373
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
7474
self.check_def_id(def.def_id());
7575
}
76-
_ if self.in_pat => (),
76+
_ if self.in_pat => {},
7777
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
7878
Def::Local(..) | Def::Upvar(..) => {}
7979
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
@@ -91,6 +91,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9191
self.check_def_id(variant_id);
9292
}
9393
}
94+
Def::ToolMod | Def::NonMacroAttr(..) | Def::Err => {}
9495
_ => {
9596
self.check_def_id(def.def_id());
9697
}
@@ -166,16 +167,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
166167
}
167168
hir::ItemKind::Enum(..) => {
168169
self.inherited_pub_visibility = item.vis.node.is_pub();
170+
169171
intravisit::walk_item(self, &item);
170172
}
171-
hir::ItemKind::Fn(..)
172-
| hir::ItemKind::Ty(..)
173-
| hir::ItemKind::Static(..)
174-
| hir::ItemKind::Existential(..)
175-
| hir::ItemKind::Const(..) => {
173+
hir::ItemKind::ForeignMod(..) => {}
174+
_ => {
176175
intravisit::walk_item(self, &item);
177176
}
178-
_ => ()
179177
}
180178
}
181179
Node::TraitItem(trait_item) => {
@@ -187,7 +185,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
187185
Node::ForeignItem(foreign_item) => {
188186
intravisit::walk_foreign_item(self, &foreign_item);
189187
}
190-
_ => ()
188+
_ => {}
191189
}
192190
self.repr_has_repr_c = had_repr_c;
193191
self.inherited_pub_visibility = had_inherited_pub_visibility;

src/test/ui/dead-code-impl.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![deny(dead_code)]
4+
5+
pub struct GenericFoo<T>(T);
6+
7+
type Foo = GenericFoo<u32>;
8+
9+
impl Foo {
10+
fn bar(self) -> u8 {
11+
0
12+
}
13+
}
14+
15+
fn main() {
16+
println!("{}", GenericFoo(0).bar());
17+
}

0 commit comments

Comments
 (0)