about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-14 16:59:06 +0000
committerbors <bors@rust-lang.org>2015-03-14 16:59:06 +0000
commit3400c9ed9f1200a59f6452db5c71af2182db29a5 (patch)
tree929ebf1d616a719550c221cb0790f67c2c818b9d /src
parent766a4e1acc06061a30cf456840a9915526fb681e (diff)
parentc908d1c1f996e46ce9ec82b0add26e0c5a18b5c3 (diff)
Auto merge of #23357 - Manishearth:oops, r=Manishearth
Oops, merged #21468 by accident.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/dead.rs28
-rw-r--r--src/librustc/middle/pat_util.rs24
-rw-r--r--src/libtest/lib.rs1
-rw-r--r--src/test/compile-fail/lint-dead-code-variant.rs42
4 files changed, 1 insertions, 94 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs
index 09378f2c973..5efea66ab0c 100644
--- a/src/librustc/middle/dead.rs
+++ b/src/librustc/middle/dead.rs
@@ -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> {
@@ -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![],
         }
     }
 
@@ -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());
@@ -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 {
@@ -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);
     }
 
diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs
index eca3296e65c..c5abff3b963 100644
--- a/src/librustc/middle/pat_util.rs
+++ b/src/librustc/middle/pat_util.rs
@@ -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
-}
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index ca8a60553ab..3de24b1383f 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -123,7 +123,6 @@ impl fmt::Display for TestName {
 #[derive(Clone, Copy)]
 enum NamePadding {
     PadNone,
-    #[allow(dead_code)]
     PadOnLeft,
     PadOnRight,
 }
diff --git a/src/test/compile-fail/lint-dead-code-variant.rs b/src/test/compile-fail/lint-dead-code-variant.rs
deleted file mode 100644
index 6146be65e38..00000000000
--- a/src/test/compile-fail/lint-dead-code-variant.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![deny(dead_code)]
-
-#[derive(Copy)]
-enum Enum {
-    Variant1, //~ ERROR: variant is never used
-    Variant2,
-    Variant3,
-}
-
-fn copy(e: Enum) -> Enum {
-    use Enum::*;
-    match e {
-        Variant1 => Variant1,
-        Variant2 => Variant2,
-        Variant3 => Variant3,
-    }
-}
-
-fn max(e: Enum) -> Enum {
-    use Enum::*;
-    match e {
-        Variant1 => Variant3,
-        Variant2 => Variant3,
-        Variant3 => Variant3,
-    }
-}
-
-fn main() {
-    let e = Enum::Variant2;
-    copy(e);
-    max(e);
-}