diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index c651baae28224..944b77dbf01fd 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -17,14 +17,14 @@ use graphviz::IntoCow; use syntax::ast; -use hir::map as ast_map; +use hir::map as hir_map; use cfg; pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode); pub type Edge<'a> = &'a cfg::CFGEdge; -pub struct LabelledCFG<'a, 'ast: 'a> { - pub ast_map: &'a ast_map::Map<'ast>, +pub struct LabelledCFG<'a, 'hir: 'a> { + pub hir_map: &'a hir_map::Map<'hir>, pub cfg: &'a cfg::CFG, pub name: String, /// `labelled_edges` controls whether we emit labels on the edges @@ -52,7 +52,7 @@ fn replace_newline_with_backslash_l(s: String) -> String { } } -impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> { +impl<'a, 'hir> dot::Labeller<'a> for LabelledCFG<'a, 'hir> { type Node = Node<'a>; type Edge = Edge<'a>; fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).unwrap() } @@ -69,7 +69,7 @@ impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> { } else if n.data.id() == ast::DUMMY_NODE_ID { dot::LabelText::LabelStr("(dummy_node)".into_cow()) } else { - let s = self.ast_map.node_to_string(n.data.id()); + let s = self.hir_map.node_to_string(n.data.id()); // left-aligns the lines let s = replace_newline_with_backslash_l(s); dot::LabelText::EscStr(s.into_cow()) @@ -88,7 +88,7 @@ impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> { } else { put_one = true; } - let s = self.ast_map.node_to_string(node_id); + let s = self.hir_map.node_to_string(node_id); // left-aligns the lines let s = replace_newline_with_backslash_l(s); label.push_str(&format!("exiting scope_{} {}", @@ -120,7 +120,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG { } } -impl<'a, 'ast> dot::GraphWalk<'a> for LabelledCFG<'a, 'ast> +impl<'a, 'hir> dot::GraphWalk<'a> for LabelledCFG<'a, 'hir> { type Node = Node<'a>; type Edge = Edge<'a>; diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index cc6d61c21c696..d4095c6875c1d 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -1085,13 +1085,13 @@ impl IdRange { } -pub struct IdRangeComputingVisitor<'a, 'ast: 'a> { +pub struct IdRangeComputingVisitor<'a, 'hir: 'a> { result: IdRange, - map: &'a map::Map<'ast>, + map: &'a map::Map<'hir>, } -impl<'a, 'ast> IdRangeComputingVisitor<'a, 'ast> { - pub fn new(map: &'a map::Map<'ast>) -> IdRangeComputingVisitor<'a, 'ast> { +impl<'a, 'hir> IdRangeComputingVisitor<'a, 'hir> { + pub fn new(map: &'a map::Map<'hir>) -> IdRangeComputingVisitor<'a, 'hir> { IdRangeComputingVisitor { result: IdRange::max(), map: map } } @@ -1100,8 +1100,8 @@ impl<'a, 'ast> IdRangeComputingVisitor<'a, 'ast> { } } -impl<'a, 'ast> Visitor<'ast> for IdRangeComputingVisitor<'a, 'ast> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { +impl<'a, 'hir> Visitor<'hir> for IdRangeComputingVisitor<'a, 'hir> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { NestedVisitorMap::OnlyBodies(&self.map) } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index bd0ff695d093a..904f74b8787fd 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -16,17 +16,17 @@ use syntax::ast::{NodeId, CRATE_NODE_ID}; use syntax_pos::Span; /// A Visitor that walks over the HIR and collects Nodes into a HIR map -pub struct NodeCollector<'ast> { +pub struct NodeCollector<'hir> { /// The crate - pub krate: &'ast Crate, + pub krate: &'hir Crate, /// The node map - pub(super) map: Vec>, + pub(super) map: Vec>, /// The parent of this node pub parent_node: NodeId, } -impl<'ast> NodeCollector<'ast> { - pub fn root(krate: &'ast Crate) -> NodeCollector<'ast> { +impl<'hir> NodeCollector<'hir> { + pub fn root(krate: &'hir Crate) -> NodeCollector<'hir> { let mut collector = NodeCollector { krate: krate, map: vec![], @@ -37,8 +37,8 @@ impl<'ast> NodeCollector<'ast> { collector } - fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'ast>) { - debug!("ast_map: {:?} => {:?}", id, entry); + fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'hir>) { + debug!("hir_map: {:?} => {:?}", id, entry); let len = self.map.len(); if id.as_usize() >= len { self.map.extend(repeat(NotPresent).take(id.as_usize() - len + 1)); @@ -46,7 +46,7 @@ impl<'ast> NodeCollector<'ast> { self.map[id.as_usize()] = entry; } - fn insert(&mut self, id: NodeId, node: Node<'ast>) { + fn insert(&mut self, id: NodeId, node: Node<'hir>) { let entry = MapEntry::from_node(self.parent_node, node); self.insert_entry(id, entry); } @@ -59,12 +59,12 @@ impl<'ast> NodeCollector<'ast> { } } -impl<'ast> Visitor<'ast> for NodeCollector<'ast> { +impl<'hir> Visitor<'hir> for NodeCollector<'hir> { /// Because we want to track parent items and so forth, enable /// deep walking so that we walk nested items in the context of /// their outer items. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { panic!("visit_nested_xxx must be manually implemented in this visitor") } @@ -85,7 +85,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { self.visit_body(self.krate.body(id)); } - fn visit_item(&mut self, i: &'ast Item) { + fn visit_item(&mut self, i: &'hir Item) { debug!("visit_item: {:?}", i); self.insert(i.id, NodeItem(i)); @@ -104,7 +104,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) { self.insert(foreign_item.id, NodeForeignItem(foreign_item)); self.with_parent(foreign_item.id, |this| { @@ -112,7 +112,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_generics(&mut self, generics: &'ast Generics) { + fn visit_generics(&mut self, generics: &'hir Generics) { for ty_param in generics.ty_params.iter() { self.insert(ty_param.id, NodeTyParam(ty_param)); } @@ -120,7 +120,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { intravisit::walk_generics(self, generics); } - fn visit_trait_item(&mut self, ti: &'ast TraitItem) { + fn visit_trait_item(&mut self, ti: &'hir TraitItem) { self.insert(ti.id, NodeTraitItem(ti)); self.with_parent(ti.id, |this| { @@ -128,7 +128,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_impl_item(&mut self, ii: &'ast ImplItem) { + fn visit_impl_item(&mut self, ii: &'hir ImplItem) { self.insert(ii.id, NodeImplItem(ii)); self.with_parent(ii.id, |this| { @@ -136,7 +136,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_pat(&mut self, pat: &'ast Pat) { + fn visit_pat(&mut self, pat: &'hir Pat) { let node = if let PatKind::Binding(..) = pat.node { NodeLocal(pat) } else { @@ -149,7 +149,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_expr(&mut self, expr: &'ast Expr) { + fn visit_expr(&mut self, expr: &'hir Expr) { self.insert(expr.id, NodeExpr(expr)); self.with_parent(expr.id, |this| { @@ -157,7 +157,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_stmt(&mut self, stmt: &'ast Stmt) { + fn visit_stmt(&mut self, stmt: &'hir Stmt) { let id = stmt.node.id(); self.insert(id, NodeStmt(stmt)); @@ -166,7 +166,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_ty(&mut self, ty: &'ast Ty) { + fn visit_ty(&mut self, ty: &'hir Ty) { self.insert(ty.id, NodeTy(ty)); self.with_parent(ty.id, |this| { @@ -174,7 +174,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_trait_ref(&mut self, tr: &'ast TraitRef) { + fn visit_trait_ref(&mut self, tr: &'hir TraitRef) { self.insert(tr.ref_id, NodeTraitRef(tr)); self.with_parent(tr.ref_id, |this| { @@ -182,24 +182,24 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_fn(&mut self, fk: intravisit::FnKind<'ast>, fd: &'ast FnDecl, + fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl, b: BodyId, s: Span, id: NodeId) { assert_eq!(self.parent_node, id); intravisit::walk_fn(self, fk, fd, b, s, id); } - fn visit_block(&mut self, block: &'ast Block) { + fn visit_block(&mut self, block: &'hir Block) { self.insert(block.id, NodeBlock(block)); self.with_parent(block.id, |this| { intravisit::walk_block(this, block); }); } - fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) { + fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) { self.insert(lifetime.id, NodeLifetime(lifetime)); } - fn visit_vis(&mut self, visibility: &'ast Visibility) { + fn visit_vis(&mut self, visibility: &'hir Visibility) { match *visibility { Visibility::Public | Visibility::Crate | @@ -213,11 +213,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { } } - fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) { self.insert_entry(macro_def.id, NotPresent); } - fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) { let id = v.node.data.id(); self.insert(id, NodeVariant(v)); self.with_parent(id, |this| { @@ -225,7 +225,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { }); } - fn visit_struct_field(&mut self, field: &'ast StructField) { + fn visit_struct_field(&mut self, field: &'hir StructField) { self.insert(field.id, NodeField(field)); self.with_parent(field.id, |this| { intravisit::walk_struct_field(this, field); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 7c0621279fd6f..9f31b5b456b9f 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -38,67 +38,67 @@ mod def_collector; pub mod definitions; #[derive(Copy, Clone, Debug)] -pub enum Node<'ast> { - NodeItem(&'ast Item), - NodeForeignItem(&'ast ForeignItem), - NodeTraitItem(&'ast TraitItem), - NodeImplItem(&'ast ImplItem), - NodeVariant(&'ast Variant), - NodeField(&'ast StructField), - NodeExpr(&'ast Expr), - NodeStmt(&'ast Stmt), - NodeTy(&'ast Ty), - NodeTraitRef(&'ast TraitRef), - NodeLocal(&'ast Pat), - NodePat(&'ast Pat), - NodeBlock(&'ast Block), +pub enum Node<'hir> { + NodeItem(&'hir Item), + NodeForeignItem(&'hir ForeignItem), + NodeTraitItem(&'hir TraitItem), + NodeImplItem(&'hir ImplItem), + NodeVariant(&'hir Variant), + NodeField(&'hir StructField), + NodeExpr(&'hir Expr), + NodeStmt(&'hir Stmt), + NodeTy(&'hir Ty), + NodeTraitRef(&'hir TraitRef), + NodeLocal(&'hir Pat), + NodePat(&'hir Pat), + NodeBlock(&'hir Block), /// NodeStructCtor represents a tuple struct. - NodeStructCtor(&'ast VariantData), + NodeStructCtor(&'hir VariantData), - NodeLifetime(&'ast Lifetime), - NodeTyParam(&'ast TyParam), - NodeVisibility(&'ast Visibility), + NodeLifetime(&'hir Lifetime), + NodeTyParam(&'hir TyParam), + NodeVisibility(&'hir Visibility), } /// Represents an entry and its parent NodeID. /// The odd layout is to bring down the total size. #[derive(Copy, Debug)] -enum MapEntry<'ast> { +enum MapEntry<'hir> { /// Placeholder for holes in the map. NotPresent, /// All the node types, with a parent ID. - EntryItem(NodeId, &'ast Item), - EntryForeignItem(NodeId, &'ast ForeignItem), - EntryTraitItem(NodeId, &'ast TraitItem), - EntryImplItem(NodeId, &'ast ImplItem), - EntryVariant(NodeId, &'ast Variant), - EntryField(NodeId, &'ast StructField), - EntryExpr(NodeId, &'ast Expr), - EntryStmt(NodeId, &'ast Stmt), - EntryTy(NodeId, &'ast Ty), - EntryTraitRef(NodeId, &'ast TraitRef), - EntryLocal(NodeId, &'ast Pat), - EntryPat(NodeId, &'ast Pat), - EntryBlock(NodeId, &'ast Block), - EntryStructCtor(NodeId, &'ast VariantData), - EntryLifetime(NodeId, &'ast Lifetime), - EntryTyParam(NodeId, &'ast TyParam), - EntryVisibility(NodeId, &'ast Visibility), + EntryItem(NodeId, &'hir Item), + EntryForeignItem(NodeId, &'hir ForeignItem), + EntryTraitItem(NodeId, &'hir TraitItem), + EntryImplItem(NodeId, &'hir ImplItem), + EntryVariant(NodeId, &'hir Variant), + EntryField(NodeId, &'hir StructField), + EntryExpr(NodeId, &'hir Expr), + EntryStmt(NodeId, &'hir Stmt), + EntryTy(NodeId, &'hir Ty), + EntryTraitRef(NodeId, &'hir TraitRef), + EntryLocal(NodeId, &'hir Pat), + EntryPat(NodeId, &'hir Pat), + EntryBlock(NodeId, &'hir Block), + EntryStructCtor(NodeId, &'hir VariantData), + EntryLifetime(NodeId, &'hir Lifetime), + EntryTyParam(NodeId, &'hir TyParam), + EntryVisibility(NodeId, &'hir Visibility), /// Roots for node trees. RootCrate, } -impl<'ast> Clone for MapEntry<'ast> { - fn clone(&self) -> MapEntry<'ast> { +impl<'hir> Clone for MapEntry<'hir> { + fn clone(&self) -> MapEntry<'hir> { *self } } -impl<'ast> MapEntry<'ast> { - fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> { +impl<'hir> MapEntry<'hir> { + fn from_node(p: NodeId, node: Node<'hir>) -> MapEntry<'hir> { match node { NodeItem(n) => EntryItem(p, n), NodeForeignItem(n) => EntryForeignItem(p, n), @@ -145,7 +145,7 @@ impl<'ast> MapEntry<'ast> { }) } - fn to_node(self) -> Option> { + fn to_node(self) -> Option> { Some(match self { EntryItem(_, n) => NodeItem(n), EntryForeignItem(_, n) => NodeForeignItem(n), @@ -225,7 +225,7 @@ impl Forest { } } - pub fn krate<'ast>(&'ast self) -> &'ast Crate { + pub fn krate<'hir>(&'hir self) -> &'hir Crate { self.dep_graph.read(DepNode::Krate); &self.krate } @@ -234,9 +234,9 @@ impl Forest { /// Represents a mapping from Node IDs to AST elements and their parent /// Node IDs #[derive(Clone)] -pub struct Map<'ast> { +pub struct Map<'hir> { /// The backing storage for all the AST nodes. - pub forest: &'ast Forest, + pub forest: &'hir Forest, /// Same as the dep_graph in forest, just available with one fewer /// deref. This is a gratuitious micro-optimization. @@ -251,15 +251,15 @@ pub struct Map<'ast> { /// /// Also, indexing is pretty quick when you've got a vector and /// plain old integers. - map: Vec>, + map: Vec>, definitions: Definitions, /// Bodies inlined from other crates are cached here. - inlined_bodies: RefCell>, + inlined_bodies: RefCell>, } -impl<'ast> Map<'ast> { +impl<'hir> Map<'hir> { /// Registers a read in the dependency graph of the AST node with /// the given `id`. This needs to be called each time a public /// function returns the HIR for a node -- in other words, when it @@ -388,15 +388,15 @@ impl<'ast> Map<'ast> { self.map.len() } - fn find_entry(&self, id: NodeId) -> Option> { + fn find_entry(&self, id: NodeId) -> Option> { self.map.get(id.as_usize()).cloned() } - pub fn krate(&self) -> &'ast Crate { + pub fn krate(&self) -> &'hir Crate { self.forest.krate() } - pub fn trait_item(&self, id: TraitItemId) -> &'ast TraitItem { + pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem { self.read(id.node_id); // NB: intentionally bypass `self.forest.krate()` so that we @@ -404,7 +404,7 @@ impl<'ast> Map<'ast> { self.forest.krate.trait_item(id) } - pub fn impl_item(&self, id: ImplItemId) -> &'ast ImplItem { + pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem { self.read(id.node_id); // NB: intentionally bypass `self.forest.krate()` so that we @@ -412,7 +412,7 @@ impl<'ast> Map<'ast> { self.forest.krate.impl_item(id) } - pub fn body(&self, id: BodyId) -> &'ast Body { + pub fn body(&self, id: BodyId) -> &'hir Body { self.read(id.node_id); // NB: intentionally bypass `self.forest.krate()` so that we @@ -440,7 +440,7 @@ impl<'ast> Map<'ast> { /// Get the attributes on the krate. This is preferable to /// invoking `krate.attrs` because it registers a tighter /// dep-graph access. - pub fn krate_attrs(&self) -> &'ast [ast::Attribute] { + pub fn krate_attrs(&self) -> &'hir [ast::Attribute] { let crate_root_def_id = DefId::local(CRATE_DEF_INDEX); self.dep_graph.read(DepNode::Hir(crate_root_def_id)); &self.forest.krate.attrs @@ -448,20 +448,20 @@ impl<'ast> Map<'ast> { /// Retrieve the Node corresponding to `id`, panicking if it cannot /// be found. - pub fn get(&self, id: NodeId) -> Node<'ast> { + pub fn get(&self, id: NodeId) -> Node<'hir> { match self.find(id) { Some(node) => node, // read recorded by `find` None => bug!("couldn't find node id {} in the AST map", id) } } - pub fn get_if_local(&self, id: DefId) -> Option> { + pub fn get_if_local(&self, id: DefId) -> Option> { self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` } /// Retrieve the Node corresponding to `id`, returning None if /// cannot be found. - pub fn find(&self, id: NodeId) -> Option> { + pub fn find(&self, id: NodeId) -> Option> { let result = self.find_entry(id).and_then(|x| x.to_node()); if result.is_some() { self.read(id); @@ -508,7 +508,7 @@ impl<'ast> Map<'ast> { /// is not an error, since items in the crate module have the crate root as /// parent. fn walk_parent_nodes(&self, start_id: NodeId, found: F) -> Result - where F: Fn(&Node<'ast>) -> bool + where F: Fn(&Node<'hir>) -> bool { let mut id = start_id; loop { @@ -611,28 +611,28 @@ impl<'ast> Map<'ast> { } } - pub fn expect_item(&self, id: NodeId) -> &'ast Item { + pub fn expect_item(&self, id: NodeId) -> &'hir Item { match self.find(id) { // read recorded by `find` Some(NodeItem(item)) => item, _ => bug!("expected item, found {}", self.node_to_string(id)) } } - pub fn expect_impl_item(&self, id: NodeId) -> &'ast ImplItem { + pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem { match self.find(id) { Some(NodeImplItem(item)) => item, _ => bug!("expected impl item, found {}", self.node_to_string(id)) } } - pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem { + pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem { match self.find(id) { Some(NodeTraitItem(item)) => item, _ => bug!("expected trait item, found {}", self.node_to_string(id)) } } - pub fn expect_variant_data(&self, id: NodeId) -> &'ast VariantData { + pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData { match self.find(id) { Some(NodeItem(i)) => { match i.node { @@ -653,35 +653,35 @@ impl<'ast> Map<'ast> { } } - pub fn expect_variant(&self, id: NodeId) -> &'ast Variant { + pub fn expect_variant(&self, id: NodeId) -> &'hir Variant { match self.find(id) { Some(NodeVariant(variant)) => variant, _ => bug!("expected variant, found {}", self.node_to_string(id)), } } - pub fn expect_foreign_item(&self, id: NodeId) -> &'ast ForeignItem { + pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem { match self.find(id) { Some(NodeForeignItem(item)) => item, _ => bug!("expected foreign item, found {}", self.node_to_string(id)) } } - pub fn expect_expr(&self, id: NodeId) -> &'ast Expr { + pub fn expect_expr(&self, id: NodeId) -> &'hir Expr { match self.find(id) { // read recorded by find Some(NodeExpr(expr)) => expr, _ => bug!("expected expr, found {}", self.node_to_string(id)) } } - pub fn get_inlined_body(&self, def_id: DefId) -> Option<&'ast Body> { + pub fn get_inlined_body(&self, def_id: DefId) -> Option<&'hir Body> { self.inlined_bodies.borrow().get(&def_id).map(|&body| { self.dep_graph.read(DepNode::MetaData(def_id)); body }) } - pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'ast Body { + pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'hir Body { let body = self.forest.inlined_bodies.alloc(body); self.inlined_bodies.borrow_mut().insert(def_id, body); body @@ -706,7 +706,7 @@ impl<'ast> Map<'ast> { /// Given a node ID, get a list of attributes associated with the AST /// corresponding to the Node ID - pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] { + pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find(id) { Some(NodeItem(i)) => Some(&i.attrs[..]), @@ -735,7 +735,7 @@ impl<'ast> Map<'ast> { /// such as `foo::bar::quux`, `bar::quux`, `other::bar::quux`, and /// any other such items it can find in the map. pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String]) - -> NodesMatchingSuffix<'a, 'ast> { + -> NodesMatchingSuffix<'a, 'hir> { NodesMatchingSuffix { map: self, item_name: parts.last().unwrap(), @@ -790,14 +790,14 @@ impl<'ast> Map<'ast> { } } -pub struct NodesMatchingSuffix<'a, 'ast:'a> { - map: &'a Map<'ast>, +pub struct NodesMatchingSuffix<'a, 'hir:'a> { + map: &'a Map<'hir>, item_name: &'a String, in_which: &'a [String], idx: NodeId, } -impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> { +impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { /// Returns true only if some suffix of the module path for parent /// matches `self.in_which`. /// @@ -853,7 +853,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> { } } -impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> { +impl<'a, 'hir> Iterator for NodesMatchingSuffix<'a, 'hir> { type Item = NodeId; fn next(&mut self) -> Option { @@ -892,9 +892,9 @@ impl Named for StructField { fn name(&self) -> Name { self.name } } impl Named for TraitItem { fn name(&self) -> Name { self.name } } impl Named for ImplItem { fn name(&self) -> Name { self.name } } -pub fn map_crate<'ast>(forest: &'ast mut Forest, +pub fn map_crate<'hir>(forest: &'hir mut Forest, definitions: Definitions) - -> Map<'ast> { + -> Map<'hir> { let mut collector = NodeCollector::root(&forest.krate); intravisit::walk_crate(&mut collector, &forest.krate); let map = collector.map; @@ -926,7 +926,7 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest, /// Identical to the `PpAnn` implementation for `hir::Crate`, /// except it avoids creating a dependency on the whole crate. -impl<'ast> print::PpAnn for Map<'ast> { +impl<'hir> print::PpAnn for Map<'hir> { fn nested(&self, state: &mut print::State, nested: print::Nested) -> io::Result<()> { match nested { Nested::Item(id) => state.print_item(self.expect_item(id.id)), @@ -966,7 +966,7 @@ impl<'a> print::State<'a> { NodeTyParam(_) => bug!("cannot print TyParam"), NodeField(_) => bug!("cannot print StructField"), // these cases do not carry enough information in the - // ast_map to reconstruct their full structure for pretty + // hir_map to reconstruct their full structure for pretty // printing. NodeStructCtor(_) => bug!("cannot print isolated StructCtor"), } diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 0b43f32e3dc29..73b5fda275819 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -73,7 +73,7 @@ use super::region_inference::SameRegions; use std::collections::HashSet; -use hir::map as ast_map; +use hir::map as hir_map; use hir; use lint; @@ -152,8 +152,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } }; let tag = match self.hir.find(scope.node_id(&self.region_maps)) { - Some(ast_map::NodeBlock(_)) => "block", - Some(ast_map::NodeExpr(expr)) => match expr.node { + Some(hir_map::NodeBlock(_)) => "block", + Some(hir_map::NodeExpr(expr)) => match expr.node { hir::ExprCall(..) => "call", hir::ExprMethodCall(..) => "method call", hir::ExprMatch(.., hir::MatchSource::IfLetDesugar { .. }) => "if let", @@ -162,10 +162,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { hir::ExprMatch(..) => "match", _ => "expression", }, - Some(ast_map::NodeStmt(_)) => "statement", - Some(ast_map::NodeItem(it)) => item_scope_tag(&it), - Some(ast_map::NodeTraitItem(it)) => trait_item_scope_tag(&it), - Some(ast_map::NodeImplItem(it)) => impl_item_scope_tag(&it), + Some(hir_map::NodeStmt(_)) => "statement", + Some(hir_map::NodeItem(it)) => item_scope_tag(&it), + Some(hir_map::NodeTraitItem(it)) => trait_item_scope_tag(&it), + Some(hir_map::NodeImplItem(it)) => impl_item_scope_tag(&it), Some(_) | None => { err.span_note(span, &unknown_scope()); return; @@ -207,11 +207,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let node = fr.scope.node_id(&self.region_maps); let unknown; let tag = match self.hir.find(node) { - Some(ast_map::NodeBlock(_)) | - Some(ast_map::NodeExpr(_)) => "body", - Some(ast_map::NodeItem(it)) => item_scope_tag(&it), - Some(ast_map::NodeTraitItem(it)) => trait_item_scope_tag(&it), - Some(ast_map::NodeImplItem(it)) => impl_item_scope_tag(&it), + Some(hir_map::NodeBlock(_)) | + Some(hir_map::NodeExpr(_)) => "body", + Some(hir_map::NodeItem(it)) => item_scope_tag(&it), + Some(hir_map::NodeTraitItem(it)) => trait_item_scope_tag(&it), + Some(hir_map::NodeImplItem(it)) => impl_item_scope_tag(&it), // this really should not happen, but it does: // FIXME(#27942) @@ -471,14 +471,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let parent_node = tcx.hir.find(parent); match parent_node { Some(node) => match node { - ast_map::NodeItem(item) => match item.node { + hir_map::NodeItem(item) => match item.node { hir::ItemFn(..) => { Some(FreeRegionsFromSameFn::new(fr1, fr2, scope_id)) }, _ => None }, - ast_map::NodeImplItem(..) | - ast_map::NodeTraitItem(..) => { + hir_map::NodeImplItem(..) | + hir_map::NodeTraitItem(..) => { Some(FreeRegionsFromSameFn::new(fr1, fr2, scope_id)) }, _ => None @@ -1074,7 +1074,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let life_giver = LifeGiver::with_taken(&taken[..]); let node_inner = match parent_node { Some(ref node) => match *node { - ast_map::NodeItem(ref item) => { + hir_map::NodeItem(ref item) => { match item.node { hir::ItemFn(ref fn_decl, unsafety, constness, _, ref gen, body) => { Some((fn_decl, gen, unsafety, constness, item.name, item.span, body)) @@ -1082,9 +1082,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { _ => None, } } - ast_map::NodeImplItem(item) => { + hir_map::NodeImplItem(item) => { let id = self.tcx.hir.get_parent(item.id); - if let Some(ast_map::NodeItem(parent_scope)) = self.tcx.hir.find(id) { + if let Some(hir_map::NodeItem(parent_scope)) = self.tcx.hir.find(id) { if let hir::ItemImpl(_, _, _, None, _, _) = parent_scope.node { // this impl scope implements a trait, do not recomend // using explicit lifetimes (#37363) @@ -1103,7 +1103,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { None } }, - ast_map::NodeTraitItem(item) => { + hir_map::NodeTraitItem(item) => { match item.node { hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { Some((&sig.decl, @@ -1894,14 +1894,14 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, let parent = tcx.hir.get_parent(scope_id); let method_id_opt = match tcx.hir.find(parent) { Some(node) => match node { - ast_map::NodeItem(item) => match item.node { + hir_map::NodeItem(item) => match item.node { hir::ItemFn(.., ref gen, _) => { taken.extend_from_slice(&gen.lifetimes); None }, _ => None }, - ast_map::NodeImplItem(ii) => { + hir_map::NodeImplItem(ii) => { match ii.node { hir::ImplItemKind::Method(ref sig, _) => { taken.extend_from_slice(&sig.generics.lifetimes); @@ -1918,7 +1918,7 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, let parent = tcx.hir.get_parent(method_id); if let Some(node) = tcx.hir.find(parent) { match node { - ast_map::NodeItem(item) => match item.node { + hir_map::NodeItem(item) => match item.node { hir::ItemImpl(_, _, ref gen, ..) => { taken.extend_from_slice(&gen.lifetimes); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index fe1dadca05134..ae349667f9dc6 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -13,7 +13,7 @@ // from live codes are live, and everything else is dead. use dep_graph::DepNode; -use hir::map as ast_map; +use hir::map as hir_map; use hir::{self, PatKind}; use hir::intravisit::{self, Visitor, NestedVisitorMap}; use hir::itemlikevisit::ItemLikeVisitor; @@ -36,10 +36,10 @@ use syntax_pos; fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) -> bool { match tcx.hir.find(node_id) { - Some(ast_map::NodeItem(..)) | - Some(ast_map::NodeImplItem(..)) | - Some(ast_map::NodeForeignItem(..)) | - Some(ast_map::NodeTraitItem(..)) => + Some(hir_map::NodeItem(..)) | + Some(hir_map::NodeImplItem(..)) | + Some(hir_map::NodeForeignItem(..)) | + Some(hir_map::NodeTraitItem(..)) => true, _ => false @@ -150,13 +150,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } } - fn visit_node(&mut self, node: &ast_map::Node<'tcx>) { + fn visit_node(&mut self, node: &hir_map::Node<'tcx>) { let had_extern_repr = self.struct_has_extern_repr; self.struct_has_extern_repr = false; let had_inherited_pub_visibility = self.inherited_pub_visibility; self.inherited_pub_visibility = false; match *node { - ast_map::NodeItem(item) => { + hir_map::NodeItem(item) => { match item.node { hir::ItemStruct(..) | hir::ItemUnion(..) => { self.struct_has_extern_repr = item.attrs.iter().any(|attr| { @@ -179,13 +179,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { _ => () } } - ast_map::NodeTraitItem(trait_item) => { + hir_map::NodeTraitItem(trait_item) => { intravisit::walk_trait_item(self, trait_item); } - ast_map::NodeImplItem(impl_item) => { + hir_map::NodeImplItem(impl_item) => { intravisit::walk_impl_item(self, impl_item); } - ast_map::NodeForeignItem(foreign_item) => { + hir_map::NodeForeignItem(foreign_item) => { intravisit::walk_foreign_item(self, &foreign_item); } _ => () diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index f2e46d4cbc96b..ff7adfb327ad4 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -10,7 +10,7 @@ use dep_graph::DepNode; -use hir::map as ast_map; +use hir::map as hir_map; use hir::def_id::{CRATE_DEF_INDEX}; use session::{config, Session}; use syntax::ast::NodeId; @@ -23,7 +23,7 @@ use hir::itemlikevisit::ItemLikeVisitor; struct EntryContext<'a, 'tcx: 'a> { session: &'a Session, - map: &'a ast_map::Map<'tcx>, + map: &'a hir_map::Map<'tcx>, // The top-level function called 'main' main_fn: Option<(NodeId, Span)>, @@ -56,8 +56,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { } } -pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) { - let _task = ast_map.dep_graph.in_task(DepNode::EntryPoint); +pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) { + let _task = hir_map.dep_graph.in_task(DepNode::EntryPoint); let any_exe = session.crate_types.borrow().iter().any(|ty| { *ty == config::CrateTypeExecutable @@ -68,21 +68,21 @@ pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) { } // If the user wants no main function at all, then stop here. - if attr::contains_name(&ast_map.krate().attrs, "no_main") { + if attr::contains_name(&hir_map.krate().attrs, "no_main") { session.entry_type.set(Some(config::EntryNone)); return } let mut ctxt = EntryContext { session: session, - map: ast_map, + map: hir_map, main_fn: None, attr_main_fn: None, start_fn: None, non_main_fns: Vec::new(), }; - ast_map.krate().visit_all_item_likes(&mut ctxt); + hir_map.krate().visit_all_item_likes(&mut ctxt); configure_main(&mut ctxt); } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index cd7859af8ee7b..b9f1611f62baf 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -117,7 +117,7 @@ impl LanguageItems { struct LanguageItemCollector<'a, 'tcx: 'a> { items: LanguageItems, - ast_map: &'a hir_map::Map<'tcx>, + hir_map: &'a hir_map::Map<'tcx>, session: &'a Session, @@ -130,9 +130,9 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> { let item_index = self.item_refs.get(&*value.as_str()).cloned(); if let Some(item_index) = item_index { - self.collect_item(item_index, self.ast_map.local_def_id(item.id)) + self.collect_item(item_index, self.hir_map.local_def_id(item.id)) } else { - let span = self.ast_map.span(item.id); + let span = self.hir_map.span(item.id); span_err!(self.session, span, E0522, "definition of an unknown language item: `{}`.", value); @@ -150,7 +150,7 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> { } impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { - pub fn new(session: &'a Session, ast_map: &'a hir_map::Map<'tcx>) + pub fn new(session: &'a Session, hir_map: &'a hir_map::Map<'tcx>) -> LanguageItemCollector<'a, 'tcx> { let mut item_refs = FxHashMap(); @@ -158,7 +158,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { LanguageItemCollector { session: session, - ast_map: ast_map, + hir_map: hir_map, items: LanguageItems::new(), item_refs: item_refs, } @@ -171,7 +171,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { Some(original_def_id) if original_def_id != item_def_id => { let cstore = &self.session.cstore; let name = LanguageItems::item_name(item_index); - let mut err = match self.ast_map.span_if_local(item_def_id) { + let mut err = match self.hir_map.span_if_local(item_def_id) { Some(span) => struct_span_err!( self.session, span, @@ -183,7 +183,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { cstore.crate_name(item_def_id.krate), name)), }; - if let Some(span) = self.ast_map.span_if_local(original_def_id) { + if let Some(span) = self.hir_map.span_if_local(original_def_id) { span_note!(&mut err, span, "first defined here."); } else { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index d4438f5ecfa1a..126d43aa6900e 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -71,7 +71,7 @@ pub use self::Note::*; use self::Aliasability::*; use hir::def_id::DefId; -use hir::map as ast_map; +use hir::map as hir_map; use infer::InferCtxt; use hir::def::{Def, CtorKind}; use ty::adjustment; @@ -269,7 +269,7 @@ impl MutabilityCategory { fn from_local(tcx: TyCtxt, id: ast::NodeId) -> MutabilityCategory { let ret = match tcx.hir.get(id) { - ast_map::NodeLocal(p) => match p.node { + hir_map::NodeLocal(p) => match p.node { PatKind::Binding(bind_mode, ..) => { if bind_mode == hir::BindByValue(hir::MutMutable) { McDeclared @@ -699,7 +699,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { // a free region within it let fn_body_id = { let fn_expr = match self.tcx().hir.find(upvar_id.closure_expr_id) { - Some(ast_map::NodeExpr(e)) => e, + Some(hir_map::NodeExpr(e)) => e, _ => bug!() }; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 9b00fc3f220ec..4ec43e368a60d 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -16,7 +16,7 @@ // reachable as well. use dep_graph::DepNode; -use hir::map as ast_map; +use hir::map as hir_map; use hir::def::Def; use hir::def_id::DefId; use ty::{self, TyCtxt}; @@ -65,7 +65,7 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) { match tcx.hir.find(impl_node_id) { - Some(ast_map::NodeItem(item)) => + Some(hir_map::NodeItem(item)) => item_might_be_inlined(&item), Some(..) | None => span_bug!(impl_item.span, "impl did is not an item") @@ -153,13 +153,13 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { }; match self.tcx.hir.find(node_id) { - Some(ast_map::NodeItem(item)) => { + Some(hir_map::NodeItem(item)) => { match item.node { hir::ItemFn(..) => item_might_be_inlined(&item), _ => false, } } - Some(ast_map::NodeTraitItem(trait_method)) => { + Some(hir_map::NodeTraitItem(trait_method)) => { match trait_method.node { hir::TraitItemKind::Const(_, ref default) => default.is_some(), hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true, @@ -167,7 +167,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { hir::TraitItemKind::Type(..) => false, } } - Some(ast_map::NodeImplItem(impl_item)) => { + Some(hir_map::NodeImplItem(impl_item)) => { match impl_item.node { hir::ImplItemKind::Const(..) => true, hir::ImplItemKind::Method(ref sig, _) => { @@ -216,12 +216,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } } - fn propagate_node(&mut self, node: &ast_map::Node<'tcx>, + fn propagate_node(&mut self, node: &hir_map::Node<'tcx>, search_item: ast::NodeId) { if !self.any_library { // If we are building an executable, only explicitly extern // types need to be exported. - if let ast_map::NodeItem(item) = *node { + if let hir_map::NodeItem(item) = *node { let reachable = if let hir::ItemFn(.., abi, _, _) = item.node { abi != Abi::Rust } else { @@ -242,7 +242,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } match *node { - ast_map::NodeItem(item) => { + hir_map::NodeItem(item) => { match item.node { hir::ItemFn(.., body) => { if item_might_be_inlined(&item) { @@ -268,7 +268,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { hir::ItemUnion(..) | hir::ItemDefaultImpl(..) => {} } } - ast_map::NodeTraitItem(trait_method) => { + hir_map::NodeTraitItem(trait_method) => { match trait_method.node { hir::TraitItemKind::Const(_, None) | hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => { @@ -281,7 +281,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { hir::TraitItemKind::Type(..) => {} } } - ast_map::NodeImplItem(impl_item) => { + hir_map::NodeImplItem(impl_item) => { match impl_item.node { hir::ImplItemKind::Const(_, body) => { self.visit_nested_body(body); @@ -296,11 +296,11 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } } // Nothing to recurse on for these - ast_map::NodeForeignItem(_) | - ast_map::NodeVariant(_) | - ast_map::NodeStructCtor(_) | - ast_map::NodeField(_) | - ast_map::NodeTy(_) => {} + hir_map::NodeForeignItem(_) | + hir_map::NodeVariant(_) | + hir_map::NodeStructCtor(_) | + hir_map::NodeField(_) | + hir_map::NodeTy(_) => {} _ => { bug!("found unexpected thingy in worklist: {}", self.tcx.hir.node_to_string(search_item)) diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index faf4a448b7a84..7337c03795b6d 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -17,7 +17,7 @@ //! `middle/infer/region_inference/README.md` use dep_graph::DepNode; -use hir::map as ast_map; +use hir::map as hir_map; use session::Session; use util::nodemap::{FxHashMap, NodeMap, NodeSet}; use ty; @@ -217,9 +217,9 @@ impl CodeExtent { /// Returns the span of this CodeExtent. Note that in general the /// returned span may not correspond to the span of any node id in /// the AST. - pub fn span(&self, region_maps: &RegionMaps, ast_map: &ast_map::Map) -> Option { - match ast_map.find(self.node_id(region_maps)) { - Some(ast_map::NodeBlock(ref blk)) => { + pub fn span(&self, region_maps: &RegionMaps, hir_map: &hir_map::Map) -> Option { + match hir_map.find(self.node_id(region_maps)) { + Some(hir_map::NodeBlock(ref blk)) => { match region_maps.code_extent_data(*self) { CodeExtentData::CallSiteScope { .. } | CodeExtentData::ParameterScope { .. } | @@ -240,9 +240,9 @@ impl CodeExtent { } } } - Some(ast_map::NodeExpr(ref expr)) => Some(expr.span), - Some(ast_map::NodeStmt(ref stmt)) => Some(stmt.span), - Some(ast_map::NodeItem(ref item)) => Some(item.span), + Some(hir_map::NodeExpr(ref expr)) => Some(expr.span), + Some(hir_map::NodeStmt(ref stmt)) => Some(stmt.span), + Some(hir_map::NodeItem(ref item)) => Some(item.span), Some(_) | None => None, } } @@ -302,7 +302,7 @@ pub struct Context { parent: CodeExtent } -struct RegionResolutionVisitor<'ast: 'a, 'a> { +struct RegionResolutionVisitor<'hir: 'a, 'a> { sess: &'a Session, // Generated maps: @@ -310,7 +310,7 @@ struct RegionResolutionVisitor<'ast: 'a, 'a> { cx: Context, - map: &'a ast_map::Map<'ast>, + map: &'a hir_map::Map<'hir>, /// `terminating_scopes` is a set containing the ids of each /// statement, or conditional/repeating expression. These scopes @@ -1137,7 +1137,7 @@ fn resolve_fn<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'tcx, 'a>, visitor.terminating_scopes = outer_ts; } -impl<'ast, 'a> RegionResolutionVisitor<'ast, 'a> { +impl<'hir, 'a> RegionResolutionVisitor<'hir, 'a> { /// Records the current parent (if any) as the parent of `child_scope`. fn new_code_extent(&mut self, child_scope: CodeExtentData) -> CodeExtent { self.region_maps.intern_code_extent(child_scope, self.cx.parent) @@ -1173,49 +1173,49 @@ impl<'ast, 'a> RegionResolutionVisitor<'ast, 'a> { } } -impl<'ast, 'a> Visitor<'ast> for RegionResolutionVisitor<'ast, 'a> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { +impl<'hir, 'a> Visitor<'hir> for RegionResolutionVisitor<'hir, 'a> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { NestedVisitorMap::OnlyBodies(&self.map) } - fn visit_block(&mut self, b: &'ast Block) { + fn visit_block(&mut self, b: &'hir Block) { resolve_block(self, b); } - fn visit_item(&mut self, i: &'ast Item) { + fn visit_item(&mut self, i: &'hir Item) { resolve_item_like(self, i.id, |this| intravisit::walk_item(this, i)); } - fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) { resolve_item_like(self, ii.id, |this| intravisit::walk_impl_item(this, ii)); } - fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) { resolve_item_like(self, ti.id, |this| intravisit::walk_trait_item(this, ti)); } - fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, + fn visit_fn(&mut self, fk: FnKind<'hir>, fd: &'hir FnDecl, b: hir::BodyId, s: Span, n: NodeId) { resolve_fn(self, fk, fd, b, s, n); } - fn visit_arm(&mut self, a: &'ast Arm) { + fn visit_arm(&mut self, a: &'hir Arm) { resolve_arm(self, a); } - fn visit_pat(&mut self, p: &'ast Pat) { + fn visit_pat(&mut self, p: &'hir Pat) { resolve_pat(self, p); } - fn visit_stmt(&mut self, s: &'ast Stmt) { + fn visit_stmt(&mut self, s: &'hir Stmt) { resolve_stmt(self, s); } - fn visit_expr(&mut self, ex: &'ast Expr) { + fn visit_expr(&mut self, ex: &'hir Expr) { resolve_expr(self, ex); } - fn visit_local(&mut self, l: &'ast Local) { + fn visit_local(&mut self, l: &'hir Local) { resolve_local(self, l); } } -pub fn resolve_crate(sess: &Session, map: &ast_map::Map) -> RegionMaps { +pub fn resolve_crate(sess: &Session, map: &hir_map::Map) -> RegionMaps { let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate); let krate = map.krate(); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 7f26fdfba5693..c78ba3b8a9bbf 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -16,7 +16,7 @@ use middle; use hir::TraitMap; use hir::def::Def; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use hir::map as ast_map; +use hir::map as hir_map; use hir::map::DisambiguatedDefPathData; use middle::free_region::FreeRegionMap; use middle::region::RegionMaps; @@ -428,7 +428,7 @@ pub struct GlobalCtxt<'tcx> { /// additional acyclicity requirements). pub super_predicates: RefCell>>, - pub hir: ast_map::Map<'tcx>, + pub hir: hir_map::Map<'tcx>, /// Maps from the def-id of a function/method or const/static /// to its MIR. Mutation is done at an item granularity to @@ -730,7 +730,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { arena: &'tcx DroplessArena, resolutions: ty::Resolutions, named_region_map: resolve_lifetime::NamedRegionMap, - hir: ast_map::Map<'tcx>, + hir: hir_map::Map<'tcx>, region_maps: RegionMaps, lang_items: middle::lang_items::LanguageItems, stability: stability::Index<'tcx>, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 7a8788f053dd0..5681e8c776623 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -17,7 +17,7 @@ pub use self::LvaluePreference::*; pub use self::fold::TypeFoldable; use dep_graph::{self, DepNode}; -use hir::{map as ast_map, FreevarMap, TraitMap}; +use hir::{map as hir_map, FreevarMap, TraitMap}; use middle; use hir::def::{Def, CtorKind, ExportMap}; use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; @@ -1199,7 +1199,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> { pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> { match tcx.hir.find(id) { - Some(ast_map::NodeImplItem(ref impl_item)) => { + Some(hir_map::NodeImplItem(ref impl_item)) => { match impl_item.node { hir::ImplItemKind::Type(_) | hir::ImplItemKind::Const(..) => { // associated types don't have their own entry (for some reason), @@ -1218,7 +1218,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> { } } } - Some(ast_map::NodeTraitItem(trait_item)) => { + Some(hir_map::NodeTraitItem(trait_item)) => { match trait_item.node { hir::TraitItemKind::Type(..) | hir::TraitItemKind::Const(..) => { // associated types don't have their own entry (for some reason), @@ -1247,7 +1247,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> { } } } - Some(ast_map::NodeItem(item)) => { + Some(hir_map::NodeItem(item)) => { match item.node { hir::ItemFn(.., body_id) => { // We assume this is a function. @@ -1284,7 +1284,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> { } } } - Some(ast_map::NodeExpr(expr)) => { + Some(hir_map::NodeExpr(expr)) => { // This is a convenience to allow closures to work. if let hir::ExprClosure(.., body, _) = expr.node { let def_id = tcx.hir.local_def_id(id); @@ -1297,7 +1297,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> { tcx.empty_parameter_environment() } } - Some(ast_map::NodeForeignItem(item)) => { + Some(hir_map::NodeForeignItem(item)) => { let def_id = tcx.hir.local_def_id(id); tcx.construct_parameter_environment(item.span, def_id, @@ -1945,7 +1945,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn expr_span(self, id: NodeId) -> Span { match self.hir.find(id) { - Some(ast_map::NodeExpr(e)) => { + Some(hir_map::NodeExpr(e)) => { e.span } Some(f) => { @@ -1959,7 +1959,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn local_var_name_str(self, id: NodeId) -> InternedString { match self.hir.find(id) { - Some(ast_map::NodeLocal(pat)) => { + Some(hir_map::NodeLocal(pat)) => { match pat.node { hir::PatKind::Binding(_, _, ref path1, _) => path1.node.as_str(), _ => { @@ -2225,7 +2225,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn def_key(self, id: DefId) -> ast_map::DefKey { + pub fn def_key(self, id: DefId) -> hir_map::DefKey { if id.is_local() { self.hir.def_key(id) } else { @@ -2238,7 +2238,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// /// Note that if `id` is not local to this crate, the result will // be a non-local `DefPath`. - pub fn def_path(self, id: DefId) -> ast_map::DefPath { + pub fn def_path(self, id: DefId) -> hir_map::DefPath { if id.is_local() { self.hir.def_path(id) } else { @@ -2266,7 +2266,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } else { let def_key = self.sess.cstore.def_key(id); // The name of a StructCtor is that of its struct parent. - if let ast_map::DefPathData::StructCtor = def_key.disambiguated_data.data { + if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data { self.item_name(DefId { krate: id.krate, index: def_key.parent.unwrap() diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 65bec9ecdaf95..c05375c47b03a 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -13,7 +13,7 @@ use hir::def_id::DefId; use hir::map::DefPathData; use infer::InferCtxt; -use hir::map as ast_map; +use hir::map as hir_map; use traits::{self, Reveal}; use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable}; use ty::{Disr, ParameterEnvironment}; @@ -429,7 +429,7 @@ impl<'a, 'gcx, 'tcx, W> TypeIdHasher<'a, 'gcx, 'tcx, W> self.def_path(&path) } - pub fn def_path(&mut self, def_path: &ast_map::DefPath) { + pub fn def_path(&mut self, def_path: &hir_map::DefPath) { def_path.deterministic_hash_to(self.tcx, &mut self.state); } } diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index a02aba7208c7f..2047a58f8ed85 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -490,7 +490,7 @@ impl<'a, 'tcx> MoveData<'tcx> { /// Adds a new record for a match of `base_lp`, downcast to /// variant `lp`, that occurs at location `pattern_id`. (One /// should be able to recover the span info from the - /// `pattern_id` and the ast_map, I think.) + /// `pattern_id` and the hir_map, I think.) pub fn add_variant_match(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, lp: Rc>, pattern_id: ast::NodeId, diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index e8055602087e5..a9dcb1ed89613 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -15,7 +15,7 @@ use rustc::middle::const_val::ConstVal; use self::ErrKind::*; use self::EvalHint::*; -use rustc::hir::map as ast_map; +use rustc::hir::map as hir_map; use rustc::hir::map::blocks::FnLikeNode; use rustc::traits; use rustc::hir::def::Def; @@ -55,7 +55,7 @@ fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, -> Option<(&'tcx Expr, Option<&'a ty::TypeckTables<'tcx>>)> { if let Some(variant_node_id) = tcx.hir.as_local_node_id(variant_def) { let enum_node_id = tcx.hir.get_parent(variant_node_id); - if let Some(ast_map::NodeItem(it)) = tcx.hir.find(enum_node_id) { + if let Some(hir_map::NodeItem(it)) = tcx.hir.find(enum_node_id) { if let hir::ItemEnum(ref edef, _) = it.node { for variant in &edef.variants { if variant.node.data.id() == variant_node_id { @@ -86,17 +86,17 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if let Some(node_id) = tcx.hir.as_local_node_id(def_id) { match tcx.hir.find(node_id) { None => None, - Some(ast_map::NodeItem(&hir::Item { + Some(hir_map::NodeItem(&hir::Item { node: hir::ItemConst(ref ty, body), .. })) | - Some(ast_map::NodeImplItem(&hir::ImplItem { + Some(hir_map::NodeImplItem(&hir::ImplItem { node: hir::ImplItemKind::Const(ref ty, body), .. })) => { Some((&tcx.hir.body(body).value, tcx.tables.borrow().get(&def_id).cloned(), tcx.ast_ty_to_prim_ty(ty))) } - Some(ast_map::NodeTraitItem(ti)) => match ti.node { + Some(hir_map::NodeTraitItem(ti)) => match ti.node { hir::TraitItemKind::Const(ref ty, default) => { if let Some(substs) = substs { // If we have a trait item and the substitutions for it, diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 1991fbb58edf1..a7188f6da1ff9 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -340,7 +340,7 @@ pub struct CompileState<'a, 'tcx: 'a> { pub arenas: Option<&'tcx GlobalArenas<'tcx>>, pub expanded_crate: Option<&'a ast::Crate>, pub hir_crate: Option<&'a hir::Crate>, - pub ast_map: Option<&'a hir_map::Map<'tcx>>, + pub hir_map: Option<&'a hir_map::Map<'tcx>>, pub resolutions: Option<&'a Resolutions>, pub analysis: Option<&'a ty::CrateAnalysis<'tcx>>, pub tcx: Option>, @@ -366,7 +366,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> { output_filenames: None, expanded_crate: None, hir_crate: None, - ast_map: None, + hir_map: None, resolutions: None, analysis: None, tcx: None, @@ -427,7 +427,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> { arena: Some(arena), arenas: Some(arenas), cstore: Some(cstore), - ast_map: Some(hir_map), + hir_map: Some(hir_map), analysis: Some(analysis), resolutions: Some(resolutions), expanded_crate: Some(krate), diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index ad2aefbb79539..7fd4fa44ca45d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -454,7 +454,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { }; control.after_hir_lowering.callback = box move |state| { pretty::print_after_hir_lowering(state.session, - state.ast_map.unwrap(), + state.hir_map.unwrap(), state.analysis.unwrap(), state.resolutions.unwrap(), state.input, diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 1885f76f1e4cd..21fe13997b787 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -167,7 +167,7 @@ impl PpSourceMode { /// Constructs a `PrinterSupport` object and passes it to `f`. fn call_with_pp_support<'tcx, A, B, F>(&self, sess: &'tcx Session, - ast_map: Option<&hir_map::Map<'tcx>>, + hir_map: Option<&hir_map::Map<'tcx>>, payload: B, f: F) -> A @@ -177,7 +177,7 @@ impl PpSourceMode { PpmNormal | PpmEveryBodyLoops | PpmExpanded => { let annotation = NoAnn { sess: sess, - ast_map: ast_map.map(|m| m.clone()), + hir_map: hir_map.map(|m| m.clone()), }; f(&annotation, payload) } @@ -185,14 +185,13 @@ impl PpSourceMode { PpmIdentified | PpmExpandedIdentified => { let annotation = IdentifiedAnnotation { sess: sess, - ast_map: ast_map.map(|m| m.clone()), + hir_map: hir_map.map(|m| m.clone()), }; f(&annotation, payload) } PpmExpandedHygiene => { let annotation = HygieneAnnotation { sess: sess, - ast_map: ast_map.map(|m| m.clone()), }; f(&annotation, payload) } @@ -201,7 +200,7 @@ impl PpSourceMode { } fn call_with_pp_support_hir<'tcx, A, B, F>(&self, sess: &'tcx Session, - ast_map: &hir_map::Map<'tcx>, + hir_map: &hir_map::Map<'tcx>, analysis: &ty::CrateAnalysis<'tcx>, resolutions: &Resolutions, arena: &'tcx DroplessArena, @@ -216,21 +215,21 @@ impl PpSourceMode { PpmNormal => { let annotation = NoAnn { sess: sess, - ast_map: Some(ast_map.clone()), + hir_map: Some(hir_map.clone()), }; - f(&annotation, payload, ast_map.forest.krate()) + f(&annotation, payload, hir_map.forest.krate()) } PpmIdentified => { let annotation = IdentifiedAnnotation { sess: sess, - ast_map: Some(ast_map.clone()), + hir_map: Some(hir_map.clone()), }; - f(&annotation, payload, ast_map.forest.krate()) + f(&annotation, payload, hir_map.forest.krate()) } PpmTyped => { abort_on_err(driver::phase_3_run_analysis_passes(sess, - ast_map.clone(), + hir_map.clone(), analysis.clone(), resolutions.clone(), arena, @@ -243,7 +242,7 @@ impl PpSourceMode { tables: Cell::new(&empty_tables) }; let _ignore = tcx.dep_graph.in_ignore(); - f(&annotation, payload, ast_map.forest.krate()) + f(&annotation, payload, hir_map.forest.krate()) }), sess) } @@ -252,15 +251,11 @@ impl PpSourceMode { } } -trait PrinterSupport<'ast>: pprust::PpAnn { +trait PrinterSupport: pprust::PpAnn { /// Provides a uniform interface for re-extracting a reference to a /// `Session` from a value that now owns it. fn sess<'a>(&'a self) -> &'a Session; - /// Provides a uniform interface for re-extracting a reference to an - /// `hir_map::Map` from a value that now owns it. - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>>; - /// Produces the pretty-print annotation object. /// /// (Rust does not yet support upcasting from a trait object to @@ -268,14 +263,14 @@ trait PrinterSupport<'ast>: pprust::PpAnn { fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn; } -trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { +trait HirPrinterSupport<'hir>: pprust_hir::PpAnn { /// Provides a uniform interface for re-extracting a reference to a /// `Session` from a value that now owns it. fn sess<'a>(&'a self) -> &'a Session; /// Provides a uniform interface for re-extracting a reference to an /// `hir_map::Map` from a value that now owns it. - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>>; + fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>>; /// Produces the pretty-print annotation object. /// @@ -285,7 +280,7 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { /// Computes an user-readable representation of a path, if possible. fn node_path(&self, id: ast::NodeId) -> Option { - self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| { + self.hir_map().and_then(|map| map.def_path_from_id(id)).map(|path| { path.data .into_iter() .map(|elem| elem.data.to_string()) @@ -295,32 +290,28 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { } } -struct NoAnn<'ast> { - sess: &'ast Session, - ast_map: Option>, +struct NoAnn<'hir> { + sess: &'hir Session, + hir_map: Option>, } -impl<'ast> PrinterSupport<'ast> for NoAnn<'ast> { +impl<'hir> PrinterSupport for NoAnn<'hir> { fn sess<'a>(&'a self) -> &'a Session { self.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> { - self.ast_map.as_ref() - } - fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self } } -impl<'ast> HirPrinterSupport<'ast> for NoAnn<'ast> { +impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> { fn sess<'a>(&'a self) -> &'a Session { self.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> { - self.ast_map.as_ref() + fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> { + self.hir_map.as_ref() } fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { @@ -328,11 +319,11 @@ impl<'ast> HirPrinterSupport<'ast> for NoAnn<'ast> { } } -impl<'ast> pprust::PpAnn for NoAnn<'ast> {} -impl<'ast> pprust_hir::PpAnn for NoAnn<'ast> { +impl<'hir> pprust::PpAnn for NoAnn<'hir> {} +impl<'hir> pprust_hir::PpAnn for NoAnn<'hir> { fn nested(&self, state: &mut pprust_hir::State, nested: pprust_hir::Nested) -> io::Result<()> { - if let Some(ref map) = self.ast_map { + if let Some(ref map) = self.hir_map { pprust_hir::PpAnn::nested(map, state, nested) } else { Ok(()) @@ -340,26 +331,22 @@ impl<'ast> pprust_hir::PpAnn for NoAnn<'ast> { } } -struct IdentifiedAnnotation<'ast> { - sess: &'ast Session, - ast_map: Option>, +struct IdentifiedAnnotation<'hir> { + sess: &'hir Session, + hir_map: Option>, } -impl<'ast> PrinterSupport<'ast> for IdentifiedAnnotation<'ast> { +impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> { fn sess<'a>(&'a self) -> &'a Session { self.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> { - self.ast_map.as_ref() - } - fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self } } -impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { +impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> { fn pre(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeExpr(_) => s.popen(), @@ -396,13 +383,13 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { } } -impl<'ast> HirPrinterSupport<'ast> for IdentifiedAnnotation<'ast> { +impl<'hir> HirPrinterSupport<'hir> for IdentifiedAnnotation<'hir> { fn sess<'a>(&'a self) -> &'a Session { self.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> { - self.ast_map.as_ref() + fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> { + self.hir_map.as_ref() } fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { @@ -410,10 +397,10 @@ impl<'ast> HirPrinterSupport<'ast> for IdentifiedAnnotation<'ast> { } } -impl<'ast> pprust_hir::PpAnn for IdentifiedAnnotation<'ast> { +impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> { fn nested(&self, state: &mut pprust_hir::State, nested: pprust_hir::Nested) -> io::Result<()> { - if let Some(ref map) = self.ast_map { + if let Some(ref map) = self.hir_map { pprust_hir::PpAnn::nested(map, state, nested) } else { Ok(()) @@ -453,26 +440,21 @@ impl<'ast> pprust_hir::PpAnn for IdentifiedAnnotation<'ast> { } } -struct HygieneAnnotation<'ast> { - sess: &'ast Session, - ast_map: Option>, +struct HygieneAnnotation<'a> { + sess: &'a Session } -impl<'ast> PrinterSupport<'ast> for HygieneAnnotation<'ast> { - fn sess<'a>(&'a self) -> &'a Session { +impl<'a> PrinterSupport for HygieneAnnotation<'a> { + fn sess(&self) -> &Session { self.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> { - self.ast_map.as_ref() - } - - fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { + fn pp_ann(&self) -> &pprust::PpAnn { self } } -impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> { +impl<'a> pprust::PpAnn for HygieneAnnotation<'a> { fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeIdent(&ast::Ident { name, ctxt }) => { @@ -501,7 +483,7 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { &self.tcx.sess } - fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> { + fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> { Some(&self.tcx.hir) } @@ -579,12 +561,12 @@ impl FromStr for UserIdentifiedItem { } } -enum NodesMatchingUII<'a, 'ast: 'a> { +enum NodesMatchingUII<'a, 'hir: 'a> { NodesMatchingDirect(option::IntoIter), - NodesMatchingSuffix(hir_map::NodesMatchingSuffix<'a, 'ast>), + NodesMatchingSuffix(hir_map::NodesMatchingSuffix<'a, 'hir>), } -impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> { +impl<'a, 'hir> Iterator for NodesMatchingUII<'a, 'hir> { type Item = ast::NodeId; fn next(&mut self) -> Option { @@ -603,9 +585,9 @@ impl UserIdentifiedItem { } } - fn all_matching_node_ids<'a, 'ast>(&'a self, - map: &'a hir_map::Map<'ast>) - -> NodesMatchingUII<'a, 'ast> { + fn all_matching_node_ids<'a, 'hir>(&'a self, + map: &'a hir_map::Map<'hir>) + -> NodesMatchingUII<'a, 'hir> { match *self { ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()), ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts[..])), @@ -745,7 +727,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec, }; let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges; let lcfg = LabelledCFG { - ast_map: &tcx.hir, + hir_map: &tcx.hir, cfg: &cfg, name: format!("node_{}", code.id()), labelled_edges: labelled_edges, @@ -855,7 +837,7 @@ pub fn print_after_parsing(sess: &Session, } pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, - ast_map: &hir_map::Map<'tcx>, + hir_map: &hir_map::Map<'tcx>, analysis: &ty::CrateAnalysis<'tcx>, resolutions: &Resolutions, input: &Input, @@ -871,7 +853,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, if ppm.needs_analysis() { print_with_analysis(sess, - ast_map, + hir_map, analysis, resolutions, crate_name, @@ -892,7 +874,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, (PpmSource(s), _) => { // Silently ignores an identified node. let out: &mut Write = &mut out; - s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| { + s.call_with_pp_support(sess, Some(hir_map), box out, |annotation, out| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); pprust::print_crate(sess.codemap(), @@ -909,7 +891,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, (PpmHir(s), None) => { let out: &mut Write = &mut out; s.call_with_pp_support_hir(sess, - ast_map, + hir_map, analysis, resolutions, arena, @@ -933,7 +915,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, (PpmHir(s), Some(uii)) => { let out: &mut Write = &mut out; s.call_with_pp_support_hir(sess, - ast_map, + hir_map, analysis, resolutions, arena, @@ -943,7 +925,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, |annotation, (out, uii), _| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); - let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); + let hir_map = annotation.hir_map().expect("--unpretty missing HIR map"); let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), &sess.parse_sess, src_name.to_string(), @@ -951,8 +933,8 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, box out, annotation.pp_ann(), true); - for node_id in uii.all_matching_node_ids(ast_map) { - let node = ast_map.get(node_id); + for node_id in uii.all_matching_node_ids(hir_map) { + let node = hir_map.get(node_id); pp_state.print_node(node)?; pp::space(&mut pp_state.s)?; let path = annotation.node_path(node_id) @@ -975,7 +957,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, // with a different callback than the standard driver, so that isn't easy. // Instead, we call that function ourselves. fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, - ast_map: &hir_map::Map<'tcx>, + hir_map: &hir_map::Map<'tcx>, analysis: &ty::CrateAnalysis<'tcx>, resolutions: &Resolutions, crate_name: &str, @@ -986,7 +968,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, ofile: Option<&Path>) { let nodeid = if let Some(uii) = uii { debug!("pretty printing for {:?}", uii); - Some(uii.to_one_node_id("--unpretty", sess, &ast_map)) + Some(uii.to_one_node_id("--unpretty", sess, &hir_map)) } else { debug!("pretty printing for whole crate"); None @@ -995,7 +977,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, let mut out = Vec::new(); abort_on_err(driver::phase_3_run_analysis_passes(sess, - ast_map.clone(), + hir_map.clone(), analysis.clone(), resolutions.clone(), arena, diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 0ac95d12eeef3..59f6889ba4d94 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -131,19 +131,19 @@ fn test_env(source_string: &str, let arena = DroplessArena::new(); let arenas = ty::GlobalArenas::new(); - let ast_map = hir_map::map_crate(&mut hir_forest, defs); + let hir_map = hir_map::map_crate(&mut hir_forest, defs); // run just enough stuff to build a tcx: - let lang_items = lang_items::collect_language_items(&sess, &ast_map); - let named_region_map = resolve_lifetime::krate(&sess, &ast_map); - let region_map = region::resolve_crate(&sess, &ast_map); - let index = stability::Index::new(&ast_map); + let lang_items = lang_items::collect_language_items(&sess, &hir_map); + let named_region_map = resolve_lifetime::krate(&sess, &hir_map); + let region_map = region::resolve_crate(&sess, &hir_map); + let index = stability::Index::new(&hir_map); TyCtxt::create_and_enter(&sess, &arenas, &arena, resolutions, named_region_map.unwrap(), - ast_map, + hir_map, region_map, lang_items, index, diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index df9fe00e9a88e..a5bd69fff0138 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -43,9 +43,9 @@ enum Context { } #[derive(Copy, Clone)] -struct CheckLoopVisitor<'a, 'ast: 'a> { +struct CheckLoopVisitor<'a, 'hir: 'a> { sess: &'a Session, - hir_map: &'a Map<'ast>, + hir_map: &'a Map<'hir>, cx: Context, } @@ -59,20 +59,20 @@ pub fn check_crate(sess: &Session, map: &Map) { }.as_deep_visitor()); } -impl<'a, 'ast> Visitor<'ast> for CheckLoopVisitor<'a, 'ast> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { +impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { NestedVisitorMap::OnlyBodies(&self.hir_map) } - fn visit_item(&mut self, i: &'ast hir::Item) { + fn visit_item(&mut self, i: &'hir hir::Item) { self.with_context(Normal, |v| intravisit::walk_item(v, i)); } - fn visit_impl_item(&mut self, i: &'ast hir::ImplItem) { + fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) { self.with_context(Normal, |v| intravisit::walk_impl_item(v, i)); } - fn visit_expr(&mut self, e: &'ast hir::Expr) { + fn visit_expr(&mut self, e: &'hir hir::Expr) { match e.node { hir::ExprWhile(ref e, ref b, _) => { self.with_context(Loop(LoopKind::WhileLoop), |v| { @@ -125,9 +125,9 @@ impl<'a, 'ast> Visitor<'ast> for CheckLoopVisitor<'a, 'ast> { } } -impl<'a, 'ast> CheckLoopVisitor<'a, 'ast> { +impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> { fn with_context(&mut self, cx: Context, f: F) - where F: FnOnce(&mut CheckLoopVisitor<'a, 'ast>) + where F: FnOnce(&mut CheckLoopVisitor<'a, 'hir>) { let old_cx = self.cx; self.cx = cx; diff --git a/src/librustc_passes/static_recursion.rs b/src/librustc_passes/static_recursion.rs index ba4fc57276b2c..1ef8a5b0080f3 100644 --- a/src/librustc_passes/static_recursion.rs +++ b/src/librustc_passes/static_recursion.rs @@ -12,7 +12,7 @@ // recursively. use rustc::dep_graph::DepNode; -use rustc::hir::map as ast_map; +use rustc::hir::map as hir_map; use rustc::session::{CompileResult, Session}; use rustc::hir::def::{Def, CtorKind}; use rustc::util::nodemap::{NodeMap, NodeSet}; @@ -23,9 +23,9 @@ use syntax_pos::Span; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir; -struct CheckCrateVisitor<'a, 'ast: 'a> { +struct CheckCrateVisitor<'a, 'hir: 'a> { sess: &'a Session, - ast_map: &'a ast_map::Map<'ast>, + hir_map: &'a hir_map::Map<'hir>, // `discriminant_map` is a cache that associates the `NodeId`s of local // variant definitions with the discriminant expression that applies to // each one. If the variant uses the default values (starting from `0`), @@ -34,12 +34,12 @@ struct CheckCrateVisitor<'a, 'ast: 'a> { detected_recursive_ids: NodeSet, } -impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { +impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { NestedVisitorMap::None } - fn visit_item(&mut self, it: &'ast hir::Item) { + fn visit_item(&mut self, it: &'hir hir::Item) { match it.node { hir::ItemStatic(..) | hir::ItemConst(..) => { @@ -64,7 +64,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> { intravisit::walk_item(self, it) } - fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) { match ti.node { hir::TraitItemKind::Const(_, ref default) => { if let Some(_) = *default { @@ -77,7 +77,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> { intravisit::walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) { match ii.node { hir::ImplItemKind::Const(..) => { let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span); @@ -89,36 +89,36 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> { } } -pub fn check_crate<'ast>(sess: &Session, ast_map: &ast_map::Map<'ast>) -> CompileResult { - let _task = ast_map.dep_graph.in_task(DepNode::CheckStaticRecursion); +pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult { + let _task = hir_map.dep_graph.in_task(DepNode::CheckStaticRecursion); let mut visitor = CheckCrateVisitor { sess: sess, - ast_map: ast_map, + hir_map: hir_map, discriminant_map: NodeMap(), detected_recursive_ids: NodeSet(), }; sess.track_errors(|| { // FIXME(#37712) could use ItemLikeVisitor if trait items were item-like - ast_map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor()); + hir_map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor()); }) } -struct CheckItemRecursionVisitor<'a, 'b: 'a, 'ast: 'b> { +struct CheckItemRecursionVisitor<'a, 'b: 'a, 'hir: 'b> { root_span: &'b Span, sess: &'b Session, - ast_map: &'b ast_map::Map<'ast>, + hir_map: &'b hir_map::Map<'hir>, discriminant_map: &'a mut NodeMap>, idstack: Vec, detected_recursive_ids: &'a mut NodeSet, } -impl<'a, 'b: 'a, 'ast: 'b> CheckItemRecursionVisitor<'a, 'b, 'ast> { - fn new(v: &'a mut CheckCrateVisitor<'b, 'ast>, span: &'b Span) -> Self { +impl<'a, 'b: 'a, 'hir: 'b> CheckItemRecursionVisitor<'a, 'b, 'hir> { + fn new(v: &'a mut CheckCrateVisitor<'b, 'hir>, span: &'b Span) -> Self { CheckItemRecursionVisitor { root_span: span, sess: v.sess, - ast_map: v.ast_map, + hir_map: v.hir_map, discriminant_map: &mut v.discriminant_map, idstack: Vec::new(), detected_recursive_ids: &mut v.detected_recursive_ids, @@ -133,7 +133,7 @@ impl<'a, 'b: 'a, 'ast: 'b> CheckItemRecursionVisitor<'a, 'b, 'ast> { } self.detected_recursive_ids.insert(id); let any_static = self.idstack.iter().any(|&x| { - if let ast_map::NodeItem(item) = self.ast_map.get(x) { + if let hir_map::NodeItem(item) = self.hir_map.get(x) { if let hir::ItemStatic(..) = item.node { true } else { @@ -170,7 +170,7 @@ impl<'a, 'b: 'a, 'ast: 'b> CheckItemRecursionVisitor<'a, 'b, 'ast> { // So for every variant, we need to track whether there is an expression // somewhere in the enum definition that controls its discriminant. We do // this by starting from the end and searching backward. - fn populate_enum_discriminants(&mut self, enum_definition: &'ast hir::EnumDef) { + fn populate_enum_discriminants(&mut self, enum_definition: &'hir hir::EnumDef) { // Get the map, and return if we already processed this enum or if it // has no variants. match enum_definition.variants.first() { @@ -204,17 +204,17 @@ impl<'a, 'b: 'a, 'ast: 'b> CheckItemRecursionVisitor<'a, 'b, 'ast> { } } -impl<'a, 'b: 'a, 'ast: 'b> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'b, 'ast> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { - NestedVisitorMap::OnlyBodies(&self.ast_map) +impl<'a, 'b: 'a, 'hir: 'b> Visitor<'hir> for CheckItemRecursionVisitor<'a, 'b, 'hir> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { + NestedVisitorMap::OnlyBodies(&self.hir_map) } - fn visit_item(&mut self, it: &'ast hir::Item) { + fn visit_item(&mut self, it: &'hir hir::Item) { self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span); } fn visit_enum_def(&mut self, - enum_definition: &'ast hir::EnumDef, - generics: &'ast hir::Generics, + enum_definition: &'hir hir::EnumDef, + generics: &'hir hir::Generics, item_id: ast::NodeId, _: Span) { self.populate_enum_discriminants(enum_definition); @@ -222,8 +222,8 @@ impl<'a, 'b: 'a, 'ast: 'b> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'b, ' } fn visit_variant(&mut self, - variant: &'ast hir::Variant, - _: &'ast hir::Generics, + variant: &'hir hir::Variant, + _: &'hir hir::Generics, _: ast::NodeId) { let variant_id = variant.node.data.id(); let maybe_expr = *self.discriminant_map.get(&variant_id).unwrap_or_else(|| { @@ -234,34 +234,34 @@ impl<'a, 'b: 'a, 'ast: 'b> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'b, ' // If `maybe_expr` is `None`, that's because no discriminant is // specified that affects this variant. Thus, no risk of recursion. if let Some(expr) = maybe_expr { - let expr = &self.ast_map.body(expr).value; + let expr = &self.hir_map.body(expr).value; self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr), expr.span); } } - fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) { self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti), ti.span); } - fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) { self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii), ii.span); } - fn visit_path(&mut self, path: &'ast hir::Path, _: ast::NodeId) { + fn visit_path(&mut self, path: &'hir hir::Path, _: ast::NodeId) { match path.def { Def::Static(def_id, _) | Def::AssociatedConst(def_id) | Def::Const(def_id) => { - if let Some(node_id) = self.ast_map.as_local_node_id(def_id) { - match self.ast_map.get(node_id) { - ast_map::NodeItem(item) => self.visit_item(item), - ast_map::NodeTraitItem(item) => self.visit_trait_item(item), - ast_map::NodeImplItem(item) => self.visit_impl_item(item), - ast_map::NodeForeignItem(_) => {} + if let Some(node_id) = self.hir_map.as_local_node_id(def_id) { + match self.hir_map.get(node_id) { + hir_map::NodeItem(item) => self.visit_item(item), + hir_map::NodeTraitItem(item) => self.visit_trait_item(item), + hir_map::NodeImplItem(item) => self.visit_impl_item(item), + hir_map::NodeForeignItem(_) => {} _ => { span_bug!(path.span, "expected item, found {}", - self.ast_map.node_to_string(node_id)); + self.hir_map.node_to_string(node_id)); } } } @@ -271,10 +271,10 @@ impl<'a, 'b: 'a, 'ast: 'b> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'b, ' // the whole enum definition to see what expression that // might be (if any). Def::VariantCtor(variant_id, CtorKind::Const) => { - if let Some(variant_id) = self.ast_map.as_local_node_id(variant_id) { - let variant = self.ast_map.expect_variant(variant_id); - let enum_id = self.ast_map.get_parent(variant_id); - let enum_item = self.ast_map.expect_item(enum_id); + if let Some(variant_id) = self.hir_map.as_local_node_id(variant_id) { + let variant = self.hir_map.expect_variant(variant_id); + let enum_id = self.hir_map.get_parent(variant_id); + let enum_item = self.hir_map.expect_item(enum_id); if let hir::ItemEnum(ref enum_def, ref generics) = enum_item.node { self.populate_enum_discriminants(enum_def); self.visit_variant(variant, generics, enum_id);