Count type aliases in patterns
This commit is contained in:
parent
2d3b96691e
commit
b67d72b434
@ -51,7 +51,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
|
|||||||
tables: &'a ty::TypeckTables<'tcx>,
|
tables: &'a ty::TypeckTables<'tcx>,
|
||||||
live_symbols: Box<FxHashSet<ast::NodeId>>,
|
live_symbols: Box<FxHashSet<ast::NodeId>>,
|
||||||
struct_has_extern_repr: bool,
|
struct_has_extern_repr: bool,
|
||||||
ignore_non_const_paths: bool,
|
in_pat: bool,
|
||||||
inherited_pub_visibility: bool,
|
inherited_pub_visibility: bool,
|
||||||
ignore_variant_stack: Vec<DefId>,
|
ignore_variant_stack: Vec<DefId>,
|
||||||
}
|
}
|
||||||
@ -75,10 +75,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||||||
|
|
||||||
fn handle_definition(&mut self, def: Def) {
|
fn handle_definition(&mut self, def: Def) {
|
||||||
match def {
|
match def {
|
||||||
Def::Const(_) | Def::AssociatedConst(..) => {
|
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
|
||||||
self.check_def_id(def.def_id());
|
self.check_def_id(def.def_id());
|
||||||
}
|
}
|
||||||
_ if self.ignore_non_const_paths => (),
|
_ if self.in_pat => (),
|
||||||
Def::PrimTy(..) | Def::SelfTy(..) |
|
Def::PrimTy(..) | Def::SelfTy(..) |
|
||||||
Def::Local(..) | Def::Upvar(..) => {}
|
Def::Local(..) | Def::Upvar(..) => {}
|
||||||
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
|
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
|
||||||
@ -289,9 +289,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
|||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ignore_non_const_paths = true;
|
self.in_pat = true;
|
||||||
intravisit::walk_pat(self, pat);
|
intravisit::walk_pat(self, pat);
|
||||||
self.ignore_non_const_paths = false;
|
self.in_pat = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
|
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
|
||||||
@ -429,7 +429,7 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
tables: &ty::TypeckTables::empty(None),
|
tables: &ty::TypeckTables::empty(None),
|
||||||
live_symbols: box FxHashSet(),
|
live_symbols: box FxHashSet(),
|
||||||
struct_has_extern_repr: false,
|
struct_has_extern_repr: false,
|
||||||
ignore_non_const_paths: false,
|
in_pat: false,
|
||||||
inherited_pub_visibility: false,
|
inherited_pub_visibility: false,
|
||||||
ignore_variant_stack: vec![],
|
ignore_variant_stack: vec![],
|
||||||
};
|
};
|
||||||
|
18
src/test/run-pass/dead-code-alias-in-pat.rs
Normal file
18
src/test/run-pass/dead-code-alias-in-pat.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2017 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)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
struct Foo<T> { x: T }
|
||||||
|
type Bar = Foo<u32>;
|
||||||
|
let spam = |Bar { x }| x != 0;
|
||||||
|
println!("{}", spam(Foo { x: 10 }));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user