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