提交 0f4d7f24 编写于 作者: A Alex Crichton

rollup merge of #18493 : jakub-/issue-18464

......@@ -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 @@ fn new(tcx: &'a ty::ctxt<'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 @@ fn check_def_id(&mut self, def_id: ast::DefId) {
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 @@ fn visit_pat(&mut self, pat: &ast::Pat) {
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);
}
......
// 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 => (),
_ => ()
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册