Skip to content

Commit

Permalink
Revert "Extend dead code lint to detect more unused enum variants"
Browse files Browse the repository at this point in the history
This reverts commit b042ffc.

Conflicts:
	src/librustc/middle/pat_util.rs
  • Loading branch information
Manishearth committed Mar 14, 2015
1 parent 82bcc55 commit c908d1c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 93 deletions.
28 changes: 1 addition & 27 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
struct_has_extern_repr: bool,
ignore_non_const_paths: bool,
inherited_pub_visibility: bool,
ignore_variant_stack: Vec<ast::NodeId>,
}

impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Expand All @@ -60,7 +59,6 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
struct_has_extern_repr: false,
ignore_non_const_paths: false,
inherited_pub_visibility: false,
ignore_variant_stack: vec![],
}
}

Expand All @@ -81,9 +79,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
def::DefPrimTy(_) => (),
def::DefVariant(enum_id, variant_id, _) => {
self.check_def_id(enum_id);
if !self.ignore_variant_stack.contains(&variant_id.node) {
self.check_def_id(variant_id);
}
self.check_def_id(variant_id);
}
_ => {
self.check_def_id(def.def_id());
Expand Down Expand Up @@ -282,23 +278,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
visit::walk_expr(self, expr);
}

fn visit_arm(&mut self, arm: &ast::Arm) {
if arm.pats.len() == 1 {
let pat = &*arm.pats[0];
let variants = pat_util::necessary_variants(&self.tcx.def_map, pat);

// Inside the body, ignore constructions of variants
// necessary for the pattern to match. Those construction sites
// can't be reached unless the variant is constructed elsewhere.
let len = self.ignore_variant_stack.len();
self.ignore_variant_stack.push_all(&*variants);
visit::walk_arm(self, arm);
self.ignore_variant_stack.truncate(len);
} else {
visit::walk_arm(self, arm);
}
}

fn visit_pat(&mut self, pat: &ast::Pat) {
let def_map = &self.tcx.def_map;
match pat.node {
Expand Down Expand Up @@ -418,11 +397,6 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
worklist.push(*id);
}
for id in reachable_symbols {
// Reachable variants can be dead, because we warn about
// variants never constructed, not variants never used.
if let Some(ast_map::NodeVariant(..)) = tcx.map.find(*id) {
continue;
}
worklist.push(*id);
}

Expand Down
24 changes: 0 additions & 24 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,3 @@ pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path {
span: DUMMY_SP,
})
}

/// Return variants that are necessary to exist for the pattern to match.
pub fn necessary_variants(dm: &DefMap, pat: &ast::Pat) -> Vec<ast::NodeId> {
let mut variants = vec![];
walk_pat(pat, |p| {
match p.node {
ast::PatEnum(_, _) |
ast::PatIdent(_, _, None) |
ast::PatStruct(..) => {
match dm.borrow().get(&p.id) {
Some(&PathResolution {base_def: DefVariant(_, id, _), ..}) => {
variants.push(id.node);
}
_ => ()
}
}
_ => ()
}
true
});
variants.sort();
variants.dedup();
variants
}
42 changes: 0 additions & 42 deletions src/test/compile-fail/lint-dead-code-variant.rs

This file was deleted.

0 comments on commit c908d1c

Please sign in to comment.