Skip to content

Commit

Permalink
Check more live Path nodes in dead-code pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ktt3ja committed Dec 14, 2013
1 parent 64ecb78 commit d5ad32f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/librustc/middle/dead.rs
Expand Up @@ -61,11 +61,10 @@ impl MarkSymbolVisitor {
}
}

fn lookup_and_handle_definition(&mut self, id: &ast::NodeId,
span: codemap::Span) {
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
let def = match self.tcx.def_map.find(id) {
Some(&def) => def,
None => self.tcx.sess.span_bug(span, "def ID not in def map?!"),
None => return
};
let def_id = match def {
ast::DefVariant(enum_id, _, _) => Some(enum_id),
Expand Down Expand Up @@ -129,9 +128,6 @@ impl Visitor<()> for MarkSymbolVisitor {

fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
match expr.node {
ast::ExprPath(_) | ast::ExprStruct(..) => {
self.lookup_and_handle_definition(&expr.id, expr.span);
}
ast::ExprMethodCall(..) => {
match self.method_map.find(&expr.id) {
Some(&typeck::method_map_entry {
Expand Down Expand Up @@ -160,12 +156,16 @@ impl Visitor<()> for MarkSymbolVisitor {
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
match typ.node {
ast::ty_path(_, _, ref id) => {
self.lookup_and_handle_definition(id, typ.span);
self.lookup_and_handle_definition(id);
}
_ => visit::walk_ty(self, typ, ()),
}
}

fn visit_path(&mut self, _: &ast::Path, id: ast::NodeId, _: ()) {
self.lookup_and_handle_definition(&id);
}

fn visit_item(&mut self, _item: @ast::item, _: ()) {
// Do not recurse into items. These items will be added to the
// worklist and recursed into manually if necessary.
Expand Down
34 changes: 20 additions & 14 deletions src/test/compile-fail/lint-dead-code-1.rs
Expand Up @@ -26,20 +26,7 @@ pub static pub_static: int = 0;
static priv_static: int = 0; //~ ERROR: code is never used
static used_static: int = 0;
pub static used_static2: int = used_static;

pub fn pub_fn() {
used_fn();
let used_struct1 = UsedStruct1 { x: 1 };
let used_struct2 = UsedStruct2(1);
let used_struct3 = UsedStruct3;
let e = foo3;
SemiUsedStruct::la_la_la();

}
fn priv_fn() { //~ ERROR: code is never used
let unused_struct = PrivStruct;
}
fn used_fn() {}
static USED_STATIC: int = 0;

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

pub fn pub_fn() {
used_fn();
let used_struct1 = UsedStruct1 { x: 1 };
let used_struct2 = UsedStruct2(1);
let used_struct3 = UsedStruct3;
let e = foo3;
SemiUsedStruct::la_la_la();

let i = 1;
match i {
USED_STATIC => (),
_ => ()
}
}
fn priv_fn() { //~ ERROR: code is never used
let unused_struct = PrivStruct;
}
fn used_fn() {}

fn foo() { //~ ERROR: code is never used
bar();
let unused_enum = foo2;
Expand Down

0 comments on commit d5ad32f

Please sign in to comment.