Constants used in range patterns should not be considered unused
This commit is contained in:
parent
52c3fe9533
commit
d23d633eb8
src
@ -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);
|
||||
}
|
||||
|
||||
|
21
src/test/run-pass/issue-18464.rs
Normal file
21
src/test/run-pass/issue-18464.rs
Normal file
@ -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 => (),
|
||||
_ => ()
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user