Rename tcx.map to the far more descriptive tcx.hir.
Also a bit more renaming because `ast_map` and `'ast` were still used with HIR.
Main motivation is to "free up" `tcx.map`, or rather, `tcx.maps`, to consolidate `ty::maps` there.
r? @nikomatsakis
// Find the function this expression is from.
let mut node_id = body.id;
loop {
- let node = tcx.map.get(node_id);
+ let node = tcx.hir.get(node_id);
if hir::map::blocks::FnLikeNode::from_node(node).is_some() {
break;
}
- let parent = tcx.map.get_parent_node(node_id);
+ let parent = tcx.hir.get_parent_node(node_id);
assert!(node_id != parent);
node_id = parent;
}
let mut cfg_builder = CFGBuilder {
tcx: tcx,
- tables: tcx.item_tables(tcx.map.local_def_id(node_id)),
+ tables: tcx.item_tables(tcx.hir.local_def_id(node_id)),
graph: graph,
fn_exit: fn_exit,
loop_scopes: Vec::new()
use syntax::ast;
-use hir::map as ast_map;
+use hir::map as hir_map;
use cfg;
pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
pub type Edge<'a> = &'a cfg::CFGEdge;
-pub struct LabelledCFG<'a, 'ast: 'a> {
- pub ast_map: &'a ast_map::Map<'ast>,
+pub struct LabelledCFG<'a, 'hir: 'a> {
+ pub hir_map: &'a hir_map::Map<'hir>,
pub cfg: &'a cfg::CFG,
pub name: String,
/// `labelled_edges` controls whether we emit labels on the edges
}
}
-impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> {
+impl<'a, 'hir> dot::Labeller<'a> for LabelledCFG<'a, 'hir> {
type Node = Node<'a>;
type Edge = Edge<'a>;
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).unwrap() }
} else if n.data.id() == ast::DUMMY_NODE_ID {
dot::LabelText::LabelStr("(dummy_node)".into_cow())
} else {
- let s = self.ast_map.node_to_string(n.data.id());
+ let s = self.hir_map.node_to_string(n.data.id());
// left-aligns the lines
let s = replace_newline_with_backslash_l(s);
dot::LabelText::EscStr(s.into_cow())
} else {
put_one = true;
}
- let s = self.ast_map.node_to_string(node_id);
+ let s = self.hir_map.node_to_string(node_id);
// left-aligns the lines
let s = replace_newline_with_backslash_l(s);
label.push_str(&format!("exiting scope_{} {}",
}
}
-impl<'a, 'ast> dot::GraphWalk<'a> for LabelledCFG<'a, 'ast>
+impl<'a, 'hir> dot::GraphWalk<'a> for LabelledCFG<'a, 'hir>
{
type Node = Node<'a>;
type Edge = Edge<'a>;
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
// distinct from the krate module). This is basically a hash of
// the entire krate, so if you read from `Krate` (e.g., by calling
- // `tcx.map.krate()`), we will have to assume that any change
+ // `tcx.hir.krate()`), we will have to assume that any change
// means that you need to be recompiled. This is because the
// `Krate` value gives you access to all other items. To avoid
- // this fate, do not call `tcx.map.krate()`; instead, prefer
+ // this fate, do not call `tcx.hir.krate()`; instead, prefer
// wrappers like `tcx.visit_all_items_in_krate()`. If there is no
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
// access to the krate, but you must remember to add suitable
///
/// ```
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
- /// let item_def_id = ccx.tcx.map.local_def_id(it.id);
+ /// let item_def_id = ccx.tcx.hir.local_def_id(it.id);
/// ccx.tcx.item_types.memoized(item_def_id, || {
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
/// compute_type_of_item(ccx, item)
where F: FnMut(DefId) -> DepNode<DefId>, V: ItemLikeVisitor<'tcx>
{
fn visit_item(&mut self, i: &'tcx hir::Item) {
- let item_def_id = self.tcx.map.local_def_id(i.id);
+ let item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
}
fn visit_trait_item(&mut self, i: &'tcx hir::TraitItem) {
- let trait_item_def_id = self.tcx.map.local_def_id(i.id);
+ let trait_item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(trait_item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
}
fn visit_impl_item(&mut self, i: &'tcx hir::ImplItem) {
- let impl_item_def_id = self.tcx.map.local_def_id(i.id);
+ let impl_item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(impl_item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
}
}
- let krate = tcx.dep_graph.with_ignore(|| tcx.map.krate());
+ let krate = tcx.dep_graph.with_ignore(|| tcx.hir.krate());
let mut tracking_visitor = TrackingVisitor {
tcx: tcx,
dep_node_fn: &mut dep_node_fn,
}
-pub struct IdRangeComputingVisitor<'a, 'ast: 'a> {
+pub struct IdRangeComputingVisitor<'a, 'hir: 'a> {
result: IdRange,
- map: &'a map::Map<'ast>,
+ map: &'a map::Map<'hir>,
}
-impl<'a, 'ast> IdRangeComputingVisitor<'a, 'ast> {
- pub fn new(map: &'a map::Map<'ast>) -> IdRangeComputingVisitor<'a, 'ast> {
+impl<'a, 'hir> IdRangeComputingVisitor<'a, 'hir> {
+ pub fn new(map: &'a map::Map<'hir>) -> IdRangeComputingVisitor<'a, 'hir> {
IdRangeComputingVisitor { result: IdRange::max(), map: map }
}
}
}
-impl<'a, 'ast> Visitor<'ast> for IdRangeComputingVisitor<'a, 'ast> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
+impl<'a, 'hir> Visitor<'hir> for IdRangeComputingVisitor<'a, 'hir> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
NestedVisitorMap::OnlyBodies(&self.map)
}
/// - How: Implement `intravisit::Visitor` and override the
/// `visit_nested_map()` methods to return
/// `NestedVisitorMap::All`. Walk your crate with
-/// `intravisit::walk_crate()` invoked on `tcx.map.krate()`.
+/// `intravisit::walk_crate()` invoked on `tcx.hir.krate()`.
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
/// - Pro: Preserves nesting information
/// - Con: Does not integrate well into dependency tracking.
use syntax_pos::Span;
/// A Visitor that walks over the HIR and collects Nodes into a HIR map
-pub struct NodeCollector<'ast> {
+pub struct NodeCollector<'hir> {
/// The crate
- pub krate: &'ast Crate,
+ pub krate: &'hir Crate,
/// The node map
- pub(super) map: Vec<MapEntry<'ast>>,
+ pub(super) map: Vec<MapEntry<'hir>>,
/// The parent of this node
pub parent_node: NodeId,
}
-impl<'ast> NodeCollector<'ast> {
- pub fn root(krate: &'ast Crate) -> NodeCollector<'ast> {
+impl<'hir> NodeCollector<'hir> {
+ pub fn root(krate: &'hir Crate) -> NodeCollector<'hir> {
let mut collector = NodeCollector {
krate: krate,
map: vec![],
collector
}
- fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'ast>) {
- debug!("ast_map: {:?} => {:?}", id, entry);
+ fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'hir>) {
+ debug!("hir_map: {:?} => {:?}", id, entry);
let len = self.map.len();
if id.as_usize() >= len {
self.map.extend(repeat(NotPresent).take(id.as_usize() - len + 1));
self.map[id.as_usize()] = entry;
}
- fn insert(&mut self, id: NodeId, node: Node<'ast>) {
+ fn insert(&mut self, id: NodeId, node: Node<'hir>) {
let entry = MapEntry::from_node(self.parent_node, node);
self.insert_entry(id, entry);
}
}
}
-impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
+impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
/// Because we want to track parent items and so forth, enable
/// deep walking so that we walk nested items in the context of
/// their outer items.
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
panic!("visit_nested_xxx must be manually implemented in this visitor")
}
self.visit_body(self.krate.body(id));
}
- fn visit_item(&mut self, i: &'ast Item) {
+ fn visit_item(&mut self, i: &'hir Item) {
debug!("visit_item: {:?}", i);
self.insert(i.id, NodeItem(i));
});
}
- fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
+ fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
self.insert(foreign_item.id, NodeForeignItem(foreign_item));
self.with_parent(foreign_item.id, |this| {
});
}
- fn visit_generics(&mut self, generics: &'ast Generics) {
+ fn visit_generics(&mut self, generics: &'hir Generics) {
for ty_param in generics.ty_params.iter() {
self.insert(ty_param.id, NodeTyParam(ty_param));
}
intravisit::walk_generics(self, generics);
}
- fn visit_trait_item(&mut self, ti: &'ast TraitItem) {
+ fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
self.insert(ti.id, NodeTraitItem(ti));
self.with_parent(ti.id, |this| {
});
}
- fn visit_impl_item(&mut self, ii: &'ast ImplItem) {
+ fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
self.insert(ii.id, NodeImplItem(ii));
self.with_parent(ii.id, |this| {
});
}
- fn visit_pat(&mut self, pat: &'ast Pat) {
+ fn visit_pat(&mut self, pat: &'hir Pat) {
let node = if let PatKind::Binding(..) = pat.node {
NodeLocal(pat)
} else {
});
}
- fn visit_expr(&mut self, expr: &'ast Expr) {
+ fn visit_expr(&mut self, expr: &'hir Expr) {
self.insert(expr.id, NodeExpr(expr));
self.with_parent(expr.id, |this| {
});
}
- fn visit_stmt(&mut self, stmt: &'ast Stmt) {
+ fn visit_stmt(&mut self, stmt: &'hir Stmt) {
let id = stmt.node.id();
self.insert(id, NodeStmt(stmt));
});
}
- fn visit_ty(&mut self, ty: &'ast Ty) {
+ fn visit_ty(&mut self, ty: &'hir Ty) {
self.insert(ty.id, NodeTy(ty));
self.with_parent(ty.id, |this| {
});
}
- fn visit_trait_ref(&mut self, tr: &'ast TraitRef) {
+ fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
self.insert(tr.ref_id, NodeTraitRef(tr));
self.with_parent(tr.ref_id, |this| {
});
}
- fn visit_fn(&mut self, fk: intravisit::FnKind<'ast>, fd: &'ast FnDecl,
+ fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl,
b: BodyId, s: Span, id: NodeId) {
assert_eq!(self.parent_node, id);
intravisit::walk_fn(self, fk, fd, b, s, id);
}
- fn visit_block(&mut self, block: &'ast Block) {
+ fn visit_block(&mut self, block: &'hir Block) {
self.insert(block.id, NodeBlock(block));
self.with_parent(block.id, |this| {
intravisit::walk_block(this, block);
});
}
- fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
+ fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
self.insert(lifetime.id, NodeLifetime(lifetime));
}
- fn visit_vis(&mut self, visibility: &'ast Visibility) {
+ fn visit_vis(&mut self, visibility: &'hir Visibility) {
match *visibility {
Visibility::Public |
Visibility::Crate |
}
}
- fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
+ fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
self.insert_entry(macro_def.id, NotPresent);
}
- fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) {
+ fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
let id = v.node.data.id();
self.insert(id, NodeVariant(v));
self.with_parent(id, |this| {
});
}
- fn visit_struct_field(&mut self, field: &'ast StructField) {
+ fn visit_struct_field(&mut self, field: &'hir StructField) {
self.insert(field.id, NodeField(field));
self.with_parent(field.id, |this| {
intravisit::walk_struct_field(this, field);
pub mod definitions;
#[derive(Copy, Clone, Debug)]
-pub enum Node<'ast> {
- NodeItem(&'ast Item),
- NodeForeignItem(&'ast ForeignItem),
- NodeTraitItem(&'ast TraitItem),
- NodeImplItem(&'ast ImplItem),
- NodeVariant(&'ast Variant),
- NodeField(&'ast StructField),
- NodeExpr(&'ast Expr),
- NodeStmt(&'ast Stmt),
- NodeTy(&'ast Ty),
- NodeTraitRef(&'ast TraitRef),
- NodeLocal(&'ast Pat),
- NodePat(&'ast Pat),
- NodeBlock(&'ast Block),
+pub enum Node<'hir> {
+ NodeItem(&'hir Item),
+ NodeForeignItem(&'hir ForeignItem),
+ NodeTraitItem(&'hir TraitItem),
+ NodeImplItem(&'hir ImplItem),
+ NodeVariant(&'hir Variant),
+ NodeField(&'hir StructField),
+ NodeExpr(&'hir Expr),
+ NodeStmt(&'hir Stmt),
+ NodeTy(&'hir Ty),
+ NodeTraitRef(&'hir TraitRef),
+ NodeLocal(&'hir Pat),
+ NodePat(&'hir Pat),
+ NodeBlock(&'hir Block),
/// NodeStructCtor represents a tuple struct.
- NodeStructCtor(&'ast VariantData),
+ NodeStructCtor(&'hir VariantData),
- NodeLifetime(&'ast Lifetime),
- NodeTyParam(&'ast TyParam),
- NodeVisibility(&'ast Visibility),
+ NodeLifetime(&'hir Lifetime),
+ NodeTyParam(&'hir TyParam),
+ NodeVisibility(&'hir Visibility),
}
/// Represents an entry and its parent NodeID.
/// The odd layout is to bring down the total size.
#[derive(Copy, Debug)]
-enum MapEntry<'ast> {
+enum MapEntry<'hir> {
/// Placeholder for holes in the map.
NotPresent,
/// All the node types, with a parent ID.
- EntryItem(NodeId, &'ast Item),
- EntryForeignItem(NodeId, &'ast ForeignItem),
- EntryTraitItem(NodeId, &'ast TraitItem),
- EntryImplItem(NodeId, &'ast ImplItem),
- EntryVariant(NodeId, &'ast Variant),
- EntryField(NodeId, &'ast StructField),
- EntryExpr(NodeId, &'ast Expr),
- EntryStmt(NodeId, &'ast Stmt),
- EntryTy(NodeId, &'ast Ty),
- EntryTraitRef(NodeId, &'ast TraitRef),
- EntryLocal(NodeId, &'ast Pat),
- EntryPat(NodeId, &'ast Pat),
- EntryBlock(NodeId, &'ast Block),
- EntryStructCtor(NodeId, &'ast VariantData),
- EntryLifetime(NodeId, &'ast Lifetime),
- EntryTyParam(NodeId, &'ast TyParam),
- EntryVisibility(NodeId, &'ast Visibility),
+ EntryItem(NodeId, &'hir Item),
+ EntryForeignItem(NodeId, &'hir ForeignItem),
+ EntryTraitItem(NodeId, &'hir TraitItem),
+ EntryImplItem(NodeId, &'hir ImplItem),
+ EntryVariant(NodeId, &'hir Variant),
+ EntryField(NodeId, &'hir StructField),
+ EntryExpr(NodeId, &'hir Expr),
+ EntryStmt(NodeId, &'hir Stmt),
+ EntryTy(NodeId, &'hir Ty),
+ EntryTraitRef(NodeId, &'hir TraitRef),
+ EntryLocal(NodeId, &'hir Pat),
+ EntryPat(NodeId, &'hir Pat),
+ EntryBlock(NodeId, &'hir Block),
+ EntryStructCtor(NodeId, &'hir VariantData),
+ EntryLifetime(NodeId, &'hir Lifetime),
+ EntryTyParam(NodeId, &'hir TyParam),
+ EntryVisibility(NodeId, &'hir Visibility),
/// Roots for node trees.
RootCrate,
}
-impl<'ast> Clone for MapEntry<'ast> {
- fn clone(&self) -> MapEntry<'ast> {
+impl<'hir> Clone for MapEntry<'hir> {
+ fn clone(&self) -> MapEntry<'hir> {
*self
}
}
-impl<'ast> MapEntry<'ast> {
- fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
+impl<'hir> MapEntry<'hir> {
+ fn from_node(p: NodeId, node: Node<'hir>) -> MapEntry<'hir> {
match node {
NodeItem(n) => EntryItem(p, n),
NodeForeignItem(n) => EntryForeignItem(p, n),
})
}
- fn to_node(self) -> Option<Node<'ast>> {
+ fn to_node(self) -> Option<Node<'hir>> {
Some(match self {
EntryItem(_, n) => NodeItem(n),
EntryForeignItem(_, n) => NodeForeignItem(n),
}
}
- pub fn krate<'ast>(&'ast self) -> &'ast Crate {
+ pub fn krate<'hir>(&'hir self) -> &'hir Crate {
self.dep_graph.read(DepNode::Krate);
&self.krate
}
/// Represents a mapping from Node IDs to AST elements and their parent
/// Node IDs
#[derive(Clone)]
-pub struct Map<'ast> {
+pub struct Map<'hir> {
/// The backing storage for all the AST nodes.
- pub forest: &'ast Forest,
+ pub forest: &'hir Forest,
/// Same as the dep_graph in forest, just available with one fewer
/// deref. This is a gratuitious micro-optimization.
///
/// Also, indexing is pretty quick when you've got a vector and
/// plain old integers.
- map: Vec<MapEntry<'ast>>,
+ map: Vec<MapEntry<'hir>>,
definitions: Definitions,
/// Bodies inlined from other crates are cached here.
- inlined_bodies: RefCell<DefIdMap<&'ast Body>>,
+ inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
}
-impl<'ast> Map<'ast> {
+impl<'hir> Map<'hir> {
/// Registers a read in the dependency graph of the AST node with
/// the given `id`. This needs to be called each time a public
/// function returns the HIR for a node -- in other words, when it
self.map.len()
}
- fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
+ fn find_entry(&self, id: NodeId) -> Option<MapEntry<'hir>> {
self.map.get(id.as_usize()).cloned()
}
- pub fn krate(&self) -> &'ast Crate {
+ pub fn krate(&self) -> &'hir Crate {
self.forest.krate()
}
- pub fn trait_item(&self, id: TraitItemId) -> &'ast TraitItem {
+ pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem {
self.read(id.node_id);
// NB: intentionally bypass `self.forest.krate()` so that we
self.forest.krate.trait_item(id)
}
- pub fn impl_item(&self, id: ImplItemId) -> &'ast ImplItem {
+ pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
self.read(id.node_id);
// NB: intentionally bypass `self.forest.krate()` so that we
self.forest.krate.impl_item(id)
}
- pub fn body(&self, id: BodyId) -> &'ast Body {
+ pub fn body(&self, id: BodyId) -> &'hir Body {
self.read(id.node_id);
// NB: intentionally bypass `self.forest.krate()` so that we
/// Get the attributes on the krate. This is preferable to
/// invoking `krate.attrs` because it registers a tighter
/// dep-graph access.
- pub fn krate_attrs(&self) -> &'ast [ast::Attribute] {
+ pub fn krate_attrs(&self) -> &'hir [ast::Attribute] {
let crate_root_def_id = DefId::local(CRATE_DEF_INDEX);
self.dep_graph.read(DepNode::Hir(crate_root_def_id));
&self.forest.krate.attrs
/// Retrieve the Node corresponding to `id`, panicking if it cannot
/// be found.
- pub fn get(&self, id: NodeId) -> Node<'ast> {
+ pub fn get(&self, id: NodeId) -> Node<'hir> {
match self.find(id) {
Some(node) => node, // read recorded by `find`
None => bug!("couldn't find node id {} in the AST map", id)
}
}
- pub fn get_if_local(&self, id: DefId) -> Option<Node<'ast>> {
+ pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get`
}
/// Retrieve the Node corresponding to `id`, returning None if
/// cannot be found.
- pub fn find(&self, id: NodeId) -> Option<Node<'ast>> {
+ pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
let result = self.find_entry(id).and_then(|x| x.to_node());
if result.is_some() {
self.read(id);
/// is not an error, since items in the crate module have the crate root as
/// parent.
fn walk_parent_nodes<F>(&self, start_id: NodeId, found: F) -> Result<NodeId, NodeId>
- where F: Fn(&Node<'ast>) -> bool
+ where F: Fn(&Node<'hir>) -> bool
{
let mut id = start_id;
loop {
}
}
- pub fn expect_item(&self, id: NodeId) -> &'ast Item {
+ pub fn expect_item(&self, id: NodeId) -> &'hir Item {
match self.find(id) { // read recorded by `find`
Some(NodeItem(item)) => item,
_ => bug!("expected item, found {}", self.node_to_string(id))
}
}
- pub fn expect_impl_item(&self, id: NodeId) -> &'ast ImplItem {
+ pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem {
match self.find(id) {
Some(NodeImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(id))
}
}
- pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
+ pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
match self.find(id) {
Some(NodeTraitItem(item)) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(id))
}
}
- pub fn expect_variant_data(&self, id: NodeId) -> &'ast VariantData {
+ pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
match self.find(id) {
Some(NodeItem(i)) => {
match i.node {
}
}
- pub fn expect_variant(&self, id: NodeId) -> &'ast Variant {
+ pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
match self.find(id) {
Some(NodeVariant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
}
}
- pub fn expect_foreign_item(&self, id: NodeId) -> &'ast ForeignItem {
+ pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem {
match self.find(id) {
Some(NodeForeignItem(item)) => item,
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
}
}
- pub fn expect_expr(&self, id: NodeId) -> &'ast Expr {
+ pub fn expect_expr(&self, id: NodeId) -> &'hir Expr {
match self.find(id) { // read recorded by find
Some(NodeExpr(expr)) => expr,
_ => bug!("expected expr, found {}", self.node_to_string(id))
}
}
- pub fn get_inlined_body(&self, def_id: DefId) -> Option<&'ast Body> {
+ pub fn get_inlined_body(&self, def_id: DefId) -> Option<&'hir Body> {
self.inlined_bodies.borrow().get(&def_id).map(|&body| {
self.dep_graph.read(DepNode::MetaData(def_id));
body
})
}
- pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'ast Body {
+ pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'hir Body {
let body = self.forest.inlined_bodies.alloc(body);
self.inlined_bodies.borrow_mut().insert(def_id, body);
body
/// Given a node ID, get a list of attributes associated with the AST
/// corresponding to the Node ID
- pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
+ pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
self.read(id); // reveals attributes on the node
let attrs = match self.find(id) {
Some(NodeItem(i)) => Some(&i.attrs[..]),
/// such as `foo::bar::quux`, `bar::quux`, `other::bar::quux`, and
/// any other such items it can find in the map.
pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String])
- -> NodesMatchingSuffix<'a, 'ast> {
+ -> NodesMatchingSuffix<'a, 'hir> {
NodesMatchingSuffix {
map: self,
item_name: parts.last().unwrap(),
}
}
-pub struct NodesMatchingSuffix<'a, 'ast:'a> {
- map: &'a Map<'ast>,
+pub struct NodesMatchingSuffix<'a, 'hir:'a> {
+ map: &'a Map<'hir>,
item_name: &'a String,
in_which: &'a [String],
idx: NodeId,
}
-impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
+impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> {
/// Returns true only if some suffix of the module path for parent
/// matches `self.in_which`.
///
}
}
-impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> {
+impl<'a, 'hir> Iterator for NodesMatchingSuffix<'a, 'hir> {
type Item = NodeId;
fn next(&mut self) -> Option<NodeId> {
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
-pub fn map_crate<'ast>(forest: &'ast mut Forest,
+pub fn map_crate<'hir>(forest: &'hir mut Forest,
definitions: Definitions)
- -> Map<'ast> {
+ -> Map<'hir> {
let mut collector = NodeCollector::root(&forest.krate);
intravisit::walk_crate(&mut collector, &forest.krate);
let map = collector.map;
/// Identical to the `PpAnn` implementation for `hir::Crate`,
/// except it avoids creating a dependency on the whole crate.
-impl<'ast> print::PpAnn for Map<'ast> {
+impl<'hir> print::PpAnn for Map<'hir> {
fn nested(&self, state: &mut print::State, nested: print::Nested) -> io::Result<()> {
match nested {
Nested::Item(id) => state.print_item(self.expect_item(id.id)),
NodeTyParam(_) => bug!("cannot print TyParam"),
NodeField(_) => bug!("cannot print StructField"),
// these cases do not carry enough information in the
- // ast_map to reconstruct their full structure for pretty
+ // hir_map to reconstruct their full structure for pretty
// printing.
NodeStructCtor(_) => bug!("cannot print isolated StructCtor"),
}
use std::collections::HashSet;
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir;
use lint;
format!("{}unknown scope: {:?}{}. Please report a bug.",
prefix, scope, suffix)
};
- let span = match scope.span(&self.region_maps, &self.map) {
+ let span = match scope.span(&self.region_maps, &self.hir) {
Some(s) => s,
None => {
err.note(&unknown_scope());
return;
}
};
- let tag = match self.map.find(scope.node_id(&self.region_maps)) {
- Some(ast_map::NodeBlock(_)) => "block",
- Some(ast_map::NodeExpr(expr)) => match expr.node {
+ let tag = match self.hir.find(scope.node_id(&self.region_maps)) {
+ Some(hir_map::NodeBlock(_)) => "block",
+ Some(hir_map::NodeExpr(expr)) => match expr.node {
hir::ExprCall(..) => "call",
hir::ExprMethodCall(..) => "method call",
hir::ExprMatch(.., hir::MatchSource::IfLetDesugar { .. }) => "if let",
hir::ExprMatch(..) => "match",
_ => "expression",
},
- Some(ast_map::NodeStmt(_)) => "statement",
- Some(ast_map::NodeItem(it)) => item_scope_tag(&it),
- Some(ast_map::NodeTraitItem(it)) => trait_item_scope_tag(&it),
- Some(ast_map::NodeImplItem(it)) => impl_item_scope_tag(&it),
+ Some(hir_map::NodeStmt(_)) => "statement",
+ Some(hir_map::NodeItem(it)) => item_scope_tag(&it),
+ Some(hir_map::NodeTraitItem(it)) => trait_item_scope_tag(&it),
+ Some(hir_map::NodeImplItem(it)) => impl_item_scope_tag(&it),
Some(_) | None => {
err.span_note(span, &unknown_scope());
return;
let node = fr.scope.node_id(&self.region_maps);
let unknown;
- let tag = match self.map.find(node) {
- Some(ast_map::NodeBlock(_)) |
- Some(ast_map::NodeExpr(_)) => "body",
- Some(ast_map::NodeItem(it)) => item_scope_tag(&it),
- Some(ast_map::NodeTraitItem(it)) => trait_item_scope_tag(&it),
- Some(ast_map::NodeImplItem(it)) => impl_item_scope_tag(&it),
+ let tag = match self.hir.find(node) {
+ Some(hir_map::NodeBlock(_)) |
+ Some(hir_map::NodeExpr(_)) => "body",
+ Some(hir_map::NodeItem(it)) => item_scope_tag(&it),
+ Some(hir_map::NodeTraitItem(it)) => trait_item_scope_tag(&it),
+ Some(hir_map::NodeImplItem(it)) => impl_item_scope_tag(&it),
// this really should not happen, but it does:
// FIXME(#27942)
Some(_) => {
unknown = format!("unexpected node ({}) for scope {:?}. \
Please report a bug.",
- self.map.node_to_string(node), fr.scope);
+ self.hir.node_to_string(node), fr.scope);
&unknown
}
None => {
&unknown
}
};
- let (msg, opt_span) = explain_span(self, tag, self.map.span(node));
+ let (msg, opt_span) = explain_span(self, tag, self.hir.span(node));
(format!("{} {}", prefix, msg), opt_span)
}
},
_ => return None
};
- let parent = tcx.map.get_parent(scope_id);
- let parent_node = tcx.map.find(parent);
+ let parent = tcx.hir.get_parent(scope_id);
+ let parent_node = tcx.hir.find(parent);
match parent_node {
Some(node) => match node {
- ast_map::NodeItem(item) => match item.node {
+ hir_map::NodeItem(item) => match item.node {
hir::ItemFn(..) => {
Some(FreeRegionsFromSameFn::new(fr1, fr2, scope_id))
},
_ => None
},
- ast_map::NodeImplItem(..) |
- ast_map::NodeTraitItem(..) => {
+ hir_map::NodeImplItem(..) |
+ hir_map::NodeTraitItem(..) => {
Some(FreeRegionsFromSameFn::new(fr1, fr2, scope_id))
},
_ => None
fn give_suggestion(&self, err: &mut DiagnosticBuilder, same_regions: &[SameRegions]) {
let scope_id = same_regions[0].scope_id;
- let parent = self.tcx.map.get_parent(scope_id);
- let parent_node = self.tcx.map.find(parent);
+ let parent = self.tcx.hir.get_parent(scope_id);
+ let parent_node = self.tcx.hir.find(parent);
let taken = lifetimes_in_scope(self.tcx, scope_id);
let life_giver = LifeGiver::with_taken(&taken[..]);
let node_inner = match parent_node {
Some(ref node) => match *node {
- ast_map::NodeItem(ref item) => {
+ hir_map::NodeItem(ref item) => {
match item.node {
hir::ItemFn(ref fn_decl, unsafety, constness, _, ref gen, body) => {
Some((fn_decl, gen, unsafety, constness, item.name, item.span, body))
_ => None,
}
}
- ast_map::NodeImplItem(item) => {
- let id = self.tcx.map.get_parent(item.id);
- if let Some(ast_map::NodeItem(parent_scope)) = self.tcx.map.find(id) {
+ hir_map::NodeImplItem(item) => {
+ let id = self.tcx.hir.get_parent(item.id);
+ if let Some(hir_map::NodeItem(parent_scope)) = self.tcx.hir.find(id) {
if let hir::ItemImpl(_, _, _, None, _, _) = parent_scope.node {
// this impl scope implements a trait, do not recomend
// using explicit lifetimes (#37363)
None
}
},
- ast_map::NodeTraitItem(item) => {
+ hir_map::NodeTraitItem(item) => {
match item.node {
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
Some((&sig.decl,
generics: &hir::Generics,
span: Span,
body: hir::BodyId) {
- let s = hir::print::to_string(&self.tcx.map, |s| {
+ let s = hir::print::to_string(&self.tcx.hir, |s| {
use syntax::abi::Abi;
use syntax::print::pprust::PrintState;
scope_id: ast::NodeId)
-> Vec<hir::LifetimeDef> {
let mut taken = Vec::new();
- let parent = tcx.map.get_parent(scope_id);
- let method_id_opt = match tcx.map.find(parent) {
+ let parent = tcx.hir.get_parent(scope_id);
+ let method_id_opt = match tcx.hir.find(parent) {
Some(node) => match node {
- ast_map::NodeItem(item) => match item.node {
+ hir_map::NodeItem(item) => match item.node {
hir::ItemFn(.., ref gen, _) => {
taken.extend_from_slice(&gen.lifetimes);
None
},
_ => None
},
- ast_map::NodeImplItem(ii) => {
+ hir_map::NodeImplItem(ii) => {
match ii.node {
hir::ImplItemKind::Method(ref sig, _) => {
taken.extend_from_slice(&sig.generics.lifetimes);
None => None
};
if let Some(method_id) = method_id_opt {
- let parent = tcx.map.get_parent(method_id);
- if let Some(node) = tcx.map.find(parent) {
+ let parent = tcx.hir.get_parent(method_id);
+ if let Some(node) = tcx.hir.find(parent) {
match node {
- ast_map::NodeItem(item) => match item.node {
+ hir_map::NodeItem(item) => match item.node {
hir::ItemImpl(_, _, ref gen, ..) => {
taken.extend_from_slice(&gen.lifetimes);
}
-> (Option<&'a ty::TypeckTables<'tcx>>,
Option<ty::TypeckTables<'tcx>>,
Option<ty::ParameterEnvironment<'tcx>>) {
- let item_id = tcx.map.body_owner(self);
- (Some(tcx.item_tables(tcx.map.local_def_id(item_id))),
+ let item_id = tcx.hir.body_owner(self);
+ (Some(tcx.item_tables(tcx.hir.local_def_id(item_id))),
None,
Some(ty::ParameterEnvironment::for_item(tcx, item_id)))
}
self.tcx.types.err,
None => {
bug!("no type for node {}: {} in fcx",
- id, self.tcx.map.node_to_string(id));
+ id, self.tcx.hir.node_to_string(id));
}
}
}
-> Option<ty::ClosureKind>
{
if let InferTables::InProgress(tables) = self.tables {
- if let Some(id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
return tables.borrow().closure_kinds.get(&id).cloned();
}
}
-> ty::ClosureTy<'tcx>
{
if let InferTables::InProgress(tables) = self.tables {
- if let Some(id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
if let Some(ty) = tables.borrow().closure_tys.get(&id) {
return ty.subst(self.tcx, substs.substs);
}
/// items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'tcx> {
- hir_visit::NestedVisitorMap::All(&self.tcx.map)
+ hir_visit::NestedVisitorMap::All(&self.tcx.hir)
}
// Output any lints that were previously added to the session.
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
- let body = self.tcx.map.body(body);
+ let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
// in order for `check_fn` to be able to use them.
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body_id);
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
run_lints!(self, check_fn, late_passes, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body_id, span, id);
run_lints!(self, check_fn_post, late_passes, fk, decl, body, span, id);
access_levels: &AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck);
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
// We want to own the lint store, so move it out of the session.
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(), LintStore::new());
for early_lint in v {
span_bug!(early_lint.diagnostic.span.clone(),
"unprocessed lint {:?} at {}",
- early_lint, tcx.map.node_to_string(*id));
+ early_lint, tcx.hir.node_to_string(*id));
}
}
impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> {
fn nested(&self, state: &mut pprust::State, nested: pprust::Nested) -> io::Result<()> {
- pprust::PpAnn::nested(&self.tcx.map, state, nested)
+ pprust::PpAnn::nested(&self.tcx.hir, state, nested)
}
fn pre(&self,
ps: &mut pprust::State,
// from live codes are live, and everything else is dead.
use dep_graph::DepNode;
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir::{self, PatKind};
use hir::intravisit::{self, Visitor, NestedVisitorMap};
use hir::itemlikevisit::ItemLikeVisitor;
// may need to be marked as live.
fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
node_id: ast::NodeId) -> bool {
- match tcx.map.find(node_id) {
- Some(ast_map::NodeItem(..)) |
- Some(ast_map::NodeImplItem(..)) |
- Some(ast_map::NodeForeignItem(..)) |
- Some(ast_map::NodeTraitItem(..)) =>
+ match tcx.hir.find(node_id) {
+ Some(hir_map::NodeItem(..)) |
+ Some(hir_map::NodeImplItem(..)) |
+ Some(hir_map::NodeForeignItem(..)) |
+ Some(hir_map::NodeTraitItem(..)) =>
true,
_ =>
false
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
fn check_def_id(&mut self, def_id: DefId) {
- if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
if should_explore(self.tcx, node_id) {
self.worklist.push(node_id);
}
}
fn insert_def_id(&mut self, def_id: DefId) {
- if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
debug_assert!(!should_explore(self.tcx, node_id));
self.live_symbols.insert(node_id);
}
}
scanned.insert(id);
- if let Some(ref node) = self.tcx.map.find(id) {
+ if let Some(ref node) = self.tcx.hir.find(id) {
self.live_symbols.insert(id);
self.visit_node(node);
}
}
}
- fn visit_node(&mut self, node: &ast_map::Node<'tcx>) {
+ fn visit_node(&mut self, node: &hir_map::Node<'tcx>) {
let had_extern_repr = self.struct_has_extern_repr;
self.struct_has_extern_repr = false;
let had_inherited_pub_visibility = self.inherited_pub_visibility;
self.inherited_pub_visibility = false;
match *node {
- ast_map::NodeItem(item) => {
+ hir_map::NodeItem(item) => {
match item.node {
hir::ItemStruct(..) | hir::ItemUnion(..) => {
self.struct_has_extern_repr = item.attrs.iter().any(|attr| {
_ => ()
}
}
- ast_map::NodeTraitItem(trait_item) => {
+ hir_map::NodeTraitItem(trait_item) => {
intravisit::walk_trait_item(self, trait_item);
}
- ast_map::NodeImplItem(impl_item) => {
+ hir_map::NodeImplItem(impl_item) => {
intravisit::walk_impl_item(self, impl_item);
}
- ast_map::NodeForeignItem(foreign_item) => {
+ hir_map::NodeForeignItem(foreign_item) => {
intravisit::walk_foreign_item(self, &foreign_item);
}
_ => ()
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
- let body = self.tcx.map.body(body);
+ let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
}
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
- let field_type = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
+ let field_type = self.tcx.item_type(self.tcx.hir.local_def_id(field.id));
let is_marker_field = match field_type.ty_to_def_id() {
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
_ => false
// method of a private type is used, but the type itself is never
// called directly.
if let Some(impl_list) =
- self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
+ self.tcx.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) {
for &impl_did in impl_list.iter() {
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
- if let Some(item_node_id) = self.tcx.map.as_local_node_id(item_did) {
+ if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
if self.live_symbols.contains(&item_node_id) {
return true;
}
/// an error. We could do this also by checking the parents, but
/// this is how the code is setup and it seems harmless enough.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.map)
+ NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &privacy::AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::DeadCheck);
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
let live_symbols = find_live(tcx, access_levels, krate);
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };
intravisit::walk_crate(&mut visitor, krate);
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
- let body = self.tcx.map.body(body);
+ let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
if let Def::Static(def_id, mutbl) = path.def {
if mutbl {
self.require_unsafe(expr.span, "use of mutable static");
- } else if match self.tcx.map.get_if_local(def_id) {
+ } else if match self.tcx.hir.get_if_local(def_id) {
Some(hir::map::NodeForeignItem(..)) => true,
Some(..) => false,
None => self.tcx.sess.cstore.is_foreign_item(def_id),
unsafe_context: UnsafeContext::new(SafeContext),
};
- tcx.map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
+ tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
}
use dep_graph::DepNode;
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir::def_id::{CRATE_DEF_INDEX};
use session::{config, Session};
use syntax::ast::NodeId;
struct EntryContext<'a, 'tcx: 'a> {
session: &'a Session,
- map: &'a ast_map::Map<'tcx>,
+ map: &'a hir_map::Map<'tcx>,
// The top-level function called 'main'
main_fn: Option<(NodeId, Span)>,
}
}
-pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
- let _task = ast_map.dep_graph.in_task(DepNode::EntryPoint);
+pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) {
+ let _task = hir_map.dep_graph.in_task(DepNode::EntryPoint);
let any_exe = session.crate_types.borrow().iter().any(|ty| {
*ty == config::CrateTypeExecutable
}
// If the user wants no main function at all, then stop here.
- if attr::contains_name(&ast_map.krate().attrs, "no_main") {
+ if attr::contains_name(&hir_map.krate().attrs, "no_main") {
session.entry_type.set(Some(config::EntryNone));
return
}
let mut ctxt = EntryContext {
session: session,
- map: ast_map,
+ map: hir_map,
main_fn: None,
attr_main_fn: None,
start_fn: None,
non_main_fns: Vec::new(),
};
- ast_map.krate().visit_all_item_likes(&mut ctxt);
+ hir_map.krate().visit_all_item_likes(&mut ctxt);
configure_main(&mut ctxt);
}
self.tcx().with_freevars(closure_expr.id, |freevars| {
for freevar in freevars {
let def_id = freevar.def.def_id();
- let id_var = self.tcx().map.as_local_node_id(def_id).unwrap();
+ let id_var = self.tcx().hir.as_local_node_id(def_id).unwrap();
let upvar_id = ty::UpvarId { var_id: id_var,
closure_expr_id: closure_expr.id };
let upvar_capture = self.mc.infcx.upvar_capture(upvar_id).unwrap();
-> mc::McResult<mc::cmt<'tcx>> {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
- let var_id = self.tcx().map.as_local_node_id(upvar_def.def_id()).unwrap();
+ let var_id = self.tcx().hir.as_local_node_id(upvar_def.def_id()).unwrap();
let var_ty = self.mc.infcx.node_ty(var_id)?;
self.mc.cat_def(closure_id, closure_span, var_ty, upvar_def)
}
}
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
self.tcx.infer_ctxt(body_id, Reveal::All).enter(|infcx| {
let mut visitor = ExprVisitor {
infcx: &infcx
struct LanguageItemCollector<'a, 'tcx: 'a> {
items: LanguageItems,
- ast_map: &'a hir_map::Map<'tcx>,
+ hir_map: &'a hir_map::Map<'tcx>,
session: &'a Session,
let item_index = self.item_refs.get(&*value.as_str()).cloned();
if let Some(item_index) = item_index {
- self.collect_item(item_index, self.ast_map.local_def_id(item.id))
+ self.collect_item(item_index, self.hir_map.local_def_id(item.id))
} else {
- let span = self.ast_map.span(item.id);
+ let span = self.hir_map.span(item.id);
span_err!(self.session, span, E0522,
"definition of an unknown language item: `{}`.",
value);
}
impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
- pub fn new(session: &'a Session, ast_map: &'a hir_map::Map<'tcx>)
+ pub fn new(session: &'a Session, hir_map: &'a hir_map::Map<'tcx>)
-> LanguageItemCollector<'a, 'tcx> {
let mut item_refs = FxHashMap();
LanguageItemCollector {
session: session,
- ast_map: ast_map,
+ hir_map: hir_map,
items: LanguageItems::new(),
item_refs: item_refs,
}
Some(original_def_id) if original_def_id != item_def_id => {
let cstore = &self.session.cstore;
let name = LanguageItems::item_name(item_index);
- let mut err = match self.ast_map.span_if_local(item_def_id) {
+ let mut err = match self.hir_map.span_if_local(item_def_id) {
Some(span) => struct_span_err!(
self.session,
span,
cstore.crate_name(item_def_id.krate),
name)),
};
- if let Some(span) = self.ast_map.span_if_local(original_def_id) {
+ if let Some(span) = self.hir_map.span_if_local(original_def_id) {
span_note!(&mut err, span,
"first defined here.");
} else {
impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let _task = tcx.dep_graph.in_task(DepNode::Liveness);
- tcx.map.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor());
+ tcx.hir.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor());
tcx.sess.abort_if_errors();
}
debug!("creating fn_maps: {:?}", &fn_maps as *const IrMaps);
- let body = ir.tcx.map.body(body_id);
+ let body = ir.tcx.hir.body(body_id);
for arg in &body.arguments {
arg.pat.each_binding(|_bm, arg_id, _x, path1| {
ir.tcx.with_freevars(expr.id, |freevars| {
for fv in freevars {
if let Def::Local(def_id) = fv.def {
- let rv = ir.tcx.map.as_local_node_id(def_id).unwrap();
+ let rv = ir.tcx.hir.as_local_node_id(def_id).unwrap();
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
call_caps.push(CaptureInfo {ln: fv_ln,
var_nid: rv});
// effectively a return---this only occurs in `for` loops,
// where the body is really a closure.
- debug!("compute: using id for body, {}", self.ir.tcx.map.node_to_pretty_string(body.id));
+ debug!("compute: using id for body, {}", self.ir.tcx.hir.node_to_pretty_string(body.id));
let exit_ln = self.s.exit_ln;
let entry_ln: LiveNode = self.with_loop_nodes(body.id, exit_ln, exit_ln, |this| {
fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
-> LiveNode {
- debug!("propagate_through_expr: {}", self.ir.tcx.map.node_to_pretty_string(expr.id));
+ debug!("propagate_through_expr: {}", self.ir.tcx.hir.node_to_pretty_string(expr.id));
match expr.node {
// Interesting cases with control flow or which gen/kill
hir::ExprClosure(.., blk_id, _) => {
debug!("{} is an ExprClosure",
- self.ir.tcx.map.node_to_pretty_string(expr.id));
+ self.ir.tcx.hir.node_to_pretty_string(expr.id));
/*
The next-node for a break is the successor of the entire
-> LiveNode {
match path.def {
Def::Local(def_id) => {
- let nid = self.ir.tcx.map.as_local_node_id(def_id).unwrap();
+ let nid = self.ir.tcx.hir.as_local_node_id(def_id).unwrap();
let ln = self.live_node(id, path.span);
if acc != 0 {
self.init_from_succ(ln, succ);
}
}
debug!("propagate_through_loop: using id for loop body {} {}",
- expr.id, self.ir.tcx.map.node_to_pretty_string(body.id));
+ expr.id, self.ir.tcx.hir.node_to_pretty_string(body.id));
let cond_ln = match kind {
LoopLoop => ln,
entry_ln: LiveNode,
body: &hir::Body)
{
- let fn_ty = self.ir.tcx.item_type(self.ir.tcx.map.local_def_id(id));
+ let fn_ty = self.ir.tcx.item_type(self.ir.tcx.hir.local_def_id(id));
let fn_ret = match fn_ty.sty {
ty::TyClosure(closure_def_id, substs) =>
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
// if there is no later assignment. If this local is actually
// mutable, then check for a reassignment to flag the mutability
// as being used.
- let nid = self.ir.tcx.map.as_local_node_id(def_id).unwrap();
+ let nid = self.ir.tcx.hir.as_local_node_id(def_id).unwrap();
let ln = self.live_node(expr.id, expr.span);
let var = self.variable(nid, expr.span);
self.warn_about_dead_assign(expr.span, expr.id, ln, var);
use self::Aliasability::*;
use hir::def_id::DefId;
-use hir::map as ast_map;
+use hir::map as hir_map;
use infer::InferCtxt;
use hir::def::{Def, CtorKind};
use ty::adjustment;
}
fn from_local(tcx: TyCtxt, id: ast::NodeId) -> MutabilityCategory {
- let ret = match tcx.map.get(id) {
- ast_map::NodeLocal(p) => match p.node {
+ let ret = match tcx.hir.get(id) {
+ hir_map::NodeLocal(p) => match p.node {
PatKind::Binding(bind_mode, ..) => {
if bind_mode == hir::BindByValue(hir::MutMutable) {
McDeclared
}
_ => span_bug!(p.span, "expected identifier pattern")
},
- _ => span_bug!(tcx.map.span(id), "expected identifier pattern")
+ _ => span_bug!(tcx.hir.span(id), "expected identifier pattern")
};
debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}",
"from_local", id, ret);
}
Def::Upvar(def_id, _, fn_node_id) => {
- let var_id = self.tcx().map.as_local_node_id(def_id).unwrap();
+ let var_id = self.tcx().hir.as_local_node_id(def_id).unwrap();
let ty = self.node_ty(fn_node_id)?;
match ty.sty {
ty::TyClosure(closure_id, _) => {
}
Def::Local(def_id) => {
- let vid = self.tcx().map.as_local_node_id(def_id).unwrap();
+ let vid = self.tcx().hir.as_local_node_id(def_id).unwrap();
Ok(Rc::new(cmt_ {
id: id,
span: span,
// Look up the node ID of the closure body so we can construct
// a free region within it
let fn_body_id = {
- let fn_expr = match self.tcx().map.find(upvar_id.closure_expr_id) {
- Some(ast_map::NodeExpr(e)) => e,
+ let fn_expr = match self.tcx().hir.find(upvar_id.closure_expr_id) {
+ Some(hir_map::NodeExpr(e)) => e,
_ => bug!()
};
"non-lvalue".to_string()
}
Categorization::Local(vid) => {
- if tcx.map.is_argument(vid) {
+ if tcx.hir.is_argument(vid) {
"argument".to_string()
} else {
"local variable".to_string()
// reachable as well.
use dep_graph::DepNode;
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir::def::Def;
use hir::def_id::DefId;
use ty::{self, TyCtxt};
generics_require_inlining(&sig.generics) {
return true
}
- if let Some(impl_node_id) = tcx.map.as_local_node_id(impl_src) {
- match tcx.map.find(impl_node_id) {
- Some(ast_map::NodeItem(item)) =>
+ if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) {
+ match tcx.hir.find(impl_node_id) {
+ Some(hir_map::NodeItem(item)) =>
item_might_be_inlined(&item),
Some(..) | None =>
span_bug!(impl_item.span, "impl did is not an item")
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
- let body = self.tcx.map.body(body);
+ let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
if let Some(def) = def {
let def_id = def.def_id();
- if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
if self.def_id_represents_local_inlined_item(def_id) {
self.worklist.push(node_id);
} else {
// Returns true if the given def ID represents a local item that is
// eligible for inlining and false otherwise.
fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
- let node_id = match self.tcx.map.as_local_node_id(def_id) {
+ let node_id = match self.tcx.hir.as_local_node_id(def_id) {
Some(node_id) => node_id,
None => { return false; }
};
- match self.tcx.map.find(node_id) {
- Some(ast_map::NodeItem(item)) => {
+ match self.tcx.hir.find(node_id) {
+ Some(hir_map::NodeItem(item)) => {
match item.node {
hir::ItemFn(..) => item_might_be_inlined(&item),
_ => false,
}
}
- Some(ast_map::NodeTraitItem(trait_method)) => {
+ Some(hir_map::NodeTraitItem(trait_method)) => {
match trait_method.node {
hir::TraitItemKind::Const(_, ref default) => default.is_some(),
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Type(..) => false,
}
}
- Some(ast_map::NodeImplItem(impl_item)) => {
+ Some(hir_map::NodeImplItem(impl_item)) => {
match impl_item.node {
hir::ImplItemKind::Const(..) => true,
hir::ImplItemKind::Method(ref sig, _) => {
true
} else {
let impl_did = self.tcx
- .map
+ .hir
.get_parent_did(node_id);
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
// does too.
- let impl_node_id = self.tcx.map.as_local_node_id(impl_did).unwrap();
- match self.tcx.map.expect_item(impl_node_id).node {
+ let impl_node_id = self.tcx.hir.as_local_node_id(impl_did).unwrap();
+ match self.tcx.hir.expect_item(impl_node_id).node {
hir::ItemImpl(_, _, ref generics, ..) => {
generics_require_inlining(generics)
}
continue
}
- if let Some(ref item) = self.tcx.map.find(search_item) {
+ if let Some(ref item) = self.tcx.hir.find(search_item) {
self.propagate_node(item, search_item);
}
}
}
- fn propagate_node(&mut self, node: &ast_map::Node<'tcx>,
+ fn propagate_node(&mut self, node: &hir_map::Node<'tcx>,
search_item: ast::NodeId) {
if !self.any_library {
// If we are building an executable, only explicitly extern
// types need to be exported.
- if let ast_map::NodeItem(item) = *node {
+ if let hir_map::NodeItem(item) = *node {
let reachable = if let hir::ItemFn(.., abi, _, _) = item.node {
abi != Abi::Rust
} else {
}
match *node {
- ast_map::NodeItem(item) => {
+ hir_map::NodeItem(item) => {
match item.node {
hir::ItemFn(.., body) => {
if item_might_be_inlined(&item) {
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) => {}
}
}
- ast_map::NodeTraitItem(trait_method) => {
+ hir_map::NodeTraitItem(trait_method) => {
match trait_method.node {
hir::TraitItemKind::Const(_, None) |
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
hir::TraitItemKind::Type(..) => {}
}
}
- ast_map::NodeImplItem(impl_item) => {
+ hir_map::NodeImplItem(impl_item) => {
match impl_item.node {
hir::ImplItemKind::Const(_, body) => {
self.visit_nested_body(body);
}
hir::ImplItemKind::Method(ref sig, body) => {
- let did = self.tcx.map.get_parent_did(search_item);
+ let did = self.tcx.hir.get_parent_did(search_item);
if method_might_be_inlined(self.tcx, sig, impl_item, did) {
self.visit_nested_body(body)
}
}
}
// Nothing to recurse on for these
- ast_map::NodeForeignItem(_) |
- ast_map::NodeVariant(_) |
- ast_map::NodeStructCtor(_) |
- ast_map::NodeField(_) |
- ast_map::NodeTy(_) => {}
+ hir_map::NodeForeignItem(_) |
+ hir_map::NodeVariant(_) |
+ hir_map::NodeStructCtor(_) |
+ hir_map::NodeField(_) |
+ hir_map::NodeTy(_) => {}
_ => {
bug!("found unexpected thingy in worklist: {}",
- self.tcx.map.node_to_string(search_item))
+ self.tcx.hir.node_to_string(search_item))
}
}
}
for default_method in self.tcx.provided_trait_methods(trait_def_id) {
let node_id = self.tcx
- .map
+ .hir
.as_local_node_id(default_method.def_id)
.unwrap();
self.worklist.push(node_id);
}
for item in tcx.lang_items.items().iter() {
if let Some(did) = *item {
- if let Some(node_id) = tcx.map.as_local_node_id(did) {
+ if let Some(node_id) = tcx.hir.as_local_node_id(did) {
reachable_context.worklist.push(node_id);
}
}
access_levels: access_levels,
worklist: &mut reachable_context.worklist,
};
- tcx.map.krate().visit_all_item_likes(&mut collect_private_impl_items);
+ tcx.hir.krate().visit_all_item_likes(&mut collect_private_impl_items);
}
// Step 2: Mark all symbols that the symbols on the worklist touch.
//! `middle/infer/region_inference/README.md`
use dep_graph::DepNode;
-use hir::map as ast_map;
+use hir::map as hir_map;
use session::Session;
use util::nodemap::{FxHashMap, NodeMap, NodeSet};
use ty;
/// Returns the span of this CodeExtent. Note that in general the
/// returned span may not correspond to the span of any node id in
/// the AST.
- pub fn span(&self, region_maps: &RegionMaps, ast_map: &ast_map::Map) -> Option<Span> {
- match ast_map.find(self.node_id(region_maps)) {
- Some(ast_map::NodeBlock(ref blk)) => {
+ pub fn span(&self, region_maps: &RegionMaps, hir_map: &hir_map::Map) -> Option<Span> {
+ match hir_map.find(self.node_id(region_maps)) {
+ Some(hir_map::NodeBlock(ref blk)) => {
match region_maps.code_extent_data(*self) {
CodeExtentData::CallSiteScope { .. } |
CodeExtentData::ParameterScope { .. } |
}
}
}
- Some(ast_map::NodeExpr(ref expr)) => Some(expr.span),
- Some(ast_map::NodeStmt(ref stmt)) => Some(stmt.span),
- Some(ast_map::NodeItem(ref item)) => Some(item.span),
+ Some(hir_map::NodeExpr(ref expr)) => Some(expr.span),
+ Some(hir_map::NodeStmt(ref stmt)) => Some(stmt.span),
+ Some(hir_map::NodeItem(ref item)) => Some(item.span),
Some(_) | None => None,
}
}
parent: CodeExtent
}
-struct RegionResolutionVisitor<'ast: 'a, 'a> {
+struct RegionResolutionVisitor<'hir: 'a, 'a> {
sess: &'a Session,
// Generated maps:
cx: Context,
- map: &'a ast_map::Map<'ast>,
+ map: &'a hir_map::Map<'hir>,
/// `terminating_scopes` is a set containing the ids of each
/// statement, or conditional/repeating expression. These scopes
visitor.terminating_scopes = outer_ts;
}
-impl<'ast, 'a> RegionResolutionVisitor<'ast, 'a> {
+impl<'hir, 'a> RegionResolutionVisitor<'hir, 'a> {
/// Records the current parent (if any) as the parent of `child_scope`.
fn new_code_extent(&mut self, child_scope: CodeExtentData) -> CodeExtent {
self.region_maps.intern_code_extent(child_scope, self.cx.parent)
}
}
-impl<'ast, 'a> Visitor<'ast> for RegionResolutionVisitor<'ast, 'a> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
+impl<'hir, 'a> Visitor<'hir> for RegionResolutionVisitor<'hir, 'a> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
NestedVisitorMap::OnlyBodies(&self.map)
}
- fn visit_block(&mut self, b: &'ast Block) {
+ fn visit_block(&mut self, b: &'hir Block) {
resolve_block(self, b);
}
- fn visit_item(&mut self, i: &'ast Item) {
+ fn visit_item(&mut self, i: &'hir Item) {
resolve_item_like(self, i.id, |this| intravisit::walk_item(this, i));
}
- fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
+ fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) {
resolve_item_like(self, ii.id, |this| intravisit::walk_impl_item(this, ii));
}
- fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
+ fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) {
resolve_item_like(self, ti.id, |this| intravisit::walk_trait_item(this, ti));
}
- fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl,
+ fn visit_fn(&mut self, fk: FnKind<'hir>, fd: &'hir FnDecl,
b: hir::BodyId, s: Span, n: NodeId) {
resolve_fn(self, fk, fd, b, s, n);
}
- fn visit_arm(&mut self, a: &'ast Arm) {
+ fn visit_arm(&mut self, a: &'hir Arm) {
resolve_arm(self, a);
}
- fn visit_pat(&mut self, p: &'ast Pat) {
+ fn visit_pat(&mut self, p: &'hir Pat) {
resolve_pat(self, p);
}
- fn visit_stmt(&mut self, s: &'ast Stmt) {
+ fn visit_stmt(&mut self, s: &'hir Stmt) {
resolve_stmt(self, s);
}
- fn visit_expr(&mut self, ex: &'ast Expr) {
+ fn visit_expr(&mut self, ex: &'hir Expr) {
resolve_expr(self, ex);
}
- fn visit_local(&mut self, l: &'ast Local) {
+ fn visit_local(&mut self, l: &'hir Local) {
resolve_local(self, l);
}
}
-pub fn resolve_crate(sess: &Session, map: &ast_map::Map) -> RegionMaps {
+pub fn resolve_crate(sess: &Session, map: &hir_map::Map) -> RegionMaps {
let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate);
let krate = map.krate();
}
}
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
self.index.stab_map.insert(def_id, Some(stab));
let orig_parent_stab = replace(&mut self.parent_stab, Some(stab));
debug!("annotate: not found, parent = {:?}", self.parent_stab);
if let Some(stab) = self.parent_stab {
if stab.level.is_unstable() {
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
self.index.stab_map.insert(def_id, Some(stab));
}
}
}
// `Deprecation` is just two pointers, no need to intern it
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
let depr_entry = Some(DeprecationEntry::local(depr, def_id));
self.index.depr_map.insert(def_id, depr_entry.clone());
visit_children(self);
self.parent_depr = orig_parent_depr;
} else if let parent_depr @ Some(_) = self.parent_depr.clone() {
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
self.index.depr_map.insert(def_id, parent_depr);
visit_children(self);
} else {
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.map)
+ NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_item(&mut self, i: &'tcx Item) {
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
fn check_missing_stability(&self, id: NodeId, span: Span) {
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
let is_error = !self.tcx.sess.opts.test &&
!self.tcx.stability.borrow().stab_map.contains_key(&def_id) &&
self.access_levels.is_reachable(id);
impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_item(&mut self, i: &'tcx Item) {
}
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
- let impl_def_id = self.tcx.map.local_def_id(self.tcx.map.get_parent(ii.id));
+ let impl_def_id = self.tcx.hir.local_def_id(self.tcx.hir.get_parent(ii.id));
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
self.check_missing_stability(ii.id, ii.span);
}
self.active_features = active_lib_features.iter().map(|&(ref s, _)| s.clone()).collect();
let _task = tcx.dep_graph.in_task(DepNode::StabilityIndex);
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
let mut annotator = Annotator {
tcx: tcx,
index: self,
let skip = if id == ast::DUMMY_NODE_ID {
true
} else {
- let parent_def_id = self.map.local_def_id(self.map.get_parent(id));
+ let parent_def_id = self.hir.local_def_id(self.hir.get_parent(id));
self.lookup_deprecation_entry(parent_def_id).map_or(false, |parent_depr| {
parent_depr.same_origin(&depr_entry)
})
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
hir::ItemImpl(.., Some(ref t), _, ref impl_item_refs) => {
if let Def::Trait(trait_did) = t.path.def {
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
let trait_item_def_id = self.tcx.associated_items(trait_did)
.find(|item| item.name == impl_item.name).map(|item| item.def_id);
if let Some(def_id) = trait_item_def_id {
if tcx.stability.borrow().staged_api[&LOCAL_CRATE] && tcx.sess.features.borrow().staged_api {
let _task = tcx.dep_graph.in_task(DepNode::StabilityIndex);
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
let mut missing = MissingStabilityAnnotations {
tcx: tcx,
access_levels: access_levels,
}
AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
- if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
- let name = format!("[closure@{:?}]", tcx.map.span(node_id));
+ if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+ let name = format!("[closure@{:?}]", tcx.hir.span(node_id));
let mut struct_fmt = fmt.debug_struct(&name);
tcx.with_freevars(node_id, |freevars| {
for (freevar, lv) in freevars.iter().zip(lvs) {
let def_id = freevar.def.def_id();
- let var_id = tcx.map.as_local_node_id(def_id).unwrap();
+ let var_id = tcx.hir.as_local_node_id(def_id).unwrap();
let var_name = tcx.local_var_name_str(var_id);
struct_fmt.field(&var_name, lv);
}
use hir::*;
// Handle constants in enum discriminants, types, and repeat expressions.
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
let def_key = tcx.def_key(def_id);
if def_key.disambiguated_data.data == DefPathData::Initializer {
return MirSource::Const(id);
}
- match tcx.map.get(id) {
+ match tcx.hir.get(id) {
map::NodeItem(&Item { node: ItemConst(..), .. }) |
map::NodeTraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
map::NodeImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) => {
let mir = &mut tcx.mir_map.borrow()[&def_id].borrow_mut();
tcx.dep_graph.write(DepNode::Mir(def_id));
- let id = tcx.map.as_local_node_id(def_id).unwrap();
+ let id = tcx.hir.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);
for hook in &mut *hooks {
E0276,
"impl has stricter requirements than trait");
- if let Some(trait_item_span) = self.tcx.map.span_if_local(trait_item_def_id) {
+ if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
err.span_label(trait_item_span,
&format!("definition of `{}` from trait", item_name));
}
ty::Predicate::ClosureKind(closure_def_id, kind) => {
let found_kind = self.closure_kind(closure_def_id).unwrap();
- let closure_span = self.tcx.map.span_if_local(closure_def_id).unwrap();
+ let closure_span = self.tcx.hir.span_if_local(closure_def_id).unwrap();
let mut err = struct_span_err!(
self.tcx.sess, closure_span, E0525,
"expected a closure that implements the `{}` trait, \
-> DiagnosticBuilder<'tcx>
{
assert!(type_def_id.is_local());
- let span = self.map.span_if_local(type_def_id).unwrap();
+ let span = self.hir.span_if_local(type_def_id).unwrap();
let mut err = struct_span_err!(self.sess, span, E0072,
"recursive type `{}` has infinite size",
self.item_path_str(type_def_id));
use hir::TraitMap;
use hir::def::Def;
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
-use hir::map as ast_map;
+use hir::map as hir_map;
use hir::map::DisambiguatedDefPathData;
use middle::free_region::FreeRegionMap;
use middle::region::RegionMaps;
Some(ty) => ty,
None => {
bug!("node_id_to_type: no type for node `{}`",
- tls::with(|tcx| tcx.map.node_to_string(id)))
+ tls::with(|tcx| tcx.hir.node_to_string(id)))
}
}
}
/// additional acyclicity requirements).
pub super_predicates: RefCell<DepTrackingMap<maps::Predicates<'tcx>>>,
- pub map: ast_map::Map<'tcx>,
+ pub hir: hir_map::Map<'tcx>,
/// Maps from the def-id of a function/method or const/static
/// to its MIR. Mutation is done at an item granularity to
debug!("retrace_path(path={:?}, krate={:?})", path_data, self.crate_name(krate));
if krate == LOCAL_CRATE {
- self.map
+ self.hir
.definitions()
.def_path_table()
.retrace_path(path_data)
arena: &'tcx DroplessArena,
resolutions: ty::Resolutions,
named_region_map: resolve_lifetime::NamedRegionMap,
- map: ast_map::Map<'tcx>,
+ hir: hir_map::Map<'tcx>,
region_maps: RegionMaps,
lang_items: middle::lang_items::LanguageItems,
stability: stability::Index<'tcx>,
let data_layout = TargetDataLayout::parse(s);
let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(&interners);
- let dep_graph = map.dep_graph.clone();
+ let dep_graph = hir.dep_graph.clone();
let fulfilled_predicates = traits::GlobalFulfilledPredicates::new(dep_graph.clone());
tls::enter_global(GlobalCtxt {
specializes_cache: RefCell::new(traits::SpecializesCache::new()),
predicates: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
super_predicates: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
fulfilled_predicates: RefCell::new(fulfilled_predicates),
- map: map,
+ hir: hir,
mir_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
freevars: RefCell::new(resolutions.freevars),
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
expected.ty,
found.ty));
- match self.map.span_if_local(expected.def_id) {
+ match self.hir.span_if_local(expected.def_id) {
Some(span) => {
db.span_note(span, "a default was defined here...");
}
expected.origin_span,
"...that was applied to an unconstrained type variable here");
- match self.map.span_if_local(found.def_id) {
+ match self.hir.span_if_local(found.def_id) {
Some(span) => {
db.span_note(span, "a second default was defined here...");
}
/// crate.
#[inline]
pub fn full(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForest {
- let crate_id = tcx.map.local_def_id(CRATE_NODE_ID);
+ let crate_id = tcx.hir.local_def_id(CRATE_NODE_ID);
DefIdForest::from_id(crate_id)
}
/// Returns a string identifying this local node-id.
pub fn node_path_str(self, id: ast::NodeId) -> String {
- self.item_path_str(self.map.local_def_id(id))
+ self.item_path_str(self.hir.local_def_id(id))
}
/// Returns a string identifying this def-id. This string is
// only occur very early in the compiler pipeline.
let parent_def_id = self.parent_def_id(impl_def_id).unwrap();
self.push_item_path(buffer, parent_def_id);
- let node_id = self.map.as_local_node_id(impl_def_id).unwrap();
- let item = self.map.expect_item(node_id);
+ let node_id = self.hir.as_local_node_id(impl_def_id).unwrap();
+ let item = self.hir.expect_item(node_id);
let span_str = self.sess.codemap().span_to_string(item.span);
buffer.push(&format!("<impl at {}>", span_str));
}
pub use self::fold::TypeFoldable;
use dep_graph::{self, DepNode};
-use hir::{map as ast_map, FreevarMap, TraitMap};
+use hir::{map as hir_map, FreevarMap, TraitMap};
use middle;
use hir::def::{Def, CtorKind, ExportMap};
use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
def => Visibility::Restricted(def.def_id()),
},
hir::Inherited => {
- Visibility::Restricted(tcx.map.local_def_id(tcx.map.get_module_parent(id)))
+ Visibility::Restricted(tcx.hir.local_def_id(tcx.hir.get_module_parent(id)))
}
}
}
/// Construct a parameter environment given an item, impl item, or trait item
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
-> ParameterEnvironment<'tcx> {
- match tcx.map.find(id) {
- Some(ast_map::NodeImplItem(ref impl_item)) => {
+ match tcx.hir.find(id) {
+ Some(hir_map::NodeImplItem(ref impl_item)) => {
match impl_item.node {
hir::ImplItemKind::Type(_) | hir::ImplItemKind::Const(..) => {
// associated types don't have their own entry (for some reason),
// so for now just grab environment for the impl
- let impl_id = tcx.map.get_parent(id);
- let impl_def_id = tcx.map.local_def_id(impl_id);
+ let impl_id = tcx.hir.get_parent(id);
+ let impl_def_id = tcx.hir.local_def_id(impl_id);
tcx.construct_parameter_environment(impl_item.span,
impl_def_id,
tcx.region_maps.item_extent(id))
hir::ImplItemKind::Method(_, ref body) => {
tcx.construct_parameter_environment(
impl_item.span,
- tcx.map.local_def_id(id),
+ tcx.hir.local_def_id(id),
tcx.region_maps.call_site_extent(id, body.node_id))
}
}
}
- Some(ast_map::NodeTraitItem(trait_item)) => {
+ Some(hir_map::NodeTraitItem(trait_item)) => {
match trait_item.node {
hir::TraitItemKind::Type(..) | hir::TraitItemKind::Const(..) => {
// associated types don't have their own entry (for some reason),
// so for now just grab environment for the trait
- let trait_id = tcx.map.get_parent(id);
- let trait_def_id = tcx.map.local_def_id(trait_id);
+ let trait_id = tcx.hir.get_parent(id);
+ let trait_def_id = tcx.hir.local_def_id(trait_id);
tcx.construct_parameter_environment(trait_item.span,
trait_def_id,
tcx.region_maps.item_extent(id))
};
tcx.construct_parameter_environment(
trait_item.span,
- tcx.map.local_def_id(id),
+ tcx.hir.local_def_id(id),
extent)
}
}
}
- Some(ast_map::NodeItem(item)) => {
+ Some(hir_map::NodeItem(item)) => {
match item.node {
hir::ItemFn(.., body_id) => {
// We assume this is a function.
- let fn_def_id = tcx.map.local_def_id(id);
+ let fn_def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(
item.span,
hir::ItemImpl(..) |
hir::ItemConst(..) |
hir::ItemStatic(..) => {
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(item.span,
def_id,
tcx.region_maps.item_extent(id))
}
hir::ItemTrait(..) => {
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(item.span,
def_id,
tcx.region_maps.item_extent(id))
}
}
}
- Some(ast_map::NodeExpr(expr)) => {
+ Some(hir_map::NodeExpr(expr)) => {
// This is a convenience to allow closures to work.
if let hir::ExprClosure(.., body, _) = expr.node {
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
let base_def_id = tcx.closure_base_def_id(def_id);
tcx.construct_parameter_environment(
expr.span,
tcx.empty_parameter_environment()
}
}
- Some(ast_map::NodeForeignItem(item)) => {
- let def_id = tcx.map.local_def_id(id);
+ Some(hir_map::NodeForeignItem(item)) => {
+ let def_id = tcx.hir.local_def_id(id);
tcx.construct_parameter_environment(item.span,
def_id,
ROOT_CODE_EXTENT)
_ => {
bug!("ParameterEnvironment::from_item(): \
`{}` is not an item",
- tcx.map.node_to_string(id))
+ tcx.hir.node_to_string(id))
}
}
}
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn body_tables(self, body: hir::BodyId) -> &'gcx TypeckTables<'gcx> {
- self.item_tables(self.map.body_owner_def_id(body))
+ self.item_tables(self.hir.body_owner_def_id(body))
}
pub fn item_tables(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> {
}
pub fn expr_span(self, id: NodeId) -> Span {
- match self.map.find(id) {
- Some(ast_map::NodeExpr(e)) => {
+ match self.hir.find(id) {
+ Some(hir_map::NodeExpr(e)) => {
e.span
}
Some(f) => {
}
pub fn local_var_name_str(self, id: NodeId) -> InternedString {
- match self.map.find(id) {
- Some(ast_map::NodeLocal(pat)) => {
+ match self.hir.find(id) {
+ Some(hir_map::NodeLocal(pat)) => {
match pat.node {
hir::PatKind::Binding(_, _, ref path1, _) => path1.node.as_str(),
_ => {
}
pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity {
- if let Some(id) = self.map.as_local_node_id(id) {
- match self.map.expect_item(id).node {
+ if let Some(id) = self.hir.as_local_node_id(id) {
+ match self.hir.expect_item(id).node {
hir::ItemImpl(_, polarity, ..) => polarity,
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
}
// those tasks that just need to scan the names of items
// and so forth.
- let id = self.map.as_local_node_id(def_id).unwrap();
- let parent_id = self.map.get_parent(id);
- let parent_def_id = self.map.local_def_id(parent_id);
- let parent_item = self.map.expect_item(parent_id);
+ let id = self.hir.as_local_node_id(def_id).unwrap();
+ let parent_id = self.hir.get_parent(id);
+ let parent_def_id = self.hir.local_def_id(parent_id);
+ let parent_item = self.hir.expect_item(parent_id);
match parent_item.node {
hir::ItemImpl(.., ref impl_trait_ref, _, ref impl_item_refs) => {
for impl_item_ref in impl_item_refs {
parent_def_id: DefId,
trait_item_ref: &hir::TraitItemRef)
-> AssociatedItem {
- let def_id = self.map.local_def_id(trait_item_ref.id.node_id);
+ let def_id = self.hir.local_def_id(trait_item_ref.id.node_id);
let (kind, has_self) = match trait_item_ref.kind {
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
hir::AssociatedItemKind::Method { has_self } => {
from_trait_impl: bool,
impl_item_ref: &hir::ImplItemRef)
-> AssociatedItem {
- let def_id = self.map.local_def_id(impl_item_ref.id.node_id);
+ let def_id = self.hir.local_def_id(impl_item_ref.id.node_id);
let (kind, has_self) = match impl_item_ref.kind {
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
hir::AssociatedItemKind::Method { has_self } => {
return Rc::new(self.sess.cstore.associated_item_def_ids(def_id));
}
- let id = self.map.as_local_node_id(def_id).unwrap();
- let item = self.map.expect_item(id);
+ let id = self.hir.as_local_node_id(def_id).unwrap();
+ let item = self.hir.expect_item(id);
let vec: Vec<_> = match item.node {
hir::ItemTrait(.., ref trait_item_refs) => {
trait_item_refs.iter()
.map(|trait_item_ref| trait_item_ref.id)
- .map(|id| self.map.local_def_id(id.node_id))
+ .map(|id| self.hir.local_def_id(id.node_id))
.collect()
}
hir::ItemImpl(.., ref impl_item_refs) => {
impl_item_refs.iter()
.map(|impl_item_ref| impl_item_ref.id)
- .map(|id| self.map.local_def_id(id.node_id))
+ .map(|id| self.hir.local_def_id(id.node_id))
.collect()
}
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
}
}
- pub fn def_key(self, id: DefId) -> ast_map::DefKey {
+ pub fn def_key(self, id: DefId) -> hir_map::DefKey {
if id.is_local() {
- self.map.def_key(id)
+ self.hir.def_key(id)
} else {
self.sess.cstore.def_key(id)
}
///
/// Note that if `id` is not local to this crate, the result will
// be a non-local `DefPath`.
- pub fn def_path(self, id: DefId) -> ast_map::DefPath {
+ pub fn def_path(self, id: DefId) -> hir_map::DefPath {
if id.is_local() {
- self.map.def_path(id)
+ self.hir.def_path(id)
} else {
self.sess.cstore.def_path(id)
}
}
pub fn def_span(self, def_id: DefId) -> Span {
- if let Some(id) = self.map.as_local_node_id(def_id) {
- self.map.span(id)
+ if let Some(id) = self.hir.as_local_node_id(def_id) {
+ self.hir.span(id)
} else {
self.sess.cstore.def_span(&self.sess, def_id)
}
}
pub fn vis_is_accessible_from(self, vis: Visibility, block: NodeId) -> bool {
- vis.is_accessible_from(self.map.local_def_id(self.map.get_module_parent(block)), self)
+ vis.is_accessible_from(self.hir.local_def_id(self.hir.get_module_parent(block)), self)
}
pub fn item_name(self, id: DefId) -> ast::Name {
- if let Some(id) = self.map.as_local_node_id(id) {
- self.map.name(id)
+ if let Some(id) = self.hir.as_local_node_id(id) {
+ self.hir.name(id)
} else if id.index == CRATE_DEF_INDEX {
self.sess.cstore.original_crate_name(id.krate)
} else {
let def_key = self.sess.cstore.def_key(id);
// The name of a StructCtor is that of its struct parent.
- if let ast_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
+ if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
self.item_name(DefId {
krate: id.krate,
index: def_key.parent.unwrap()
/// Get the attributes of a definition.
pub fn get_attrs(self, did: DefId) -> Cow<'gcx, [ast::Attribute]> {
- if let Some(id) = self.map.as_local_node_id(did) {
- Cow::Borrowed(self.map.attrs(id))
+ if let Some(id) = self.hir.as_local_node_id(did) {
+ Cow::Borrowed(self.hir.attrs(id))
} else {
Cow::Owned(self.sess.cstore.item_attrs(did))
}
/// with the name of the crate containing the impl.
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {
if impl_did.is_local() {
- let node_id = self.map.as_local_node_id(impl_did).unwrap();
- Ok(self.map.span(node_id))
+ let node_id = self.hir.as_local_node_id(impl_did).unwrap();
+ Ok(self.hir.span(node_id))
} else {
Err(self.sess.cstore.crate_name(impl_did.krate))
}
use hir::def_id::DefId;
use hir::map::DefPathData;
use infer::InferCtxt;
-use hir::map as ast_map;
+use hir::map as hir_map;
use traits::{self, Reveal};
use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable};
use ty::{Disr, ParameterEnvironment};
self.def_path(&path)
}
- pub fn def_path(&mut self, def_path: &ast_map::DefPath) {
+ pub fn def_path(&mut self, def_path: &hir_map::DefPath) {
def_path.deterministic_hash_to(self.tcx, &mut self.state);
}
}
ty::BrEnv => {
let name = Symbol::intern("'r");
let _ = write!(f, "{}", name);
- ty::BrNamed(tcx.map.local_def_id(CRATE_NODE_ID),
+ ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID),
name,
ty::Issue32330::WontChange)
}
let upvar_tys = substs.upvar_tys(did, tcx);
write!(f, "[closure")?;
- if let Some(node_id) = tcx.map.as_local_node_id(did) {
- write!(f, "@{:?}", tcx.map.span(node_id))?;
+ if let Some(node_id) = tcx.hir.as_local_node_id(did) {
+ write!(f, "@{:?}", tcx.hir.span(node_id))?;
let mut sep = " ";
tcx.with_freevars(node_id, |freevars| {
for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {
let def_id = freevar.def.def_id();
- let node_id = tcx.map.as_local_node_id(def_id).unwrap();
+ let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
write!(f,
"{}{}:{}",
sep,
// 3. Where does old loan expire.
let previous_end_span =
- self.tcx().map.span(old_loan.kill_scope.node_id(&self.tcx().region_maps))
+ self.tcx().hir.span(old_loan.kill_scope.node_id(&self.tcx().region_maps))
.end_point();
let mut err = match (new_loan.kind, old_loan.kind) {
borrow_kind: ty::BorrowKind)
-> UseError<'tcx> {
debug!("analyze_restrictions_on_use(expr_id={}, use_path={:?})",
- self.tcx().map.node_to_string(expr_id),
+ self.tcx().hir.node_to_string(expr_id),
use_path);
let mut ret = UseOk;
}
let mut fraginfo_map = this.tcx.fragment_infos.borrow_mut();
- let fn_did = this.tcx.map.local_def_id(id);
+ let fn_did = this.tcx.hir.local_def_id(id);
let prev = fraginfo_map.insert(fn_did, fragment_infos);
assert!(prev.is_none());
}
tcx: TyCtxt<'a, 'tcx, 'tcx>,
sp: Span,
id: ast::NodeId) {
- let span_err = tcx.map.attrs(id).iter()
+ let span_err = tcx.hir.attrs(id).iter()
.any(|a| a.check_name("rustc_move_fragments"));
let print = tcx.sess.opts.debugging_opts.print_move_fragments;
},
ref ty => {
- let span = origin_id.map_or(DUMMY_SP, |id| tcx.map.span(id));
+ let span = origin_id.map_or(DUMMY_SP, |id| tcx.hir.span(id));
span_bug!(span,
"type {:?} ({:?}) is not fragmentable",
parent_ty, ty);
move_error_collector: move_error::MoveErrorCollector::new(),
};
- let body = glcx.bccx.tcx.map.body(body);
+ let body = glcx.bccx.tcx.hir.body(body);
euv::ExprUseVisitor::new(&mut glcx, &infcx).consume_body(body);
glcx.report_potential_errors();
body_id: body
};
- let body = sicx.bccx.tcx.map.body(body);
+ let body = sicx.bccx.tcx.hir.body(body);
sicx.visit_body(body);
}
id: ast::NodeId,
attributes: &[ast::Attribute]) {
let tcx = bcx.tcx;
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
debug!("borrowck_mir({}) UNIMPLEMENTED", tcx.item_path_str(def_id));
let mir = &tcx.item_mir(def_id);
impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
attributes: &[ast::Attribute]) {
debug!("borrowck_fn(id={})", id);
- let body = this.tcx.map.body(body_id);
+ let body = this.tcx.hir.body(body_id);
if attributes.iter().any(|item| item.check_name("rustc_mir_borrowck")) {
this.with_temp_region_map(id, |this| {
{
// Check the body of fn items.
let tcx = this.tcx;
- let body = tcx.map.body(body_id);
+ let body = tcx.hir.body(body_id);
let id_range = {
- let mut visitor = intravisit::IdRangeComputingVisitor::new(&tcx.map);
+ let mut visitor = intravisit::IdRangeComputingVisitor::new(&tcx.hir);
visitor.visit_body(body);
visitor.result()
};
pub fn closure_to_block(closure_id: ast::NodeId,
tcx: TyCtxt) -> ast::NodeId {
- match tcx.map.get(closure_id) {
+ match tcx.hir.get(closure_id) {
hir_map::NodeExpr(expr) => match expr.node {
hir::ExprClosure(.., body_id, _) => {
body_id.node_id
move_data::MoveExpr |
move_data::MovePat =>
- (self.tcx.map.span(the_move.id), ""),
+ (self.tcx.hir.span(the_move.id), ""),
move_data::Captured =>
- (match self.tcx.map.expect_expr(the_move.id).node {
+ (match self.tcx.hir.expect_expr(the_move.id).node {
hir::ExprClosure(.., fn_decl_span) => fn_decl_span,
ref r => bug!("Captured({}) maps to non-closure: {:?}",
the_move.id, r),
// happen for nested closures, so we know the enclosing
// closure incorrectly accepts an `Fn` while it needs to
// be `FnMut`.
- span_help!(&mut err, self.tcx.map.span(id),
+ span_help!(&mut err, self.tcx.hir.span(id),
"consider changing this to accept closures that implement `FnMut`");
} else {
- span_help!(&mut err, self.tcx.map.span(id),
+ span_help!(&mut err, self.tcx.hir.span(id),
"consider changing this closure to take self by mutable reference");
}
err
fn region_end_span(&self, region: &'tcx ty::Region) -> Option<Span> {
match *region {
ty::ReScope(scope) => {
- match scope.span(&self.tcx.region_maps, &self.tcx.map) {
+ match scope.span(&self.tcx.region_maps, &self.tcx.hir) {
Some(s) => {
Some(s.end_point())
}
_ => bug!()
};
if kind == ty::ClosureKind::Fn {
- db.span_help(self.tcx.map.span(upvar_id.closure_expr_id),
+ db.span_help(self.tcx.hir.span(upvar_id.closure_expr_id),
"consider changing this closure to take \
self by mutable reference");
}
_ => {
if let Categorization::Deref(ref inner_cmt, ..) = err.cmt.cat {
if let Categorization::Local(local_id) = inner_cmt.cat {
- let parent = self.tcx.map.get_parent_node(local_id);
+ let parent = self.tcx.hir.get_parent_node(local_id);
- if let Some(fn_like) = FnLikeNode::from_node(self.tcx.map.get(parent)) {
- if let Some(i) = self.tcx.map.body(fn_like.body()).arguments.iter()
+ if let Some(fn_like) = FnLikeNode::from_node(self.tcx.hir.get(parent)) {
+ if let Some(i) = self.tcx.hir.body(fn_like.body()).arguments.iter()
.position(|arg| arg.pat.id == local_id) {
let arg_ty = &fn_like.decl().inputs[i];
if let hir::TyRptr(
}
}
} else if let Categorization::Local(local_id) = err.cmt.cat {
- let span = self.tcx.map.span(local_id);
+ let span = self.tcx.hir.span(local_id);
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
if snippet.starts_with("ref mut ") || snippet.starts_with("&mut ") {
db.span_label(*error_span, &format!("cannot reborrow mutably"));
fn statement_scope_span(tcx: TyCtxt, region: &ty::Region) -> Option<Span> {
match *region {
ty::ReScope(scope) => {
- match tcx.map.find(scope.node_id(&tcx.region_maps)) {
+ match tcx.hir.find(scope.node_id(&tcx.region_maps)) {
Some(hir_map::NodeStmt(stmt)) => Some(stmt.span),
_ => None
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
LpVar(id) => {
- write!(f, "$({})", ty::tls::with(|tcx| tcx.map.node_to_string(id)))
+ write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_string(id)))
}
LpUpvar(ty::UpvarId{ var_id, closure_expr_id }) => {
- let s = ty::tls::with(|tcx| tcx.map.node_to_string(var_id));
+ let s = ty::tls::with(|tcx| tcx.hir.node_to_string(var_id));
write!(f, "$({} captured by id={})", s, closure_expr_id)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
LpVar(id) => {
- write!(f, "$({})", ty::tls::with(|tcx| tcx.map.node_to_user_string(id)))
+ write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_user_string(id)))
}
LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
- let s = ty::tls::with(|tcx| tcx.map.node_to_user_string(var_id));
+ let s = ty::tls::with(|tcx| tcx.hir.node_to_user_string(var_id));
write!(f, "$({} captured by closure)", s)
}
/// Adds a new record for a match of `base_lp`, downcast to
/// variant `lp`, that occurs at location `pattern_id`. (One
/// should be able to recover the span info from the
- /// `pattern_id` and the ast_map, I think.)
+ /// `pattern_id` and the hir_map, I think.)
pub fn add_variant_match(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
lp: Rc<LoanPath<'tcx>>,
pattern_id: ast::NodeId,
impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
tcx: self.tcx,
tables: self.tcx.body_tables(b),
param_env: &ty::ParameterEnvironment::for_item(self.tcx, id)
- }.visit_body(self.tcx.map.body(b));
+ }.visit_body(self.tcx.hir.body(b));
}
}
}
}
- let module = self.tcx.map.local_def_id(self.tcx.map.get_module_parent(scrut.id));
+ let module = self.tcx.hir.local_def_id(self.tcx.hir.get_module_parent(scrut.id));
MatchCheckCtxt::create_and_enter(self.tcx, module, |ref mut cx| {
let mut have_errors = false;
"local binding"
};
- let module = self.tcx.map.local_def_id(self.tcx.map.get_module_parent(pat.id));
+ let module = self.tcx.hir.local_def_id(self.tcx.hir.get_module_parent(pat.id));
MatchCheckCtxt::create_and_enter(self.tcx, module, |ref mut cx| {
let mut patcx = PatternContext::new(self.tcx, self.tables);
let pattern = patcx.lower_pattern(pat);
use self::ErrKind::*;
use self::EvalHint::*;
-use rustc::hir::map as ast_map;
+use rustc::hir::map as hir_map;
use rustc::hir::map::blocks::FnLikeNode;
use rustc::traits;
use rustc::hir::def::Def;
fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
variant_def: DefId)
-> Option<(&'tcx Expr, Option<&'a ty::TypeckTables<'tcx>>)> {
- if let Some(variant_node_id) = tcx.map.as_local_node_id(variant_def) {
- let enum_node_id = tcx.map.get_parent(variant_node_id);
- if let Some(ast_map::NodeItem(it)) = tcx.map.find(enum_node_id) {
+ if let Some(variant_node_id) = tcx.hir.as_local_node_id(variant_def) {
+ let enum_node_id = tcx.hir.get_parent(variant_node_id);
+ if let Some(hir_map::NodeItem(it)) = tcx.hir.find(enum_node_id) {
if let hir::ItemEnum(ref edef, _) = it.node {
for variant in &edef.variants {
if variant.node.data.id() == variant_node_id {
return variant.node.disr_expr.map(|e| {
- let def_id = tcx.map.body_owner_def_id(e);
- (&tcx.map.body(e).value,
+ let def_id = tcx.hir.body_owner_def_id(e);
+ (&tcx.hir.body(e).value,
tcx.tables.borrow().get(&def_id).cloned())
});
}
-> Option<(&'tcx Expr,
Option<&'a ty::TypeckTables<'tcx>>,
Option<ty::Ty<'tcx>>)> {
- if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
- match tcx.map.find(node_id) {
+ if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+ match tcx.hir.find(node_id) {
None => None,
- Some(ast_map::NodeItem(&hir::Item {
+ Some(hir_map::NodeItem(&hir::Item {
node: hir::ItemConst(ref ty, body), ..
})) |
- Some(ast_map::NodeImplItem(&hir::ImplItem {
+ Some(hir_map::NodeImplItem(&hir::ImplItem {
node: hir::ImplItemKind::Const(ref ty, body), ..
})) => {
- Some((&tcx.map.body(body).value,
+ Some((&tcx.hir.body(body).value,
tcx.tables.borrow().get(&def_id).cloned(),
tcx.ast_ty_to_prim_ty(ty)))
}
- Some(ast_map::NodeTraitItem(ti)) => match ti.node {
+ Some(hir_map::NodeTraitItem(ti)) => match ti.node {
hir::TraitItemKind::Const(ref ty, default) => {
if let Some(substs) = substs {
// If we have a trait item and the substitutions for it,
// `resolve_trait_associated_const` will select an impl
// or the default.
- let trait_id = tcx.map.get_parent(node_id);
- let trait_id = tcx.map.local_def_id(trait_id);
+ let trait_id = tcx.hir.get_parent(node_id);
+ let trait_id = tcx.hir.local_def_id(trait_id);
let default_value = default.map(|body| {
- (&tcx.map.body(body).value,
+ (&tcx.hir.body(body).value,
tcx.tables.borrow().get(&def_id).cloned(),
tcx.ast_ty_to_prim_ty(ty))
});
fn lookup_const_fn_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
-> Option<(&'tcx hir::Body, Option<&'a ty::TypeckTables<'tcx>>)>
{
- if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
- FnLikeNode::from_node(tcx.map.get(node_id)).and_then(|fn_like| {
+ if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+ FnLikeNode::from_node(tcx.hir.get(node_id)).and_then(|fn_like| {
if fn_like.constness() == hir::Constness::Const {
- Some((tcx.map.body(fn_like.body()),
+ Some((tcx.hir.body(fn_like.body()),
tcx.tables.borrow().get(&def_id).cloned()))
} else {
None
impl<'a, 'tcx> ConstContext<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, body: hir::BodyId) -> Self {
- let def_id = tcx.map.body_owner_def_id(body);
+ let def_id = tcx.hir.body_owner_def_id(body);
ConstContext {
tcx: tcx,
tables: tcx.tables.borrow().get(&def_id).cloned(),
_ => bug!()
}
} else {
- let n = &tcx.map.body(count).value;
+ let n = &tcx.hir.body(count).value;
match ConstContext::new(tcx, count).eval(n, len_hint)? {
Integral(Usize(i)) => i.as_u64(tcx.sess.target.uint_type),
Integral(_) => signal!(e, RepeatCountNotNatural),
-> Result<usize, ErrorReported>
{
let hint = UncheckedExprHint(tcx.types.usize);
- let count_expr = &tcx.map.body(count).value;
+ let count_expr = &tcx.hir.body(count).value;
match ConstContext::new(tcx, count).eval(count_expr, hint) {
Ok(Integral(Usize(count))) => {
let val = count.as_u64(tcx.sess.target.uint_type);
if let hir::ExprPath(hir::QPath::Resolved(None, ref path)) = count_expr.node {
if let Def::Local(..) = path.def {
diag.note(&format!("`{}` is a variable",
- tcx.map.node_to_pretty_string(count_expr.id)));
+ tcx.hir.node_to_pretty_string(count_expr.id)));
}
}
}
PatKind::Binding(bm, def_id, ref ident, ref sub) => {
- let id = self.tcx.map.as_local_node_id(def_id).unwrap();
+ let id = self.tcx.hir.as_local_node_id(def_id).unwrap();
let var_ty = self.tables.node_id_to_type(pat.id);
let region = match var_ty.sty {
ty::TyRef(r, _) => Some(r),
outdir,
output,
opt_crate,
- tcx.map.krate(),
+ tcx.hir.krate(),
&analysis,
tcx,
&crate_name);
pub arenas: Option<&'tcx GlobalArenas<'tcx>>,
pub expanded_crate: Option<&'a ast::Crate>,
pub hir_crate: Option<&'a hir::Crate>,
- pub ast_map: Option<&'a hir_map::Map<'tcx>>,
+ pub hir_map: Option<&'a hir_map::Map<'tcx>>,
pub resolutions: Option<&'a Resolutions>,
pub analysis: Option<&'a ty::CrateAnalysis<'tcx>>,
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
output_filenames: None,
expanded_crate: None,
hir_crate: None,
- ast_map: None,
+ hir_map: None,
resolutions: None,
analysis: None,
tcx: None,
arena: Some(arena),
arenas: Some(arenas),
cstore: Some(cstore),
- ast_map: Some(hir_map),
+ hir_map: Some(hir_map),
analysis: Some(analysis),
resolutions: Some(resolutions),
expanded_crate: Some(krate),
};
control.after_hir_lowering.callback = box move |state| {
pretty::print_after_hir_lowering(state.session,
- state.ast_map.unwrap(),
+ state.hir_map.unwrap(),
state.analysis.unwrap(),
state.resolutions.unwrap(),
state.input,
/// Constructs a `PrinterSupport` object and passes it to `f`.
fn call_with_pp_support<'tcx, A, B, F>(&self,
sess: &'tcx Session,
- ast_map: Option<&hir_map::Map<'tcx>>,
+ hir_map: Option<&hir_map::Map<'tcx>>,
payload: B,
f: F)
-> A
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
let annotation = NoAnn {
sess: sess,
- ast_map: ast_map.map(|m| m.clone()),
+ hir_map: hir_map.map(|m| m.clone()),
};
f(&annotation, payload)
}
PpmIdentified | PpmExpandedIdentified => {
let annotation = IdentifiedAnnotation {
sess: sess,
- ast_map: ast_map.map(|m| m.clone()),
+ hir_map: hir_map.map(|m| m.clone()),
};
f(&annotation, payload)
}
PpmExpandedHygiene => {
let annotation = HygieneAnnotation {
sess: sess,
- ast_map: ast_map.map(|m| m.clone()),
};
f(&annotation, payload)
}
}
fn call_with_pp_support_hir<'tcx, A, B, F>(&self,
sess: &'tcx Session,
- ast_map: &hir_map::Map<'tcx>,
+ hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis<'tcx>,
resolutions: &Resolutions,
arena: &'tcx DroplessArena,
PpmNormal => {
let annotation = NoAnn {
sess: sess,
- ast_map: Some(ast_map.clone()),
+ hir_map: Some(hir_map.clone()),
};
- f(&annotation, payload, ast_map.forest.krate())
+ f(&annotation, payload, hir_map.forest.krate())
}
PpmIdentified => {
let annotation = IdentifiedAnnotation {
sess: sess,
- ast_map: Some(ast_map.clone()),
+ hir_map: Some(hir_map.clone()),
};
- f(&annotation, payload, ast_map.forest.krate())
+ f(&annotation, payload, hir_map.forest.krate())
}
PpmTyped => {
abort_on_err(driver::phase_3_run_analysis_passes(sess,
- ast_map.clone(),
+ hir_map.clone(),
analysis.clone(),
resolutions.clone(),
arena,
tables: Cell::new(&empty_tables)
};
let _ignore = tcx.dep_graph.in_ignore();
- f(&annotation, payload, ast_map.forest.krate())
+ f(&annotation, payload, hir_map.forest.krate())
}),
sess)
}
}
}
-trait PrinterSupport<'ast>: pprust::PpAnn {
+trait PrinterSupport: pprust::PpAnn {
/// Provides a uniform interface for re-extracting a reference to a
/// `Session` from a value that now owns it.
fn sess<'a>(&'a self) -> &'a Session;
- /// Provides a uniform interface for re-extracting a reference to an
- /// `hir_map::Map` from a value that now owns it.
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>>;
-
/// Produces the pretty-print annotation object.
///
/// (Rust does not yet support upcasting from a trait object to
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn;
}
-trait HirPrinterSupport<'ast>: pprust_hir::PpAnn {
+trait HirPrinterSupport<'hir>: pprust_hir::PpAnn {
/// Provides a uniform interface for re-extracting a reference to a
/// `Session` from a value that now owns it.
fn sess<'a>(&'a self) -> &'a Session;
/// Provides a uniform interface for re-extracting a reference to an
/// `hir_map::Map` from a value that now owns it.
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>>;
+ fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>>;
/// Produces the pretty-print annotation object.
///
/// Computes an user-readable representation of a path, if possible.
fn node_path(&self, id: ast::NodeId) -> Option<String> {
- self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| {
+ self.hir_map().and_then(|map| map.def_path_from_id(id)).map(|path| {
path.data
.into_iter()
.map(|elem| elem.data.to_string())
}
}
-struct NoAnn<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+struct NoAnn<'hir> {
+ sess: &'hir Session,
+ hir_map: Option<hir_map::Map<'hir>>,
}
-impl<'ast> PrinterSupport<'ast> for NoAnn<'ast> {
+impl<'hir> PrinterSupport for NoAnn<'hir> {
fn sess<'a>(&'a self) -> &'a Session {
self.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> {
- self.ast_map.as_ref()
- }
-
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn {
self
}
}
-impl<'ast> HirPrinterSupport<'ast> for NoAnn<'ast> {
+impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> {
fn sess<'a>(&'a self) -> &'a Session {
self.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> {
- self.ast_map.as_ref()
+ fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
+ self.hir_map.as_ref()
}
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn {
}
}
-impl<'ast> pprust::PpAnn for NoAnn<'ast> {}
-impl<'ast> pprust_hir::PpAnn for NoAnn<'ast> {
+impl<'hir> pprust::PpAnn for NoAnn<'hir> {}
+impl<'hir> pprust_hir::PpAnn for NoAnn<'hir> {
fn nested(&self, state: &mut pprust_hir::State, nested: pprust_hir::Nested)
-> io::Result<()> {
- if let Some(ref map) = self.ast_map {
+ if let Some(ref map) = self.hir_map {
pprust_hir::PpAnn::nested(map, state, nested)
} else {
Ok(())
}
}
-struct IdentifiedAnnotation<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+struct IdentifiedAnnotation<'hir> {
+ sess: &'hir Session,
+ hir_map: Option<hir_map::Map<'hir>>,
}
-impl<'ast> PrinterSupport<'ast> for IdentifiedAnnotation<'ast> {
+impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> {
fn sess<'a>(&'a self) -> &'a Session {
self.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> {
- self.ast_map.as_ref()
- }
-
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn {
self
}
}
-impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> {
+impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> {
fn pre(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node {
pprust::NodeExpr(_) => s.popen(),
}
}
-impl<'ast> HirPrinterSupport<'ast> for IdentifiedAnnotation<'ast> {
+impl<'hir> HirPrinterSupport<'hir> for IdentifiedAnnotation<'hir> {
fn sess<'a>(&'a self) -> &'a Session {
self.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> {
- self.ast_map.as_ref()
+ fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
+ self.hir_map.as_ref()
}
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn {
}
}
-impl<'ast> pprust_hir::PpAnn for IdentifiedAnnotation<'ast> {
+impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
fn nested(&self, state: &mut pprust_hir::State, nested: pprust_hir::Nested)
-> io::Result<()> {
- if let Some(ref map) = self.ast_map {
+ if let Some(ref map) = self.hir_map {
pprust_hir::PpAnn::nested(map, state, nested)
} else {
Ok(())
}
}
-struct HygieneAnnotation<'ast> {
- sess: &'ast Session,
- ast_map: Option<hir_map::Map<'ast>>,
+struct HygieneAnnotation<'a> {
+ sess: &'a Session
}
-impl<'ast> PrinterSupport<'ast> for HygieneAnnotation<'ast> {
- fn sess<'a>(&'a self) -> &'a Session {
+impl<'a> PrinterSupport for HygieneAnnotation<'a> {
+ fn sess(&self) -> &Session {
self.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'ast>> {
- self.ast_map.as_ref()
- }
-
- fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn {
+ fn pp_ann(&self) -> &pprust::PpAnn {
self
}
}
-impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> {
+impl<'a> pprust::PpAnn for HygieneAnnotation<'a> {
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node {
pprust::NodeIdent(&ast::Ident { name, ctxt }) => {
&self.tcx.sess
}
- fn ast_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> {
- Some(&self.tcx.map)
+ fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> {
+ Some(&self.tcx.hir)
}
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn {
if let pprust_hir::Nested::Body(id) = nested {
self.tables.set(self.tcx.body_tables(id));
}
- pprust_hir::PpAnn::nested(&self.tcx.map, state, nested)?;
+ pprust_hir::PpAnn::nested(&self.tcx.hir, state, nested)?;
self.tables.set(old_tables);
Ok(())
}
}
}
-enum NodesMatchingUII<'a, 'ast: 'a> {
+enum NodesMatchingUII<'a, 'hir: 'a> {
NodesMatchingDirect(option::IntoIter<ast::NodeId>),
- NodesMatchingSuffix(hir_map::NodesMatchingSuffix<'a, 'ast>),
+ NodesMatchingSuffix(hir_map::NodesMatchingSuffix<'a, 'hir>),
}
-impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> {
+impl<'a, 'hir> Iterator for NodesMatchingUII<'a, 'hir> {
type Item = ast::NodeId;
fn next(&mut self) -> Option<ast::NodeId> {
}
}
- fn all_matching_node_ids<'a, 'ast>(&'a self,
- map: &'a hir_map::Map<'ast>)
- -> NodesMatchingUII<'a, 'ast> {
+ fn all_matching_node_ids<'a, 'hir>(&'a self,
+ map: &'a hir_map::Map<'hir>)
+ -> NodesMatchingUII<'a, 'hir> {
match *self {
ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()),
ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts[..])),
let cfg = match code {
blocks::Code::Expr(expr) => cfg::CFG::new(tcx, expr),
blocks::Code::FnLike(fn_like) => {
- let body = tcx.map.body(fn_like.body());
+ let body = tcx.hir.body(fn_like.body());
cfg::CFG::new(tcx, &body.value)
},
};
let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
let lcfg = LabelledCFG {
- ast_map: &tcx.map,
+ hir_map: &tcx.hir,
cfg: &cfg,
name: format!("node_{}", code.id()),
labelled_edges: labelled_edges,
}
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
- ast_map: &hir_map::Map<'tcx>,
+ hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis<'tcx>,
resolutions: &Resolutions,
input: &Input,
if ppm.needs_analysis() {
print_with_analysis(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
crate_name,
(PpmSource(s), _) => {
// Silently ignores an identified node.
let out: &mut Write = &mut out;
- s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
+ s.call_with_pp_support(sess, Some(hir_map), box out, |annotation, out| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
(PpmHir(s), None) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
arena,
(PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess,
- ast_map,
+ hir_map,
analysis,
resolutions,
arena,
|annotation, (out, uii), _| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
- let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
+ let hir_map = annotation.hir_map().expect("--unpretty missing HIR map");
let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(),
&sess.parse_sess,
src_name.to_string(),
box out,
annotation.pp_ann(),
true);
- for node_id in uii.all_matching_node_ids(ast_map) {
- let node = ast_map.get(node_id);
+ for node_id in uii.all_matching_node_ids(hir_map) {
+ let node = hir_map.get(node_id);
pp_state.print_node(node)?;
pp::space(&mut pp_state.s)?;
let path = annotation.node_path(node_id)
// with a different callback than the standard driver, so that isn't easy.
// Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
- ast_map: &hir_map::Map<'tcx>,
+ hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis<'tcx>,
resolutions: &Resolutions,
crate_name: &str,
ofile: Option<&Path>) {
let nodeid = if let Some(uii) = uii {
debug!("pretty printing for {:?}", uii);
- Some(uii.to_one_node_id("--unpretty", sess, &ast_map))
+ Some(uii.to_one_node_id("--unpretty", sess, &hir_map))
} else {
debug!("pretty printing for whole crate");
None
let mut out = Vec::new();
abort_on_err(driver::phase_3_run_analysis_passes(sess,
- ast_map.clone(),
+ hir_map.clone(),
analysis.clone(),
resolutions.clone(),
arena,
match ppm {
PpmMir | PpmMirCFG => {
if let Some(nodeid) = nodeid {
- let def_id = tcx.map.local_def_id(nodeid);
+ let def_id = tcx.hir.local_def_id(nodeid);
match ppm {
PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out),
PpmMirCFG => write_mir_graphviz(tcx, iter::once(def_id), &mut out),
let nodeid =
nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
suffix (b::c::d)");
- let node = tcx.map.find(nodeid).unwrap_or_else(|| {
+ let node = tcx.hir.find(nodeid).unwrap_or_else(|| {
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
});
- match blocks::Code::from_node(&tcx.map, nodeid) {
+ match blocks::Code::from_node(&tcx.hir, nodeid) {
Some(code) => {
let variants = gather_flowgraph_variants(tcx.sess);
got {:?}",
node);
- tcx.sess.span_fatal(tcx.map.span(nodeid), &message)
+ tcx.sess.span_fatal(tcx.hir.span(nodeid), &message)
}
}
}
let arena = DroplessArena::new();
let arenas = ty::GlobalArenas::new();
- let ast_map = hir_map::map_crate(&mut hir_forest, defs);
+ let hir_map = hir_map::map_crate(&mut hir_forest, defs);
// run just enough stuff to build a tcx:
- let lang_items = lang_items::collect_language_items(&sess, &ast_map);
- let named_region_map = resolve_lifetime::krate(&sess, &ast_map);
- let region_map = region::resolve_crate(&sess, &ast_map);
- let index = stability::Index::new(&ast_map);
+ let lang_items = lang_items::collect_language_items(&sess, &hir_map);
+ let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
+ let region_map = region::resolve_crate(&sess, &hir_map);
+ let index = stability::Index::new(&hir_map);
TyCtxt::create_and_enter(&sess,
&arenas,
&arena,
resolutions,
named_region_map.unwrap(),
- ast_map,
+ hir_map,
region_map,
lang_items,
index,
#[allow(dead_code)] // this seems like it could be useful, even if we don't use it now
pub fn lookup_item(&self, names: &[String]) -> ast::NodeId {
- return match search_mod(self, &self.infcx.tcx.map.krate().module, 0, names) {
+ return match search_mod(self, &self.infcx.tcx.hir.krate().module, 0, names) {
Some(id) => id,
None => {
panic!("no item found: `{}`", names.join("::"));
-> Option<ast::NodeId> {
assert!(idx < names.len());
for item in &m.item_ids {
- let item = this.infcx.tcx.map.expect_item(item.id);
+ let item = this.infcx.tcx.hir.expect_item(item.id);
if item.name.to_string() == names[idx] {
return search(this, item, idx + 1, names);
}
let mut visitor = IfThisChanged { tcx: tcx,
if_this_changed: vec![],
then_this_would_need: vec![] };
- visitor.process_attrs(ast::CRATE_NODE_ID, &tcx.map.krate().attrs);
- tcx.map.krate().visit_all_item_likes(&mut visitor);
+ visitor.process_attrs(ast::CRATE_NODE_ID, &tcx.hir.krate().attrs);
+ tcx.hir.krate().visit_all_item_likes(&mut visitor);
(visitor.if_this_changed, visitor.then_this_would_need)
};
}
fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
- let def_id = self.tcx.map.local_def_id(node_id);
+ let def_id = self.tcx.hir.local_def_id(node_id);
for attr in attrs {
if attr.check_name(ATTR_IF_THIS_CHANGED) {
let dep_node_interned = self.argument(attr);
pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> IncrementalHashesMap {
let _ignore = tcx.dep_graph.in_ignore();
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
let hash_spans = tcx.sess.opts.debuginfo != NoDebugInfo;
let mut visitor = HashItemsVisitor {
tcx: tcx,
fn calculate_node_id<W>(&mut self, id: ast::NodeId, walk_op: W)
where W: for<'v> FnMut(&mut StrictVersionHashVisitor<'v, 'a, 'tcx>)
{
- let def_id = self.tcx.map.local_def_id(id);
+ let def_id = self.tcx.hir.local_def_id(id);
self.calculate_def_id(def_id, walk_op)
}
}
fn compute_crate_hash(&mut self) {
- let krate = self.tcx.map.krate();
+ let krate = self.tcx.hir.krate();
let mut crate_state = IchHasher::new();
impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'hash, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> visit::NestedVisitorMap<'this, 'tcx> {
if self.hash_bodies {
- visit::NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ visit::NestedVisitorMap::OnlyBodies(&self.tcx.hir)
} else {
visit::NestedVisitorMap::None
}
.collect();
let query = tcx.dep_graph.query();
debug!("query-nodes: {:?}", query.nodes());
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
krate.visit_all_item_likes(&mut DirtyCleanVisitor {
tcx: tcx,
query: &query,
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item) {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
for attr in self.tcx.get_attrs(def_id).iter() {
if attr.check_name(ATTR_DIRTY) {
if check_config(self.tcx, attr) {
}
tcx.dep_graph.with_ignore(||{
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
krate.visit_all_item_likes(&mut DirtyCleanMetadataVisitor {
tcx: tcx,
prev_metadata_hashes: prev_metadata_hashes,
impl<'a, 'tcx, 'm> ItemLikeVisitor<'tcx> for DirtyCleanMetadataVisitor<'a, 'tcx, 'm> {
fn visit_item(&mut self, item: &'tcx hir::Item) {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
for attr in self.tcx.get_attrs(def_id).iter() {
if attr.check_name(ATTR_DIRTY_METADATA) {
}
pub fn method_context(cx: &LateContext, id: ast::NodeId, span: Span) -> MethodLateContext {
- let def_id = cx.tcx.map.local_def_id(id);
+ let def_id = cx.tcx.hir.local_def_id(id);
match cx.tcx.associated_items.borrow().get(&def_id) {
None => span_bug!(span, "missing method descriptor?!"),
Some(item) => {
hir::ItemEnum(..) |
hir::ItemStruct(..) |
hir::ItemUnion(..) => {
- let def_id = cx.tcx.map.local_def_id(it.id);
+ let def_id = cx.tcx.hir.local_def_id(it.id);
self.check_heap_type(cx, it.span, cx.tcx.item_type(def_id))
}
_ => ()
hir::ItemStruct(ref struct_def, _) |
hir::ItemUnion(ref struct_def, _) => {
for struct_field in struct_def.fields() {
- let def_id = cx.tcx.map.local_def_id(struct_field.id);
+ let def_id = cx.tcx.hir.local_def_id(struct_field.id);
self.check_heap_type(cx, struct_field.span,
cx.tcx.item_type(def_id));
}
// If the trait is private, add the impl items to private_traits so they don't get
// reported for missing docs.
let real_trait = trait_ref.path.def.def_id();
- if let Some(node_id) = cx.tcx.map.as_local_node_id(real_trait) {
- match cx.tcx.map.find(node_id) {
+ if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
+ match cx.tcx.hir.find(node_id) {
Some(hir_map::NodeItem(item)) => {
if item.vis == hir::Visibility::Inherited {
for impl_item_ref in impl_item_refs {
if ast_generics.is_parameterized() {
return;
}
- let def = cx.tcx.lookup_adt_def(cx.tcx.map.local_def_id(item.id));
+ let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id));
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
}
hir::ItemUnion(_, ref ast_generics) => {
if ast_generics.is_parameterized() {
return;
}
- let def = cx.tcx.lookup_adt_def(cx.tcx.map.local_def_id(item.id));
+ let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id));
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
}
hir::ItemEnum(_, ref ast_generics) => {
if ast_generics.is_parameterized() {
return;
}
- let def = cx.tcx.lookup_adt_def(cx.tcx.map.local_def_id(item.id));
+ let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id));
(def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[])))
}
_ => return,
let mut impls = NodeSet();
debug_def.for_each_impl(cx.tcx, |d| {
if let Some(ty_def) = cx.tcx.item_type(d).ty_to_def_id() {
- if let Some(node_id) = cx.tcx.map.as_local_node_id(ty_def) {
+ if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def) {
impls.insert(node_id);
}
}
let method = match fn_kind {
FnKind::ItemFn(..) => None,
FnKind::Method(..) => {
- Some(cx.tcx.associated_item(cx.tcx.map.local_def_id(id)))
+ Some(cx.tcx.associated_item(cx.tcx.hir.local_def_id(id)))
}
// closures can't recur, so they don't matter.
FnKind::Closure(_) => return,
false
};
if self_recursive {
- self_call_spans.push(cx.tcx.map.span(node_id));
+ self_call_spans.push(cx.tcx.hir.span(node_id));
// this is a self call, so we shouldn't explore past
// this node in the CFG.
continue;
// represents a call to the function `fn_id`/method `method`.
fn expr_refers_to_this_fn(cx: &LateContext, fn_id: ast::NodeId, id: ast::NodeId) -> bool {
- match cx.tcx.map.get(id) {
+ match cx.tcx.hir.get(id) {
hir_map::NodeExpr(&hir::Expr { node: hir::ExprCall(ref callee, _), .. }) => {
let def = if let hir::ExprPath(ref qpath) = callee.node {
cx.tables.qpath_def(qpath, callee.id)
} else {
return false;
};
- def.def_id() == cx.tcx.map.local_def_id(fn_id)
+ def.def_id() == cx.tcx.hir.local_def_id(fn_id)
}
_ => false,
}
}
// Check for calls to methods via explicit paths (e.g. `T::method()`).
- match cx.tcx.map.get(id) {
+ match cx.tcx.hir.get(id) {
hir_map::NodeExpr(&hir::Expr { node: hir::ExprCall(ref callee, _), .. }) => {
let def = if let hir::ExprPath(ref qpath) = callee.node {
cx.tables.qpath_def(qpath, callee.id)
ty::TraitContainer(trait_def_id) => {
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, callee_substs);
let trait_ref = ty::Binder(trait_ref);
- let span = tcx.map.span(expr_id);
+ let span = tcx.hir.span(expr_id);
let obligation =
traits::Obligation::new(traits::ObligationCause::misc(span, expr_id),
trait_ref.to_poly_trait_predicate());
// unwrap() is ok here b/c `method` is the method
// defined in this crate whose body we are
// checking, so it's always local
- let node_id = tcx.map.as_local_node_id(method.def_id).unwrap();
+ let node_id = tcx.hir.as_local_node_id(method.def_id).unwrap();
let param_env = ty::ParameterEnvironment::for_item(tcx, node_id);
tcx.infer_ctxt(param_env, Reveal::NotSpecializable).enter(|infcx| {
if let hir::ItemUnion(ref vdata, _) = item.node {
let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id);
for field in vdata.fields() {
- let field_ty = ctx.tcx.item_type(ctx.tcx.map.local_def_id(field.id));
+ let field_ty = ctx.tcx.item_type(ctx.tcx.hir.local_def_id(field.id));
if ctx.tcx.type_needs_drop_given_env(field_ty, param_env) {
ctx.span_lint(UNIONS_WITH_DROP_FIELDS,
field.span,
}
fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) {
- let def_id = self.cx.tcx.map.local_def_id(id);
+ let def_id = self.cx.tcx.hir.local_def_id(id);
let sig = self.cx.tcx.item_type(def_id).fn_sig();
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
}
fn check_foreign_static(&mut self, id: ast::NodeId, span: Span) {
- let def_id = self.cx.tcx.map.local_def_id(id);
+ let def_id = self.cx.tcx.hir.local_def_id(id);
let ty = self.cx.tcx.item_type(def_id);
self.check_type_for_ffi_and_report_errors(span, ty);
}
if let hir::ItemEnum(ref enum_definition, ref gens) = it.node {
if gens.ty_params.is_empty() {
// sizes only make sense for non-generic types
- let t = cx.tcx.item_type(cx.tcx.map.local_def_id(it.id));
+ let t = cx.tcx.item_type(cx.tcx.hir.local_def_id(it.id));
let layout = cx.tcx.infer_ctxt((), Reveal::All).enter(|infcx| {
let ty = cx.tcx.erase_regions(&t);
ty.layout(&infcx).unwrap_or_else(|e| {
for (_, v) in &mutables {
if !v.iter().any(|e| used_mutables.contains(e)) {
cx.span_lint(UNUSED_MUT,
- cx.tcx.map.span(v[0]),
+ cx.tcx.hir.span(v[0]),
"variable does not need to be mutable");
}
}
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
pub fn encode_body(&mut self, body_id: hir::BodyId) -> Lazy<Ast<'tcx>> {
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
let lazy_body = self.lazy(body);
let tables = self.tcx.body_tables(body_id);
}
fn visit_nested_body(&mut self, body: hir::BodyId) {
- let body = self.ecx.tcx.map.body(body);
+ let body = self.ecx.tcx.hir.body(body);
body.encode(self.ecx).unwrap();
self.count += 1;
def_id: DefId)
-> Option<&'tcx hir::Body>
{
- if let Some(cached) = tcx.map.get_inlined_body(def_id) {
+ if let Some(cached) = tcx.hir.get_inlined_body(def_id) {
return Some(cached);
}
tcx.tables.borrow_mut().insert(def_id, tcx.alloc_tables(tables));
let body = ast.body.decode((self, tcx));
- tcx.map.intern_inlined_body(def_id, body)
+ tcx.hir.intern_inlined_body(def_id, body)
})
}
struct_ctor: None,
};
- let enum_id = tcx.map.as_local_node_id(enum_did).unwrap();
- let enum_vis = &tcx.map.expect_item(enum_id).vis;
+ let enum_id = tcx.hir.as_local_node_id(enum_did).unwrap();
+ let enum_vis = &tcx.hir.expect_item(enum_id).vis;
Entry {
kind: EntryKind::Variant(self.lazy(&data)),
&hir::Visibility)>)
-> Entry<'tcx> {
let tcx = self.tcx;
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
let data = ModData {
reexports: match self.reexports.get(&id) {
span: self.lazy(&md.inner),
attributes: self.encode_attributes(attrs),
children: self.lazy_seq(md.item_ids.iter().map(|item_id| {
- tcx.map.local_def_id(item_id.id).index
+ tcx.hir.local_def_id(item_id.id).index
})),
stability: self.encode_stability(def_id),
deprecation: self.encode_deprecation(def_id),
let field = &variant.fields[field_index];
let def_id = field.did;
- let variant_id = tcx.map.as_local_node_id(variant.did).unwrap();
- let variant_data = tcx.map.expect_variant_data(variant_id);
+ let variant_id = tcx.hir.as_local_node_id(variant.did).unwrap();
+ let variant_data = tcx.hir.expect_variant_data(variant_id);
Entry {
kind: EntryKind::Field,
struct_ctor: Some(def_id.index),
};
- let struct_id = tcx.map.as_local_node_id(adt_def_id).unwrap();
- let struct_vis = &tcx.map.expect_item(struct_id).vis;
+ let struct_id = tcx.hir.as_local_node_id(adt_def_id).unwrap();
+ let struct_vis = &tcx.hir.expect_item(struct_id).vis;
Entry {
kind: EntryKind::Struct(self.lazy(&data)),
fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
let tcx = self.tcx;
- let node_id = tcx.map.as_local_node_id(def_id).unwrap();
- let ast_item = tcx.map.expect_trait_item(node_id);
+ let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
+ let ast_item = tcx.hir.expect_trait_item(node_id);
let trait_item = tcx.associated_item(def_id);
let container = match trait_item.defaultness {
}
fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
- let node_id = self.tcx.map.as_local_node_id(def_id).unwrap();
- let ast_item = self.tcx.map.expect_impl_item(node_id);
+ let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
+ let ast_item = self.tcx.hir.expect_impl_item(node_id);
let impl_item = self.tcx.associated_item(def_id);
let container = match impl_item.defaultness {
fn encode_fn_arg_names_for_body(&mut self, body_id: hir::BodyId)
-> LazySeq<ast::Name> {
let _ignore = self.tcx.dep_graph.in_ignore();
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
self.lazy_seq(body.arguments.iter().map(|arg| {
match arg.pat.node {
PatKind::Binding(_, _, name, _) => name.node,
// for methods, write all the stuff get_trait_method
// needs to know
let struct_ctor = if !struct_def.is_struct() {
- Some(tcx.map.local_def_id(struct_def.id()).index)
+ Some(tcx.hir.local_def_id(struct_def.id()).index)
} else {
None
};
hir::ItemForeignMod(ref fm) => {
self.lazy_seq(fm.items
.iter()
- .map(|foreign_item| tcx.map.local_def_id(foreign_item.id).index))
+ .map(|foreign_item| tcx.hir.local_def_id(foreign_item.id).index))
}
hir::ItemEnum(..) => {
let def = self.tcx.lookup_adt_def(def_id);
/// so it's easier to do that here then to wait until we would encounter
/// normally in the visitor walk.
fn encode_addl_info_for_item(&mut self, item: &hir::Item) {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
match item.node {
hir::ItemStatic(..) |
hir::ItemConst(..) |
// If the struct has a constructor, encode it.
if !struct_def.is_struct() {
- let ctor_def_id = self.tcx.map.local_def_id(struct_def.id());
+ let ctor_def_id = self.tcx.hir.local_def_id(struct_def.id());
self.record(ctor_def_id,
EncodeContext::encode_struct_ctor,
(def_id, ctor_def_id));
impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.index.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.index.tcx.hir)
}
fn visit_expr(&mut self, ex: &'tcx hir::Expr) {
intravisit::walk_expr(self, ex);
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
intravisit::walk_item(self, item);
- let def_id = self.index.tcx.map.local_def_id(item.id);
+ let def_id = self.index.tcx.hir.local_def_id(item.id);
match item.node {
hir::ItemExternCrate(_) |
hir::ItemUse(..) => (), // ignore these
}
fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem) {
intravisit::walk_foreign_item(self, ni);
- let def_id = self.index.tcx.map.local_def_id(ni.id);
+ let def_id = self.index.tcx.hir.local_def_id(ni.id);
self.index.record(def_id,
EncodeContext::encode_info_for_foreign_item,
(def_id, ni));
self.index.encode_info_for_ty(ty);
}
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) {
- let def_id = self.index.tcx.map.local_def_id(macro_def.id);
+ let def_id = self.index.tcx.hir.local_def_id(macro_def.id);
self.index.record(def_id, EncodeContext::encode_info_for_macro_def, macro_def);
}
}
impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
fn encode_info_for_ty(&mut self, ty: &hir::Ty) {
if let hir::TyImplTrait(_) = ty.node {
- let def_id = self.tcx.map.local_def_id(ty.id);
+ let def_id = self.tcx.hir.local_def_id(ty.id);
self.record(def_id, EncodeContext::encode_info_for_anon_ty, def_id);
}
}
fn encode_info_for_expr(&mut self, expr: &hir::Expr) {
match expr.node {
hir::ExprClosure(..) => {
- let def_id = self.tcx.map.local_def_id(expr.id);
+ let def_id = self.tcx.hir.local_def_id(expr.id);
self.record(def_id, EncodeContext::encode_info_for_closure, def_id);
}
_ => {}
}
fn encode_info_for_items(&mut self) -> Index {
- let krate = self.tcx.map.krate();
+ let krate = self.tcx.hir.krate();
let mut index = IndexBuilder::new(self);
index.record(DefId::local(CRATE_DEF_INDEX),
EncodeContext::encode_info_for_mod,
}
fn encode_def_path_table(&mut self) -> Lazy<DefPathTable> {
- let definitions = self.tcx.map.definitions();
+ let definitions = self.tcx.hir.definitions();
self.lazy(definitions.def_path_table())
}
}
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
if let hir::ItemImpl(..) = item.node {
- let impl_id = self.tcx.map.local_def_id(item.id);
+ let impl_id = self.tcx.hir.local_def_id(item.id);
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
self.impls
.entry(trait_ref.def_id)
tcx: self.tcx,
impls: FxHashMap(),
};
- self.tcx.map.krate().visit_all_item_likes(&mut visitor);
+ self.tcx.hir.krate().visit_all_item_likes(&mut visitor);
let all_impls: Vec<_> = visitor.impls
.into_iter()
fn encode_exported_symbols(&mut self) -> LazySeq<DefIndex> {
let exported_symbols = self.exported_symbols;
let tcx = self.tcx;
- self.lazy_seq(exported_symbols.iter().map(|&id| tcx.map.local_def_id(id).index))
+ self.lazy_seq(exported_symbols.iter().map(|&id| tcx.hir.local_def_id(id).index))
}
fn encode_dylib_dependency_formats(&mut self) -> LazySeq<Option<LinkagePreference>> {
plugin_registrar_fn: tcx.sess
.plugin_registrar_fn
.get()
- .map(|id| tcx.map.local_def_id(id).index),
+ .map(|id| tcx.hir.local_def_id(id).index),
macro_derive_registrar: if is_proc_macro {
let id = tcx.sess.derive_registrar_fn.get().unwrap();
- Some(tcx.map.local_def_id(id).index)
+ Some(tcx.hir.local_def_id(id).index)
} else {
None
},
impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
pub fn new(ecx: &'a mut EncodeContext<'b, 'tcx>) -> Self {
IndexBuilder {
- items: Index::new(ecx.tcx.map.num_local_def_ids()),
+ items: Index::new(ecx.tcx.hir.num_local_def_ids()),
ecx: ecx,
}
}
($t:ty) => {
impl<'tcx> DepGraphRead for &'tcx $t {
fn read(&self, tcx: TyCtxt) {
- tcx.map.read(self.id);
+ tcx.hir.read(self.id);
}
}
}
impl<T> DepGraphRead for FromId<T> {
fn read(&self, tcx: TyCtxt) {
- tcx.map.read(self.0);
+ tcx.hir.read(self.0);
}
}
let_extent_stack.push(remainder_scope);
// Declare the bindings, which may create a visibility scope.
- let remainder_span = remainder_scope.span(&tcx.region_maps, &tcx.map);
+ let remainder_span = remainder_scope.span(&tcx.region_maps, &tcx.hir);
let remainder_span = remainder_span.unwrap_or(span);
let scope = this.declare_bindings(None, remainder_span, &pattern);
let arguments: Vec<_> = arguments.collect();
let tcx = hir.tcx();
- let span = tcx.map.span(fn_id);
+ let span = tcx.hir.span(fn_id);
let mut builder = Builder::new(hir, span, arguments.len(), return_ty);
let call_site_extent =
// Gather the upvars of a closure, if any.
let upvar_decls: Vec<_> = tcx.with_freevars(fn_id, |freevars| {
freevars.iter().map(|fv| {
- let var_id = tcx.map.as_local_node_id(fv.def.def_id()).unwrap();
+ let var_id = tcx.hir.as_local_node_id(fv.def.def_id()).unwrap();
let by_ref = hir.tables().upvar_capture(ty::UpvarId {
var_id: var_id,
closure_expr_id: fn_id
debug_name: keywords::Invalid.name(),
by_ref: by_ref
};
- if let Some(hir::map::NodeLocal(pat)) = tcx.map.find(var_id) {
+ if let Some(hir::map::NodeLocal(pat)) = tcx.hir.find(var_id) {
if let hir::PatKind::Binding(_, _, ref ident, _) = pat.node {
decl.debug_name = ident.node;
}
body_id: hir::BodyId)
-> Mir<'tcx> {
let tcx = hir.tcx();
- let ast_expr = &tcx.map.body(body_id).value;
+ let ast_expr = &tcx.hir.body(body_id).value;
let ty = hir.tables().expr_ty_adjusted(ast_expr);
- let span = tcx.map.span(tcx.map.body_owner(body_id));
+ let span = tcx.hir.span(tcx.hir.body_owner(body_id));
let mut builder = Builder::new(hir, span, 0, ty);
let extent = tcx.region_maps.temporary_scope(ast_expr.id)
scope.needs_cleanup = true;
}
let tcx = self.hir.tcx();
- let extent_span = extent.span(&tcx.region_maps, &tcx.map).unwrap();
+ let extent_span = extent.span(&tcx.region_maps, &tcx.hir).unwrap();
// Attribute scope exit drops to scope's closing brace
let scope_end = Span { lo: extent_span.hi, .. extent_span};
scope.drops.push(DropData {
where W: Write, I: Iterator<Item=DefId>
{
for def_id in iter {
- let nodeid = tcx.map.as_local_node_id(def_id).unwrap();
+ let nodeid = tcx.hir.as_local_node_id(def_id).unwrap();
let mir = &tcx.item_mir(def_id);
writeln!(w, "digraph Mir_{} {{", nodeid)?;
// Now comes the rote stuff:
hir::ExprRepeat(ref v, count) => {
let tcx = cx.tcx.global_tcx();
- let c = &cx.tcx.map.body(count).value;
+ let c = &cx.tcx.hir.body(count).value;
let count = match ConstContext::new(tcx, count).eval(c, EvalHint::ExprTypeChecked) {
Ok(ConstVal::Integral(ConstInt::Usize(u))) => u,
Ok(other) => bug!("constant evaluation of repeat count yielded {:?}", other),
match def {
Def::Local(def_id) => {
- let node_id = cx.tcx.map.as_local_node_id(def_id).unwrap();
+ let node_id = cx.tcx.hir.as_local_node_id(def_id).unwrap();
ExprKind::VarRef { id: node_id }
}
Def::Upvar(def_id, index, closure_expr_id) => {
- let id_var = cx.tcx.map.as_local_node_id(def_id).unwrap();
+ let id_var = cx.tcx.hir.as_local_node_id(def_id).unwrap();
debug!("convert_var(upvar({:?}, {:?}, {:?}))",
id_var,
index,
closure_expr_id);
let var_ty = cx.tables().node_id_to_type(id_var);
- let body_id = match cx.tcx.map.find(closure_expr_id) {
+ let body_id = match cx.tcx.hir.find(closure_expr_id) {
Some(map::NodeExpr(expr)) => {
match expr.node {
hir::ExprClosure(.., body, _) => body.node_id,
});
let region = cx.tcx.mk_region(region);
- let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) {
+ let self_expr = match cx.tcx.closure_kind(cx.tcx.hir.local_def_id(closure_expr_id)) {
ty::ClosureKind::Fn => {
let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut {
freevar: &hir::Freevar,
freevar_ty: Ty<'tcx>)
-> ExprRef<'tcx> {
- let id_var = cx.tcx.map.as_local_node_id(freevar.def.def_id()).unwrap();
+ let id_var = cx.tcx.hir.as_local_node_id(freevar.def.def_id()).unwrap();
let upvar_id = ty::UpvarId {
var_id: id_var,
closure_expr_id: closure_expr.id,
MirSource::Const(_) |
MirSource::Static(..) => hir::Constness::Const,
MirSource::Fn(id) => {
- let fn_like = FnLikeNode::from_node(infcx.tcx.map.get(id));
+ let fn_like = FnLikeNode::from_node(infcx.tcx.hir.get(id));
fn_like.map_or(hir::Constness::NotConst, |f| f.constness())
}
MirSource::Promoted(..) => bug!(),
};
- let attrs = infcx.tcx.map.attrs(src.item_id());
+ let attrs = infcx.tcx.hir.attrs(src.item_id());
// Some functions always have overflow checks enabled,
// however, they may not get codegen'd, depending on
-> (Mir<'tcx>, MirSource) {
let tcx = infcx.tcx.global_tcx();
- let item_id = tcx.map.body_owner(body_id);
+ let item_id = tcx.hir.body_owner(body_id);
let src = MirSource::from_node(tcx, item_id);
let cx = Cx::new(infcx, src);
if let MirSource::Fn(id) = src {
// types/lifetimes replaced)
let fn_sig = cx.tables().liberated_fn_sigs[&id].clone();
- let ty = tcx.item_type(tcx.map.local_def_id(id));
+ let ty = tcx.item_type(tcx.hir.local_def_id(id));
let (abi, implicit_argument) = if let ty::TyClosure(..) = ty.sty {
(Abi::Rust, Some((closure_self_ty(tcx, id, body_id), None)))
} else {
(ty.fn_abi(), None)
};
- let body = tcx.map.body(body_id);
+ let body = tcx.hir.body(body_id);
let explicit_arguments =
body.arguments
.iter()
pretty::dump_mir(tcx, "mir_map", &0, src, &mir);
let mir = tcx.alloc_mir(mir);
- let def_id = tcx.map.local_def_id(src.item_id());
+ let def_id = tcx.hir.local_def_id(src.item_id());
assert!(tcx.mir_map.borrow_mut().insert(def_id, mir).is_none());
});
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
self.visit_body(body);
}
}
});
let region = tcx.mk_region(region);
- match tcx.closure_kind(tcx.map.local_def_id(closure_expr_id)) {
+ match tcx.closure_kind(tcx.hir.local_def_id(closure_expr_id)) {
ty::ClosureKind::Fn =>
tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
Some(ref filters) => filters,
};
let node_id = src.item_id();
- let node_path = tcx.item_path_str(tcx.map.local_def_id(node_id));
+ let node_path = tcx.item_path_str(tcx.hir.local_def_id(node_id));
let is_matched =
filters.split("&")
.any(|filter| {
writeln!(w, "")?;
}
- let id = tcx.map.as_local_node_id(def_id).unwrap();
+ let id = tcx.hir.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);
write_mir_fn(tcx, src, mir, w)?;
return
}
MirSource::Fn(function_node_id) => {
- if qualify_consts::is_const_fn(tcx, tcx.map.local_def_id(function_node_id)) {
+ if qualify_consts::is_const_fn(tcx, tcx.hir.local_def_id(function_node_id)) {
// Don't run on const functions, as, again, trans might not be able to evaluate
// the optimized IR.
return
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource, mir: &mut Mir<'tcx>) {
let node_id = source.item_id();
- let node_path = tcx.item_path_str(tcx.map.local_def_id(node_id));
+ let node_path = tcx.item_path_str(tcx.hir.local_def_id(node_id));
debug!("running on: {:?}", node_path);
// we only run when mir_opt_level > 2
if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 {
}
pub fn is_const_fn(tcx: TyCtxt, def_id: DefId) -> bool {
- if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
- if let Some(fn_like) = FnLikeNode::from_node(tcx.map.get(node_id)) {
+ if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+ if let Some(fn_like) = FnLikeNode::from_node(tcx.hir.get(node_id)) {
fn_like.constness() == hir::Constness::Const
} else {
false
self.tcx
.lookup_trait_def(drop_trait_id)
.for_each_relevant_impl(self.tcx, self.mir.return_ty, |impl_did| {
- self.tcx.map
+ self.tcx.hir
.as_local_node_id(impl_did)
- .and_then(|impl_node_id| self.tcx.map.find(impl_node_id))
+ .and_then(|impl_node_id| self.tcx.hir.find(impl_node_id))
.map(|node| {
if let hir_map::NodeItem(item) = node {
if let hir::ItemImpl(.., ref impl_item_refs) = item.node {
span = impl_item_refs.first()
.map(|iiref| {
- self.tcx.map.impl_item(iiref.id)
+ self.tcx.hir.impl_item(iiref.id)
.span
});
}
}
let param_env = if def_id.is_local() {
- let node_id = tcx.map.as_local_node_id(def_id).unwrap();
+ let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
ty::ParameterEnvironment::for_item(tcx, node_id)
} else {
// These should only be monomorphic constants.
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
src: MirSource, mir: &mut Mir<'tcx>) {
let id = src.item_id();
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
let mode = match src {
MirSource::Fn(_) => {
if is_const_fn(tcx, def_id) {
fn handle_const_fn_call(&mut self, def_id: DefId, ret_ty: Ty<'gcx>) {
self.add_type(ret_ty);
- self.promotable &= if let Some(fn_id) = self.tcx.map.as_local_node_id(def_id) {
- FnLikeNode::from_node(self.tcx.map.get(fn_id)).map_or(false, |fn_like| {
+ self.promotable &= if let Some(fn_id) = self.tcx.hir.as_local_node_id(def_id) {
+ FnLikeNode::from_node(self.tcx.hir.get(fn_id)).map_or(false, |fn_like| {
fn_like.constness() == hir::Constness::Const
})
} else {
}
}
- let item_id = self.tcx.map.body_owner(body_id);
+ let item_id = self.tcx.hir.body_owner(body_id);
let outer_in_fn = self.in_fn;
self.in_fn = match MirSource::from_node(self.tcx, item_id) {
};
let outer_tables = self.tables;
- self.tables = self.tcx.item_tables(self.tcx.map.local_def_id(item_id));
+ self.tables = self.tcx.item_tables(self.tcx.hir.local_def_id(item_id));
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
if !self.in_fn {
self.check_const_eval(&body.value);
}
Def::Fn(..) | Def::Method(..) => {}
Def::AssociatedConst(_) => v.add_type(node_ty),
Def::Const(did) => {
- v.promotable &= if let Some(node_id) = v.tcx.map.as_local_node_id(did) {
- match v.tcx.map.expect_item(node_id).node {
+ v.promotable &= if let Some(node_id) = v.tcx.hir.as_local_node_id(did) {
+ match v.tcx.hir.expect_item(node_id).node {
hir::ItemConst(_, body) => {
v.visit_nested_body(body);
v.tcx.rvalue_promotable_to_static.borrow()[&body.node_id]
}
#[derive(Copy, Clone)]
-struct CheckLoopVisitor<'a, 'ast: 'a> {
+struct CheckLoopVisitor<'a, 'hir: 'a> {
sess: &'a Session,
- hir_map: &'a Map<'ast>,
+ hir_map: &'a Map<'hir>,
cx: Context,
}
}.as_deep_visitor());
}
-impl<'a, 'ast> Visitor<'ast> for CheckLoopVisitor<'a, 'ast> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
+impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
NestedVisitorMap::OnlyBodies(&self.hir_map)
}
- fn visit_item(&mut self, i: &'ast hir::Item) {
+ fn visit_item(&mut self, i: &'hir hir::Item) {
self.with_context(Normal, |v| intravisit::walk_item(v, i));
}
- fn visit_impl_item(&mut self, i: &'ast hir::ImplItem) {
+ fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) {
self.with_context(Normal, |v| intravisit::walk_impl_item(v, i));
}
- fn visit_expr(&mut self, e: &'ast hir::Expr) {
+ fn visit_expr(&mut self, e: &'hir hir::Expr) {
match e.node {
hir::ExprWhile(ref e, ref b, _) => {
self.with_context(Loop(LoopKind::WhileLoop), |v| {
}
}
-impl<'a, 'ast> CheckLoopVisitor<'a, 'ast> {
+impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
fn with_context<F>(&mut self, cx: Context, f: F)
- where F: FnOnce(&mut CheckLoopVisitor<'a, 'ast>)
+ where F: FnOnce(&mut CheckLoopVisitor<'a, 'hir>)
{
let old_cx = self.cx;
self.cx = cx;
}
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
self.tcx.infer_ctxt(body_id, Reveal::NotSpecializable).enter(|infcx| {
let mut delegate = RvalueContextDelegate {
tcx: infcx.tcx,
// recursively.
use rustc::dep_graph::DepNode;
-use rustc::hir::map as ast_map;
+use rustc::hir::map as hir_map;
use rustc::session::{CompileResult, Session};
use rustc::hir::def::{Def, CtorKind};
use rustc::util::nodemap::{NodeMap, NodeSet};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir;
-struct CheckCrateVisitor<'a, 'ast: 'a> {
+struct CheckCrateVisitor<'a, 'hir: 'a> {
sess: &'a Session,
- ast_map: &'a ast_map::Map<'ast>,
+ hir_map: &'a hir_map::Map<'hir>,
// `discriminant_map` is a cache that associates the `NodeId`s of local
// variant definitions with the discriminant expression that applies to
// each one. If the variant uses the default values (starting from `0`),
detected_recursive_ids: NodeSet,
}
-impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
+impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
NestedVisitorMap::None
}
- fn visit_item(&mut self, it: &'ast hir::Item) {
+ fn visit_item(&mut self, it: &'hir hir::Item) {
match it.node {
hir::ItemStatic(..) |
hir::ItemConst(..) => {
intravisit::walk_item(self, it)
}
- fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
+ fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) {
match ti.node {
hir::TraitItemKind::Const(_, ref default) => {
if let Some(_) = *default {
intravisit::walk_trait_item(self, ti)
}
- fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
+ fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) {
match ii.node {
hir::ImplItemKind::Const(..) => {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
}
}
-pub fn check_crate<'ast>(sess: &Session, ast_map: &ast_map::Map<'ast>) -> CompileResult {
- let _task = ast_map.dep_graph.in_task(DepNode::CheckStaticRecursion);
+pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult {
+ let _task = hir_map.dep_graph.in_task(DepNode::CheckStaticRecursion);
let mut visitor = CheckCrateVisitor {
sess: sess,
- ast_map: ast_map,
+ hir_map: hir_map,
discriminant_map: NodeMap(),
detected_recursive_ids: NodeSet(),
};
sess.track_errors(|| {
// FIXME(#37712) could use ItemLikeVisitor if trait items were item-like
- ast_map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
+ hir_map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
})
}
-struct CheckItemRecursionVisitor<'a, 'b: 'a, 'ast: 'b> {
+struct CheckItemRecursionVisitor<'a, 'b: 'a, 'hir: 'b> {
root_span: &'b Span,
sess: &'b Session,
- ast_map: &'b ast_map::Map<'ast>,
+ hir_map: &'b hir_map::Map<'hir>,
discriminant_map: &'a mut NodeMap<Option<hir::BodyId>>,
idstack: Vec<ast::NodeId>,
detected_recursive_ids: &'a mut NodeSet,
}
-impl<'a, 'b: 'a, 'ast: 'b> CheckItemRecursionVisitor<'a, 'b, 'ast> {
- fn new(v: &'a mut CheckCrateVisitor<'b, 'ast>, span: &'b Span) -> Self {
+impl<'a, 'b: 'a, 'hir: 'b> CheckItemRecursionVisitor<'a, 'b, 'hir> {
+ fn new(v: &'a mut CheckCrateVisitor<'b, 'hir>, span: &'b Span) -> Self {
CheckItemRecursionVisitor {
root_span: span,
sess: v.sess,
- ast_map: v.ast_map,
+ hir_map: v.hir_map,
discriminant_map: &mut v.discriminant_map,
idstack: Vec::new(),
detected_recursive_ids: &mut v.detected_recursive_ids,
}
self.detected_recursive_ids.insert(id);
let any_static = self.idstack.iter().any(|&x| {
- if let ast_map::NodeItem(item) = self.ast_map.get(x) {
+ if let hir_map::NodeItem(item) = self.hir_map.get(x) {
if let hir::ItemStatic(..) = item.node {
true
} else {
// So for every variant, we need to track whether there is an expression
// somewhere in the enum definition that controls its discriminant. We do
// this by starting from the end and searching backward.
- fn populate_enum_discriminants(&mut self, enum_definition: &'ast hir::EnumDef) {
+ fn populate_enum_discriminants(&mut self, enum_definition: &'hir hir::EnumDef) {
// Get the map, and return if we already processed this enum or if it
// has no variants.
match enum_definition.variants.first() {
}
}
-impl<'a, 'b: 'a, 'ast: 'b> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'b, 'ast> {
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
- NestedVisitorMap::OnlyBodies(&self.ast_map)
+impl<'a, 'b: 'a, 'hir: 'b> Visitor<'hir> for CheckItemRecursionVisitor<'a, 'b, 'hir> {
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
+ NestedVisitorMap::OnlyBodies(&self.hir_map)
}
- fn visit_item(&mut self, it: &'ast hir::Item) {
+ fn visit_item(&mut self, it: &'hir hir::Item) {
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span);
}
fn visit_enum_def(&mut self,
- enum_definition: &'ast hir::EnumDef,
- generics: &'ast hir::Generics,
+ enum_definition: &'hir hir::EnumDef,
+ generics: &'hir hir::Generics,
item_id: ast::NodeId,
_: Span) {
self.populate_enum_discriminants(enum_definition);
}
fn visit_variant(&mut self,
- variant: &'ast hir::Variant,
- _: &'ast hir::Generics,
+ variant: &'hir hir::Variant,
+ _: &'hir hir::Generics,
_: ast::NodeId) {
let variant_id = variant.node.data.id();
let maybe_expr = *self.discriminant_map.get(&variant_id).unwrap_or_else(|| {
// If `maybe_expr` is `None`, that's because no discriminant is
// specified that affects this variant. Thus, no risk of recursion.
if let Some(expr) = maybe_expr {
- let expr = &self.ast_map.body(expr).value;
+ let expr = &self.hir_map.body(expr).value;
self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr), expr.span);
}
}
- fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
+ fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) {
self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti), ti.span);
}
- fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
+ fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) {
self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii), ii.span);
}
- fn visit_path(&mut self, path: &'ast hir::Path, _: ast::NodeId) {
+ fn visit_path(&mut self, path: &'hir hir::Path, _: ast::NodeId) {
match path.def {
Def::Static(def_id, _) |
Def::AssociatedConst(def_id) |
Def::Const(def_id) => {
- if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
- match self.ast_map.get(node_id) {
- ast_map::NodeItem(item) => self.visit_item(item),
- ast_map::NodeTraitItem(item) => self.visit_trait_item(item),
- ast_map::NodeImplItem(item) => self.visit_impl_item(item),
- ast_map::NodeForeignItem(_) => {}
+ if let Some(node_id) = self.hir_map.as_local_node_id(def_id) {
+ match self.hir_map.get(node_id) {
+ hir_map::NodeItem(item) => self.visit_item(item),
+ hir_map::NodeTraitItem(item) => self.visit_trait_item(item),
+ hir_map::NodeImplItem(item) => self.visit_impl_item(item),
+ hir_map::NodeForeignItem(_) => {}
_ => {
span_bug!(path.span,
"expected item, found {}",
- self.ast_map.node_to_string(node_id));
+ self.hir_map.node_to_string(node_id));
}
}
}
// the whole enum definition to see what expression that
// might be (if any).
Def::VariantCtor(variant_id, CtorKind::Const) => {
- if let Some(variant_id) = self.ast_map.as_local_node_id(variant_id) {
- let variant = self.ast_map.expect_variant(variant_id);
- let enum_id = self.ast_map.get_parent(variant_id);
- let enum_item = self.ast_map.expect_item(enum_id);
+ if let Some(variant_id) = self.hir_map.as_local_node_id(variant_id) {
+ let variant = self.hir_map.expect_variant(variant_id);
+ let enum_id = self.hir_map.get_parent(variant_id);
+ let enum_item = self.hir_map.expect_item(enum_id);
if let hir::ItemEnum(ref enum_def, ref generics) = enum_item.node {
self.populate_enum_discriminants(enum_def);
self.visit_variant(variant, generics, enum_id);
ty::TyProjection(ref proj) => proj.trait_ref.def_id,
_ => return Some(AccessLevel::Public)
};
- if let Some(node_id) = self.tcx.map.as_local_node_id(ty_def_id) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(ty_def_id) {
self.get(node_id)
} else {
Some(AccessLevel::Public)
fn impl_trait_level(&self, impl_def_id: DefId) -> Option<AccessLevel> {
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_def_id) {
- if let Some(node_id) = self.tcx.map.as_local_node_id(trait_ref.def_id) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(trait_ref.def_id) {
return self.get(node_id);
}
}
fn reach<'b>(&'b mut self, item_id: ast::NodeId)
-> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
ReachEverythingInTheInterfaceVisitor {
- item_def_id: self.tcx.map.local_def_id(item_id),
+ item_def_id: self.tcx.hir.local_def_id(item_id),
ev: self,
}
}
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.map)
+ NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
let inherited_item_level = match item.node {
// Impls inherit level from their types and traits
hir::ItemImpl(..) => {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
cmp::min(self.item_ty_level(def_id), self.impl_trait_level(def_id))
}
hir::ItemDefaultImpl(..) => {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
self.impl_trait_level(def_id)
}
// Foreign mods inherit level from parents
if self.prev_level.is_some() {
if let Some(exports) = self.export_map.get(&id) {
for export in exports {
- if let Some(node_id) = self.tcx.map.as_local_node_id(export.def.def_id()) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
self.update(node_id, Some(AccessLevel::Exported));
}
}
};
if let Some(def_id) = ty_def_id {
- if let Some(node_id) = self.ev.tcx.map.as_local_node_id(def_id) {
+ if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(def_id) {
self.ev.update(node_id, Some(AccessLevel::Reachable));
}
}
}
fn visit_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) -> bool {
- if let Some(node_id) = self.ev.tcx.map.as_local_node_id(trait_ref.def_id) {
- let item = self.ev.tcx.map.expect_item(node_id);
+ if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(trait_ref.def_id) {
+ let item = self.ev.tcx.hir.expect_item(node_id);
self.ev.update(item.id, Some(AccessLevel::Reachable));
}
impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
fn item_is_accessible(&self, did: DefId) -> bool {
- match self.tcx.map.as_local_node_id(did) {
+ match self.tcx.hir.as_local_node_id(did) {
Some(node_id) =>
- ty::Visibility::from_hir(&self.tcx.map.expect_item(node_id).vis, node_id, self.tcx),
+ ty::Visibility::from_hir(&self.tcx.hir.expect_item(node_id).vis, node_id, self.tcx),
None => self.tcx.sess.cstore.visibility(did),
}.is_accessible_from(self.curitem, self.tcx)
}
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.map)
+ NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
- let body = self.tcx.map.body(body);
+ let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
- let orig_curitem = replace(&mut self.curitem, self.tcx.map.local_def_id(item.id));
+ let orig_curitem = replace(&mut self.curitem, self.tcx.hir.local_def_id(item.id));
intravisit::walk_item(self, item);
self.curitem = orig_curitem;
}
error.span_label(expr.span,
&format!("cannot construct with a private field"));
- if let Some(node_id) = self.tcx.map.as_local_node_id(adt_def.did) {
- let node = self.tcx.map.find(node_id);
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(adt_def.did) {
+ let node = self.tcx.hir.find(node_id);
if let Some(hir::map::NodeStructCtor(vdata)) = node {
for i in private_indexes {
error.span_label(vdata.fields()[i].span,
// A path can only be private if:
// it's in this crate...
- if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(did) {
// .. and it corresponds to a private type in the AST (this returns
// None for type parameters)
- match self.tcx.map.find(node_id) {
+ match self.tcx.hir.find(node_id) {
Some(hir::map::NodeItem(ref item)) => item.vis != hir::Public,
Some(_) | None => false,
}
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.map)
+ NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
|tr| {
let did = tr.path.def.def_id();
- if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(did) {
self.trait_is_public(node_id)
} else {
true // external traits must be public
trait_ref.is_some() ||
impl_item_refs.iter()
.any(|impl_item_ref| {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
match impl_item.node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Method(..) => {
// should only walk into public items so that we
// don't erroneously report errors for private
// types in private items.
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
match impl_item.node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Method(..)
// Those in 3. are warned with this call.
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
if let hir::ImplItemKind::Type(ref ty) = impl_item.node {
self.visit_ty(ty);
}
let mut found_pub_static = false;
for impl_item_ref in impl_item_refs {
if self.item_is_public(&impl_item_ref.id.node_id, &impl_item_ref.vis) {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
match impl_item_ref.kind {
hir::AssociatedItemKind::Const => {
found_pub_static = true;
if let Some(def_id) = ty_def_id {
// Non-local means public (private items can't leave their crate, modulo bugs)
- if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
- let item = self.tcx.map.expect_item(node_id);
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
+ let item = self.tcx.hir.expect_item(node_id);
let vis = ty::Visibility::from_hir(&item.vis, node_id, self.tcx);
if !vis.is_at_least(self.min_visibility, self.tcx) {
fn visit_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) -> bool {
// Non-local means public (private items can't leave their crate, modulo bugs)
- if let Some(node_id) = self.tcx.map.as_local_node_id(trait_ref.def_id) {
- let item = self.tcx.map.expect_item(node_id);
+ if let Some(node_id) = self.tcx.hir.as_local_node_id(trait_ref.def_id) {
+ let item = self.tcx.hir.expect_item(node_id);
let vis = ty::Visibility::from_hir(&item.vis, node_id, self.tcx);
if !vis.is_at_least(self.min_visibility, self.tcx) {
has_old_errors = true;
break;
}
- let parent = self.tcx.map.get_parent_node(id);
+ let parent = self.tcx.hir.get_parent_node(id);
if parent == id {
break;
}
SearchInterfaceForPrivateItemsVisitor {
tcx: self.tcx,
- item_def_id: self.tcx.map.local_def_id(item_id),
- span: self.tcx.map.span(item_id),
+ item_def_id: self.tcx.hir.local_def_id(item_id),
+ span: self.tcx.hir.span(item_id),
min_visibility: ty::Visibility::Public,
required_visibility: required_visibility,
has_old_errors: has_old_errors,
impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
self.check(item.id, ty_vis).generics().predicates();
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
let impl_item_vis =
ty::Visibility::from_hir(&impl_item.vis, item.id, tcx);
self.check(impl_item.id, min(impl_item_vis, ty_vis))
.item_type().impl_trait_ref().min_visibility;
self.check(item.id, vis).generics().predicates();
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
self.check(impl_item.id, vis).generics().predicates().item_type();
// Recurse for e.g. `impl Trait` (see `visit_ty`).
-> AccessLevels {
let _task = tcx.dep_graph.in_task(DepNode::Privacy);
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
// Use the parent map to check the privacy of everything
let mut visitor = PrivacyVisitor {
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>)
{
let old_tables = self.save_ctxt.tables;
- let item_def_id = self.tcx.map.local_def_id(item_id);
+ let item_def_id = self.tcx.hir.local_def_id(item_id);
self.save_ctxt.tables = self.tcx.item_tables(item_def_id);
f(self);
self.save_ctxt.tables = old_tables;
// with the right name.
if !self.span.filter_generated(Some(method_data.span), span) {
let container =
- self.tcx.associated_item(self.tcx.map.local_def_id(id)).container;
+ self.tcx.associated_item(self.tcx.hir.local_def_id(id)).container;
let mut trait_id;
let mut decl_id = None;
match container {
}
}
None => {
- if let Some(NodeItem(item)) = self.tcx.map.get_if_local(id) {
+ if let Some(NodeItem(item)) = self.tcx.hir.get_if_local(id) {
if let hir::ItemImpl(_, _, _, _, ref ty, _) = item.node {
trait_id = self.lookup_def_id(ty.id);
}
type_value: enum_data.qualname.clone(),
value: val,
scope: enum_data.scope,
- parent: Some(make_def_id(item.id, &self.tcx.map)),
+ parent: Some(make_def_id(item.id, &self.tcx.hir)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
}.lower(self.tcx));
type_value: enum_data.qualname.clone(),
value: val,
scope: enum_data.scope,
- parent: Some(make_def_id(item.id, &self.tcx.map)),
+ parent: Some(make_def_id(item.id, &self.tcx.hir)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
}.lower(self.tcx));
}
self.process_generic_params(type_parameters, item.span, "", item.id);
for impl_item in impl_items {
- let map = &self.tcx.map;
+ let map = &self.tcx.hir;
self.process_impl_item(impl_item, make_def_id(item.id, map));
}
}
// walk generics and methods
self.process_generic_params(generics, item.span, &qualname, item.id);
for method in methods {
- let map = &self.tcx.map;
+ let map = &self.tcx.hir;
self.process_trait_item(method, make_def_id(item.id, map))
}
}
visit::walk_expr(self, ex);
}
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
- let hir_expr = self.save_ctxt.tcx.map.expect_expr(ex.id);
+ let hir_expr = self.save_ctxt.tcx.hir.expect_expr(ex.id);
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
Some(ty) => ty.ty_adt_def().unwrap(),
None => {
ast::ExprKind::TupField(ref sub_ex, idx) => {
self.visit_expr(&sub_ex);
- let hir_node = match self.save_ctxt.tcx.map.find(sub_ex.id) {
+ let hir_node = match self.save_ctxt.tcx.hir.find(sub_ex.id) {
Some(Node::NodeExpr(expr)) => expr,
_ => {
debug!("Missing or weird node for sub-expression {} in {:?}",
for &(id, ref p, immut, ref_kind) in &collector.collected_paths {
match self.save_ctxt.get_path_def(id) {
Def::Local(def_id) => {
- let id = self.tcx.map.as_local_node_id(def_id).unwrap();
+ let id = self.tcx.hir.as_local_node_id(def_id).unwrap();
let mut value = if immut == ast::Mutability::Immutable {
self.span.snippet(p.span).to_string()
} else {
fn lower(self, tcx: TyCtxt) -> EnumData {
EnumData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
value: self.value,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
- variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
+ scope: make_def_id(self.scope, &tcx.hir),
+ variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
fn lower(self, tcx: TyCtxt) -> ExternCrateData {
ExternCrateData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
crate_num: self.crate_num,
location: self.location,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
}
}
}
fn lower(self, tcx: TyCtxt) -> FunctionCallData {
FunctionCallData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
fn lower(self, tcx: TyCtxt) -> FunctionData {
FunctionData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
declaration: self.declaration,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
visibility: self.visibility,
parent: self.parent,
fn lower(self, tcx: TyCtxt) -> FunctionRefData {
FunctionRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
fn lower(self, tcx: TyCtxt) -> ImplData {
ImplData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
trait_ref: self.trait_ref,
self_ref: self.self_ref,
}
InheritanceData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
base_id: self.base_id,
- deriv_id: make_def_id(self.deriv_id, &tcx.map)
+ deriv_id: make_def_id(self.deriv_id, &tcx.hir)
}
}
}
name: self.name,
qualname: self.qualname,
callee_span: SpanData::from_span(self.callee_span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
}
}
}
fn lower(self, tcx: TyCtxt) -> MethodCallData {
MethodCallData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
decl_id: self.decl_id,
}
MethodData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
- scope: make_def_id(self.scope, &tcx.map),
- id: make_def_id(self.id, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
+ id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
value: self.value,
decl_id: self.decl_id,
fn lower(self, tcx: TyCtxt) -> ModData {
ModData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
filename: self.filename,
- items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
+ items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
fn lower(self, tcx: TyCtxt) -> ModRefData {
ModRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
qualname: self.qualname,
}
StructData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
- id: make_def_id(self.id, &tcx.map),
- ctor_id: make_def_id(self.ctor_id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
+ ctor_id: make_def_id(self.ctor_id, &tcx.hir),
qualname: self.qualname,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
- fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
+ fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
StructVariantData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
type_value: self.type_value,
value: self.value,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
TraitData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
- items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
+ items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
fn lower(self, tcx: TyCtxt) -> TupleVariantData {
TupleVariantData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
type_value: self.type_value,
value: self.value,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
fn lower(self, tcx: TyCtxt) -> TypeDefData {
TypeDefData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
name: self.name,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
qualname: self.qualname,
fn lower(self, tcx: TyCtxt) -> TypeRefData {
TypeRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
qualname: self.qualname,
}
fn lower(self, tcx: TyCtxt) -> UseData {
UseData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
mod_id: self.mod_id,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
visibility: self.visibility,
}
}
fn lower(self, tcx: TyCtxt) -> UseGlobData {
UseGlobData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
names: self.names,
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
visibility: self.visibility,
}
}
fn lower(self, tcx: TyCtxt) -> VariableData {
VariableData {
- id: make_def_id(self.id, &tcx.map),
+ id: make_def_id(self.id, &tcx.hir),
kind: self.kind,
name: self.name,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
type_value: self.type_value,
parent: self.parent,
VariableRefData {
name: self.name,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
- scope: make_def_id(self.scope, &tcx.map),
+ scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
filter!(self.span_utils, sub_span, field.span, None);
- let def_id = self.tcx.map.local_def_id(field.id);
+ let def_id = self.tcx.hir.local_def_id(field.id);
let typ = self.tcx.item_type(def_id).to_string();
let span = field.span;
qualname: qualname,
span: sub_span.unwrap(),
scope: scope,
- parent: Some(make_def_id(scope, &self.tcx.map)),
+ parent: Some(make_def_id(scope, &self.tcx.hir)),
value: "".to_owned(),
type_value: typ,
visibility: From::from(&field.vis),
// The qualname for a method is the trait name or name of the struct in an impl in
// which the method is declared in, followed by the method's name.
let (qualname, parent_scope, decl_id, vis, docs) =
- match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) {
- Some(impl_id) => match self.tcx.map.get_if_local(impl_id) {
+ match self.tcx.impl_of_method(self.tcx.hir.local_def_id(id)) {
+ Some(impl_id) => match self.tcx.hir.get_if_local(impl_id) {
Some(Node::NodeItem(item)) => {
match item.node {
hir::ItemImpl(.., ref ty, _) => {
let mut result = String::from("<");
- result.push_str(&self.tcx.map.node_to_pretty_string(ty.id));
+ result.push_str(&self.tcx.hir.node_to_pretty_string(ty.id));
let trait_id = self.tcx.trait_id_of_impl(impl_id);
let mut decl_id = None;
r);
}
},
- None => match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) {
+ None => match self.tcx.trait_of_item(self.tcx.hir.local_def_id(id)) {
Some(def_id) => {
- match self.tcx.map.get_if_local(def_id) {
+ match self.tcx.hir.get_if_local(def_id) {
Some(Node::NodeItem(item)) => {
(format!("::{}", self.tcx.item_path_str(def_id)),
Some(def_id), None,
}
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
- let hir_node = self.tcx.map.expect_expr(expr.id);
+ let hir_node = self.tcx.hir.expect_expr(expr.id);
let ty = self.tables.expr_ty_adjusted_opt(&hir_node);
if ty.is_none() || ty.unwrap().sty == ty::TyError {
return None;
}
match expr.node {
ast::ExprKind::Field(ref sub_ex, ident) => {
- let hir_node = match self.tcx.map.find(sub_ex.id) {
+ let hir_node = match self.tcx.hir.find(sub_ex.id) {
Some(Node::NodeExpr(expr)) => expr,
_ => {
debug!("Missing or weird node for sub-expression {} in {:?}",
}
pub fn get_path_def(&self, id: NodeId) -> Def {
- match self.tcx.map.get(id) {
+ match self.tcx.hir.get(id) {
Node::NodeTraitRef(tr) => tr.path.def,
Node::NodeItem(&hir::Item { node: hir::ItemUse(ref path, _), .. }) |
#[inline]
pub fn enclosing_scope(&self, id: NodeId) -> NodeId {
- self.tcx.map.get_enclosing_scope(id).unwrap_or(CRATE_NODE_ID)
+ self.tcx.hir.get_enclosing_scope(id).unwrap_or(CRATE_NODE_ID)
}
}
}
let ams = AssertModuleSource { tcx: tcx, modules: modules };
- for attr in &tcx.map.krate().attrs {
+ for attr in &tcx.hir.krate().attrs {
ams.check_attr(attr);
}
}
.exported_symbols()
.iter()
.map(|&node_id| {
- scx.tcx().map.local_def_id(node_id)
+ scx.tcx().hir.local_def_id(node_id)
})
.map(|def_id| {
let name = symbol_for_def_id(scx, def_id, symbol_map);
if let Some(id) = scx.sess().derive_registrar_fn.get() {
let svh = &scx.link_meta().crate_hash;
- let def_id = scx.tcx().map.local_def_id(id);
+ let def_id = scx.tcx().hir.local_def_id(id);
let idx = def_id.index;
let registrar = scx.sess().generate_derive_registrar_symbol(svh, idx);
local_crate.push((registrar, SymbolExportLevel::C));
-> String {
// Just try to look things up in the symbol map. If nothing's there, we
// recompute.
- if let Some(node_id) = scx.tcx().map.as_local_node_id(def_id) {
+ if let Some(node_id) = scx.tcx().hir.as_local_node_id(def_id) {
if let Some(sym) = symbol_map.get(TransItem::Static(node_id)) {
return sym.to_owned();
}
debug!("symbol_name(def_id={:?}, substs={:?})",
def_id, substs);
- let node_id = scx.tcx().map.as_local_node_id(def_id);
+ let node_id = scx.tcx().hir.as_local_node_id(def_id);
if let Some(id) = node_id {
if scx.sess().plugin_registrar_fn.get() == Some(id) {
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
let attrs = scx.tcx().get_attrs(def_id);
let is_foreign = if let Some(id) = node_id {
- match scx.tcx().map.get(id) {
+ match scx.tcx().hir.get(id) {
hir_map::NodeForeignItem(_) => true,
_ => false
}
pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
let (main_def_id, span) = match *ccx.sess().entry_fn.borrow() {
Some((id, span)) => {
- (ccx.tcx().map.local_def_id(id), span)
+ (ccx.tcx().hir.local_def_id(id), span)
}
None => return,
};
//
// As a result, if this id is an FFI item (foreign item) then we only
// let it through if it's included statically.
- match tcx.map.get(id) {
+ match tcx.hir.get(id) {
hir_map::NodeForeignItem(..) => {
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
tcx.sess.cstore.is_statically_included_foreign_item(def_id)
}
node: hir::ItemFn(..), .. }) |
hir_map::NodeImplItem(&hir::ImplItem {
node: hir::ImplItemKind::Method(..), .. }) => {
- let def_id = tcx.map.local_def_id(id);
+ let def_id = tcx.hir.local_def_id(id);
let generics = tcx.item_generics(def_id);
let attributes = tcx.get_attrs(def_id);
(generics.parent_types == 0 && generics.types.is_empty()) &&
// entire contents of the krate. So if you push any subtasks of
// `TransCrate`, you need to be careful to register "reads" of the
// particular items that will be processed.
- let krate = tcx.map.krate();
+ let krate = tcx.hir.krate();
let ty::CrateAnalysis { export_map, reachable, name, .. } = analysis;
let exported_symbols = find_exported_symbols(tcx, reachable);
output: &mut roots,
};
- scx.tcx().map.krate().visit_all_item_likes(&mut visitor);
+ scx.tcx().hir.krate().visit_all_item_likes(&mut visitor);
}
roots
recursion_depth_reset = None;
}
TransItem::Static(node_id) => {
- let def_id = scx.tcx().map.local_def_id(node_id);
+ let def_id = scx.tcx().hir.local_def_id(node_id);
// Sanity check whether this ended up being collected accidentally
debug_assert!(should_trans_locally(scx.tcx(), def_id));
if recursion_depth > tcx.sess.recursion_limit.get() {
let error = format!("reached the recursion limit while instantiating `{}`",
instance);
- if let Some(node_id) = tcx.map.as_local_node_id(instance.def) {
- tcx.sess.span_fatal(tcx.map.span(node_id), &error);
+ if let Some(node_id) = tcx.hir.as_local_node_id(instance.def) {
+ tcx.sess.span_fatal(tcx.hir.span(node_id), &error);
} else {
tcx.sess.fatal(&error);
}
let instance_name = instance.to_string();
let msg = format!("reached the type-length limit while instantiating `{:.64}...`",
instance_name);
- let mut diag = if let Some(node_id) = tcx.map.as_local_node_id(instance.def) {
- tcx.sess.struct_span_fatal(tcx.map.span(node_id), &msg)
+ let mut diag = if let Some(node_id) = tcx.hir.as_local_node_id(instance.def) {
+ tcx.sess.struct_span_fatal(tcx.hir.span(node_id), &msg)
} else {
tcx.sess.struct_fatal(&msg)
};
// Some constructors also have type TyFnDef but they are
// always instantiated inline and don't result in a
// translation item. Same for FFI functions.
- if let Some(hir_map::NodeForeignItem(_)) = tcx.map.get_if_local(def_id) {
+ if let Some(hir_map::NodeForeignItem(_)) = tcx.hir.get_if_local(def_id) {
return false;
}
hir::ItemUnion(_, ref generics) => {
if !generics.is_parameterized() {
if self.mode == TransItemCollectionMode::Eager {
- let def_id = self.scx.tcx().map.local_def_id(item.id);
+ let def_id = self.scx.tcx().hir.local_def_id(item.id);
debug!("RootCollector: ADT drop-glue for {}",
def_id_to_string(self.scx.tcx(), def_id));
hir::ItemStatic(..) => {
debug!("RootCollector: ItemStatic({})",
def_id_to_string(self.scx.tcx(),
- self.scx.tcx().map.local_def_id(item.id)));
+ self.scx.tcx().hir.local_def_id(item.id)));
self.output.push(TransItem::Static(item.id));
}
hir::ItemConst(..) => {
}
hir::ItemFn(.., ref generics, _) => {
if !generics.is_type_parameterized() {
- let def_id = self.scx.tcx().map.local_def_id(item.id);
+ let def_id = self.scx.tcx().hir.local_def_id(item.id);
debug!("RootCollector: ItemFn({})",
def_id_to_string(self.scx.tcx(), def_id));
ref generics,
..
}, _) => {
- let hir_map = &self.scx.tcx().map;
+ let hir_map = &self.scx.tcx().hir;
let parent_node_id = hir_map.get_parent_node(ii.id);
let is_impl_generic = match hir_map.expect_item(parent_node_id) {
&hir::Item {
};
if !generics.is_type_parameterized() && !is_impl_generic {
- let def_id = self.scx.tcx().map.local_def_id(ii.id);
+ let def_id = self.scx.tcx().hir.local_def_id(ii.id);
debug!("RootCollector: MethodImplItem({})",
def_id_to_string(self.scx.tcx(), def_id));
return
}
- let impl_def_id = tcx.map.local_def_id(item.id);
+ let impl_def_id = tcx.hir.local_def_id(item.id);
debug!("create_trans_items_for_default_impls(item={})",
def_id_to_string(tcx, impl_def_id));
}
let ty = ccx.tcx().item_type(def_id);
- let g = if let Some(id) = ccx.tcx().map.as_local_node_id(def_id) {
+ let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
let llty = type_of::type_of(ccx, ty);
- let (g, attrs) = match ccx.tcx().map.get(id) {
+ let (g, attrs) = match ccx.tcx().hir.get(id) {
hir_map::NodeItem(&hir::Item {
ref attrs, span, node: hir::ItemStatic(..), ..
}) => {
attrs: &[ast::Attribute])
-> Result<ValueRef, ConstEvalErr> {
unsafe {
- let def_id = ccx.tcx().map.local_def_id(id);
+ let def_id = ccx.tcx().hir.local_def_id(id);
let g = get_static(ccx, def_id);
let v = ::mir::trans_static_initializer(ccx, def_id)?;
pub fn needs_gdb_debug_scripts_section(ccx: &CrateContext) -> bool {
let omit_gdb_pretty_printer_section =
- attr::contains_name(&ccx.tcx().map.krate_attrs(),
+ attr::contains_name(&ccx.tcx().hir.krate_attrs(),
"omit_gdb_pretty_printer_section");
!omit_gdb_pretty_printer_section &&
let tcx = cx.tcx();
- let node_def_id = tcx.map.local_def_id(node_id);
+ let node_def_id = tcx.hir.local_def_id(node_id);
let (var_scope, span) = get_namespace_and_span_for_item(cx, node_def_id);
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
let scope_line = span_start(cx, span).line;
- let local_id = cx.tcx().map.as_local_node_id(instance.def);
+ let local_id = cx.tcx().hir.as_local_node_id(instance.def);
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
let function_name = CString::new(name).unwrap();
// compiler-rt, then we want to implicitly compile everything with hidden
// visibility as we're going to link this object all over the place but
// don't want the symbols to get exported.
- if attr::contains_name(ccx.tcx().map.krate_attrs(), "compiler_builtins") {
+ if attr::contains_name(ccx.tcx().hir.krate_attrs(), "compiler_builtins") {
unsafe {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
symbol_name.hash(&mut state);
let exported = match item {
TransItem::Fn(ref instance) => {
- let node_id = scx.tcx().map.as_local_node_id(instance.def);
+ let node_id = scx.tcx().hir.as_local_node_id(instance.def);
node_id.map(|node_id| exported_symbols.contains(&node_id))
.unwrap_or(false)
}
fn local_node_id(tcx: TyCtxt, trans_item: TransItem) -> Option<NodeId> {
match trans_item {
TransItem::Fn(instance) => {
- tcx.map.as_local_node_id(instance.def)
+ tcx.hir.as_local_node_id(instance.def)
}
TransItem::Static(node_id) => Some(node_id),
TransItem::DropGlue(_) => None,
Some(instance.def)
}
TransItem::DropGlue(dg) => characteristic_def_id_of_type(dg.ty()),
- TransItem::Static(node_id) => Some(tcx.map.local_def_id(node_id)),
+ TransItem::Static(node_id) => Some(tcx.hir.local_def_id(node_id)),
}
}
trans_item: TransItem<'tcx>) -> Option<Span> {
match trans_item {
TransItem::Fn(Instance { def, .. }) => {
- tcx.map.as_local_node_id(def)
+ tcx.hir.as_local_node_id(def)
}
TransItem::Static(node_id) => Some(node_id),
TransItem::DropGlue(_) => None,
}.map(|node_id| {
- tcx.map.span(node_id)
+ tcx.hir.span(node_id)
})
}
let _ignore = tcx.dep_graph.in_ignore();
let mut visitor = SymbolNamesTest { scx: scx };
// FIXME(#37712) could use ItemLikeVisitor if trait items were item-like
- tcx.map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
+ tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
}
struct SymbolNamesTest<'a, 'tcx:'a> {
fn process_attrs(&mut self,
node_id: ast::NodeId) {
let tcx = self.scx.tcx();
- let def_id = tcx.map.local_def_id(node_id);
+ let def_id = tcx.hir.local_def_id(node_id);
for attr in tcx.get_attrs(def_id).iter() {
if attr.check_name(SYMBOL_NAME) {
// for now, can only use on monomorphic names
match *self {
TransItem::Static(node_id) => {
- let def_id = ccx.tcx().map.local_def_id(node_id);
+ let def_id = ccx.tcx().hir.local_def_id(node_id);
let _task = ccx.tcx().dep_graph.in_task(DepNode::TransCrateItem(def_id)); // (*)
- let item = ccx.tcx().map.expect_item(node_id);
+ let item = ccx.tcx().hir.expect_item(node_id);
if let hir::ItemStatic(_, m, _) = item.node {
match consts::trans_static(&ccx, m, item.id, &item.attrs) {
Ok(_) => { /* Cool, everything's alright. */ },
node_id: ast::NodeId,
linkage: llvm::Linkage,
symbol_name: &str) {
- let def_id = ccx.tcx().map.local_def_id(node_id);
+ let def_id = ccx.tcx().hir.local_def_id(node_id);
let ty = ccx.tcx().item_type(def_id);
let llty = type_of::type_of(ccx, ty);
let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| {
- ccx.sess().span_fatal(ccx.tcx().map.span(node_id),
+ ccx.sess().span_fatal(ccx.tcx().hir.span(node_id),
&format!("symbol `{}` is already defined", symbol_name))
});
match *self {
TransItem::Fn(instance) => instance.symbol_name(scx),
TransItem::Static(node_id) => {
- let def_id = scx.tcx().map.local_def_id(node_id);
+ let def_id = scx.tcx().hir.local_def_id(node_id);
Instance::mono(scx, def_id).symbol_name(scx)
}
TransItem::DropGlue(dg) => {
pub fn explicit_linkage(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<llvm::Linkage> {
let def_id = match *self {
TransItem::Fn(ref instance) => instance.def,
- TransItem::Static(node_id) => tcx.map.local_def_id(node_id),
+ TransItem::Static(node_id) => tcx.hir.local_def_id(node_id),
TransItem::DropGlue(..) => return None,
};
if let Some(linkage) = base::llvm_linkage_by_name(&name.as_str()) {
Some(linkage)
} else {
- let span = tcx.map.span_if_local(def_id);
+ let span = tcx.hir.span_if_local(def_id);
if let Some(span) = span {
tcx.sess.span_fatal(span, "invalid linkage specified")
} else {
}
pub fn to_string(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
- let hir_map = &tcx.map;
+ let hir_map = &tcx.hir;
return match *self {
TransItem::DropGlue(dg) => {
.get(&id)
.cloned()
.unwrap_or(ty::Issue32330::WontChange);
- ty::ReLateBound(debruijn, ty::BrNamed(tcx.map.local_def_id(id),
+ ty::ReLateBound(debruijn, ty::BrNamed(tcx.hir.local_def_id(id),
lifetime.name,
issue_32330))
}
.unwrap_or(ty::Issue32330::WontChange);
ty::ReFree(ty::FreeRegion {
scope: scope.to_code_extent(&tcx.region_maps),
- bound_region: ty::BrNamed(tcx.map.local_def_id(id),
+ bound_region: ty::BrNamed(tcx.hir.local_def_id(id),
lifetime.name,
issue_32330)
})
} = info;
let help_name = if let Some(body) = parent {
- let arg = &tcx.map.body(body).arguments[index];
- format!("`{}`", tcx.map.node_to_pretty_string(arg.pat.id))
+ let arg = &tcx.hir.body(body).arguments[index];
+ format!("`{}`", tcx.hir.node_to_pretty_string(arg.pat.id))
} else {
format!("argument {}", index + 1)
};
}
_ => {
span_fatal!(self.tcx().sess, path.span, E0245, "`{}` is not a trait",
- self.tcx().map.node_to_pretty_string(trait_ref.ref_id));
+ self.tcx().hir.node_to_pretty_string(trait_ref.ref_id));
}
}
}
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
item.kind == ty::AssociatedKind::Type && item.name == assoc_name
})
- .and_then(|item| self.tcx().map.span_if_local(item.def_id));
+ .and_then(|item| self.tcx().hir.span_if_local(item.def_id));
if let Some(span) = bound_span {
err.span_label(span, &format!("ambiguous `{}` from `{}`",
}
}
(&ty::TyParam(_), Def::SelfTy(Some(trait_did), None)) => {
- let trait_node_id = tcx.map.as_local_node_id(trait_did).unwrap();
+ let trait_node_id = tcx.hir.as_local_node_id(trait_did).unwrap();
match self.find_bound_for_assoc_item(trait_node_id,
keywords::SelfType.name(),
assoc_name,
}
}
(&ty::TyParam(_), Def::TyParam(param_did)) => {
- let param_node_id = tcx.map.as_local_node_id(param_did).unwrap();
+ let param_node_id = tcx.hir.as_local_node_id(param_did).unwrap();
let param_name = tcx.type_parameter_def(param_node_id).name;
match self.find_bound_for_assoc_item(param_node_id,
param_name,
assert_eq!(opt_self_ty, None);
tcx.prohibit_type_params(&path.segments);
- let node_id = tcx.map.as_local_node_id(did).unwrap();
+ let node_id = tcx.hir.as_local_node_id(did).unwrap();
let param = tcx.ty_param_defs.borrow().get(&node_id)
.map(ty::ParamTy::for_def);
if let Some(p) = param {
use collect::{compute_bounds, SizedByDefault};
// Create the anonymized type.
- let def_id = tcx.map.local_def_id(ast_ty.id);
+ let def_id = tcx.hir.local_def_id(ast_ty.id);
if let Some(anon_scope) = rscope.anon_type_scope() {
let substs = anon_scope.fresh_substs(self, ast_ty.span);
- let ty = tcx.mk_anon(tcx.map.local_def_id(ast_ty.id), substs);
+ let ty = tcx.mk_anon(tcx.hir.local_def_id(ast_ty.id), substs);
// Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`.
let bounds = compute_bounds(self, ty, bounds,
// if there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be
- let var_id = tcx.map.as_local_node_id(def_id).unwrap();
+ let var_id = tcx.hir.as_local_node_id(def_id).unwrap();
if var_id != pat.id {
let vt = self.local_ty(pat.span, var_id);
self.demand_eqtype(pat.span, vt, typ);
span_err!(tcx.sess, pat.span, E0533,
"expected unit struct/variant or constant, found {} `{}`",
def.kind_name(),
- hir::print::to_string(&tcx.map, |s| s.print_qpath(qpath, false)));
+ hir::print::to_string(&tcx.hir, |s| s.print_qpath(qpath, false)));
};
// Resolve the path and check the definition for errors.
let report_unexpected_def = |def: Def| {
let msg = format!("expected tuple struct/variant, found {} `{}`",
def.kind_name(),
- hir::print::to_string(&tcx.map, |s| s.print_qpath(qpath, false)));
+ hir::print::to_string(&tcx.hir, |s| s.print_qpath(qpath, false)));
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
.span_label(pat.span, &format!("not a tuple variant or struct")).emit();
on_error();
let (fn_sig, def_span) = match callee_ty.sty {
ty::TyFnDef(def_id, .., &ty::BareFnTy {ref sig, ..}) => {
- (sig, self.tcx.map.span_if_local(def_id))
+ (sig, self.tcx.hir.span_if_local(def_id))
}
ty::TyFnPtr(&ty::BareFnTy {ref sig, ..}) => (sig, None),
ref t => {
if let &ty::TyAdt(adt_def, ..) = t {
if adt_def.is_enum() {
if let hir::ExprCall(ref expr, _) = call_expr.node {
- unit_variant = Some(self.tcx.map.node_to_pretty_string(expr.id))
+ unit_variant = Some(self.tcx.hir.node_to_pretty_string(expr.id))
}
}
}
Def::Err
};
if def != Def::Err {
- if let Some(span) = self.tcx.map.span_if_local(def.def_id()) {
+ if let Some(span) = self.tcx.hir.span_if_local(def.def_id()) {
err.span_note(span, "defined here");
}
}
Some(ty) => self.deduce_expectations_from_expected_type(ty),
None => (None, None),
};
- let body = self.tcx.map.body(body_id);
+ let body = self.tcx.hir.body(body_id);
self.check_closure(expr, expected_kind, decl, body, expected_sig)
}
opt_kind,
expected_sig);
- let expr_def_id = self.tcx.map.local_def_id(expr.id);
+ let expr_def_id = self.tcx.hir.local_def_id(expr.id);
let mut fn_ty = AstConv::ty_of_closure(self,
hir::Unsafety::Normal,
decl,
// Create a parameter environment that represents the implementation's
// method.
- let impl_m_node_id = tcx.map.as_local_node_id(impl_m.def_id).unwrap();
+ let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
let impl_param_env = ty::ParameterEnvironment::for_item(tcx, impl_m_node_id);
// Create mapping from impl to skolemized.
trait_sig: ty::FnSig<'tcx>)
-> (Span, Option<Span>) {
let tcx = infcx.tcx;
- let impl_m_node_id = tcx.map.as_local_node_id(impl_m.def_id).unwrap();
- let (impl_m_output, impl_m_iter) = match tcx.map.expect_impl_item(impl_m_node_id).node {
+ let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
+ let (impl_m_output, impl_m_iter) = match tcx.hir.expect_impl_item(impl_m_node_id).node {
ImplItemKind::Method(ref impl_m_sig, _) => {
(&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter())
}
match *terr {
TypeError::Mutability => {
- if let Some(trait_m_node_id) = tcx.map.as_local_node_id(trait_m.def_id) {
- let trait_m_iter = match tcx.map.expect_trait_item(trait_m_node_id).node {
+ if let Some(trait_m_node_id) = tcx.hir.as_local_node_id(trait_m.def_id) {
+ let trait_m_iter = match tcx.hir.expect_trait_item(trait_m_node_id).node {
TraitItemKind::Method(ref trait_m_sig, _) => {
trait_m_sig.decl.inputs.iter()
}
}).map(|(ref impl_arg, ref trait_arg)| {
(impl_arg.span, Some(trait_arg.span))
})
- .unwrap_or_else(|| (cause.span, tcx.map.span_if_local(trait_m.def_id)))
+ .unwrap_or_else(|| (cause.span, tcx.hir.span_if_local(trait_m.def_id)))
} else {
- (cause.span, tcx.map.span_if_local(trait_m.def_id))
+ (cause.span, tcx.hir.span_if_local(trait_m.def_id))
}
}
TypeError::Sorts(ExpectedFound { .. }) => {
- if let Some(trait_m_node_id) = tcx.map.as_local_node_id(trait_m.def_id) {
+ if let Some(trait_m_node_id) = tcx.hir.as_local_node_id(trait_m.def_id) {
let (trait_m_output, trait_m_iter) =
- match tcx.map.expect_trait_item(trait_m_node_id).node {
+ match tcx.hir.expect_trait_item(trait_m_node_id).node {
TraitItemKind::Method(ref trait_m_sig, _) => {
(&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter())
}
.is_err() {
(impl_m_output.span(), Some(trait_m_output.span()))
} else {
- (cause.span, tcx.map.span_if_local(trait_m.def_id))
+ (cause.span, tcx.hir.span_if_local(trait_m.def_id))
}
})
} else {
- (cause.span, tcx.map.span_if_local(trait_m.def_id))
+ (cause.span, tcx.hir.span_if_local(trait_m.def_id))
}
}
- _ => (cause.span, tcx.map.span_if_local(trait_m.def_id)),
+ _ => (cause.span, tcx.hir.span_if_local(trait_m.def_id)),
}
}
trait_m.name,
self_descr);
err.span_label(impl_m_span, &format!("`{}` used in impl", self_descr));
- if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
+ if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, &format!("trait declared without `{}`", self_descr));
}
err.emit();
self_descr);
err.span_label(impl_m_span,
&format!("expected `{}` in impl", self_descr));
- if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
+ if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, &format!("`{}` used in trait", self_descr));
}
err.emit();
let num_impl_m_type_params = impl_m_generics.types.len();
let num_trait_m_type_params = trait_m_generics.types.len();
if num_impl_m_type_params != num_trait_m_type_params {
- let impl_m_node_id = tcx.map.as_local_node_id(impl_m.def_id).unwrap();
- let span = match tcx.map.expect_impl_item(impl_m_node_id).node {
+ let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
+ let span = match tcx.hir.expect_impl_item(impl_m_node_id).node {
ImplItemKind::Method(ref impl_m_sig, _) => {
if impl_m_sig.generics.is_parameterized() {
impl_m_sig.generics.span
let trait_number_args = trait_m_fty.sig.inputs().skip_binder().len();
let impl_number_args = impl_m_fty.sig.inputs().skip_binder().len();
if trait_number_args != impl_number_args {
- let trait_m_node_id = tcx.map.as_local_node_id(trait_m.def_id);
+ let trait_m_node_id = tcx.hir.as_local_node_id(trait_m.def_id);
let trait_span = if let Some(trait_id) = trait_m_node_id {
- match tcx.map.expect_trait_item(trait_id).node {
+ match tcx.hir.expect_trait_item(trait_id).node {
TraitItemKind::Method(ref trait_m_sig, _) => {
if let Some(arg) = trait_m_sig.decl.inputs.get(if trait_number_args > 0 {
trait_number_args - 1
} else {
trait_item_span
};
- let impl_m_node_id = tcx.map.as_local_node_id(impl_m.def_id).unwrap();
- let impl_span = match tcx.map.expect_impl_item(impl_m_node_id).node {
+ let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
+ let impl_span = match tcx.hir.expect_impl_item(impl_m_node_id).node {
ImplItemKind::Method(ref impl_m_sig, _) => {
if let Some(arg) = impl_m_sig.decl.inputs.get(if impl_number_args > 0 {
impl_number_args - 1
// Create a parameter environment that represents the implementation's
// method.
- let impl_c_node_id = tcx.map.as_local_node_id(impl_c.def_id).unwrap();
+ let impl_c_node_id = tcx.hir.as_local_node_id(impl_c.def_id).unwrap();
let impl_param_env = ty::ParameterEnvironment::for_item(tcx, impl_c_node_id);
// Create mapping from impl to skolemized.
trait_ty);
// Locate the Span containing just the type of the offending impl
- match tcx.map.expect_impl_item(impl_c_node_id).node {
+ match tcx.hir.expect_impl_item(impl_c_node_id).node {
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
_ => bug!("{:?} is not a impl const", impl_c),
}
trait_c.name);
// Add a label to the Span containing just the type of the item
- let trait_c_node_id = tcx.map.as_local_node_id(trait_c.def_id).unwrap();
- let trait_c_span = match tcx.map.expect_trait_item(trait_c_node_id).node {
+ let trait_c_node_id = tcx.hir.as_local_node_id(trait_c.def_id).unwrap();
+ let trait_c_span = match tcx.hir.expect_trait_item(trait_c_node_id).node {
TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c),
};
-> Result<(), ()>
{
let tcx = ccx.tcx;
- let drop_impl_node_id = tcx.map.as_local_node_id(drop_impl_did).unwrap();
- let self_type_node_id = tcx.map.as_local_node_id(self_type_did).unwrap();
+ let drop_impl_node_id = tcx.hir.as_local_node_id(drop_impl_did).unwrap();
+ let self_type_node_id = tcx.hir.as_local_node_id(self_type_did).unwrap();
// check that the impl type can be made to match the trait type.
assert!(obligations.is_empty());
}
Err(_) => {
- let item_span = tcx.map.span(self_type_node_id);
+ let item_span = tcx.hir.span(self_type_node_id);
struct_span_err!(tcx.sess, drop_impl_span, E0366,
"Implementations of Drop cannot be specialized")
.span_note(item_span,
let tcx = ccx.tcx;
- let self_type_node_id = tcx.map.as_local_node_id(self_type_did).unwrap();
+ let self_type_node_id = tcx.hir.as_local_node_id(self_type_did).unwrap();
let drop_impl_span = tcx.def_span(drop_impl_did);
// repeated `contains` calls.
if !assumptions_in_impl_context.contains(&predicate) {
- let item_span = tcx.map.span(self_type_node_id);
+ let item_span = tcx.hir.span(self_type_node_id);
struct_span_err!(tcx.sess, drop_impl_span, E0367,
"The requirement `{}` is added only by the Drop impl.", predicate)
.span_note(item_span,
inputs: Vec<Ty<'tcx>>,
output: Ty<'tcx>) {
let tcx = ccx.tcx;
- let def_id = tcx.map.local_def_id(it.id);
+ let def_id = tcx.hir.local_def_id(it.id);
let substs = Substs::for_item(tcx, def_id,
|_, _| tcx.mk_region(ty::ReErased),
};
let tcx = ccx.tcx;
- let def_id = tcx.map.local_def_id(it.id);
+ let def_id = tcx.hir.local_def_id(it.id);
let i_n_tps = tcx.item_generics(def_id).types.len();
let name = it.name.as_str();
for step in steps.iter() {
let closure_id = match step.self_ty.sty {
ty::TyClosure(def_id, _) => {
- if let Some(id) = self.tcx.map.as_local_node_id(def_id) {
+ if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
id
} else {
continue;
item_name
)
}).unwrap();
- let note_span = self.tcx.map.span_if_local(item.def_id).or_else(|| {
- self.tcx.map.span_if_local(impl_did)
+ let note_span = self.tcx.hir.span_if_local(item.def_id).or_else(|| {
+ self.tcx.hir.span_if_local(impl_did)
});
let impl_ty = self.impl_self_ty(span, impl_did).ty;
let msg = if let Some(callee) = rcvr_expr {
format!("{}; use overloaded call notation instead (e.g., `{}()`)",
msg,
- self.tcx.map.node_to_pretty_string(callee.id))
+ self.tcx.hir.node_to_pretty_string(callee.id))
} else {
msg
};
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
}
}
- ccx.tcx.map.krate().visit_all_item_likes(&mut Visitor {
- map: &ccx.tcx.map,
+ ccx.tcx.hir.krate().visit_all_item_likes(&mut Visitor {
+ map: &ccx.tcx.hir,
traits: &mut traits,
});
impl<'a, 'tcx> Visitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.ccx.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.ccx.tcx.hir)
}
fn visit_item(&mut self, i: &'tcx hir::Item) {
// bodies have been fully inferred.
for (&item_id, obligations) in ccx.deferred_obligations.borrow().iter() {
// Use the same DepNode as for the body of the original function/item.
- let def_id = ccx.tcx.map.local_def_id(item_id);
+ let def_id = ccx.tcx.hir.local_def_id(item_id);
let _task = ccx.tcx.dep_graph.in_task(DepNode::TypeckTables(def_id));
let param_env = ParameterEnvironment::for_item(ccx.tcx, item_id);
body_id: hir::BodyId,
fn_id: ast::NodeId,
span: Span) {
- let body = ccx.tcx.map.body(body_id);
+ let body = ccx.tcx.hir.body(body_id);
- let raw_fty = ccx.tcx.item_type(ccx.tcx.map.local_def_id(fn_id));
+ let raw_fty = ccx.tcx.item_type(ccx.tcx.hir.local_def_id(fn_id));
let fn_ty = match raw_fty.sty {
ty::TyFnDef(.., f) => f,
_ => span_bug!(body.value.span, "check_bare_fn: function type expected")
}
fn check_struct(ccx: &CrateCtxt, id: ast::NodeId, span: Span) {
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
check_representable(ccx.tcx, span, def_id);
if ccx.tcx.lookup_simd(def_id) {
}
fn check_union(ccx: &CrateCtxt, id: ast::NodeId, span: Span) {
- check_representable(ccx.tcx, span, ccx.tcx.map.local_def_id(id));
+ check_representable(ccx.tcx, span, ccx.tcx.hir.local_def_id(id));
}
pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
debug!("check_item_type(it.id={}, it.name={})",
it.id,
- ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(it.id)));
+ ccx.tcx.item_path_str(ccx.tcx.hir.local_def_id(it.id)));
let _indenter = indenter();
match it.node {
// Consts can play a role in type-checking, so they are included here.
hir::ItemFn(..) => {} // entirely within check_item_body
hir::ItemImpl(.., ref impl_item_refs) => {
debug!("ItemImpl {} with id {}", it.name, it.id);
- let impl_def_id = ccx.tcx.map.local_def_id(it.id);
+ let impl_def_id = ccx.tcx.hir.local_def_id(it.id);
if let Some(impl_trait_ref) = ccx.tcx.impl_trait_ref(impl_def_id) {
check_impl_items_against_trait(ccx,
it.span,
}
}
hir::ItemTrait(..) => {
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
check_on_unimplemented(ccx, def_id, it);
}
hir::ItemStruct(..) => {
check_union(ccx, it.id, it.span);
}
hir::ItemTy(_, ref generics) => {
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
let pty_ty = ccx.tcx.item_type(def_id);
check_bounds_are_used(ccx, generics, pty_ty);
}
}
} else {
for item in &m.items {
- let generics = ccx.tcx.item_generics(ccx.tcx.map.local_def_id(item.id));
+ let generics = ccx.tcx.item_generics(ccx.tcx.hir.local_def_id(item.id));
if !generics.types.is_empty() {
let mut err = struct_span_err!(ccx.tcx.sess, item.span, E0044,
"foreign items may not have type parameters");
let trait_def = tcx.lookup_trait_def(impl_trait_ref.def_id);
let mut overridden_associated_type = None;
- let impl_items = || impl_item_refs.iter().map(|iiref| ccx.tcx.map.impl_item(iiref.id));
+ let impl_items = || impl_item_refs.iter().map(|iiref| ccx.tcx.hir.impl_item(iiref.id));
// Check existing impl methods to see if they are both present in trait
// and compatible with trait signature
for impl_item in impl_items() {
- let ty_impl_item = tcx.associated_item(tcx.map.local_def_id(impl_item.id));
+ let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id));
let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id)
.find(|ac| ac.name == ty_impl_item.name);
err.span_label(impl_item.span, &format!("does not match trait"));
// We can only get the spans from local trait definition
// Same for E0324 and E0325
- if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait"));
}
err.emit()
}
}
hir::ImplItemKind::Method(_, body_id) => {
- let trait_span = tcx.map.span_if_local(ty_trait_item.def_id);
+ let trait_span = tcx.hir.span_if_local(ty_trait_item.def_id);
if ty_trait_item.kind == ty::AssociatedKind::Method {
let err_count = tcx.sess.err_count();
compare_impl_method(ccx,
ty_impl_item.name,
impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait"));
- if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait"));
}
err.emit()
ty_impl_item.name,
impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait"));
- if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait"));
}
err.emit()
.map(|trait_item| trait_item.name.to_string())
.collect::<Vec<_>>().join("`, `")));
for trait_item in missing_items {
- if let Some(span) = tcx.map.span_if_local(trait_item.def_id) {
+ if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) {
err.span_label(span, &format!("`{}` from trait", trait_item.name));
} else {
err.note(&format!("`{}` from trait: `{}`",
body: hir::BodyId,
expected_type: Ty<'tcx>,
id: ast::NodeId) {
- let body = ccx.tcx.map.body(body);
+ let body = ccx.tcx.hir.body(body);
ccx.inherited(id).enter(|inh| {
let fcx = FnCtxt::new(&inh, None, body.value.id);
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
fn check_const<'a, 'tcx>(ccx: &CrateCtxt<'a,'tcx>,
body: hir::BodyId,
id: ast::NodeId) {
- let decl_ty = ccx.tcx.item_type(ccx.tcx.map.local_def_id(id));
+ let decl_ty = ccx.tcx.item_type(ccx.tcx.hir.local_def_id(id));
check_const_with_type(ccx, body, decl_ty, id);
}
sp: Span,
vs: &'tcx [hir::Variant],
id: ast::NodeId) {
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
let hint = *ccx.tcx.lookup_repr_hints(def_id).get(0).unwrap_or(&attr::ReprAny);
if hint != attr::ReprAny && vs.is_empty() {
}
}
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
let variants = &ccx.tcx.lookup_adt_def(def_id).variants;
let mut disr_vals: Vec<ty::Disr> = Vec::new();
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x == current_disr_val) {
- let variant_i_node_id = ccx.tcx.map.as_local_node_id(variants[i].did).unwrap();
- let variant_i = ccx.tcx.map.expect_variant(variant_i_node_id);
+ let variant_i_node_id = ccx.tcx.hir.as_local_node_id(variants[i].did).unwrap();
+ let variant_i = ccx.tcx.hir.expect_variant(variant_i_node_id);
let i_span = match variant_i.node.disr_expr {
- Some(expr) => ccx.tcx.map.span(expr.node_id),
- None => ccx.tcx.map.span(variant_i_node_id)
+ Some(expr) => ccx.tcx.hir.span(expr.node_id),
+ None => ccx.tcx.hir.span(variant_i_node_id)
};
let span = match v.node.disr_expr {
- Some(expr) => ccx.tcx.map.span(expr.node_id),
+ Some(expr) => ccx.tcx.hir.span(expr.node_id),
None => v.span
};
struct_span_err!(ccx.tcx.sess, span, E0081,
Some(&t) => t,
None => {
span_bug!(span, "no type for local variable {}",
- self.tcx.map.node_to_string(nid));
+ self.tcx.hir.node_to_string(nid));
}
}
}
None if self.err_count_since_creation() != 0 => self.tcx.types.err,
None => {
bug!("no type for node {}: {} in fcx {}",
- id, self.tcx.map.node_to_string(id),
+ id, self.tcx.hir.node_to_string(id),
self.tag());
}
}
TypeVariableOrigin::MiscVariable(syntax_pos::DUMMY_SP)),
origin_span: syntax_pos::DUMMY_SP,
// what do I put here?
- def_id: self.tcx.map.local_def_id(ast::CRATE_NODE_ID)
+ def_id: self.tcx.hir.local_def_id(ast::CRATE_NODE_ID)
});
// This is to ensure that we elimnate any non-determinism from the error
);
self.check_argument_types(sp, &fty.sig.0.inputs()[1..], &expected_arg_tys[..],
args_no_rcvr, fty.sig.0.variadic, tuple_arguments,
- self.tcx.map.span_if_local(def_id));
+ self.tcx.hir.span_if_local(def_id));
fty.sig.0.output()
}
_ => {
ty::TyRawPtr(..) => {
err.note(&format!("`{0}` is a native pointer; perhaps you need to deref with \
`(*{0}).{1}`",
- self.tcx.map.node_to_pretty_string(base.id),
+ self.tcx.hir.node_to_pretty_string(base.id),
field.node));
}
_ => {}
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);
- debug!("type of {} is...", self.tcx.map.node_to_string(expr.id));
+ debug!("type of {} is...", self.tcx.hir.node_to_string(expr.id));
debug!("... {:?}, expected is {:?}", ty, expected);
// Add adjustments to !-expressions
if ty.is_never() {
- if let Some(hir::map::NodeExpr(node_expr)) = self.tcx.map.find(expr.id) {
+ if let Some(hir::map::NodeExpr(node_expr)) = self.tcx.hir.find(expr.id) {
let adj_ty = self.next_diverging_ty_var(
TypeVariableOrigin::AdjustmentType(node_expr.span));
self.write_adjustment(expr.id, adjustment::Adjustment {
match def {
Def::Local(def_id) | Def::Upvar(def_id, ..) => {
- let nid = self.tcx.map.as_local_node_id(def_id).unwrap();
+ let nid = self.tcx.hir.as_local_node_id(def_id).unwrap();
let ty = self.local_ty(span, nid);
let ty = self.normalize_associated_types_in(span, &ty);
self.write_ty(node_id, ty);
if self.err_count_since_creation() == 0 {
// regionck assumes typeck succeeded
- rcx.visit_fn_body(fn_id, body, self.tcx.map.span(fn_id));
+ rcx.visit_fn_body(fn_id, body, self.tcx.hir.span(fn_id));
}
rcx.free_region_map.relate_free_regions_from_predicates(
fn visit_fn(&mut self, _fk: intravisit::FnKind<'gcx>, _: &'gcx hir::FnDecl,
b: hir::BodyId, span: Span, id: ast::NodeId) {
- let body = self.tcx.map.body(b);
+ let body = self.tcx.hir.body(b);
self.visit_fn_body(id, body, span)
}
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
match expr.node {
hir::ExprClosure(cc, _, body_id, _) => {
- let body = self.fcx.tcx.map.body(body_id);
+ let body = self.fcx.tcx.hir.body(body_id);
self.visit_body(body);
self.check_closure(expr, cc);
}
self.fcx.tcx.with_freevars(expr.id, |freevars| {
for freevar in freevars {
let def_id = freevar.def.def_id();
- let var_node_id = self.fcx.tcx.map.as_local_node_id(def_id).unwrap();
+ let var_node_id = self.fcx.tcx.hir.as_local_node_id(def_id).unwrap();
let upvar_id = ty::UpvarId { var_id: var_node_id,
closure_expr_id: expr.id };
debug!("seed upvar_id {:?}", upvar_id);
// If we are also inferred the closure kind here, update the
// main table and process any deferred resolutions.
- let closure_def_id = self.fcx.tcx.map.local_def_id(id);
+ let closure_def_id = self.fcx.tcx.hir.local_def_id(id);
if let Some(&kind) = self.temp_closure_kinds.get(&id) {
self.fcx.tables.borrow_mut().closure_kinds.insert(id, kind);
debug!("closure_kind({:?}) = {:?}", closure_def_id, kind);
tcx.with_freevars(closure_id, |freevars| {
freevars.iter().map(|freevar| {
let def_id = freevar.def.def_id();
- let var_id = tcx.map.as_local_node_id(def_id).unwrap();
+ let var_id = tcx.hir.as_local_node_id(def_id).unwrap();
let freevar_ty = self.fcx.node_ty(var_id);
let upvar_id = ty::UpvarId {
var_id: var_id,
{
intravisit::walk_fn(self, fn_kind, decl, body, span, id);
- let body = self.fcx.tcx.map.body(body);
+ let body = self.fcx.tcx.hir.body(body);
self.visit_body(body);
self.analyze_closure(id, span, body);
}
let ccx = self.ccx;
debug!("check_item_well_formed(it.id={}, it.name={})",
item.id,
- ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(item.id)));
+ ccx.tcx.item_path_str(ccx.tcx.hir.local_def_id(item.id)));
match item.node {
/// Right now we check that every default trait implementation
hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), ..) => {
// FIXME(#27579) what amount of WF checking do we need for neg impls?
- let trait_ref = ccx.tcx.impl_trait_ref(ccx.tcx.map.local_def_id(item.id)).unwrap();
+ let trait_ref = ccx.tcx.impl_trait_ref(ccx.tcx.hir.local_def_id(item.id)).unwrap();
if !ccx.tcx.trait_has_default_impl(trait_ref.def_id) {
error_192(ccx, item.span);
}
let free_substs = &fcx.parameter_environment.free_substs;
let free_id_outlive = fcx.parameter_environment.free_id_outlive;
- let item = fcx.tcx.associated_item(fcx.tcx.map.local_def_id(item_id));
+ let item = fcx.tcx.associated_item(fcx.tcx.hir.local_def_id(item_id));
let (mut implied_bounds, self_ty) = match item.container {
ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()),
}
let free_substs = &fcx.parameter_environment.free_substs;
- let def_id = fcx.tcx.map.local_def_id(item.id);
+ let def_id = fcx.tcx.hir.local_def_id(item.id);
let predicates = fcx.instantiate_bounds(item.span, def_id, free_substs);
this.check_where_clauses(fcx, item.span, &predicates);
}
fn check_trait(&mut self, item: &hir::Item) {
- let trait_def_id = self.tcx().map.local_def_id(item.id);
+ let trait_def_id = self.tcx().hir.local_def_id(item.id);
if self.tcx().trait_has_default_impl(trait_def_id) {
self.check_auto_trait(trait_def_id, item.span);
{
self.for_item(item).with_fcx(|fcx, this| {
let free_substs = &fcx.parameter_environment.free_substs;
- let def_id = fcx.tcx.map.local_def_id(item.id);
+ let def_id = fcx.tcx.hir.local_def_id(item.id);
let ty = fcx.tcx.item_type(def_id);
let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &ty);
let bare_fn_ty = match item_ty.sty {
debug!("check_item_type: {:?}", item);
self.for_item(item).with_fcx(|fcx, this| {
- let ty = fcx.tcx.item_type(fcx.tcx.map.local_def_id(item.id));
+ let ty = fcx.tcx.item_type(fcx.tcx.hir.local_def_id(item.id));
let item_ty = fcx.instantiate_type_scheme(item.span,
&fcx.parameter_environment
.free_substs,
self.for_item(item).with_fcx(|fcx, this| {
let free_substs = &fcx.parameter_environment.free_substs;
- let item_def_id = fcx.tcx.map.local_def_id(item.id);
+ let item_def_id = fcx.tcx.hir.local_def_id(item.id);
match *ast_trait_ref {
Some(ref ast_trait_ref) => {
item: &hir::Item,
ast_generics: &hir::Generics)
{
- let item_def_id = self.tcx().map.local_def_id(item.id);
+ let item_def_id = self.tcx().hir.local_def_id(item.id);
let ty = self.tcx().item_type(item_def_id);
if self.tcx().has_error_field(ty) {
return;
let fields =
struct_def.fields().iter()
.map(|field| {
- let field_ty = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
+ let field_ty = self.tcx.item_type(self.tcx.hir.local_def_id(field.id));
let field_ty = self.instantiate_type_scheme(field.span,
&self.parameter_environment
.free_substs,
pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body) {
assert_eq!(self.writeback_errors.get(), false);
- let item_id = self.tcx.map.body_owner(body.id());
- let item_def_id = self.tcx.map.local_def_id(item_id);
+ let item_id = self.tcx.hir.body_owner(body.id());
+ let item_def_id = self.tcx.hir.local_def_id(item_id);
let mut wbcx = WritebackCx::new(self);
for arg in &body.arguments {
MethodCall::expr(e.id));
if let hir::ExprClosure(_, _, body, _) = e.node {
- let body = self.fcx.tcx.map.body(body);
+ let body = self.fcx.tcx.hir.body(body);
for arg in &body.arguments {
self.visit_node_id(ResolvingExpr(e.span), arg.id);
}
for (&id, closure_ty) in self.fcx.tables.borrow().closure_tys.iter() {
let closure_ty = self.resolve(closure_ty, ResolvingClosure(id));
- let def_id = self.tcx().map.local_def_id(id);
+ let def_id = self.tcx().hir.local_def_id(id);
self.tcx().closure_tys.borrow_mut().insert(def_id, closure_ty);
}
for (&id, &closure_kind) in self.fcx.tables.borrow().closure_kinds.iter() {
- let def_id = self.tcx().map.local_def_id(id);
+ let def_id = self.tcx().hir.local_def_id(id);
self.tcx().closure_kinds.borrow_mut().insert(def_id, closure_kind);
}
}
ResolvingFnSig(id) |
ResolvingFieldTypes(id) |
ResolvingTyNode(id) => {
- tcx.map.span(id)
+ tcx.hir.span(id)
}
ResolvingAnonTy(did) => {
tcx.def_span(did)
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let _task = tcx.dep_graph.in_task(DepNode::UnusedTraitCheck);
let mut visitor = UnusedTraitImportVisitor { tcx: tcx };
- tcx.map.krate().visit_all_item_likes(&mut visitor);
+ tcx.hir.krate().visit_all_item_likes(&mut visitor);
}
}
_ => {
// Destructors only work on nominal types.
- if let Some(impl_node_id) = tcx.map.as_local_node_id(impl_did) {
- match tcx.map.find(impl_node_id) {
+ if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_did) {
+ match tcx.hir.find(impl_node_id) {
Some(hir_map::NodeItem(item)) => {
let span = match item.node {
ItemImpl(.., ref ty, _) => ty.span,
impl_did: DefId) {
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
- let impl_node_id = if let Some(n) = tcx.map.as_local_node_id(impl_did) {
+ let impl_node_id = if let Some(n) = tcx.hir.as_local_node_id(impl_did) {
n
} else {
debug!("visit_implementation_of_copy(): impl not in this \
debug!("visit_implementation_of_copy: self_type={:?} (bound)",
self_type);
- let span = tcx.map.span(impl_node_id);
+ let span = tcx.hir.span(impl_node_id);
let param_env = ParameterEnvironment::for_item(tcx, impl_node_id);
let self_type = self_type.subst(tcx, ¶m_env.free_substs);
assert!(!self_type.has_escaping_regions());
match param_env.can_type_implement_copy(tcx, self_type, span) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingField(field)) => {
- let item = tcx.map.expect_item(impl_node_id);
+ let item = tcx.hir.expect_item(impl_node_id);
let span = if let ItemImpl(.., Some(ref tr), _, _) = item.node {
tr.path.span
} else {
.emit()
}
Err(CopyImplementationError::NotAnAdt) => {
- let item = tcx.map.expect_item(impl_node_id);
+ let item = tcx.hir.expect_item(impl_node_id);
let span = if let ItemImpl(.., ref ty, _) = item.node {
ty.span
} else {
}
};
- let impl_node_id = if let Some(n) = tcx.map.as_local_node_id(impl_did) {
+ let impl_node_id = if let Some(n) = tcx.hir.as_local_node_id(impl_did) {
n
} else {
debug!("visit_implementation_of_coerce_unsized(): impl not \
source,
target);
- let span = tcx.map.span(impl_node_id);
+ let span = tcx.hir.span(impl_node_id);
let param_env = ParameterEnvironment::for_item(tcx, impl_node_id);
let source = source.subst(tcx, ¶m_env.free_substs);
let target = target.subst(tcx, ¶m_env.free_substs);
being coerced, none found");
return;
} else if diff_fields.len() > 1 {
- let item = tcx.map.expect_item(impl_node_id);
+ let item = tcx.hir.expect_item(impl_node_id);
let span = if let ItemImpl(.., Some(ref t), _, _) = item.node {
t.path.span
} else {
- tcx.map.span(impl_node_id)
+ tcx.hir.span(impl_node_id)
};
let mut err = struct_span_err!(tcx.sess,
fn check_implementation(&self, item: &Item) {
let tcx = self.tcx;
- let impl_did = tcx.map.local_def_id(item.id);
+ let impl_did = tcx.hir.local_def_id(item.id);
let self_type = tcx.item_type(impl_did);
// If there are no traits, then this implementation must have a
/// to prevent inundating the user with a bunch of similar error
/// reports.
fn visit_item(&mut self, item: &hir::Item) {
- let def_id = self.tcx.map.local_def_id(item.id);
+ let def_id = self.tcx.hir.local_def_id(item.id);
match item.node {
hir::ItemImpl(.., None, ref ty, _) => {
// For inherent impls, self type must be a nominal type
// defined in this crate.
debug!("coherence2::orphan check: inherent impl {}",
- self.tcx.map.node_to_string(item.id));
+ self.tcx.hir.node_to_string(item.id));
let self_ty = self.tcx.item_type(def_id);
match self_ty.sty {
ty::TyAdt(def, _) => {
hir::ItemImpl(.., Some(_), _, _) => {
// "Trait" impl
debug!("coherence2::orphan check: trait impl {}",
- self.tcx.map.node_to_string(item.id));
+ self.tcx.hir.node_to_string(item.id));
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
let trait_def_id = trait_ref.def_id;
match traits::orphan_check(self.tcx, def_id) {
hir::ItemDefaultImpl(_, ref item_trait_ref) => {
// "Trait" impl
debug!("coherence2::orphan check: default trait impl {}",
- self.tcx.map.node_to_string(item.id));
+ self.tcx.hir.node_to_string(item.id));
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
if trait_ref.def_id.krate != LOCAL_CRATE {
struct_span_err!(self.tcx.sess,
the crate they're defined in; define a new trait instead")
.span_label(item_trait_ref.path.span,
&format!("`{}` trait not defined in this crate",
- self.tcx.map.node_to_pretty_string(item_trait_ref.ref_id)))
+ self.tcx.hir.node_to_pretty_string(item_trait_ref.ref_id)))
.emit();
return;
}
for &item2 in &impl_items2[..] {
if (name, namespace) == name_and_namespace(item2) {
let msg = format!("duplicate definitions with name `{}`", name);
- let node_id = self.tcx.map.as_local_node_id(item1).unwrap();
+ let node_id = self.tcx.hir.as_local_node_id(item1).unwrap();
self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
node_id,
self.tcx.span_of_impl(item1).unwrap(),
hir::ItemStruct(..) |
hir::ItemTrait(..) |
hir::ItemUnion(..) => {
- let type_def_id = self.tcx.map.local_def_id(item.id);
+ let type_def_id = self.tcx.hir.local_def_id(item.id);
self.check_for_overlapping_inherent_impls(type_def_id);
}
// look for another default impl; note that due to the
// general orphan/coherence rules, it must always be
// in this crate.
- let impl_def_id = self.tcx.map.local_def_id(item.id);
+ let impl_def_id = self.tcx.hir.local_def_id(item.id);
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
let prev_default_impl = self.default_impls.insert(trait_ref.def_id, item.id);
`{}`:",
trait_ref);
err.span_note(self.tcx
- .span_of_impl(self.tcx.map.local_def_id(prev_id))
+ .span_of_impl(self.tcx.hir.local_def_id(prev_id))
.unwrap(),
"redundant implementation is here:");
err.emit();
}
}
hir::ItemImpl(.., Some(_), _, _) => {
- let impl_def_id = self.tcx.map.local_def_id(item.id);
+ let impl_def_id = self.tcx.hir.local_def_id(item.id);
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_def_id = trait_ref.def_id;
pub fn check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let mut unsafety = UnsafetyChecker { tcx: tcx };
- tcx.map.krate().visit_all_item_likes(&mut unsafety);
+ tcx.hir.krate().visit_all_item_likes(&mut unsafety);
}
struct UnsafetyChecker<'cx, 'tcx: 'cx> {
impl_generics: Option<&hir::Generics>,
unsafety: hir::Unsafety,
polarity: hir::ImplPolarity) {
- match self.tcx.impl_trait_ref(self.tcx.map.local_def_id(item.id)) {
+ match self.tcx.impl_trait_ref(self.tcx.hir.local_def_id(item.id)) {
None => {
// Inherent impl.
match unsafety {
fn with_collect_item_sig<OP>(&self, id: ast::NodeId, op: OP)
where OP: FnOnce()
{
- let def_id = self.ccx.tcx.map.local_def_id(id);
+ let def_id = self.ccx.tcx.hir.local_def_id(id);
self.ccx.tcx.dep_graph.with_task(DepNode::CollectItemSig(def_id), || {
- self.ccx.tcx.map.read(id);
+ self.ccx.tcx.hir.read(id);
op();
});
}
impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.ccx.tcx.map)
+ NestedVisitorMap::OnlyBodies(&self.ccx.tcx.hir)
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
if let hir::ExprClosure(..) = expr.node {
- let def_id = self.ccx.tcx.map.local_def_id(expr.id);
+ let def_id = self.ccx.tcx.hir.local_def_id(expr.id);
generics_of_def_id(self.ccx, def_id);
type_of_def_id(self.ccx, def_id);
}
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
if let hir::TyImplTrait(..) = ty.node {
- let def_id = self.ccx.tcx.map.local_def_id(ty.id);
+ let def_id = self.ccx.tcx.hir.local_def_id(ty.id);
generics_of_def_id(self.ccx, def_id);
}
intravisit::walk_ty(self, ty);
{
let tcx = self.tcx;
- if let Some(trait_id) = tcx.map.as_local_node_id(def_id) {
- let item = match tcx.map.get(trait_id) {
+ if let Some(trait_id) = tcx.hir.as_local_node_id(def_id) {
+ let item = match tcx.hir.get(trait_id) {
hir_map::NodeItem(item) => item,
_ => bug!("get_trait_def({:?}): not an item", trait_id)
};
match path.def {
Def::SelfTy(Some(def_id), None) |
Def::TyParam(def_id) => {
- def_id == tcx.map.local_def_id(param_id)
+ def_id == tcx.hir.local_def_id(param_id)
}
_ => false
}
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &field.ty);
ccx.tcx.item_types.borrow_mut().insert(ty_f.did, tt);
- let def_id = ccx.tcx.map.local_def_id(field.id);
+ let def_id = ccx.tcx.hir.local_def_id(field.id);
ccx.tcx.item_types.borrow_mut().insert(def_id, tt);
ccx.tcx.generics.borrow_mut().insert(def_id, struct_generics);
ccx.tcx.predicates.borrow_mut().insert(def_id, struct_predicates.clone());
untransformed_rcvr_ty: Ty<'tcx>,
body: Option<hir::BodyId>,
rcvr_ty_predicates: &ty::GenericPredicates<'tcx>,) {
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
let ty_generics = generics_of_def_id(ccx, def_id);
let ty_generic_predicates =
sig, self_value_ty, body, anon_scope);
let substs = mk_item_substs(&ccx.icx(&(rcvr_ty_predicates, &sig.generics)),
- ccx.tcx.map.span(id), def_id);
+ ccx.tcx.hir.span(id), def_id);
let fty = ccx.tcx.mk_fn_def(def_id, substs, fty);
ccx.tcx.item_types.borrow_mut().insert(def_id, fty);
ccx.tcx.predicates.borrow_mut().insert(def_id, ty_generic_predicates);
parent: Some(container.id()),
predicates: vec![]
};
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
ccx.tcx.predicates.borrow_mut().insert(def_id, predicates);
ccx.tcx.item_types.borrow_mut().insert(def_id, ty);
}
parent: Some(container.id()),
predicates: vec![]
};
- let def_id = ccx.tcx.map.local_def_id(id);
+ let def_id = ccx.tcx.hir.local_def_id(id);
ccx.tcx.predicates.borrow_mut().insert(def_id, predicates);
if let Some(ty) = ty {
fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
let tcx = ccx.tcx;
debug!("convert: item {} with id {}", it.name, it.id);
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
match it.node {
// These don't define types.
hir::ItemExternCrate(_) | hir::ItemUse(..) | hir::ItemMod(_) => {
let generics = generics_of_def_id(ccx, def_id);
let predicates = predicates_of_item(ccx, it);
convert_enum_variant_types(ccx,
- tcx.lookup_adt_def(ccx.tcx.map.local_def_id(it.id)),
+ tcx.lookup_adt_def(ccx.tcx.hir.local_def_id(it.id)),
ty,
generics,
predicates,
tcx.record_trait_has_default_impl(trait_ref.def_id);
- tcx.impl_trait_refs.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id),
+ tcx.impl_trait_refs.borrow_mut().insert(ccx.tcx.hir.local_def_id(it.id),
Some(trait_ref));
}
hir::ItemImpl(..,
// we can lookup details about the trait because items are visited
// before trait-items
- let trait_def_id = tcx.map.get_parent_did(trait_item.id);
+ let trait_def_id = tcx.hir.get_parent_did(trait_item.id);
let trait_predicates = tcx.item_predicates(trait_def_id);
match trait_item.node {
hir::TraitItemKind::Const(ref ty, _) => {
- let const_def_id = ccx.tcx.map.local_def_id(trait_item.id);
+ let const_def_id = ccx.tcx.hir.local_def_id(trait_item.id);
generics_of_def_id(ccx, const_def_id);
let ty = ccx.icx(&trait_predicates)
.to_ty(&ExplicitRscope, &ty);
}
hir::TraitItemKind::Type(_, ref opt_ty) => {
- let type_def_id = ccx.tcx.map.local_def_id(trait_item.id);
+ let type_def_id = ccx.tcx.hir.local_def_id(trait_item.id);
generics_of_def_id(ccx, type_def_id);
let typ = opt_ty.as_ref().map({
// we can lookup details about the impl because items are visited
// before impl-items
- let impl_def_id = tcx.map.get_parent_did(impl_item.id);
+ let impl_def_id = tcx.hir.get_parent_did(impl_item.id);
let impl_predicates = tcx.item_predicates(impl_def_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
let impl_self_ty = tcx.item_type(impl_def_id);
match impl_item.node {
hir::ImplItemKind::Const(ref ty, _) => {
- let const_def_id = ccx.tcx.map.local_def_id(impl_item.id);
+ let const_def_id = ccx.tcx.hir.local_def_id(impl_item.id);
generics_of_def_id(ccx, const_def_id);
let ty = ccx.icx(&impl_predicates)
.to_ty(&ExplicitRscope, &ty);
}
hir::ImplItemKind::Type(ref ty) => {
- let type_def_id = ccx.tcx.map.local_def_id(impl_item.id);
+ let type_def_id = ccx.tcx.hir.local_def_id(impl_item.id);
generics_of_def_id(ccx, type_def_id);
if impl_trait_ref.is_none() {
ty: Ty<'tcx>,
predicates: ty::GenericPredicates<'tcx>) {
let tcx = ccx.tcx;
- let def_id = tcx.map.local_def_id(ctor_id);
+ let def_id = tcx.hir.local_def_id(ctor_id);
generics_of_def_id(ccx, def_id);
let ctor_ty = match variant.ctor_kind {
CtorKind::Fictive | CtorKind::Const => ty,
CtorKind::Fn => {
let inputs = variant.fields.iter().map(|field| tcx.item_type(field.did));
- let substs = mk_item_substs(&ccx.icx(&predicates), ccx.tcx.map.span(ctor_id), def_id);
+ let substs = mk_item_substs(&ccx.icx(&predicates), ccx.tcx.hir.span(ctor_id), def_id);
tcx.mk_fn_def(def_id, substs, tcx.mk_bare_fn(ty::BareFnTy {
unsafety: hir::Unsafety::Normal,
abi: abi::Abi::Rust,
}
};
tcx.item_types.borrow_mut().insert(def_id, ctor_ty);
- tcx.predicates.borrow_mut().insert(tcx.map.local_def_id(ctor_id), predicates);
+ tcx.predicates.borrow_mut().insert(tcx.hir.local_def_id(ctor_id), predicates);
}
fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
def: &hir::VariantData)
-> ty::VariantDef {
let mut seen_fields: FxHashMap<ast::Name, Span> = FxHashMap();
- let node_id = ccx.tcx.map.as_local_node_id(did).unwrap();
+ let node_id = ccx.tcx.hir.as_local_node_id(did).unwrap();
let fields = def.fields().iter().map(|f| {
- let fid = ccx.tcx.map.local_def_id(f.id);
+ let fid = ccx.tcx.hir.local_def_id(f.id);
let dup_span = seen_fields.get(&f.name).cloned();
if let Some(prev_span) = dup_span {
struct_span_err!(ccx.tcx.sess, f.span, E0124,
def: &hir::VariantData)
-> &'tcx ty::AdtDef
{
- let did = ccx.tcx.map.local_def_id(it.id);
+ let did = ccx.tcx.hir.local_def_id(it.id);
// Use separate constructor id for unit/tuple structs and reuse did for braced structs.
- let ctor_id = if !def.is_struct() { Some(ccx.tcx.map.local_def_id(def.id())) } else { None };
+ let ctor_id = if !def.is_struct() { Some(ccx.tcx.hir.local_def_id(def.id())) } else { None };
let variants = vec![convert_struct_variant(ccx, ctor_id.unwrap_or(did), it.name,
ConstInt::Infer(0), def)];
let adt = ccx.tcx.alloc_adt_def(did, AdtKind::Struct, variants);
def: &hir::VariantData)
-> &'tcx ty::AdtDef
{
- let did = ccx.tcx.map.local_def_id(it.id);
+ let did = ccx.tcx.hir.local_def_id(it.id);
let variants = vec![convert_struct_variant(ccx, did, it.name, ConstInt::Infer(0), def)];
let adt = ccx.tcx.alloc_adt_def(did, AdtKind::Union, variants);
fn evaluate_disr_expr(ccx: &CrateCtxt, repr_ty: attr::IntType, body: hir::BodyId)
-> Option<ty::Disr> {
- let e = &ccx.tcx.map.body(body).value;
- debug!("disr expr, checking {}", ccx.tcx.map.node_to_pretty_string(e.id));
+ let e = &ccx.tcx.hir.body(body).value;
+ debug!("disr expr, checking {}", ccx.tcx.hir.node_to_pretty_string(e.id));
let ty_hint = repr_ty.to_ty(ccx.tcx);
let print_err = |cv: ConstVal| {
-> &'tcx ty::AdtDef
{
let tcx = ccx.tcx;
- let did = tcx.map.local_def_id(it.id);
+ let did = tcx.hir.local_def_id(it.id);
let repr_hints = tcx.lookup_repr_hints(did);
let repr_type = tcx.enum_repr_type(repr_hints.get(0));
let initial = repr_type.initial_discriminant(tcx);
}.unwrap_or(wrapped_disr);
prev_disr = Some(disr);
- let did = tcx.map.local_def_id(v.node.data.id());
+ let did = tcx.hir.local_def_id(v.node.data.id());
convert_struct_variant(ccx, did, v.node.name, disr, &v.node.data)
}).collect();
debug!("ensure_super_predicates_step(trait_def_id={:?})", trait_def_id);
- let trait_node_id = if let Some(n) = tcx.map.as_local_node_id(trait_def_id) {
+ let trait_node_id = if let Some(n) = tcx.hir.as_local_node_id(trait_def_id) {
n
} else {
// If this trait comes from an external crate, then all of the
let superpredicates = tcx.super_predicates.borrow().get(&trait_def_id).cloned();
let superpredicates = superpredicates.unwrap_or_else(|| {
- let item = match ccx.tcx.map.get(trait_node_id) {
+ let item = match ccx.tcx.hir.get(trait_node_id) {
hir_map::NodeItem(item) => item,
_ => bug!("trait_node_id {} is not an item", trait_node_id)
};
predicates: superbounds
};
debug!("superpredicates for trait {:?} = {:?}",
- tcx.map.local_def_id(item.id),
+ tcx.hir.local_def_id(item.id),
superpredicates);
tcx.super_predicates.borrow_mut().insert(trait_def_id, superpredicates.clone());
}
fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) -> &'tcx ty::TraitDef {
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
let tcx = ccx.tcx;
tcx.trait_defs.memoize(def_id, || {
fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) {
let tcx = ccx.tcx;
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
generics_of_def_id(ccx, def_id);
trait_def_of_item(ccx, it);
-> Vec<ty::Predicate<'tcx>>
{
trait_item_refs.iter().flat_map(|trait_item_ref| {
- let trait_item = ccx.tcx.map.trait_item(trait_item_ref.id);
+ let trait_item = ccx.tcx.hir.trait_item(trait_item_ref.id);
let bounds = match trait_item.node {
hir::TraitItemKind::Type(ref bounds, _) => bounds,
_ => {
def_id: DefId)
-> &'tcx ty::Generics<'tcx> {
let tcx = ccx.tcx;
- let node_id = if let Some(id) = tcx.map.as_local_node_id(def_id) {
+ let node_id = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
id
} else {
return tcx.item_generics(def_id);
use rustc::hir::map::*;
use rustc::hir::*;
- let node = tcx.map.get(node_id);
+ let node = tcx.hir.get(node_id);
let parent_def_id = match node {
NodeImplItem(_) |
NodeTraitItem(_) |
NodeVariant(_) |
NodeStructCtor(_) => {
- let parent_id = tcx.map.get_parent(node_id);
- Some(tcx.map.local_def_id(parent_id))
+ let parent_id = tcx.hir.get_parent(node_id);
+ Some(tcx.hir.local_def_id(parent_id))
}
NodeExpr(&hir::Expr { node: hir::ExprClosure(..), .. }) => {
Some(tcx.closure_base_def_id(def_id))
NodeTy(&hir::Ty { node: hir::TyImplTrait(..), .. }) => {
let mut parent_id = node_id;
loop {
- match tcx.map.get(parent_id) {
+ match tcx.hir.get(parent_id) {
NodeItem(_) | NodeImplItem(_) | NodeTraitItem(_) => break,
_ => {
- parent_id = tcx.map.get_parent_node(parent_id);
+ parent_id = tcx.hir.get_parent_node(parent_id);
}
}
}
- Some(tcx.map.local_def_id(parent_id))
+ Some(tcx.hir.local_def_id(parent_id))
}
_ => None
};
// the node id for the Self type parameter.
let param_id = item.id;
- let parent = ccx.tcx.map.get_parent(param_id);
+ let parent = ccx.tcx.hir.get_parent(param_id);
let def = ty::TypeParameterDef {
index: 0,
name: keywords::SelfType.name(),
- def_id: tcx.map.local_def_id(param_id),
- default_def_id: tcx.map.local_def_id(parent),
+ def_id: tcx.hir.local_def_id(param_id),
+ default_def_id: tcx.hir.local_def_id(parent),
default: None,
object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault,
pure_wrt_drop: false,
ty::RegionParameterDef {
name: l.lifetime.name,
index: own_start + i as u32,
- def_id: tcx.map.local_def_id(l.lifetime.id),
+ def_id: tcx.hir.local_def_id(l.lifetime.id),
bounds: l.bounds.iter().map(|l| {
ast_region_to_region(tcx, l)
}).collect(),
d => format!("{:?}", d),
}
}).collect::<Vec<String>>().join(",");
- tcx.sess.span_err(tcx.map.span(node_id), &object_lifetime_default_reprs);
+ tcx.sess.span_err(tcx.hir.span(node_id), &object_lifetime_default_reprs);
}
tcx.alloc_generics(ty::Generics {
fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
def_id: DefId)
-> Ty<'tcx> {
- let node_id = if let Some(id) = ccx.tcx.map.as_local_node_id(def_id) {
+ let node_id = if let Some(id) = ccx.tcx.hir.as_local_node_id(def_id) {
id
} else {
return ccx.tcx.item_type(def_id);
// Alway bring in generics, as computing the type needs them.
generics_of_def_id(ccx, def_id);
- let ty = match ccx.tcx.map.get(node_id) {
+ let ty = match ccx.tcx.hir.get(node_id) {
NodeItem(item) => {
match item.node {
ItemStatic(ref t, ..) | ItemConst(ref t, _) => {
}
}
NodeForeignItem(foreign_item) => {
- let abi = ccx.tcx.map.get_foreign_abi(node_id);
+ let abi = ccx.tcx.hir.get_foreign_abi(node_id);
match foreign_item.node {
ForeignItemFn(ref fn_decl, _, ref generics) => {
compute_type_of_foreign_fn_decl(
- ccx, ccx.tcx.map.local_def_id(foreign_item.id),
+ ccx, ccx.tcx.hir.local_def_id(foreign_item.id),
fn_decl, generics, abi)
}
ForeignItemStatic(ref t, _) => {
fn predicates_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
it: &hir::Item)
-> ty::GenericPredicates<'tcx> {
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
let no_generics = hir::Generics::empty();
let generics = match it.node {
// map, and I regard each time that I use it as a personal and
// moral failing, but at the moment it seems like the only
// convenient way to extract the ABI. - ndm
- let def_id = ccx.tcx.map.local_def_id(it.id);
+ let def_id = ccx.tcx.hir.local_def_id(it.id);
type_of_def_id(ccx, def_id);
generics_of_def_id(ccx, def_id);
compute_object_lifetime_default(ccx, param.id,
¶m.bounds, &ast_generics.where_clause);
- let parent = tcx.map.get_parent(param.id);
+ let parent = tcx.hir.get_parent(param.id);
if !allow_defaults && default.is_some() {
if !tcx.sess.features.borrow().default_type_parameter_fallback {
let def = ty::TypeParameterDef {
index: index,
name: param.name,
- def_id: ccx.tcx.map.local_def_id(param.id),
- default_def_id: ccx.tcx.map.local_def_id(parent),
+ def_id: ccx.tcx.hir.local_def_id(param.id),
+ default_def_id: ccx.tcx.hir.local_def_id(parent),
default: default,
object_lifetime_default: object_lifetime_default,
pure_wrt_drop: param.pure_wrt_drop,
ccx.tcx.sess.struct_span_err(ast_ty.span,
&format!("use of SIMD type `{}` in FFI is highly experimental and \
may result in invalid code",
- ccx.tcx.map.node_to_pretty_string(ast_ty.id)))
+ ccx.tcx.hir.node_to_pretty_string(ast_ty.id)))
.help("add #![feature(simd_ffi)] to the crate attributes to enable")
.emit();
}
}
}
- let id = ccx.tcx.map.as_local_node_id(def_id).unwrap();
- let substs = mk_item_substs(&ccx.icx(ast_generics), ccx.tcx.map.span(id), def_id);
+ let id = ccx.tcx.hir.as_local_node_id(def_id).unwrap();
+ let substs = mk_item_substs(&ccx.icx(ast_generics), ccx.tcx.hir.span(id), def_id);
ccx.tcx.mk_fn_def(def_id, substs, ccx.tcx.mk_bare_fn(ty::BareFnTy {
abi: abi,
unsafety: hir::Unsafety::Unsafe,
fn visit_item(&mut self, item: &'tcx hir::Item) {
match item.node {
hir::ItemImpl(.., ref generics, _, _, ref impl_item_refs) => {
- let impl_def_id = self.ccx.tcx.map.local_def_id(item.id);
+ let impl_def_id = self.ccx.tcx.hir.local_def_id(item.id);
enforce_impl_params_are_constrained(self.ccx,
generics,
impl_def_id,
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs.iter()
- .map(|item_ref| ccx.tcx.map.local_def_id(item_ref.id.node_id))
+ .map(|item_ref| ccx.tcx.hir.local_def_id(item_ref.id.node_id))
.filter(|&def_id| {
let item = ccx.tcx.associated_item(def_id);
item.kind == ty::AssociatedKind::Type && item.defaultness.has_value()
let mut seen_type_items = FxHashMap();
let mut seen_value_items = FxHashMap();
for impl_item_ref in impl_item_refs {
- let impl_item = tcx.map.impl_item(impl_item_ref.id);
+ let impl_item = tcx.hir.impl_item(impl_item_ref.id);
let seen_items = match impl_item.node {
hir::ImplItemKind::Type(_) => &mut seen_type_items,
_ => &mut seen_value_items,
main_id: ast::NodeId,
main_span: Span) {
let tcx = ccx.tcx;
- let main_def_id = tcx.map.local_def_id(main_id);
+ let main_def_id = tcx.hir.local_def_id(main_id);
let main_t = tcx.item_type(main_def_id);
match main_t.sty {
ty::TyFnDef(..) => {
- match tcx.map.find(main_id) {
+ match tcx.hir.find(main_id) {
Some(hir_map::NodeItem(it)) => {
match it.node {
hir::ItemFn(.., ref generics, _) => {
start_id: ast::NodeId,
start_span: Span) {
let tcx = ccx.tcx;
- let start_def_id = ccx.tcx.map.local_def_id(start_id);
+ let start_def_id = ccx.tcx.hir.local_def_id(start_id);
let start_t = tcx.item_type(start_def_id);
match start_t.sty {
ty::TyFnDef(..) => {
- match tcx.map.find(start_id) {
+ match tcx.hir.find(start_id) {
Some(hir_map::NodeItem(it)) => {
match it.node {
hir::ItemFn(..,ref ps,_)
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
let tcx = self.terms_cx.tcx;
- let did = tcx.map.local_def_id(item.id);
+ let did = tcx.hir.local_def_id(item.id);
- debug!("visit_item item={}", tcx.map.node_to_string(item.id));
+ debug!("visit_item item={}", tcx.hir.node_to_string(item.id));
match item.node {
hir::ItemEnum(..) |
Some(&index) => index,
None => {
bug!("no inferred index entry for {}",
- self.tcx().map.node_to_string(param_id));
+ self.tcx().hir.node_to_string(param_id));
}
}
}
fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId {
let tcx = self.terms_cx.tcx;
- assert!(is_lifetime(&tcx.map, param_id));
+ assert!(is_lifetime(&tcx.hir, param_id));
match tcx.named_region_map.defs.get(¶m_id) {
Some(&rl::DefEarlyBoundRegion(_, lifetime_decl_id)) => lifetime_decl_id,
Some(_) => bug!("should not encounter non early-bound cases"),
let tcx = this.terms_cx.tcx;
let decl_id = this.find_binding_for_lifetime(param_id);
// Currently only called on lifetimes; double-checking that.
- assert!(is_lifetime(&tcx.map, param_id));
- let parent_id = tcx.map.get_parent(decl_id);
- let parent = tcx.map
+ assert!(is_lifetime(&tcx.hir, param_id));
+ let parent_id = tcx.hir.get_parent(decl_id);
+ let parent = tcx.hir
.find(parent_id)
- .unwrap_or_else(|| bug!("tcx.map missing entry for id: {}", parent_id));
+ .unwrap_or_else(|| bug!("tcx.hir missing entry for id: {}", parent_id));
let is_inferred;
macro_rules! cannot_happen { () => { {
bug!("invalid parent: {} for {}",
- tcx.map.node_to_string(parent_id),
- tcx.map.node_to_string(param_id));
+ tcx.hir.node_to_string(parent_id),
+ tcx.hir.node_to_string(param_id));
} } }
match parent {
-> VarianceTermPtr<'a> {
assert_eq!(param_def_id.krate, item_def_id.krate);
- if let Some(param_node_id) = self.tcx().map.as_local_node_id(param_def_id) {
+ if let Some(param_node_id) = self.tcx().hir.as_local_node_id(param_def_id) {
// Parameter on an item defined within current crate:
// variance not yet inferred, so return a symbolic
// variance.
i -= generics.regions.len();
}
let def_id = generics.types[i].def_id;
- let node_id = self.tcx().map.as_local_node_id(def_id).unwrap();
+ let node_id = self.tcx().hir.as_local_node_id(def_id).unwrap();
match self.terms_cx.inferred_map.get(&node_id) {
Some(&index) => {
self.add_constraint(index, variance);
assert_eq!(generics.parent, None);
let i = data.index as usize - generics.has_self as usize;
let def_id = generics.regions[i].def_id;
- let node_id = self.tcx().map.as_local_node_id(def_id).unwrap();
+ let node_id = self.tcx().hir.as_local_node_id(def_id).unwrap();
if self.is_to_be_inferred(node_id) {
let index = self.inferred_index(node_id);
self.add_constraint(index, variance);
debug!("item_id={} item_variances={:?}", item_id, item_variances);
- let item_def_id = tcx.map.local_def_id(item_id);
+ let item_def_id = tcx.hir.local_def_id(item_id);
// For unit testing: check for a special "rustc_variance"
// attribute and report an error with various results if found.
if tcx.has_attr(item_def_id, "rustc_variance") {
span_err!(tcx.sess,
- tcx.map.span(item_id),
+ tcx.hir.span(item_id),
E0208,
"{:?}",
item_variances);
all.into_iter() // iterating over (Option<DefId>, Variance)
.filter(|&(ref d,_)| d.is_some())
.map(|(d, v)| (d.unwrap(), v)) // (DefId, Variance)
- .filter_map(|(d, v)| tcx.map.as_local_node_id(d).map(|n| (n, v))) // (NodeId, Variance)
+ .filter_map(|(d, v)| tcx.hir.as_local_node_id(d).map(|n| (n, v))) // (NodeId, Variance)
.collect()
}
// "invalid item id" from "item id with no
// parameters".
if self.num_inferred() == inferreds_on_entry {
- let item_def_id = self.tcx.map.local_def_id(item_id);
+ let item_def_id = self.tcx.hir.local_def_id(item_id);
let newly_added = self.tcx
.item_variance_map
.borrow_mut()
param_id={}, \
inf_index={:?}, \
initial_variance={:?})",
- self.tcx.item_path_str(self.tcx.map.local_def_id(item_id)),
+ self.tcx.item_path_str(self.tcx.hir.local_def_id(item_id)),
item_id,
index,
param_id,
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
debug!("add_inferreds for item {}",
- self.tcx.map.node_to_string(item.id));
+ self.tcx.hir.node_to_string(item.id));
match item.node {
hir::ItemEnum(_, ref generics) |
None
};
let primitives = if root.is_local() {
- cx.tcx.map.krate().module.item_ids.iter().filter_map(|&id| {
- let item = cx.tcx.map.expect_item(id.id);
+ cx.tcx.hir.krate().module.item_ids.iter().filter_map(|&id| {
+ let item = cx.tcx.hir.expect_item(id.id);
match item.node {
hir::ItemMod(_) => {
- as_primitive(Def::Mod(cx.tcx.map.local_def_id(id.id)))
+ as_primitive(Def::Mod(cx.tcx.hir.local_def_id(id.id)))
}
hir::ItemUse(ref path, hir::UseKind::Single)
if item.vis == hir::Visibility::Public => {
as_primitive(path.def).map(|(_, prim, attrs)| {
// Pretend the primitive is local.
- (cx.tcx.map.local_def_id(id.id), prim, attrs)
+ (cx.tcx.hir.local_def_id(id.id), prim, attrs)
})
}
_ => None
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
inner: ModuleItem(Module {
is_crate: self.is_crate,
items: items
fn clean(&self, cx: &DocContext) -> TyParam {
TyParam {
name: self.name.clean(cx),
- did: cx.tcx.map.local_def_id(self.id),
+ did: cx.tcx.hir.local_def_id(self.id),
bounds: self.bounds.clean(cx),
default: self.default.clean(cx),
}
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
inner: FunctionItem(Function {
decl: (&self.decl, self.body).clean(cx),
generics: self.generics.clean(cx),
impl<'a> Clean<Arguments> for (&'a [P<hir::Ty>], hir::BodyId) {
fn clean(&self, cx: &DocContext) -> Arguments {
- let body = cx.tcx.map.body(self.1);
+ let body = cx.tcx.hir.body(self.1);
Arguments {
values: self.0.iter().enumerate().map(|(i, ty)| {
impl<'a, 'tcx> Clean<FnDecl> for (DefId, &'a ty::PolyFnSig<'tcx>) {
fn clean(&self, cx: &DocContext) -> FnDecl {
let (did, sig) = *self;
- let mut names = if cx.tcx.map.as_local_node_id(did).is_some() {
+ let mut names = if cx.tcx.hir.as_local_node_id(did).is_some() {
vec![].into_iter()
} else {
cx.tcx.sess.cstore.fn_arg_names(did).into_iter()
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.span.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: None,
- stability: get_stability(cx, cx.tcx.map.local_def_id(self.id)),
- deprecation: get_deprecation(cx, cx.tcx.map.local_def_id(self.id)),
+ stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
+ deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
inner: inner
}
}
name: Some(self.name.clean(cx)),
source: self.span.clean(cx),
attrs: self.attrs.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
- stability: get_stability(cx, cx.tcx.map.local_def_id(self.id)),
- deprecation: get_deprecation(cx, cx.tcx.map.local_def_id(self.id)),
+ stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
+ deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
inner: inner
}
}
let mut alias = None;
if let Def::TyAlias(def_id) = path.def {
// Substitute private type aliases
- if let Some(node_id) = cx.tcx.map.as_local_node_id(def_id) {
+ if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
if !cx.access_levels.borrow().is_exported(def_id) {
- alias = Some(&cx.tcx.map.expect_item(node_id).node);
+ alias = Some(&cx.tcx.hir.expect_item(node_id).node);
}
}
};
let mut ty_substs = FxHashMap();
let mut lt_substs = FxHashMap();
for (i, ty_param) in generics.ty_params.iter().enumerate() {
- let ty_param_def = Def::TyParam(cx.tcx.map.local_def_id(ty_param.id));
+ let ty_param_def = Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id));
if let Some(ty) = provided_params.types().get(i).cloned()
.cloned() {
ty_substs.insert(ty_param_def, ty.unwrap().clean(cx));
type_params: Vec::new(),
where_predicates: Vec::new()
},
- decl: (cx.tcx.map.local_def_id(ast::CRATE_NODE_ID), &fty.sig).clean(cx),
+ decl: (cx.tcx.hir.local_def_id(ast::CRATE_NODE_ID), &fty.sig).clean(cx),
abi: fty.abi,
}),
ty::TyAdt(def, substs) => {
attrs: self.attrs.clean(cx),
source: self.span.clean(cx),
visibility: self.vis.clean(cx),
- stability: get_stability(cx, cx.tcx.map.local_def_id(self.id)),
- deprecation: get_deprecation(cx, cx.tcx.map.local_def_id(self.id)),
- def_id: cx.tcx.map.local_def_id(self.id),
+ stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
+ deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
+ def_id: cx.tcx.hir.local_def_id(self.id),
inner: StructFieldItem(self.ty.clean(cx)),
}
}
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
visibility: None,
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.def.id()),
+ def_id: cx.tcx.hir.local_def_id(self.def.id()),
inner: VariantItem(Variant {
kind: self.def.clean(cx),
}),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id.clone()),
+ def_id: cx.tcx.hir.local_def_id(self.id.clone()),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: Some(Public),
stability: None,
deprecation: None,
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.map.local_def_id(ast::CRATE_NODE_ID),
+ def_id: cx.tcx.hir.local_def_id(ast::CRATE_NODE_ID),
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.span.clean(cx),
- def_id: cx.tcx.map.local_def_id(self.id),
+ def_id: cx.tcx.hir.local_def_id(self.id),
visibility: self.vis.clean(cx),
- stability: get_stability(cx, cx.tcx.map.local_def_id(self.id)),
- deprecation: get_deprecation(cx, cx.tcx.map.local_def_id(self.id)),
+ stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
+ deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
inner: inner,
}
}
}
fn print_const_expr(cx: &DocContext, body: hir::BodyId) -> String {
- cx.tcx.map.node_to_pretty_string(body.node_id)
+ cx.tcx.hir.node_to_pretty_string(body.node_id)
}
/// Given a type Path, resolve it to a Type using the TyCtxt
// to the map from defid -> nodeid
let access_levels = AccessLevels {
map: access_levels.map.into_iter()
- .map(|(k, v)| (tcx.map.local_def_id(k), v))
+ .map(|(k, v)| (tcx.hir.local_def_id(k), v))
.collect()
};
export_map: export_map,
hir_ty_to_ty: hir_ty_to_ty,
};
- debug!("crate: {:?}", tcx.map.krate());
+ debug!("crate: {:?}", tcx.hir.krate());
let krate = {
let mut v = RustdocVisitor::new(&ctxt);
- v.visit(tcx.map.krate());
+ v.visit(tcx.hir.krate());
v.clean(&ctxt)
};
}
fn stability(&self, id: ast::NodeId) -> Option<attr::Stability> {
- self.cx.tcx.map.opt_local_def_id(id)
+ self.cx.tcx.hir.opt_local_def_id(id)
.and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned()
}
fn deprecation(&self, id: ast::NodeId) -> Option<attr::Deprecation> {
- self.cx.tcx.map.opt_local_def_id(id)
+ self.cx.tcx.hir.opt_local_def_id(id)
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
}
let orig_inside_public_path = self.inside_public_path;
self.inside_public_path &= vis == hir::Public;
for i in &m.item_ids {
- let item = self.cx.tcx.map.expect_item(i.id);
+ let item = self.cx.tcx.hir.expect_item(i.id);
self.visit_item(item, None, &mut om);
}
self.inside_public_path = orig_inside_public_path;
please_inline: bool) -> bool {
fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool {
- while let Some(id) = cx.tcx.map.get_enclosing_scope(node) {
+ while let Some(id) = cx.tcx.hir.get_enclosing_scope(node) {
node = id;
- if cx.tcx.map.attrs(node).lists("doc").has_word("hidden") {
+ if cx.tcx.hir.attrs(node).lists("doc").has_word("hidden") {
return true;
}
if node == ast::CRATE_NODE_ID {
}
let def_did = def.def_id();
- let use_attrs = tcx.map.attrs(id);
+ let use_attrs = tcx.hir.attrs(id);
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
let is_no_inline = use_attrs.lists("doc").has_word("no_inline") ||
use_attrs.lists("doc").has_word("hidden");
return false
}
- let def_node_id = match tcx.map.as_local_node_id(def_did) {
+ let def_node_id = match tcx.hir.as_local_node_id(def_did) {
Some(n) => n, None => return false
};
if !self.view_item_stack.insert(def_node_id) { return false }
- let ret = match tcx.map.get(def_node_id) {
+ let ret = match tcx.hir.get(def_node_id) {
hir_map::NodeItem(it) => {
let prev = mem::replace(&mut self.inlining, true);
if glob {
match it.node {
hir::ItemMod(ref m) => {
for i in &m.item_ids {
- let i = self.cx.tcx.map.expect_item(i.id);
+ let i = self.cx.tcx.hir.expect_item(i.id);
self.visit_item(i, None, om);
}
}
},
hir::ItemTrait(unsafety, ref gen, ref b, ref item_ids) => {
let items = item_ids.iter()
- .map(|ti| self.cx.tcx.map.trait_item(ti.id).clone())
+ .map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
.collect();
let t = Trait {
unsafety: unsafety,
// regardless of where they're located.
if !self.inlining {
let items = item_ids.iter()
- .map(|ii| self.cx.tcx.map.impl_item(ii.id).clone())
+ .map(|ii| self.cx.tcx.hir.impl_item(ii.id).clone())
.collect();
let i = Impl {
unsafety: unsafety,
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
Macro {
- def_id: self.cx.tcx.map.local_def_id(def.id),
+ def_id: self.cx.tcx.hir.local_def_id(def.id),
attrs: def.attrs.clone(),
name: def.name,
whence: def.span,
if let Some(other) = self.map.insert(extent, node) {
cx.span_lint(REGION_HIERARCHY, span, &format!(
"different fns {:?}, {:?} with the same root extent {:?}",
- cx.tcx.map.local_def_id(other),
- cx.tcx.map.local_def_id(node),
+ cx.tcx.hir.local_def_id(other),
+ cx.tcx.hir.local_def_id(node),
extent));
}
}