Merge remote-tracking branch 'origin/master' into gen

This commit is contained in:
Alex Crichton
2017-08-21 15:45:40 -07:00
9 changed files with 53 additions and 31 deletions

View File

@@ -138,7 +138,7 @@ impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
fn visit_pat(&mut self, pat: &'hir Pat) { fn visit_pat(&mut self, pat: &'hir Pat) {
let node = if let PatKind::Binding(..) = pat.node { let node = if let PatKind::Binding(..) = pat.node {
NodeLocal(pat) NodeBinding(pat)
} else { } else {
NodePat(pat) NodePat(pat)
}; };
@@ -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) { fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
self.insert(lifetime.id, NodeLifetime(lifetime)); self.insert(lifetime.id, NodeLifetime(lifetime));
} }

View File

@@ -53,9 +53,10 @@ pub enum Node<'hir> {
NodeStmt(&'hir Stmt), NodeStmt(&'hir Stmt),
NodeTy(&'hir Ty), NodeTy(&'hir Ty),
NodeTraitRef(&'hir TraitRef), NodeTraitRef(&'hir TraitRef),
NodeLocal(&'hir Pat), NodeBinding(&'hir Pat),
NodePat(&'hir Pat), NodePat(&'hir Pat),
NodeBlock(&'hir Block), NodeBlock(&'hir Block),
NodeLocal(&'hir Local),
/// NodeStructCtor represents a tuple struct. /// NodeStructCtor represents a tuple struct.
NodeStructCtor(&'hir VariantData), NodeStructCtor(&'hir VariantData),
@@ -83,13 +84,14 @@ enum MapEntry<'hir> {
EntryStmt(NodeId, &'hir Stmt), EntryStmt(NodeId, &'hir Stmt),
EntryTy(NodeId, &'hir Ty), EntryTy(NodeId, &'hir Ty),
EntryTraitRef(NodeId, &'hir TraitRef), EntryTraitRef(NodeId, &'hir TraitRef),
EntryLocal(NodeId, &'hir Pat), EntryBinding(NodeId, &'hir Pat),
EntryPat(NodeId, &'hir Pat), EntryPat(NodeId, &'hir Pat),
EntryBlock(NodeId, &'hir Block), EntryBlock(NodeId, &'hir Block),
EntryStructCtor(NodeId, &'hir VariantData), EntryStructCtor(NodeId, &'hir VariantData),
EntryLifetime(NodeId, &'hir Lifetime), EntryLifetime(NodeId, &'hir Lifetime),
EntryTyParam(NodeId, &'hir TyParam), EntryTyParam(NodeId, &'hir TyParam),
EntryVisibility(NodeId, &'hir Visibility), EntryVisibility(NodeId, &'hir Visibility),
EntryLocal(NodeId, &'hir Local),
/// Roots for node trees. /// Roots for node trees.
RootCrate, RootCrate,
@@ -114,13 +116,14 @@ impl<'hir> MapEntry<'hir> {
NodeStmt(n) => EntryStmt(p, n), NodeStmt(n) => EntryStmt(p, n),
NodeTy(n) => EntryTy(p, n), NodeTy(n) => EntryTy(p, n),
NodeTraitRef(n) => EntryTraitRef(p, n), NodeTraitRef(n) => EntryTraitRef(p, n),
NodeLocal(n) => EntryLocal(p, n), NodeBinding(n) => EntryBinding(p, n),
NodePat(n) => EntryPat(p, n), NodePat(n) => EntryPat(p, n),
NodeBlock(n) => EntryBlock(p, n), NodeBlock(n) => EntryBlock(p, n),
NodeStructCtor(n) => EntryStructCtor(p, n), NodeStructCtor(n) => EntryStructCtor(p, n),
NodeLifetime(n) => EntryLifetime(p, n), NodeLifetime(n) => EntryLifetime(p, n),
NodeTyParam(n) => EntryTyParam(p, n), NodeTyParam(n) => EntryTyParam(p, n),
NodeVisibility(n) => EntryVisibility(p, n), NodeVisibility(n) => EntryVisibility(p, n),
NodeLocal(n) => EntryLocal(p, n),
} }
} }
@@ -136,13 +139,14 @@ impl<'hir> MapEntry<'hir> {
EntryStmt(id, _) => id, EntryStmt(id, _) => id,
EntryTy(id, _) => id, EntryTy(id, _) => id,
EntryTraitRef(id, _) => id, EntryTraitRef(id, _) => id,
EntryLocal(id, _) => id, EntryBinding(id, _) => id,
EntryPat(id, _) => id, EntryPat(id, _) => id,
EntryBlock(id, _) => id, EntryBlock(id, _) => id,
EntryStructCtor(id, _) => id, EntryStructCtor(id, _) => id,
EntryLifetime(id, _) => id, EntryLifetime(id, _) => id,
EntryTyParam(id, _) => id, EntryTyParam(id, _) => id,
EntryVisibility(id, _) => id, EntryVisibility(id, _) => id,
EntryLocal(id, _) => id,
NotPresent | NotPresent |
RootCrate => return None, RootCrate => return None,
@@ -161,13 +165,14 @@ impl<'hir> MapEntry<'hir> {
EntryStmt(_, n) => NodeStmt(n), EntryStmt(_, n) => NodeStmt(n),
EntryTy(_, n) => NodeTy(n), EntryTy(_, n) => NodeTy(n),
EntryTraitRef(_, n) => NodeTraitRef(n), EntryTraitRef(_, n) => NodeTraitRef(n),
EntryLocal(_, n) => NodeLocal(n), EntryBinding(_, n) => NodeBinding(n),
EntryPat(_, n) => NodePat(n), EntryPat(_, n) => NodePat(n),
EntryBlock(_, n) => NodeBlock(n), EntryBlock(_, n) => NodeBlock(n),
EntryStructCtor(_, n) => NodeStructCtor(n), EntryStructCtor(_, n) => NodeStructCtor(n),
EntryLifetime(_, n) => NodeLifetime(n), EntryLifetime(_, n) => NodeLifetime(n),
EntryTyParam(_, n) => NodeTyParam(n), EntryTyParam(_, n) => NodeTyParam(n),
EntryVisibility(_, n) => NodeVisibility(n), EntryVisibility(_, n) => NodeVisibility(n),
EntryLocal(_, n) => NodeLocal(n),
NotPresent | NotPresent |
RootCrate => return None RootCrate => return None
@@ -321,13 +326,14 @@ impl<'hir> Map<'hir> {
EntryStmt(p, _) | EntryStmt(p, _) |
EntryTy(p, _) | EntryTy(p, _) |
EntryTraitRef(p, _) | EntryTraitRef(p, _) |
EntryLocal(p, _) | EntryBinding(p, _) |
EntryPat(p, _) | EntryPat(p, _) |
EntryBlock(p, _) | EntryBlock(p, _) |
EntryStructCtor(p, _) | EntryStructCtor(p, _) |
EntryLifetime(p, _) | EntryLifetime(p, _) |
EntryTyParam(p, _) | EntryTyParam(p, _) |
EntryVisibility(p, _) => EntryVisibility(p, _) |
EntryLocal(p, _) =>
id = p, id = p,
EntryExpr(p, _) => { EntryExpr(p, _) => {
@@ -591,7 +597,7 @@ impl<'hir> Map<'hir> {
/// immediate parent is an item or a closure. /// immediate parent is an item or a closure.
pub fn is_argument(&self, id: NodeId) -> bool { pub fn is_argument(&self, id: NodeId) -> bool {
match self.find(id) { match self.find(id) {
Some(NodeLocal(_)) => (), Some(NodeBinding(_)) => (),
_ => return false, _ => return false,
} }
match self.find(self.get_parent_node(id)) { match self.find(self.get_parent_node(id)) {
@@ -858,7 +864,7 @@ impl<'hir> Map<'hir> {
NodeField(f) => f.name, NodeField(f) => f.name,
NodeLifetime(lt) => lt.name, NodeLifetime(lt) => lt.name,
NodeTyParam(tp) => tp.name, NodeTyParam(tp) => tp.name,
NodeLocal(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node, NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
NodeStructCtor(_) => self.name(self.get_parent(id)), NodeStructCtor(_) => self.name(self.get_parent(id)),
_ => bug!("no name for {}", self.node_to_string(id)) _ => bug!("no name for {}", self.node_to_string(id))
} }
@@ -917,7 +923,7 @@ impl<'hir> Map<'hir> {
Some(EntryStmt(_, stmt)) => stmt.span, Some(EntryStmt(_, stmt)) => stmt.span,
Some(EntryTy(_, ty)) => ty.span, Some(EntryTy(_, ty)) => ty.span,
Some(EntryTraitRef(_, tr)) => tr.path.span, Some(EntryTraitRef(_, tr)) => tr.path.span,
Some(EntryLocal(_, pat)) => pat.span, Some(EntryBinding(_, pat)) => pat.span,
Some(EntryPat(_, pat)) => pat.span, Some(EntryPat(_, pat)) => pat.span,
Some(EntryBlock(_, block)) => block.span, Some(EntryBlock(_, block)) => block.span,
Some(EntryStructCtor(_, _)) => self.expect_item(self.get_parent(id)).span, Some(EntryStructCtor(_, _)) => self.expect_item(self.get_parent(id)).span,
@@ -925,6 +931,7 @@ impl<'hir> Map<'hir> {
Some(EntryTyParam(_, ty_param)) => ty_param.span, Some(EntryTyParam(_, ty_param)) => ty_param.span,
Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span, Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span,
Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v), Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v),
Some(EntryLocal(_, local)) => local.span,
Some(RootCrate) => self.forest.krate.span, Some(RootCrate) => self.forest.krate.span,
Some(NotPresent) | None => { Some(NotPresent) | None => {
@@ -1114,7 +1121,7 @@ impl<'a> print::State<'a> {
NodeStmt(a) => self.print_stmt(&a), NodeStmt(a) => self.print_stmt(&a),
NodeTy(a) => self.print_type(&a), NodeTy(a) => self.print_type(&a),
NodeTraitRef(a) => self.print_trait_ref(&a), NodeTraitRef(a) => self.print_trait_ref(&a),
NodeLocal(a) | NodeBinding(a) |
NodePat(a) => self.print_pat(&a), NodePat(a) => self.print_pat(&a),
NodeBlock(a) => { NodeBlock(a) => {
use syntax::print::pprust::PrintState; use syntax::print::pprust::PrintState;
@@ -1133,6 +1140,7 @@ impl<'a> print::State<'a> {
// hir_map to reconstruct their full structure for pretty // hir_map to reconstruct their full structure for pretty
// printing. // printing.
NodeStructCtor(_) => bug!("cannot print isolated StructCtor"), NodeStructCtor(_) => bug!("cannot print isolated StructCtor"),
NodeLocal(a) => self.print_local_decl(&a),
} }
} }
} }
@@ -1225,7 +1233,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
Some(NodeTraitRef(_)) => { Some(NodeTraitRef(_)) => {
format!("trait_ref {}{}", map.node_to_pretty_string(id), id_str) format!("trait_ref {}{}", map.node_to_pretty_string(id), id_str)
} }
Some(NodeLocal(_)) => { Some(NodeBinding(_)) => {
format!("local {}{}", map.node_to_pretty_string(id), id_str) format!("local {}{}", map.node_to_pretty_string(id), id_str)
} }
Some(NodePat(_)) => { Some(NodePat(_)) => {
@@ -1234,6 +1242,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
Some(NodeBlock(_)) => { Some(NodeBlock(_)) => {
format!("block {}{}", map.node_to_pretty_string(id), id_str) format!("block {}{}", map.node_to_pretty_string(id), id_str)
} }
Some(NodeLocal(_)) => {
format!("local {}{}", map.node_to_pretty_string(id), id_str)
}
Some(NodeStructCtor(_)) => { Some(NodeStructCtor(_)) => {
format!("struct_ctor {}{}", path_str(), id_str) format!("struct_ctor {}{}", path_str(), id_str)
} }

View File

@@ -332,7 +332,7 @@ impl MutabilityCategory {
fn from_local(tcx: TyCtxt, tables: &ty::TypeckTables, id: ast::NodeId) -> MutabilityCategory { fn from_local(tcx: TyCtxt, tables: &ty::TypeckTables, id: ast::NodeId) -> MutabilityCategory {
let ret = match tcx.hir.get(id) { let ret = match tcx.hir.get(id) {
hir_map::NodeLocal(p) => match p.node { hir_map::NodeBinding(p) => match p.node {
PatKind::Binding(..) => { PatKind::Binding(..) => {
let bm = *tables.pat_binding_modes() let bm = *tables.pat_binding_modes()
.get(p.hir_id) .get(p.hir_id)

View File

@@ -1974,7 +1974,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn local_var_name_str(self, id: NodeId) -> InternedString { pub fn local_var_name_str(self, id: NodeId) -> InternedString {
match self.hir.find(id) { match self.hir.find(id) {
Some(hir_map::NodeLocal(pat)) => { Some(hir_map::NodeBinding(pat)) => {
match pat.node { match pat.node {
hir::PatKind::Binding(_, _, ref path1, _) => path1.node.as_str(), hir::PatKind::Binding(_, _, ref path1, _) => path1.node.as_str(),
_ => { _ => {

View File

@@ -68,19 +68,7 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte
}); });
PatternSource::MatchExpr(e) PatternSource::MatchExpr(e)
} }
NodeStmt(ref s) => { NodeLocal(local) => PatternSource::LetDecl(local),
// 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,
}
}
_ => return PatternSource::Other, _ => return PatternSource::Other,
} }

View File

@@ -1108,7 +1108,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
fn local_binding_mode(&self, node_id: ast::NodeId) -> ty::BindingMode { fn local_binding_mode(&self, node_id: ast::NodeId) -> ty::BindingMode {
let pat = match self.tcx.hir.get(node_id) { let pat = match self.tcx.hir.get(node_id) {
hir_map::Node::NodeLocal(pat) => pat, hir_map::Node::NodeBinding(pat) => pat,
node => bug!("bad node for local: {:?}", node) node => bug!("bad node for local: {:?}", node)
}; };

View File

@@ -399,7 +399,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
debug_name: keywords::Invalid.name(), debug_name: keywords::Invalid.name(),
by_ref, by_ref,
}; };
if let Some(hir::map::NodeLocal(pat)) = tcx.hir.find(var_node_id) { if let Some(hir::map::NodeBinding(pat)) = tcx.hir.find(var_node_id) {
if let hir::PatKind::Binding(_, _, ref ident, _) = pat.node { if let hir::PatKind::Binding(_, _, ref ident, _) = pat.node {
decl.debug_name = ident.node; decl.debug_name = ident.node;
} }

View File

@@ -589,7 +589,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
self.tables.qpath_def(qpath, hir_id) self.tables.qpath_def(qpath, hir_id)
} }
Node::NodeLocal(&hir::Pat { node: hir::PatKind::Binding(_, def_id, ..), .. }) => { Node::NodeBinding(&hir::Pat { node: hir::PatKind::Binding(_, def_id, ..), .. }) => {
HirDef::Local(def_id) HirDef::Local(def_id)
} }

View File

@@ -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 <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(unused_variables)]
fn main() {
#[allow(unused_variables)]
let x = 12;
}