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
}
}
-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() }
} 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())
} 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_{} {}",
}
}
-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>;
}
-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 }
}
}
}
-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)
}
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<MapEntry<'ast>>,
+ pub(super) map: Vec<MapEntry<'hir>>,
/// 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![],
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));
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);
}
}
}
-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")
}
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));
});
}
- 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| {
});
}
- 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));
}
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| {
});
}
- 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| {
});
}
- 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 {
});
}
- 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| {
});
}
- 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));
});
}
- 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| {
});
}
- 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| {
});
}
- 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 |
}
}
- 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| {
});
}
- 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);
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),
})
}
- fn to_node(self) -> Option<Node<'ast>> {
+ fn to_node(self) -> Option<Node<'hir>> {
Some(match self {
EntryItem(_, n) => NodeItem(n),
EntryForeignItem(_, n) => NodeForeignItem(n),
}
}
- pub fn krate<'ast>(&'ast self) -> &'ast Crate {
+ pub fn krate<'hir>(&'hir self) -> &'hir Crate {
self.dep_graph.read(DepNode::Krate);
&self.krate
}
/// 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.
///
/// Also, indexing is pretty quick when you've got a vector and
/// plain old integers.
- map: Vec<MapEntry<'ast>>,
+ map: Vec<MapEntry<'hir>>,
definitions: Definitions,
/// Bodies inlined from other crates are cached here.
- inlined_bodies: RefCell<DefIdMap<&'ast Body>>,
+ inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
}
-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
self.map.len()
}
- fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
+ fn find_entry(&self, id: NodeId) -> Option<MapEntry<'hir>> {
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
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
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
/// 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
/// 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<Node<'ast>> {
+ pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
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<Node<'ast>> {
+ pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
let result = self.find_entry(id).and_then(|x| x.to_node());
if result.is_some() {
self.read(id);
/// is not an error, since items in the crate module have the crate root as
/// parent.
fn walk_parent_nodes<F>(&self, start_id: NodeId, found: F) -> Result<NodeId, NodeId>
- where F: Fn(&Node<'ast>) -> bool
+ where F: Fn(&Node<'hir>) -> bool
{
let mut id = start_id;
loop {
}
}
- 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 {
}
}
- 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
/// 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[..]),
/// 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(),
}
}
-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`.
///
}
}
-impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> {
+impl<'a, 'hir> Iterator for NodesMatchingSuffix<'a, 'hir> {
type Item = NodeId;
fn next(&mut self) -> Option<NodeId> {
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;
/// 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)),
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"),
}
use std::collections::HashSet;
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir;
use lint;
}
};
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",
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;
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)
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
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))
_ => 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)
None
}
},
- ast_map::NodeTraitItem(item) => {
+ hir_map::NodeTraitItem(item) => {
match item.node {
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
Some((&sig.decl,
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);
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);
}
// 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;
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
}
}
- 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| {
_ => ()
}
}
- 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);
}
_ => ()
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;
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)>,
}
}
-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
}
// 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);
}
struct LanguageItemCollector<'a, 'tcx: 'a> {
items: LanguageItems,
- ast_map: &'a hir_map::Map<'tcx>,
+ hir_map: &'a hir_map::Map<'tcx>,
session: &'a Session,
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);
}
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();
LanguageItemCollector {
session: session,
- ast_map: ast_map,
+ hir_map: hir_map,
items: LanguageItems::new(),
item_refs: item_refs,
}
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,
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 {
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;
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
// 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!()
};
// 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};
}
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")
};
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,
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, _) => {
}
}
- 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 {
}
match *node {
- ast_map::NodeItem(item) => {
+ hir_map::NodeItem(item) => {
match item.node {
hir::ItemFn(.., body) => {
if item_might_be_inlined(&item) {
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(_)) => {
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);
}
}
// 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))
//! `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;
/// 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<Span> {
- 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<Span> {
+ 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 { .. } |
}
}
}
- 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,
}
}
parent: CodeExtent
}
-struct RegionResolutionVisitor<'ast: 'a, 'a> {
+struct RegionResolutionVisitor<'hir: 'a, 'a> {
sess: &'a Session,
// Generated maps:
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
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)
}
}
-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();
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;
/// additional acyclicity requirements).
pub super_predicates: RefCell<DepTrackingMap<maps::Predicates<'tcx>>>,
- 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
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>,
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};
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),
}
}
}
- 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),
}
}
}
- Some(ast_map::NodeItem(item)) => {
+ Some(hir_map::NodeItem(item)) => {
match item.node {
hir::ItemFn(.., body_id) => {
// We assume this is a function.
}
}
}
- 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);
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,
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) => {
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(),
_ => {
}
}
- 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 {
///
/// 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 {
} 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()
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};
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);
}
}
/// 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<LoanPath<'tcx>>,
pattern_id: ast::NodeId,
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;
-> 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 {
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,
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<TyCtxt<'a, 'tcx, 'tcx>>,
output_filenames: None,
expanded_crate: None,
hir_crate: None,
- ast_map: None,
+ hir_map: None,
resolutions: None,
analysis: None,
tcx: None,
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),
};
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,
/// 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
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)
}
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)
}
}
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,
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,
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)
}
}
}
-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
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.
///
/// Computes an user-readable representation of a path, if possible.
fn node_path(&self, id: ast::NodeId) -> Option<String> {
- 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())
}
}
-struct NoAnn<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+struct NoAnn<'hir> {
+ sess: &'hir Session,
+ hir_map: Option<hir_map::Map<'hir>>,
}
-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 {
}
}
-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(())
}
}
-struct IdentifiedAnnotation<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+struct IdentifiedAnnotation<'hir> {
+ sess: &'hir Session,
+ hir_map: Option<hir_map::Map<'hir>>,
}
-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(),
}
}
-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 {
}
}
-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(())
}
}
-struct HygieneAnnotation<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+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 }) => {
&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)
}
}
}
-enum NodesMatchingUII<'a, 'ast: 'a> {
+enum NodesMatchingUII<'a, 'hir: 'a> {
NodesMatchingDirect(option::IntoIter<ast::NodeId>),
- 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<ast::NodeId> {
}
}
- 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[..])),
};
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,
}
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,
if ppm.needs_analysis() {
print_with_analysis(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
crate_name,
(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(),
(PpmHir(s), None) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
arena,
(PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
arena,
|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(),
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)
// 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,
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
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,
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,
}
#[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,
}
}.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| {
}
}
-impl<'a, 'ast> CheckLoopVisitor<'a, 'ast> {
+impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
fn with_context<F>(&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;
// 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};
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`),
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(..) => {
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 {
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);
}
}
-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<Option<hir::BodyId>>,
idstack: Vec<ast::NodeId>,
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,
}
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 {
// 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() {
}
}
-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);
}
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(|| {
// 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));
}
}
}
// 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);