Skip to content

Commit 3d8b29c

Browse files
committed
auto merge of #18493 : jakub-/rust/issue-18464, r=alexcrichton
Fixes #18464.
2 parents 3327ecc + d23d633 commit 3d8b29c

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Diff for: src/librustc/middle/dead.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
5151
tcx: &'a ty::ctxt<'tcx>,
5252
live_symbols: Box<HashSet<ast::NodeId>>,
5353
struct_has_extern_repr: bool,
54-
ignore_paths: bool
54+
ignore_non_const_paths: bool
5555
}
5656

5757
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
@@ -62,7 +62,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
6262
tcx: tcx,
6363
live_symbols: box HashSet::new(),
6464
struct_has_extern_repr: false,
65-
ignore_paths: false
65+
ignore_non_const_paths: false
6666
}
6767
}
6868

@@ -76,6 +76,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7676
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
7777
self.tcx.def_map.borrow().find(id).map(|def| {
7878
match def {
79+
&def::DefConst(_) => {
80+
self.check_def_id(def.def_id())
81+
}
82+
_ if self.ignore_non_const_paths => (),
7983
&def::DefPrimTy(_) => (),
8084
&def::DefVariant(enum_id, variant_id, _) => {
8185
self.check_def_id(enum_id);
@@ -283,21 +287,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
283287
self.handle_field_pattern_match(pat, fields.as_slice());
284288
}
285289
_ if pat_util::pat_is_const(def_map, pat) => {
286-
// it might be the only use of a static:
290+
// it might be the only use of a const
287291
self.lookup_and_handle_definition(&pat.id)
288292
}
289293
_ => ()
290294
}
291295

292-
self.ignore_paths = true;
296+
self.ignore_non_const_paths = true;
293297
visit::walk_pat(self, pat);
294-
self.ignore_paths = false;
298+
self.ignore_non_const_paths = false;
295299
}
296300

297301
fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
298-
if !self.ignore_paths {
299-
self.lookup_and_handle_definition(&id);
300-
}
302+
self.lookup_and_handle_definition(&id);
301303
visit::walk_path(self, path);
302304
}
303305

Diff for: src/test/run-pass/issue-18464.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(dead_code)]
12+
13+
const LOW_RANGE: char = '0';
14+
const HIGH_RANGE: char = '9';
15+
16+
fn main() {
17+
match '5' {
18+
LOW_RANGE...HIGH_RANGE => (),
19+
_ => ()
20+
};
21+
}

0 commit comments

Comments
 (0)