about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-11-02 18:44:49 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-11-03 08:31:44 -0800
commit0f4d7f248d56f06a9902edf45524dd0f7fcbd9a5 (patch)
tree1436a683cf85f40d27ff62e3476e5a203051a183
parent68e7dd0ffe45d679a36e81a767dc6d4aa13dbf94 (diff)
parentd23d633eb843078551f382fc729e5d20f62b9c87 (diff)
rollup merge of #18493 : jakub-/issue-18464
-rw-r--r--src/librustc/middle/dead.rs18
-rw-r--r--src/test/run-pass/issue-18464.rs21
2 files changed, 31 insertions, 8 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs
index 80cef763d24..ec09706f97e 100644
--- a/src/librustc/middle/dead.rs
+++ b/src/librustc/middle/dead.rs
@@ -51,7 +51,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
     tcx: &'a ty::ctxt<'tcx>,
     live_symbols: Box<HashSet<ast::NodeId>>,
     struct_has_extern_repr: bool,
-    ignore_paths: bool
+    ignore_non_const_paths: bool
 }
 
 impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
@@ -62,7 +62,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
             tcx: tcx,
             live_symbols: box HashSet::new(),
             struct_has_extern_repr: false,
-            ignore_paths: false
+            ignore_non_const_paths: false
         }
     }
 
@@ -76,6 +76,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
     fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
         self.tcx.def_map.borrow().find(id).map(|def| {
             match def {
+                &def::DefConst(_) => {
+                    self.check_def_id(def.def_id())
+                }
+                _ if self.ignore_non_const_paths => (),
                 &def::DefPrimTy(_) => (),
                 &def::DefVariant(enum_id, variant_id, _) => {
                     self.check_def_id(enum_id);
@@ -283,21 +287,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
                 self.handle_field_pattern_match(pat, fields.as_slice());
             }
             _ if pat_util::pat_is_const(def_map, pat) => {
-                // it might be the only use of a static:
+                // it might be the only use of a const
                 self.lookup_and_handle_definition(&pat.id)
             }
             _ => ()
         }
 
-        self.ignore_paths = true;
+        self.ignore_non_const_paths = true;
         visit::walk_pat(self, pat);
-        self.ignore_paths = false;
+        self.ignore_non_const_paths = false;
     }
 
     fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
-        if !self.ignore_paths {
-            self.lookup_and_handle_definition(&id);
-        }
+        self.lookup_and_handle_definition(&id);
         visit::walk_path(self, path);
     }
 
diff --git a/src/test/run-pass/issue-18464.rs b/src/test/run-pass/issue-18464.rs
new file mode 100644
index 00000000000..dff86bc1b45
--- /dev/null
+++ b/src/test/run-pass/issue-18464.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 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)]
+
+const LOW_RANGE: char = '0';
+const HIGH_RANGE: char = '9';
+
+fn main() {
+    match '5' {
+        LOW_RANGE...HIGH_RANGE => (),
+        _ => ()
+    };
+}