diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 7b7d9adec05ed..0928081decda0 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -195,6 +195,13 @@ impl<'hir> Visitor<'hir> for NodeCollector<'hir> { }); } + fn visit_local(&mut self, l: &'hir Local) { + self.insert(l.id, NodeLocal(l)); + self.with_parent(l.id, |this| { + intravisit::walk_local(this, l) + }) + } + fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) { self.insert(lifetime.id, NodeLifetime(lifetime)); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 1cf4e799ca769..1ff3166110aa0 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -56,6 +56,7 @@ pub enum Node<'hir> { NodeBinding(&'hir Pat), NodePat(&'hir Pat), NodeBlock(&'hir Block), + NodeLocal(&'hir Local), /// NodeStructCtor represents a tuple struct. NodeStructCtor(&'hir VariantData), @@ -90,6 +91,7 @@ enum MapEntry<'hir> { EntryLifetime(NodeId, &'hir Lifetime), EntryTyParam(NodeId, &'hir TyParam), EntryVisibility(NodeId, &'hir Visibility), + EntryLocal(NodeId, &'hir Local), /// Roots for node trees. RootCrate, @@ -121,6 +123,7 @@ impl<'hir> MapEntry<'hir> { NodeLifetime(n) => EntryLifetime(p, n), NodeTyParam(n) => EntryTyParam(p, n), NodeVisibility(n) => EntryVisibility(p, n), + NodeLocal(n) => EntryLocal(p, n), } } @@ -143,6 +146,7 @@ impl<'hir> MapEntry<'hir> { EntryLifetime(id, _) => id, EntryTyParam(id, _) => id, EntryVisibility(id, _) => id, + EntryLocal(id, _) => id, NotPresent | RootCrate => return None, @@ -168,6 +172,7 @@ impl<'hir> MapEntry<'hir> { EntryLifetime(_, n) => NodeLifetime(n), EntryTyParam(_, n) => NodeTyParam(n), EntryVisibility(_, n) => NodeVisibility(n), + EntryLocal(_, n) => NodeLocal(n), _ => return None }) } @@ -325,7 +330,8 @@ impl<'hir> Map<'hir> { EntryStructCtor(p, _) | EntryLifetime(p, _) | EntryTyParam(p, _) | - EntryVisibility(p, _) => + EntryVisibility(p, _) | + EntryLocal(p, _) => id = p, EntryExpr(p, _) => { @@ -923,6 +929,7 @@ impl<'hir> Map<'hir> { Some(EntryTyParam(_, ty_param)) => ty_param.span, Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span, Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v), + Some(EntryLocal(_, local)) => local.span, Some(RootCrate) => self.forest.krate.span, Some(NotPresent) | None => { @@ -1131,6 +1138,7 @@ impl<'a> print::State<'a> { // hir_map to reconstruct their full structure for pretty // printing. NodeStructCtor(_) => bug!("cannot print isolated StructCtor"), + NodeLocal(a) => self.print_local_decl(&a), } } } @@ -1232,6 +1240,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { Some(NodeBlock(_)) => { format!("block {}{}", map.node_to_pretty_string(id), id_str) } + Some(NodeLocal(_)) => { + format!("local {}{}", map.node_to_pretty_string(id), id_str) + } Some(NodeStructCtor(_)) => { format!("struct_ctor {}{}", path_str(), id_str) } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index bca980c5ccf4c..9ccf157ed8974 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -68,19 +68,7 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte }); PatternSource::MatchExpr(e) } - NodeStmt(ref s) => { - // the enclosing statement must be a `let` or something else - match s.node { - StmtDecl(ref decl, _) => { - match decl.node { - DeclLocal(ref local) => PatternSource::LetDecl(local), - _ => return PatternSource::Other, - } - } - _ => return PatternSource::Other, - } - } - + NodeLocal(local) => PatternSource::LetDecl(local), _ => return PatternSource::Other, } diff --git a/src/test/run-pass/issue-43910.rs b/src/test/run-pass/issue-43910.rs new file mode 100644 index 0000000000000..d61ce7f4689bb --- /dev/null +++ b/src/test/run-pass/issue-43910.rs @@ -0,0 +1,16 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(unused_variables)] + +fn main() { + #[allow(unused_variables)] + let x = 12; +}