Skip to content

Commit b67d72b

Browse files
committed
Count type aliases in patterns
1 parent 2d3b966 commit b67d72b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/librustc/middle/dead.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
5151
tables: &'a ty::TypeckTables<'tcx>,
5252
live_symbols: Box<FxHashSet<ast::NodeId>>,
5353
struct_has_extern_repr: bool,
54-
ignore_non_const_paths: bool,
54+
in_pat: bool,
5555
inherited_pub_visibility: bool,
5656
ignore_variant_stack: Vec<DefId>,
5757
}
@@ -75,10 +75,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7575

7676
fn handle_definition(&mut self, def: Def) {
7777
match def {
78-
Def::Const(_) | Def::AssociatedConst(..) => {
78+
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
7979
self.check_def_id(def.def_id());
8080
}
81-
_ if self.ignore_non_const_paths => (),
81+
_ if self.in_pat => (),
8282
Def::PrimTy(..) | Def::SelfTy(..) |
8383
Def::Local(..) | Def::Upvar(..) => {}
8484
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
@@ -289,9 +289,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
289289
_ => ()
290290
}
291291

292-
self.ignore_non_const_paths = true;
292+
self.in_pat = true;
293293
intravisit::walk_pat(self, pat);
294-
self.ignore_non_const_paths = false;
294+
self.in_pat = false;
295295
}
296296

297297
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>,
429429
tables: &ty::TypeckTables::empty(None),
430430
live_symbols: box FxHashSet(),
431431
struct_has_extern_repr: false,
432-
ignore_non_const_paths: false,
432+
in_pat: false,
433433
inherited_pub_visibility: false,
434434
ignore_variant_stack: vec![],
435435
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
fn main() {
14+
struct Foo<T> { x: T }
15+
type Bar = Foo<u32>;
16+
let spam = |Bar { x }| x != 0;
17+
println!("{}", spam(Foo { x: 10 }));
18+
}

0 commit comments

Comments
 (0)