Check more live Path nodes in dead-code pass

This commit is contained in:
Kiet Tran 2013-12-11 20:49:46 -05:00
parent 64ecb78716
commit d5ad32f388
2 changed files with 27 additions and 21 deletions

View File

@ -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),
@ -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 {
@ -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.

View File

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