Skip to content

Commit 562cf6d

Browse files
committed
auto merge of #10870 : ktt3ja/rust/issue-10865, r=alexcrichton
Fix #10865.
2 parents 1b12dca + 54e1179 commit 562cf6d

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

src/librustc/middle/dead.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ impl MarkSymbolVisitor {
6161
}
6262
}
6363

64-
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId,
65-
span: codemap::Span) {
66-
let def = match self.tcx.def_map.find(id) {
67-
Some(&def) => def,
68-
None => self.tcx.sess.span_bug(span, "def ID not in def map?!"),
69-
};
70-
let def_id = match def {
71-
ast::DefVariant(enum_id, _, _) => Some(enum_id),
72-
ast::DefPrimTy(_) => None,
73-
_ => Some(def_id_of_def(def)),
74-
};
75-
match def_id {
76-
Some(def_id) => {
77-
if should_explore(self.tcx, def_id) {
78-
self.worklist.push(def_id.node);
64+
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
65+
match self.tcx.def_map.find(id) {
66+
Some(&def) => {
67+
let def_id = match def {
68+
ast::DefVariant(enum_id, _, _) => Some(enum_id),
69+
ast::DefPrimTy(_) => None,
70+
_ => Some(def_id_of_def(def)),
71+
};
72+
match def_id {
73+
Some(def_id) => {
74+
if should_explore(self.tcx, def_id) {
75+
self.worklist.push(def_id.node);
76+
}
77+
self.live_symbols.insert(def_id.node);
78+
}
79+
None => (),
7980
}
80-
self.live_symbols.insert(def_id.node);
8181
}
8282
None => (),
8383
}
@@ -129,9 +129,6 @@ impl Visitor<()> for MarkSymbolVisitor {
129129

130130
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
131131
match expr.node {
132-
ast::ExprPath(_) | ast::ExprStruct(..) => {
133-
self.lookup_and_handle_definition(&expr.id, expr.span);
134-
}
135132
ast::ExprMethodCall(..) => {
136133
match self.method_map.find(&expr.id) {
137134
Some(&typeck::method_map_entry {
@@ -160,12 +157,16 @@ impl Visitor<()> for MarkSymbolVisitor {
160157
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
161158
match typ.node {
162159
ast::ty_path(_, _, ref id) => {
163-
self.lookup_and_handle_definition(id, typ.span);
160+
self.lookup_and_handle_definition(id);
164161
}
165162
_ => visit::walk_ty(self, typ, ()),
166163
}
167164
}
168165

166+
fn visit_path(&mut self, _: &ast::Path, id: ast::NodeId, _: ()) {
167+
self.lookup_and_handle_definition(&id);
168+
}
169+
169170
fn visit_item(&mut self, _item: @ast::item, _: ()) {
170171
// Do not recurse into items. These items will be added to the
171172
// worklist and recursed into manually if necessary.

src/test/compile-fail/lint-dead-code-1.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,7 @@ pub static pub_static: int = 0;
2626
static priv_static: int = 0; //~ ERROR: code is never used
2727
static used_static: int = 0;
2828
pub static used_static2: int = used_static;
29-
30-
pub fn pub_fn() {
31-
used_fn();
32-
let used_struct1 = UsedStruct1 { x: 1 };
33-
let used_struct2 = UsedStruct2(1);
34-
let used_struct3 = UsedStruct3;
35-
let e = foo3;
36-
SemiUsedStruct::la_la_la();
37-
38-
}
39-
fn priv_fn() { //~ ERROR: code is never used
40-
let unused_struct = PrivStruct;
41-
}
42-
fn used_fn() {}
29+
static USED_STATIC: int = 0;
4330

4431
pub type typ = ~UsedStruct4;
4532
pub struct PubStruct();
@@ -59,6 +46,25 @@ pub enum pub_enum { foo1, bar1 }
5946
enum priv_enum { foo2, bar2 } //~ ERROR: code is never used
6047
enum used_enum { foo3, bar3 }
6148

49+
pub fn pub_fn() {
50+
used_fn();
51+
let used_struct1 = UsedStruct1 { x: 1 };
52+
let used_struct2 = UsedStruct2(1);
53+
let used_struct3 = UsedStruct3;
54+
let e = foo3;
55+
SemiUsedStruct::la_la_la();
56+
57+
let i = 1;
58+
match i {
59+
USED_STATIC => (),
60+
_ => ()
61+
}
62+
}
63+
fn priv_fn() { //~ ERROR: code is never used
64+
let unused_struct = PrivStruct;
65+
}
66+
fn used_fn() {}
67+
6268
fn foo() { //~ ERROR: code is never used
6369
bar();
6470
let unused_enum = foo2;

0 commit comments

Comments
 (0)