Rename hir::map::NodeKind to hir::Node
This commit is contained in:
parent
ecbdfb4988
commit
e2a1cce9c5
48 changed files with 500 additions and 507 deletions
|
@ -22,8 +22,8 @@
|
|||
//! for the `Code` associated with a particular NodeId.
|
||||
|
||||
use hir as ast;
|
||||
use hir::map::{self, NodeKind};
|
||||
use hir::{Expr, FnDecl};
|
||||
use hir::map;
|
||||
use hir::{Expr, FnDecl, Node};
|
||||
use hir::intravisit::FnKind;
|
||||
use syntax::ast::{Attribute, Ident, Name, NodeId};
|
||||
use syntax_pos::Span;
|
||||
|
@ -39,7 +39,7 @@ use syntax_pos::Span;
|
|||
///
|
||||
/// To construct one, use the `Code::from_node` function.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct FnLikeNode<'a> { node: NodeKind<'a> }
|
||||
pub struct FnLikeNode<'a> { node: Node<'a> }
|
||||
|
||||
/// MaybeFnLike wraps a method that indicates if an object
|
||||
/// corresponds to some FnLikeNode.
|
||||
|
@ -95,11 +95,11 @@ impl<'a> Code<'a> {
|
|||
/// Attempts to construct a Code from presumed FnLike or Expr node input.
|
||||
pub fn from_node(map: &map::Map<'a>, id: NodeId) -> Option<Code<'a>> {
|
||||
match map.get(id) {
|
||||
map::NodeKind::Block(_) => {
|
||||
map::Node::Block(_) => {
|
||||
// Use the parent, hopefully an expression node.
|
||||
Code::from_node(map, map.get_parent_node(id))
|
||||
}
|
||||
map::NodeKind::Expr(expr) => Some(Code::Expr(expr)),
|
||||
map::Node::Expr(expr) => Some(Code::Expr(expr)),
|
||||
node => FnLikeNode::from_node(node).map(Code::FnLike)
|
||||
}
|
||||
}
|
||||
|
@ -143,12 +143,12 @@ impl<'a> ClosureParts<'a> {
|
|||
|
||||
impl<'a> FnLikeNode<'a> {
|
||||
/// Attempts to construct a FnLikeNode from presumed FnLike node input.
|
||||
pub fn from_node(node: NodeKind) -> Option<FnLikeNode> {
|
||||
pub fn from_node(node: Node) -> Option<FnLikeNode> {
|
||||
let fn_like = match node {
|
||||
map::NodeKind::Item(item) => item.is_fn_like(),
|
||||
map::NodeKind::TraitItem(tm) => tm.is_fn_like(),
|
||||
map::NodeKind::ImplItem(it) => it.is_fn_like(),
|
||||
map::NodeKind::Expr(e) => e.is_fn_like(),
|
||||
map::Node::Item(item) => item.is_fn_like(),
|
||||
map::Node::TraitItem(tm) => tm.is_fn_like(),
|
||||
map::Node::ImplItem(it) => it.is_fn_like(),
|
||||
map::Node::Expr(e) => e.is_fn_like(),
|
||||
_ => false
|
||||
};
|
||||
if fn_like {
|
||||
|
@ -234,7 +234,7 @@ impl<'a> FnLikeNode<'a> {
|
|||
C: FnOnce(ClosureParts<'a>) -> A,
|
||||
{
|
||||
match self.node {
|
||||
map::NodeKind::Item(i) => match i.node {
|
||||
map::Node::Item(i) => match i.node {
|
||||
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
|
||||
item_fn(ItemFnParts {
|
||||
id: i.id,
|
||||
|
@ -249,13 +249,13 @@ impl<'a> FnLikeNode<'a> {
|
|||
}),
|
||||
_ => bug!("item FnLikeNode that is not fn-like"),
|
||||
},
|
||||
map::NodeKind::TraitItem(ti) => match ti.node {
|
||||
map::Node::TraitItem(ti) => match ti.node {
|
||||
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
|
||||
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
|
||||
}
|
||||
_ => bug!("trait method FnLikeNode that is not fn-like"),
|
||||
},
|
||||
map::NodeKind::ImplItem(ii) => {
|
||||
map::Node::ImplItem(ii) => {
|
||||
match ii.node {
|
||||
ast::ImplItemKind::Method(ref sig, body) => {
|
||||
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
|
||||
|
@ -265,7 +265,7 @@ impl<'a> FnLikeNode<'a> {
|
|||
}
|
||||
}
|
||||
},
|
||||
map::NodeKind::Expr(e) => match e.node {
|
||||
map::Node::Expr(e) => match e.node {
|
||||
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) =>
|
||||
closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)),
|
||||
_ => bug!("expr FnLikeNode that is not fn-like"),
|
||||
|
|
|
@ -117,7 +117,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
|||
collector.insert_entry(CRATE_NODE_ID, Entry {
|
||||
parent: ast::DUMMY_NODE_ID,
|
||||
dep_node: root_mod_sig_dep_index,
|
||||
node: NodeKind::Crate,
|
||||
node: Node::Crate,
|
||||
});
|
||||
|
||||
collector
|
||||
|
@ -190,7 +190,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
|||
self.map[id.as_usize()] = Some(entry);
|
||||
}
|
||||
|
||||
fn insert(&mut self, id: NodeId, node: NodeKind<'hir>) {
|
||||
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
|
||||
let entry = Entry {
|
||||
parent: self.parent_node,
|
||||
dep_node: if self.currently_in_body {
|
||||
|
@ -309,13 +309,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
debug_assert_eq!(i.hir_id.owner,
|
||||
self.definitions.opt_def_index(i.id).unwrap());
|
||||
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
|
||||
this.insert(i.id, NodeKind::Item(i));
|
||||
this.insert(i.id, Node::Item(i));
|
||||
this.with_parent(i.id, |this| {
|
||||
match i.node {
|
||||
ItemKind::Struct(ref struct_def, _) => {
|
||||
// If this is a tuple-like struct, register the constructor.
|
||||
if !struct_def.is_struct() {
|
||||
this.insert(struct_def.id(), NodeKind::StructCtor(struct_def));
|
||||
this.insert(struct_def.id(), Node::StructCtor(struct_def));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -326,7 +326,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
|
||||
self.insert(foreign_item.id, NodeKind::ForeignItem(foreign_item));
|
||||
self.insert(foreign_item.id, Node::ForeignItem(foreign_item));
|
||||
|
||||
self.with_parent(foreign_item.id, |this| {
|
||||
intravisit::walk_foreign_item(this, foreign_item);
|
||||
|
@ -334,7 +334,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_generic_param(&mut self, param: &'hir GenericParam) {
|
||||
self.insert(param.id, NodeKind::GenericParam(param));
|
||||
self.insert(param.id, Node::GenericParam(param));
|
||||
intravisit::walk_generic_param(self, param);
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
debug_assert_eq!(ti.hir_id.owner,
|
||||
self.definitions.opt_def_index(ti.id).unwrap());
|
||||
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
|
||||
this.insert(ti.id, NodeKind::TraitItem(ti));
|
||||
this.insert(ti.id, Node::TraitItem(ti));
|
||||
|
||||
this.with_parent(ti.id, |this| {
|
||||
intravisit::walk_trait_item(this, ti);
|
||||
|
@ -354,7 +354,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
debug_assert_eq!(ii.hir_id.owner,
|
||||
self.definitions.opt_def_index(ii.id).unwrap());
|
||||
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
|
||||
this.insert(ii.id, NodeKind::ImplItem(ii));
|
||||
this.insert(ii.id, Node::ImplItem(ii));
|
||||
|
||||
this.with_parent(ii.id, |this| {
|
||||
intravisit::walk_impl_item(this, ii);
|
||||
|
@ -364,9 +364,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
|
||||
fn visit_pat(&mut self, pat: &'hir Pat) {
|
||||
let node = if let PatKind::Binding(..) = pat.node {
|
||||
NodeKind::Binding(pat)
|
||||
Node::Binding(pat)
|
||||
} else {
|
||||
NodeKind::Pat(pat)
|
||||
Node::Pat(pat)
|
||||
};
|
||||
self.insert(pat.id, node);
|
||||
|
||||
|
@ -376,7 +376,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
|
||||
self.insert(constant.id, NodeKind::AnonConst(constant));
|
||||
self.insert(constant.id, Node::AnonConst(constant));
|
||||
|
||||
self.with_parent(constant.id, |this| {
|
||||
intravisit::walk_anon_const(this, constant);
|
||||
|
@ -384,7 +384,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'hir Expr) {
|
||||
self.insert(expr.id, NodeKind::Expr(expr));
|
||||
self.insert(expr.id, Node::Expr(expr));
|
||||
|
||||
self.with_parent(expr.id, |this| {
|
||||
intravisit::walk_expr(this, expr);
|
||||
|
@ -393,7 +393,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
|
||||
fn visit_stmt(&mut self, stmt: &'hir Stmt) {
|
||||
let id = stmt.node.id();
|
||||
self.insert(id, NodeKind::Stmt(stmt));
|
||||
self.insert(id, Node::Stmt(stmt));
|
||||
|
||||
self.with_parent(id, |this| {
|
||||
intravisit::walk_stmt(this, stmt);
|
||||
|
@ -401,7 +401,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'hir Ty) {
|
||||
self.insert(ty.id, NodeKind::Ty(ty));
|
||||
self.insert(ty.id, Node::Ty(ty));
|
||||
|
||||
self.with_parent(ty.id, |this| {
|
||||
intravisit::walk_ty(this, ty);
|
||||
|
@ -409,7 +409,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
|
||||
self.insert(tr.ref_id, NodeKind::TraitRef(tr));
|
||||
self.insert(tr.ref_id, Node::TraitRef(tr));
|
||||
|
||||
self.with_parent(tr.ref_id, |this| {
|
||||
intravisit::walk_trait_ref(this, tr);
|
||||
|
@ -423,21 +423,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_block(&mut self, block: &'hir Block) {
|
||||
self.insert(block.id, NodeKind::Block(block));
|
||||
self.insert(block.id, Node::Block(block));
|
||||
self.with_parent(block.id, |this| {
|
||||
intravisit::walk_block(this, block);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, l: &'hir Local) {
|
||||
self.insert(l.id, NodeKind::Local(l));
|
||||
self.insert(l.id, Node::Local(l));
|
||||
self.with_parent(l.id, |this| {
|
||||
intravisit::walk_local(this, l)
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
|
||||
self.insert(lifetime.id, NodeKind::Lifetime(lifetime));
|
||||
self.insert(lifetime.id, Node::Lifetime(lifetime));
|
||||
}
|
||||
|
||||
fn visit_vis(&mut self, visibility: &'hir Visibility) {
|
||||
|
@ -446,7 +446,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
VisibilityKind::Crate(_) |
|
||||
VisibilityKind::Inherited => {}
|
||||
VisibilityKind::Restricted { id, .. } => {
|
||||
self.insert(id, NodeKind::Visibility(visibility));
|
||||
self.insert(id, Node::Visibility(visibility));
|
||||
self.with_parent(id, |this| {
|
||||
intravisit::walk_vis(this, visibility);
|
||||
});
|
||||
|
@ -458,20 +458,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
let def_index = self.definitions.opt_def_index(macro_def.id).unwrap();
|
||||
|
||||
self.with_dep_node_owner(def_index, macro_def, |this| {
|
||||
this.insert(macro_def.id, NodeKind::MacroDef(macro_def));
|
||||
this.insert(macro_def.id, Node::MacroDef(macro_def));
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
|
||||
let id = v.node.data.id();
|
||||
self.insert(id, NodeKind::Variant(v));
|
||||
self.insert(id, Node::Variant(v));
|
||||
self.with_parent(id, |this| {
|
||||
intravisit::walk_variant(this, v, g, item_id);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &'hir StructField) {
|
||||
self.insert(field.id, NodeKind::Field(field));
|
||||
self.insert(field.id, Node::Field(field));
|
||||
self.with_parent(field.id, |this| {
|
||||
intravisit::walk_struct_field(this, field);
|
||||
});
|
||||
|
|
|
@ -40,88 +40,56 @@ mod def_collector;
|
|||
pub mod definitions;
|
||||
mod hir_id_validator;
|
||||
|
||||
|
||||
pub const ITEM_LIKE_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::Low;
|
||||
pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum NodeKind<'hir> {
|
||||
Item(&'hir Item),
|
||||
ForeignItem(&'hir ForeignItem),
|
||||
TraitItem(&'hir TraitItem),
|
||||
ImplItem(&'hir ImplItem),
|
||||
Variant(&'hir Variant),
|
||||
Field(&'hir StructField),
|
||||
AnonConst(&'hir AnonConst),
|
||||
Expr(&'hir Expr),
|
||||
Stmt(&'hir Stmt),
|
||||
Ty(&'hir Ty),
|
||||
TraitRef(&'hir TraitRef),
|
||||
Binding(&'hir Pat),
|
||||
Pat(&'hir Pat),
|
||||
Block(&'hir Block),
|
||||
Local(&'hir Local),
|
||||
MacroDef(&'hir MacroDef),
|
||||
|
||||
/// StructCtor represents a tuple struct.
|
||||
StructCtor(&'hir VariantData),
|
||||
|
||||
Lifetime(&'hir Lifetime),
|
||||
GenericParam(&'hir GenericParam),
|
||||
Visibility(&'hir Visibility),
|
||||
|
||||
/// Roots for node trees. Its DepNodeIndex when in `Entry`
|
||||
/// is the dependency node of the crate's root module.
|
||||
Crate,
|
||||
}
|
||||
|
||||
/// Represents an entry and its parent NodeId.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Entry<'hir> {
|
||||
parent: NodeId,
|
||||
dep_node: DepNodeIndex,
|
||||
node: NodeKind<'hir>,
|
||||
node: Node<'hir>,
|
||||
}
|
||||
|
||||
impl<'hir> Entry<'hir> {
|
||||
fn parent_node(self) -> Option<NodeId> {
|
||||
match self.node {
|
||||
NodeKind::Crate | NodeKind::MacroDef(_) => None,
|
||||
Node::Crate | Node::MacroDef(_) => None,
|
||||
_ => Some(self.parent),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_node(self) -> Option<NodeKind<'hir>> {
|
||||
fn to_node(self) -> Option<Node<'hir>> {
|
||||
match self.node {
|
||||
NodeKind::Crate => None,
|
||||
Node::Crate => None,
|
||||
_ => Some(self.node),
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_decl(&self) -> Option<&FnDecl> {
|
||||
match self.node {
|
||||
NodeKind::Item(ref item) => {
|
||||
Node::Item(ref item) => {
|
||||
match item.node {
|
||||
ItemKind::Fn(ref fn_decl, _, _, _) => Some(&fn_decl),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
NodeKind::TraitItem(ref item) => {
|
||||
Node::TraitItem(ref item) => {
|
||||
match item.node {
|
||||
TraitItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
NodeKind::ImplItem(ref item) => {
|
||||
Node::ImplItem(ref item) => {
|
||||
match item.node {
|
||||
ImplItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
NodeKind::Expr(ref expr) => {
|
||||
Node::Expr(ref expr) => {
|
||||
match expr.node {
|
||||
ExprKind::Closure(_, ref fn_decl, ..) => Some(&fn_decl),
|
||||
_ => None,
|
||||
|
@ -134,7 +102,7 @@ impl<'hir> Entry<'hir> {
|
|||
|
||||
fn associated_body(self) -> Option<BodyId> {
|
||||
match self.node {
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Const(_, body) |
|
||||
ItemKind::Static(.., body) |
|
||||
|
@ -143,7 +111,7 @@ impl<'hir> Entry<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::TraitItem(item) => {
|
||||
Node::TraitItem(item) => {
|
||||
match item.node {
|
||||
TraitItemKind::Const(_, Some(body)) |
|
||||
TraitItemKind::Method(_, TraitMethod::Provided(body)) => Some(body),
|
||||
|
@ -151,7 +119,7 @@ impl<'hir> Entry<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ImplItem(item) => {
|
||||
Node::ImplItem(item) => {
|
||||
match item.node {
|
||||
ImplItemKind::Const(_, body) |
|
||||
ImplItemKind::Method(_, body) => Some(body),
|
||||
|
@ -159,9 +127,9 @@ impl<'hir> Entry<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::AnonConst(constant) => Some(constant.body),
|
||||
Node::AnonConst(constant) => Some(constant.body),
|
||||
|
||||
NodeKind::Expr(expr) => {
|
||||
Node::Expr(expr) => {
|
||||
match expr.node {
|
||||
ExprKind::Closure(.., body, _, _) => Some(body),
|
||||
_ => None,
|
||||
|
@ -200,8 +168,8 @@ impl Forest {
|
|||
}
|
||||
}
|
||||
|
||||
/// Represents a mapping from NodeKind IDs to AST elements and their parent
|
||||
/// NodeKind IDs
|
||||
/// Represents a mapping from Node IDs to AST elements and their parent
|
||||
/// Node IDs
|
||||
#[derive(Clone)]
|
||||
pub struct Map<'hir> {
|
||||
/// The backing storage for all the AST nodes.
|
||||
|
@ -324,7 +292,7 @@ impl<'hir> Map<'hir> {
|
|||
};
|
||||
|
||||
match node {
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
let def_id = || {
|
||||
self.local_def_id(item.id)
|
||||
};
|
||||
|
@ -351,7 +319,7 @@ impl<'hir> Map<'hir> {
|
|||
ItemKind::Impl(..) => None,
|
||||
}
|
||||
}
|
||||
NodeKind::ForeignItem(item) => {
|
||||
Node::ForeignItem(item) => {
|
||||
let def_id = self.local_def_id(item.id);
|
||||
match item.node {
|
||||
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
|
||||
|
@ -359,7 +327,7 @@ impl<'hir> Map<'hir> {
|
|||
ForeignItemKind::Type => Some(Def::ForeignTy(def_id)),
|
||||
}
|
||||
}
|
||||
NodeKind::TraitItem(item) => {
|
||||
Node::TraitItem(item) => {
|
||||
let def_id = self.local_def_id(item.id);
|
||||
match item.node {
|
||||
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
|
||||
|
@ -367,7 +335,7 @@ impl<'hir> Map<'hir> {
|
|||
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
|
||||
}
|
||||
}
|
||||
NodeKind::ImplItem(item) => {
|
||||
Node::ImplItem(item) => {
|
||||
let def_id = self.local_def_id(item.id);
|
||||
match item.node {
|
||||
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
|
||||
|
@ -376,31 +344,31 @@ impl<'hir> Map<'hir> {
|
|||
ImplItemKind::Existential(..) => Some(Def::AssociatedExistential(def_id)),
|
||||
}
|
||||
}
|
||||
NodeKind::Variant(variant) => {
|
||||
Node::Variant(variant) => {
|
||||
let def_id = self.local_def_id(variant.node.data.id());
|
||||
Some(Def::Variant(def_id))
|
||||
}
|
||||
NodeKind::Field(_) |
|
||||
NodeKind::AnonConst(_) |
|
||||
NodeKind::Expr(_) |
|
||||
NodeKind::Stmt(_) |
|
||||
NodeKind::Ty(_) |
|
||||
NodeKind::TraitRef(_) |
|
||||
NodeKind::Pat(_) |
|
||||
NodeKind::Binding(_) |
|
||||
NodeKind::StructCtor(_) |
|
||||
NodeKind::Lifetime(_) |
|
||||
NodeKind::Visibility(_) |
|
||||
NodeKind::Block(_) |
|
||||
NodeKind::Crate => None,
|
||||
NodeKind::Local(local) => {
|
||||
Node::Field(_) |
|
||||
Node::AnonConst(_) |
|
||||
Node::Expr(_) |
|
||||
Node::Stmt(_) |
|
||||
Node::Ty(_) |
|
||||
Node::TraitRef(_) |
|
||||
Node::Pat(_) |
|
||||
Node::Binding(_) |
|
||||
Node::StructCtor(_) |
|
||||
Node::Lifetime(_) |
|
||||
Node::Visibility(_) |
|
||||
Node::Block(_) |
|
||||
Node::Crate => None,
|
||||
Node::Local(local) => {
|
||||
Some(Def::Local(local.id))
|
||||
}
|
||||
NodeKind::MacroDef(macro_def) => {
|
||||
Node::MacroDef(macro_def) => {
|
||||
Some(Def::Macro(self.local_def_id(macro_def.id),
|
||||
MacroKind::Bang))
|
||||
}
|
||||
NodeKind::GenericParam(param) => {
|
||||
Node::GenericParam(param) => {
|
||||
Some(match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => Def::Local(param.id),
|
||||
GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)),
|
||||
|
@ -492,13 +460,13 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
|
||||
match self.get(id) {
|
||||
NodeKind::Item(&Item { node: ItemKind::Const(..), .. }) |
|
||||
NodeKind::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
|
||||
NodeKind::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) |
|
||||
NodeKind::AnonConst(_) => {
|
||||
Node::Item(&Item { node: ItemKind::Const(..), .. }) |
|
||||
Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
|
||||
Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) |
|
||||
Node::AnonConst(_) => {
|
||||
BodyOwnerKind::Const
|
||||
}
|
||||
NodeKind::Item(&Item { node: ItemKind::Static(_, m, _), .. }) => {
|
||||
Node::Item(&Item { node: ItemKind::Static(_, m, _), .. }) => {
|
||||
BodyOwnerKind::Static(m)
|
||||
}
|
||||
// Default to function if it's not a constant or static.
|
||||
|
@ -508,8 +476,8 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
|
||||
match self.get(id) {
|
||||
NodeKind::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
|
||||
NodeKind::GenericParam(_) => self.get_parent_node(id),
|
||||
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
|
||||
Node::GenericParam(_) => self.get_parent_node(id),
|
||||
_ => {
|
||||
bug!("ty_param_owner: {} not a type parameter",
|
||||
self.node_to_string(id))
|
||||
|
@ -519,10 +487,10 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn ty_param_name(&self, id: NodeId) -> Name {
|
||||
match self.get(id) {
|
||||
NodeKind::Item(&Item { node: ItemKind::Trait(..), .. }) => {
|
||||
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => {
|
||||
keywords::SelfType.name()
|
||||
}
|
||||
NodeKind::GenericParam(param) => param.name.ident().name,
|
||||
Node::GenericParam(param) => param.name.ident().name,
|
||||
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
|
||||
}
|
||||
}
|
||||
|
@ -557,25 +525,25 @@ impl<'hir> Map<'hir> {
|
|||
&self.forest.krate.attrs
|
||||
}
|
||||
|
||||
/// Retrieve the NodeKind corresponding to `id`, panicking if it cannot
|
||||
/// Retrieve the Node corresponding to `id`, panicking if it cannot
|
||||
/// be found.
|
||||
pub fn get(&self, id: NodeId) -> NodeKind<'hir> {
|
||||
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<NodeKind<'hir>> {
|
||||
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`
|
||||
}
|
||||
|
||||
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
|
||||
self.get_if_local(id).and_then(|node| {
|
||||
match node {
|
||||
NodeKind::ImplItem(ref impl_item) => Some(&impl_item.generics),
|
||||
NodeKind::TraitItem(ref trait_item) => Some(&trait_item.generics),
|
||||
NodeKind::Item(ref item) => {
|
||||
Node::ImplItem(ref impl_item) => Some(&impl_item.generics),
|
||||
Node::TraitItem(ref trait_item) => Some(&trait_item.generics),
|
||||
Node::Item(ref item) => {
|
||||
match item.node {
|
||||
ItemKind::Fn(_, _, ref generics, _) |
|
||||
ItemKind::Ty(_, ref generics) |
|
||||
|
@ -597,9 +565,9 @@ impl<'hir> Map<'hir> {
|
|||
self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP)
|
||||
}
|
||||
|
||||
/// Retrieve the NodeKind corresponding to `id`, returning None if
|
||||
/// Retrieve the Node corresponding to `id`, returning None if
|
||||
/// cannot be found.
|
||||
pub fn find(&self, id: NodeId) -> Option<NodeKind<'hir>> {
|
||||
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);
|
||||
|
@ -631,14 +599,14 @@ impl<'hir> Map<'hir> {
|
|||
/// immediate parent is an item or a closure.
|
||||
pub fn is_argument(&self, id: NodeId) -> bool {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::Binding(_)) => (),
|
||||
Some(Node::Binding(_)) => (),
|
||||
_ => return false,
|
||||
}
|
||||
match self.find(self.get_parent_node(id)) {
|
||||
Some(NodeKind::Item(_)) |
|
||||
Some(NodeKind::TraitItem(_)) |
|
||||
Some(NodeKind::ImplItem(_)) => true,
|
||||
Some(NodeKind::Expr(e)) => {
|
||||
Some(Node::Item(_)) |
|
||||
Some(Node::TraitItem(_)) |
|
||||
Some(Node::ImplItem(_)) => true,
|
||||
Some(Node::Expr(e)) => {
|
||||
match e.node {
|
||||
ExprKind::Closure(..) => true,
|
||||
_ => false,
|
||||
|
@ -658,7 +626,7 @@ impl<'hir> Map<'hir> {
|
|||
found: F,
|
||||
bail_early: F2)
|
||||
-> Result<NodeId, NodeId>
|
||||
where F: Fn(&NodeKind<'hir>) -> bool, F2: Fn(&NodeKind<'hir>) -> bool
|
||||
where F: Fn(&Node<'hir>) -> bool, F2: Fn(&Node<'hir>) -> bool
|
||||
{
|
||||
let mut id = start_id;
|
||||
loop {
|
||||
|
@ -711,18 +679,18 @@ impl<'hir> Map<'hir> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
|
||||
let match_fn = |node: &NodeKind| {
|
||||
let match_fn = |node: &Node| {
|
||||
match *node {
|
||||
NodeKind::Item(_) |
|
||||
NodeKind::ForeignItem(_) |
|
||||
NodeKind::TraitItem(_) |
|
||||
NodeKind::ImplItem(_) => true,
|
||||
Node::Item(_) |
|
||||
Node::ForeignItem(_) |
|
||||
Node::TraitItem(_) |
|
||||
Node::ImplItem(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
let match_non_returning_block = |node: &NodeKind| {
|
||||
let match_non_returning_block = |node: &Node| {
|
||||
match *node {
|
||||
NodeKind::Expr(ref expr) => {
|
||||
Node::Expr(ref expr) => {
|
||||
match expr.node {
|
||||
ExprKind::While(..) | ExprKind::Loop(..) => true,
|
||||
_ => false,
|
||||
|
@ -744,10 +712,10 @@ impl<'hir> Map<'hir> {
|
|||
/// in a module, trait, or impl.
|
||||
pub fn get_parent(&self, id: NodeId) -> NodeId {
|
||||
match self.walk_parent_nodes(id, |node| match *node {
|
||||
NodeKind::Item(_) |
|
||||
NodeKind::ForeignItem(_) |
|
||||
NodeKind::TraitItem(_) |
|
||||
NodeKind::ImplItem(_) => true,
|
||||
Node::Item(_) |
|
||||
Node::ForeignItem(_) |
|
||||
Node::TraitItem(_) |
|
||||
Node::ImplItem(_) => true,
|
||||
_ => false,
|
||||
}, |_| false) {
|
||||
Ok(id) => id,
|
||||
|
@ -759,7 +727,7 @@ impl<'hir> Map<'hir> {
|
|||
/// module parent is in this map.
|
||||
pub fn get_module_parent(&self, id: NodeId) -> DefId {
|
||||
let id = match self.walk_parent_nodes(id, |node| match *node {
|
||||
NodeKind::Item(&Item { node: ItemKind::Mod(_), .. }) => true,
|
||||
Node::Item(&Item { node: ItemKind::Mod(_), .. }) => true,
|
||||
_ => false,
|
||||
}, |_| false) {
|
||||
Ok(id) => id,
|
||||
|
@ -774,11 +742,11 @@ impl<'hir> Map<'hir> {
|
|||
/// regard should be expected to be highly unstable.
|
||||
pub fn get_enclosing_scope(&self, id: NodeId) -> Option<NodeId> {
|
||||
match self.walk_parent_nodes(id, |node| match *node {
|
||||
NodeKind::Item(_) |
|
||||
NodeKind::ForeignItem(_) |
|
||||
NodeKind::TraitItem(_) |
|
||||
NodeKind::ImplItem(_) |
|
||||
NodeKind::Block(_) => true,
|
||||
Node::Item(_) |
|
||||
Node::ForeignItem(_) |
|
||||
Node::TraitItem(_) |
|
||||
Node::ImplItem(_) |
|
||||
Node::Block(_) => true,
|
||||
_ => false,
|
||||
}, |_| false) {
|
||||
Ok(id) => Some(id),
|
||||
|
@ -794,7 +762,7 @@ impl<'hir> Map<'hir> {
|
|||
let parent = self.get_parent(id);
|
||||
if let Some(entry) = self.find_entry(parent) {
|
||||
match entry {
|
||||
Entry { node: NodeKind::Item(Item { node: ItemKind::ForeignMod(ref nm), .. }), .. }
|
||||
Entry { node: Node::Item(Item { node: ItemKind::ForeignMod(ref nm), .. }), .. }
|
||||
=> {
|
||||
self.read(id); // reveals some of the content of a node
|
||||
return nm.abi;
|
||||
|
@ -807,28 +775,28 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn expect_item(&self, id: NodeId) -> &'hir Item {
|
||||
match self.find(id) { // read recorded by `find`
|
||||
Some(NodeKind::Item(item)) => item,
|
||||
Some(Node::Item(item)) => item,
|
||||
_ => bug!("expected item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::ImplItem(item)) => item,
|
||||
Some(Node::ImplItem(item)) => item,
|
||||
_ => bug!("expected impl item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::TraitItem(item)) => item,
|
||||
Some(Node::TraitItem(item)) => item,
|
||||
_ => bug!("expected trait item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::Item(i)) => {
|
||||
Some(Node::Item(i)) => {
|
||||
match i.node {
|
||||
ItemKind::Struct(ref struct_def, _) |
|
||||
ItemKind::Union(ref struct_def, _) => struct_def,
|
||||
|
@ -838,8 +806,8 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(NodeKind::StructCtor(data)) => data,
|
||||
Some(NodeKind::Variant(variant)) => &variant.node.data,
|
||||
Some(Node::StructCtor(data)) => data,
|
||||
Some(Node::Variant(variant)) => &variant.node.data,
|
||||
_ => {
|
||||
bug!("expected struct or variant, found {}",
|
||||
self.node_to_string(id));
|
||||
|
@ -849,21 +817,21 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::Variant(variant)) => variant,
|
||||
Some(Node::Variant(variant)) => variant,
|
||||
_ => bug!("expected variant, found {}", self.node_to_string(id)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem {
|
||||
match self.find(id) {
|
||||
Some(NodeKind::ForeignItem(item)) => item,
|
||||
Some(Node::ForeignItem(item)) => item,
|
||||
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_expr(&self, id: NodeId) -> &'hir Expr {
|
||||
match self.find(id) { // read recorded by find
|
||||
Some(NodeKind::Expr(expr)) => expr,
|
||||
Some(Node::Expr(expr)) => expr,
|
||||
_ => bug!("expected expr, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
@ -871,37 +839,37 @@ impl<'hir> Map<'hir> {
|
|||
/// Returns the name associated with the given NodeId's AST.
|
||||
pub fn name(&self, id: NodeId) -> Name {
|
||||
match self.get(id) {
|
||||
NodeKind::Item(i) => i.name,
|
||||
NodeKind::ForeignItem(i) => i.name,
|
||||
NodeKind::ImplItem(ii) => ii.ident.name,
|
||||
NodeKind::TraitItem(ti) => ti.ident.name,
|
||||
NodeKind::Variant(v) => v.node.name,
|
||||
NodeKind::Field(f) => f.ident.name,
|
||||
NodeKind::Lifetime(lt) => lt.name.ident().name,
|
||||
NodeKind::GenericParam(param) => param.name.ident().name,
|
||||
NodeKind::Binding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.name,
|
||||
NodeKind::StructCtor(_) => self.name(self.get_parent(id)),
|
||||
Node::Item(i) => i.name,
|
||||
Node::ForeignItem(i) => i.name,
|
||||
Node::ImplItem(ii) => ii.ident.name,
|
||||
Node::TraitItem(ti) => ti.ident.name,
|
||||
Node::Variant(v) => v.node.name,
|
||||
Node::Field(f) => f.ident.name,
|
||||
Node::Lifetime(lt) => lt.name.ident().name,
|
||||
Node::GenericParam(param) => param.name.ident().name,
|
||||
Node::Binding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.name,
|
||||
Node::StructCtor(_) => self.name(self.get_parent(id)),
|
||||
_ => bug!("no name for {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a node ID, get a list of attributes associated with the AST
|
||||
/// corresponding to the NodeKind ID
|
||||
/// corresponding to the Node ID
|
||||
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
|
||||
self.read(id); // reveals attributes on the node
|
||||
let attrs = match self.find(id) {
|
||||
Some(NodeKind::Item(i)) => Some(&i.attrs[..]),
|
||||
Some(NodeKind::ForeignItem(fi)) => Some(&fi.attrs[..]),
|
||||
Some(NodeKind::TraitItem(ref ti)) => Some(&ti.attrs[..]),
|
||||
Some(NodeKind::ImplItem(ref ii)) => Some(&ii.attrs[..]),
|
||||
Some(NodeKind::Variant(ref v)) => Some(&v.node.attrs[..]),
|
||||
Some(NodeKind::Field(ref f)) => Some(&f.attrs[..]),
|
||||
Some(NodeKind::Expr(ref e)) => Some(&*e.attrs),
|
||||
Some(NodeKind::Stmt(ref s)) => Some(s.node.attrs()),
|
||||
Some(NodeKind::GenericParam(param)) => Some(¶m.attrs[..]),
|
||||
Some(Node::Item(i)) => Some(&i.attrs[..]),
|
||||
Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]),
|
||||
Some(Node::TraitItem(ref ti)) => Some(&ti.attrs[..]),
|
||||
Some(Node::ImplItem(ref ii)) => Some(&ii.attrs[..]),
|
||||
Some(Node::Variant(ref v)) => Some(&v.node.attrs[..]),
|
||||
Some(Node::Field(ref f)) => Some(&f.attrs[..]),
|
||||
Some(Node::Expr(ref e)) => Some(&*e.attrs),
|
||||
Some(Node::Stmt(ref s)) => Some(s.node.attrs()),
|
||||
Some(Node::GenericParam(param)) => Some(¶m.attrs[..]),
|
||||
// unit/tuple structs take the attributes straight from
|
||||
// the struct definition.
|
||||
Some(NodeKind::StructCtor(_)) => {
|
||||
Some(Node::StructCtor(_)) => {
|
||||
return self.attrs(self.get_parent(id));
|
||||
}
|
||||
_ => None
|
||||
|
@ -929,31 +897,31 @@ impl<'hir> Map<'hir> {
|
|||
pub fn span(&self, id: NodeId) -> Span {
|
||||
self.read(id); // reveals span from node
|
||||
match self.find_entry(id).map(|entry| entry.node) {
|
||||
Some(NodeKind::Item(item)) => item.span,
|
||||
Some(NodeKind::ForeignItem(foreign_item)) => foreign_item.span,
|
||||
Some(NodeKind::TraitItem(trait_method)) => trait_method.span,
|
||||
Some(NodeKind::ImplItem(impl_item)) => impl_item.span,
|
||||
Some(NodeKind::Variant(variant)) => variant.span,
|
||||
Some(NodeKind::Field(field)) => field.span,
|
||||
Some(NodeKind::AnonConst(constant)) => self.body(constant.body).value.span,
|
||||
Some(NodeKind::Expr(expr)) => expr.span,
|
||||
Some(NodeKind::Stmt(stmt)) => stmt.span,
|
||||
Some(NodeKind::Ty(ty)) => ty.span,
|
||||
Some(NodeKind::TraitRef(tr)) => tr.path.span,
|
||||
Some(NodeKind::Binding(pat)) => pat.span,
|
||||
Some(NodeKind::Pat(pat)) => pat.span,
|
||||
Some(NodeKind::Block(block)) => block.span,
|
||||
Some(NodeKind::StructCtor(_)) => self.expect_item(self.get_parent(id)).span,
|
||||
Some(NodeKind::Lifetime(lifetime)) => lifetime.span,
|
||||
Some(NodeKind::GenericParam(param)) => param.span,
|
||||
Some(NodeKind::Visibility(&Spanned {
|
||||
Some(Node::Item(item)) => item.span,
|
||||
Some(Node::ForeignItem(foreign_item)) => foreign_item.span,
|
||||
Some(Node::TraitItem(trait_method)) => trait_method.span,
|
||||
Some(Node::ImplItem(impl_item)) => impl_item.span,
|
||||
Some(Node::Variant(variant)) => variant.span,
|
||||
Some(Node::Field(field)) => field.span,
|
||||
Some(Node::AnonConst(constant)) => self.body(constant.body).value.span,
|
||||
Some(Node::Expr(expr)) => expr.span,
|
||||
Some(Node::Stmt(stmt)) => stmt.span,
|
||||
Some(Node::Ty(ty)) => ty.span,
|
||||
Some(Node::TraitRef(tr)) => tr.path.span,
|
||||
Some(Node::Binding(pat)) => pat.span,
|
||||
Some(Node::Pat(pat)) => pat.span,
|
||||
Some(Node::Block(block)) => block.span,
|
||||
Some(Node::StructCtor(_)) => self.expect_item(self.get_parent(id)).span,
|
||||
Some(Node::Lifetime(lifetime)) => lifetime.span,
|
||||
Some(Node::GenericParam(param)) => param.span,
|
||||
Some(Node::Visibility(&Spanned {
|
||||
node: VisibilityKind::Restricted { ref path, .. }, ..
|
||||
})) => path.span,
|
||||
Some(NodeKind::Visibility(v)) => bug!("unexpected Visibility {:?}", v),
|
||||
Some(NodeKind::Local(local)) => local.span,
|
||||
Some(NodeKind::MacroDef(macro_def)) => macro_def.span,
|
||||
Some(Node::Visibility(v)) => bug!("unexpected Visibility {:?}", v),
|
||||
Some(Node::Local(local)) => local.span,
|
||||
Some(Node::MacroDef(macro_def)) => macro_def.span,
|
||||
|
||||
Some(NodeKind::Crate) => self.forest.krate.span,
|
||||
Some(Node::Crate) => self.forest.krate.span,
|
||||
None => bug!("hir::map::Map::span: id not in map: {:?}", id),
|
||||
}
|
||||
}
|
||||
|
@ -1012,7 +980,7 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> {
|
|||
fn find_first_mod_parent<'a>(map: &'a Map, mut id: NodeId) -> Option<(NodeId, Name)> {
|
||||
loop {
|
||||
match map.find(id)? {
|
||||
NodeKind::Item(item) if item_is_mod(&item) =>
|
||||
Node::Item(item) if item_is_mod(&item) =>
|
||||
return Some((id, item.name)),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -1048,12 +1016,12 @@ impl<'a, 'hir> Iterator for NodesMatchingSuffix<'a, 'hir> {
|
|||
}
|
||||
self.idx = NodeId::from_u32(self.idx.as_u32() + 1);
|
||||
let name = match self.map.find_entry(idx).map(|entry| entry.node) {
|
||||
Some(NodeKind::Item(n)) => n.name(),
|
||||
Some(NodeKind::ForeignItem(n)) => n.name(),
|
||||
Some(NodeKind::TraitItem(n)) => n.name(),
|
||||
Some(NodeKind::ImplItem(n)) => n.name(),
|
||||
Some(NodeKind::Variant(n)) => n.name(),
|
||||
Some(NodeKind::Field(n)) => n.name(),
|
||||
Some(Node::Item(n)) => n.name(),
|
||||
Some(Node::ForeignItem(n)) => n.name(),
|
||||
Some(Node::TraitItem(n)) => n.name(),
|
||||
Some(Node::ImplItem(n)) => n.name(),
|
||||
Some(Node::Variant(n)) => n.name(),
|
||||
Some(Node::Field(n)) => n.name(),
|
||||
_ => continue,
|
||||
};
|
||||
if self.matches_names(self.map.get_parent(idx), name) {
|
||||
|
@ -1144,21 +1112,21 @@ impl<'hir> print::PpAnn for Map<'hir> {
|
|||
}
|
||||
|
||||
impl<'a> print::State<'a> {
|
||||
pub fn print_node(&mut self, node: NodeKind) -> io::Result<()> {
|
||||
pub fn print_node(&mut self, node: Node) -> io::Result<()> {
|
||||
match node {
|
||||
NodeKind::Item(a) => self.print_item(&a),
|
||||
NodeKind::ForeignItem(a) => self.print_foreign_item(&a),
|
||||
NodeKind::TraitItem(a) => self.print_trait_item(a),
|
||||
NodeKind::ImplItem(a) => self.print_impl_item(a),
|
||||
NodeKind::Variant(a) => self.print_variant(&a),
|
||||
NodeKind::AnonConst(a) => self.print_anon_const(&a),
|
||||
NodeKind::Expr(a) => self.print_expr(&a),
|
||||
NodeKind::Stmt(a) => self.print_stmt(&a),
|
||||
NodeKind::Ty(a) => self.print_type(&a),
|
||||
NodeKind::TraitRef(a) => self.print_trait_ref(&a),
|
||||
NodeKind::Binding(a) |
|
||||
NodeKind::Pat(a) => self.print_pat(&a),
|
||||
NodeKind::Block(a) => {
|
||||
Node::Item(a) => self.print_item(&a),
|
||||
Node::ForeignItem(a) => self.print_foreign_item(&a),
|
||||
Node::TraitItem(a) => self.print_trait_item(a),
|
||||
Node::ImplItem(a) => self.print_impl_item(a),
|
||||
Node::Variant(a) => self.print_variant(&a),
|
||||
Node::AnonConst(a) => self.print_anon_const(&a),
|
||||
Node::Expr(a) => self.print_expr(&a),
|
||||
Node::Stmt(a) => self.print_stmt(&a),
|
||||
Node::Ty(a) => self.print_type(&a),
|
||||
Node::TraitRef(a) => self.print_trait_ref(&a),
|
||||
Node::Binding(a) |
|
||||
Node::Pat(a) => self.print_pat(&a),
|
||||
Node::Block(a) => {
|
||||
use syntax::print::pprust::PrintState;
|
||||
|
||||
// containing cbox, will be closed by print-block at }
|
||||
|
@ -1167,17 +1135,17 @@ impl<'a> print::State<'a> {
|
|||
self.ibox(0)?;
|
||||
self.print_block(&a)
|
||||
}
|
||||
NodeKind::Lifetime(a) => self.print_lifetime(&a),
|
||||
NodeKind::Visibility(a) => self.print_visibility(&a),
|
||||
NodeKind::GenericParam(_) => bug!("cannot print NodeKind::GenericParam"),
|
||||
NodeKind::Field(_) => bug!("cannot print StructField"),
|
||||
Node::Lifetime(a) => self.print_lifetime(&a),
|
||||
Node::Visibility(a) => self.print_visibility(&a),
|
||||
Node::GenericParam(_) => bug!("cannot print Node::GenericParam"),
|
||||
Node::Field(_) => bug!("cannot print StructField"),
|
||||
// these cases do not carry enough information in the
|
||||
// hir_map to reconstruct their full structure for pretty
|
||||
// printing.
|
||||
NodeKind::StructCtor(_) => bug!("cannot print isolated StructCtor"),
|
||||
NodeKind::Local(a) => self.print_local_decl(&a),
|
||||
NodeKind::MacroDef(_) => bug!("cannot print MacroDef"),
|
||||
NodeKind::Crate => bug!("cannot print Crate"),
|
||||
Node::StructCtor(_) => bug!("cannot print isolated StructCtor"),
|
||||
Node::Local(a) => self.print_local_decl(&a),
|
||||
Node::MacroDef(_) => bug!("cannot print MacroDef"),
|
||||
Node::Crate => bug!("cannot print Crate"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1203,7 +1171,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
};
|
||||
|
||||
match map.find(id) {
|
||||
Some(NodeKind::Item(item)) => {
|
||||
Some(Node::Item(item)) => {
|
||||
let item_str = match item.node {
|
||||
ItemKind::ExternCrate(..) => "extern crate",
|
||||
ItemKind::Use(..) => "use",
|
||||
|
@ -1224,10 +1192,10 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
};
|
||||
format!("{} {}{}", item_str, path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::ForeignItem(_)) => {
|
||||
Some(Node::ForeignItem(_)) => {
|
||||
format!("foreign item {}{}", path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::ImplItem(ii)) => {
|
||||
Some(Node::ImplItem(ii)) => {
|
||||
match ii.node {
|
||||
ImplItemKind::Const(..) => {
|
||||
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
|
||||
|
@ -1243,7 +1211,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(NodeKind::TraitItem(ti)) => {
|
||||
Some(Node::TraitItem(ti)) => {
|
||||
let kind = match ti.node {
|
||||
TraitItemKind::Const(..) => "assoc constant",
|
||||
TraitItemKind::Method(..) => "trait method",
|
||||
|
@ -1252,59 +1220,59 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
|
||||
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::Variant(ref variant)) => {
|
||||
Some(Node::Variant(ref variant)) => {
|
||||
format!("variant {} in {}{}",
|
||||
variant.node.name,
|
||||
path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::Field(ref field)) => {
|
||||
Some(Node::Field(ref field)) => {
|
||||
format!("field {} in {}{}",
|
||||
field.ident,
|
||||
path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::AnonConst(_)) => {
|
||||
Some(Node::AnonConst(_)) => {
|
||||
format!("const {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Expr(_)) => {
|
||||
Some(Node::Expr(_)) => {
|
||||
format!("expr {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Stmt(_)) => {
|
||||
Some(Node::Stmt(_)) => {
|
||||
format!("stmt {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Ty(_)) => {
|
||||
Some(Node::Ty(_)) => {
|
||||
format!("type {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::TraitRef(_)) => {
|
||||
Some(Node::TraitRef(_)) => {
|
||||
format!("trait_ref {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Binding(_)) => {
|
||||
Some(Node::Binding(_)) => {
|
||||
format!("local {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Pat(_)) => {
|
||||
Some(Node::Pat(_)) => {
|
||||
format!("pat {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Block(_)) => {
|
||||
Some(Node::Block(_)) => {
|
||||
format!("block {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::Local(_)) => {
|
||||
Some(Node::Local(_)) => {
|
||||
format!("local {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::StructCtor(_)) => {
|
||||
Some(Node::StructCtor(_)) => {
|
||||
format!("struct_ctor {}{}", path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::Lifetime(_)) => {
|
||||
Some(Node::Lifetime(_)) => {
|
||||
format!("lifetime {}{}", map.node_to_pretty_string(id), id_str)
|
||||
}
|
||||
Some(NodeKind::GenericParam(ref param)) => {
|
||||
Some(Node::GenericParam(ref param)) => {
|
||||
format!("generic_param {:?}{}", param, id_str)
|
||||
}
|
||||
Some(NodeKind::Visibility(ref vis)) => {
|
||||
Some(Node::Visibility(ref vis)) => {
|
||||
format!("visibility {:?}{}", vis, id_str)
|
||||
}
|
||||
Some(NodeKind::MacroDef(_)) => {
|
||||
Some(Node::MacroDef(_)) => {
|
||||
format!("macro {}{}", path_str(), id_str)
|
||||
}
|
||||
Some(NodeKind::Crate) => format!("root_crate"),
|
||||
Some(Node::Crate) => format!("root_crate"),
|
||||
None => format!("unknown node{}", id_str),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2370,3 +2370,34 @@ impl CodegenFnAttrs {
|
|||
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) || self.export_name.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Node<'hir> {
|
||||
Item(&'hir Item),
|
||||
ForeignItem(&'hir ForeignItem),
|
||||
TraitItem(&'hir TraitItem),
|
||||
ImplItem(&'hir ImplItem),
|
||||
Variant(&'hir Variant),
|
||||
Field(&'hir StructField),
|
||||
AnonConst(&'hir AnonConst),
|
||||
Expr(&'hir Expr),
|
||||
Stmt(&'hir Stmt),
|
||||
Ty(&'hir Ty),
|
||||
TraitRef(&'hir TraitRef),
|
||||
Binding(&'hir Pat),
|
||||
Pat(&'hir Pat),
|
||||
Block(&'hir Block),
|
||||
Local(&'hir Local),
|
||||
MacroDef(&'hir MacroDef),
|
||||
|
||||
/// StructCtor represents a tuple struct.
|
||||
StructCtor(&'hir VariantData),
|
||||
|
||||
Lifetime(&'hir Lifetime),
|
||||
GenericParam(&'hir GenericParam),
|
||||
Visibility(&'hir Visibility),
|
||||
|
||||
/// Roots for node trees. Its DepNodeIndex when in `Entry`
|
||||
/// is the dependency node of the crate's root module.
|
||||
Crate,
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use hir::def_id::DefId;
|
||||
use hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
|
||||
use infer::outlives::free_region_map::FreeRegionRelations;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
@ -698,7 +698,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
parent_def_id == tcx.hir.local_def_id(anon_parent_node_id)
|
||||
};
|
||||
let in_definition_scope = match tcx.hir.find(anon_node_id) {
|
||||
Some(NodeKind::Item(item)) => match item.node {
|
||||
Some(Node::Item(item)) => match item.node {
|
||||
// impl trait
|
||||
hir::ItemKind::Existential(hir::ExistTy {
|
||||
impl_trait_fn: Some(parent),
|
||||
|
@ -715,7 +715,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
),
|
||||
_ => def_scope_default(),
|
||||
},
|
||||
Some(NodeKind::ImplItem(item)) => match item.node {
|
||||
Some(Node::ImplItem(item)) => match item.node {
|
||||
hir::ImplItemKind::Existential(_) => may_define_existential_type(
|
||||
tcx,
|
||||
self.parent_def_id,
|
||||
|
|
|
@ -62,7 +62,7 @@ use super::lexical_region_resolve::RegionResolutionError;
|
|||
|
||||
use std::{cmp, fmt};
|
||||
use hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::def_id::DefId;
|
||||
use middle::region;
|
||||
use traits::{ObligationCause, ObligationCauseCode};
|
||||
|
@ -100,8 +100,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
let span = scope.span(self, region_scope_tree);
|
||||
let tag = match self.hir.find(scope.node_id(self, region_scope_tree)) {
|
||||
Some(NodeKind::Block(_)) => "block",
|
||||
Some(NodeKind::Expr(expr)) => match expr.node {
|
||||
Some(Node::Block(_)) => "block",
|
||||
Some(Node::Expr(expr)) => match expr.node {
|
||||
hir::ExprKind::Call(..) => "call",
|
||||
hir::ExprKind::MethodCall(..) => "method call",
|
||||
hir::ExprKind::Match(.., hir::MatchSource::IfLetDesugar { .. }) => "if let",
|
||||
|
@ -110,10 +110,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
hir::ExprKind::Match(..) => "match",
|
||||
_ => "expression",
|
||||
},
|
||||
Some(NodeKind::Stmt(_)) => "statement",
|
||||
Some(NodeKind::Item(it)) => Self::item_scope_tag(&it),
|
||||
Some(NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
|
||||
Some(NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
|
||||
Some(Node::Stmt(_)) => "statement",
|
||||
Some(Node::Item(it)) => Self::item_scope_tag(&it),
|
||||
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
|
||||
Some(Node::ImplItem(it)) => Self::impl_item_scope_tag(&it),
|
||||
Some(_) | None => {
|
||||
err.span_note(span, &unknown_scope());
|
||||
return;
|
||||
|
@ -194,10 +194,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
let scope = region.free_region_binding_scope(self);
|
||||
let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
|
||||
let tag = match self.hir.find(node) {
|
||||
Some(NodeKind::Block(_)) | Some(NodeKind::Expr(_)) => "body",
|
||||
Some(NodeKind::Item(it)) => Self::item_scope_tag(&it),
|
||||
Some(NodeKind::TraitItem(it)) => Self::trait_item_scope_tag(&it),
|
||||
Some(NodeKind::ImplItem(it)) => Self::impl_item_scope_tag(&it),
|
||||
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
|
||||
Some(Node::Item(it)) => Self::item_scope_tag(&it),
|
||||
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
|
||||
Some(Node::ImplItem(it)) => Self::impl_item_scope_tag(&it),
|
||||
_ => unreachable!()
|
||||
};
|
||||
let (prefix, span) = match *region {
|
||||
|
@ -1127,7 +1127,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
|
||||
// instead we suggest `T: 'a + 'b` in that case.
|
||||
let mut has_bounds = false;
|
||||
if let NodeKind::GenericParam(ref param) = hir.get(id) {
|
||||
if let Node::GenericParam(ref param) = hir.get(id) {
|
||||
has_bounds = !param.bounds.is_empty();
|
||||
}
|
||||
let sp = hir.span(id);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use hir;
|
||||
use ty::{self, Region, TyCtxt};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use middle::resolve_lifetime as rl;
|
||||
use hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
|
@ -40,15 +40,15 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
|||
let def_id = anon_reg.def_id;
|
||||
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
|
||||
let fndecl = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Fn(ref fndecl, ..),
|
||||
..
|
||||
}) => &fndecl,
|
||||
NodeKind::TraitItem(&hir::TraitItem {
|
||||
Node::TraitItem(&hir::TraitItem {
|
||||
node: hir::TraitItemKind::Method(ref m, ..),
|
||||
..
|
||||
})
|
||||
| NodeKind::ImplItem(&hir::ImplItem {
|
||||
| Node::ImplItem(&hir::ImplItem {
|
||||
node: hir::ImplItemKind::Method(ref m, ..),
|
||||
..
|
||||
}) => &m.decl,
|
||||
|
|
|
@ -15,7 +15,7 @@ use infer::error_reporting::nice_region_error::NiceRegionError;
|
|||
use infer::SubregionOrigin;
|
||||
use ty::RegionKind;
|
||||
use hir::{Expr, ExprKind::Closure};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use util::common::ErrorReported;
|
||||
use infer::lexical_region_resolve::RegionResolutionError::SubSupConflict;
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
|||
let hir = &self.tcx.hir;
|
||||
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
|
||||
match hir.get(node_id) {
|
||||
NodeKind::Expr(Expr {
|
||||
Node::Expr(Expr {
|
||||
node: Closure(_, _, _, closure_span, None),
|
||||
..
|
||||
}) => {
|
||||
|
|
|
@ -15,7 +15,7 @@ use hir;
|
|||
use infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
use ty::{self, Region, Ty};
|
||||
use hir::def_id::DefId;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use syntax_pos::Span;
|
||||
|
||||
// The struct contains the information about the anonymous region
|
||||
|
@ -138,8 +138,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
|||
.as_local_node_id(suitable_region_binding_scope)
|
||||
.unwrap();
|
||||
let is_impl_item = match self.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(..)) | Some(NodeKind::TraitItem(..)) => false,
|
||||
Some(NodeKind::ImplItem(..)) => {
|
||||
Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
|
||||
Some(Node::ImplItem(..)) => {
|
||||
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
|
||||
}
|
||||
_ => return None,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// closely. The idea is that all reachable symbols are live, codes called
|
||||
// from live codes are live, and everything else is dead.
|
||||
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::{self, PatKind};
|
||||
use hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
@ -29,16 +29,16 @@ use syntax::attr;
|
|||
use syntax_pos;
|
||||
|
||||
// Any local node that may call something in its body block should be
|
||||
// explored. For example, if it's a live NodeKind::Item that is a
|
||||
// explored. For example, if it's a live Node::Item that is a
|
||||
// function, then we should explore its block to check for codes that
|
||||
// may need to be marked as live.
|
||||
fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
node_id: ast::NodeId) -> bool {
|
||||
match tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(..)) |
|
||||
Some(NodeKind::ImplItem(..)) |
|
||||
Some(NodeKind::ForeignItem(..)) |
|
||||
Some(NodeKind::TraitItem(..)) =>
|
||||
Some(Node::Item(..)) |
|
||||
Some(Node::ImplItem(..)) |
|
||||
Some(Node::ForeignItem(..)) |
|
||||
Some(Node::TraitItem(..)) =>
|
||||
true,
|
||||
_ =>
|
||||
false
|
||||
|
@ -145,13 +145,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_node(&mut self, node: &NodeKind<'tcx>) {
|
||||
fn visit_node(&mut self, node: &Node<'tcx>) {
|
||||
let had_repr_c = self.repr_has_repr_c;
|
||||
self.repr_has_repr_c = false;
|
||||
let had_inherited_pub_visibility = self.inherited_pub_visibility;
|
||||
self.inherited_pub_visibility = false;
|
||||
match *node {
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
|
||||
let def_id = self.tcx.hir.local_def_id(item.id);
|
||||
|
@ -173,13 +173,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
NodeKind::TraitItem(trait_item) => {
|
||||
Node::TraitItem(trait_item) => {
|
||||
intravisit::walk_trait_item(self, trait_item);
|
||||
}
|
||||
NodeKind::ImplItem(impl_item) => {
|
||||
Node::ImplItem(impl_item) => {
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
NodeKind::ForeignItem(foreign_item) => {
|
||||
Node::ForeignItem(foreign_item) => {
|
||||
intravisit::walk_foreign_item(self, &foreign_item);
|
||||
}
|
||||
_ => ()
|
||||
|
|
|
@ -108,7 +108,7 @@ use self::LiveNodeKind::*;
|
|||
use self::VarKind::*;
|
||||
|
||||
use hir::def::*;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use ty::{self, TyCtxt};
|
||||
use lint;
|
||||
use errors::Applicability;
|
||||
|
@ -364,7 +364,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
|
|||
// Don't run unused pass for #[derive()]
|
||||
if let FnKind::Method(..) = fk {
|
||||
let parent = ir.tcx.hir.get_parent(id);
|
||||
if let Some(NodeKind::Item(i)) = ir.tcx.hir.find(parent) {
|
||||
if let Some(Node::Item(i)) = ir.tcx.hir.find(parent) {
|
||||
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ use self::Aliasability::*;
|
|||
|
||||
use middle::region;
|
||||
use hir::def_id::{DefId, LocalDefId};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use infer::InferCtxt;
|
||||
use hir::def::{Def, CtorKind};
|
||||
use ty::adjustment;
|
||||
|
@ -343,7 +343,7 @@ impl MutabilityCategory {
|
|||
|
||||
fn from_local(tcx: TyCtxt, tables: &ty::TypeckTables, id: ast::NodeId) -> MutabilityCategory {
|
||||
let ret = match tcx.hir.get(id) {
|
||||
NodeKind::Binding(p) => match p.node {
|
||||
Node::Binding(p) => match p.node {
|
||||
PatKind::Binding(..) => {
|
||||
let bm = *tables.pat_binding_modes()
|
||||
.get(p.hir_id)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// reachable as well.
|
||||
|
||||
use hir::{CodegenFnAttrs, CodegenFnAttrFlags};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::def::Def;
|
||||
use hir::def_id::{DefId, CrateNum};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -64,7 +64,7 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) {
|
||||
match tcx.hir.find(impl_node_id) {
|
||||
Some(NodeKind::Item(item)) =>
|
||||
Some(Node::Item(item)) =>
|
||||
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
|
||||
Some(..) | None =>
|
||||
span_bug!(impl_item.span, "impl did is not an item")
|
||||
|
@ -156,14 +156,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
};
|
||||
|
||||
match self.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(item)) => {
|
||||
Some(Node::Item(item)) => {
|
||||
match item.node {
|
||||
hir::ItemKind::Fn(..) =>
|
||||
item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
Some(NodeKind::TraitItem(trait_method)) => {
|
||||
Some(Node::TraitItem(trait_method)) => {
|
||||
match trait_method.node {
|
||||
hir::TraitItemKind::Const(_, ref default) => default.is_some(),
|
||||
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
|
||||
|
@ -171,7 +171,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
hir::TraitItemKind::Type(..) => false,
|
||||
}
|
||||
}
|
||||
Some(NodeKind::ImplItem(impl_item)) => {
|
||||
Some(Node::ImplItem(impl_item)) => {
|
||||
match impl_item.node {
|
||||
hir::ImplItemKind::Const(..) => true,
|
||||
hir::ImplItemKind::Method(..) => {
|
||||
|
@ -219,12 +219,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn propagate_node(&mut self, node: &NodeKind<'tcx>,
|
||||
fn propagate_node(&mut self, node: &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 NodeKind::Item(item) = *node {
|
||||
if let Node::Item(item) = *node {
|
||||
let reachable = if let hir::ItemKind::Fn(_, header, ..) = item.node {
|
||||
header.abi != Abi::Rust
|
||||
} else {
|
||||
|
@ -248,7 +248,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
match *node {
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
hir::ItemKind::Fn(.., body) => {
|
||||
let def_id = self.tcx.hir.local_def_id(item.id);
|
||||
|
@ -285,7 +285,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
hir::ItemKind::GlobalAsm(..) => {}
|
||||
}
|
||||
}
|
||||
NodeKind::TraitItem(trait_method) => {
|
||||
Node::TraitItem(trait_method) => {
|
||||
match trait_method.node {
|
||||
hir::TraitItemKind::Const(_, None) |
|
||||
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
|
||||
|
@ -298,7 +298,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
hir::TraitItemKind::Type(..) => {}
|
||||
}
|
||||
}
|
||||
NodeKind::ImplItem(impl_item) => {
|
||||
Node::ImplItem(impl_item) => {
|
||||
match impl_item.node {
|
||||
hir::ImplItemKind::Const(_, body) => {
|
||||
self.visit_nested_body(body);
|
||||
|
@ -313,16 +313,16 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
hir::ImplItemKind::Type(_) => {}
|
||||
}
|
||||
}
|
||||
NodeKind::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., body, _, _), .. }) => {
|
||||
Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., body, _, _), .. }) => {
|
||||
self.visit_nested_body(body);
|
||||
}
|
||||
// Nothing to recurse on for these
|
||||
NodeKind::ForeignItem(_) |
|
||||
NodeKind::Variant(_) |
|
||||
NodeKind::StructCtor(_) |
|
||||
NodeKind::Field(_) |
|
||||
NodeKind::Ty(_) |
|
||||
NodeKind::MacroDef(_) => {}
|
||||
Node::ForeignItem(_) |
|
||||
Node::Variant(_) |
|
||||
Node::StructCtor(_) |
|
||||
Node::Field(_) |
|
||||
Node::Ty(_) |
|
||||
Node::MacroDef(_) => {}
|
||||
_ => {
|
||||
bug!("found unexpected thingy in worklist: {}",
|
||||
self.tcx.hir.node_to_string(search_item))
|
||||
|
|
|
@ -30,7 +30,7 @@ use ty::TyCtxt;
|
|||
use ty::query::Providers;
|
||||
|
||||
use hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::def_id::DefId;
|
||||
use hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
|
||||
|
@ -258,7 +258,7 @@ impl Scope {
|
|||
}
|
||||
let span = tcx.hir.span(node_id);
|
||||
if let ScopeData::Remainder(r) = self.data() {
|
||||
if let NodeKind::Block(ref blk) = tcx.hir.get(node_id) {
|
||||
if let Node::Block(ref blk) = tcx.hir.get(node_id) {
|
||||
// Want span for scope starting after the
|
||||
// indexed statement and ending at end of
|
||||
// `blk`; reuse span of `blk` and shift `lo`
|
||||
|
@ -1421,8 +1421,8 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
|
|||
// record its impl/trait parent, as it can also have
|
||||
// lifetime parameters free in this body.
|
||||
match tcx.hir.get(id) {
|
||||
NodeKind::ImplItem(_) |
|
||||
NodeKind::TraitItem(_) => {
|
||||
Node::ImplItem(_) |
|
||||
Node::TraitItem(_) => {
|
||||
visitor.scope_tree.root_parent = Some(tcx.hir.get_parent(id));
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
use hir::def::Def;
|
||||
use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use hir::map::{NodeKind, Map};
|
||||
use hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, ParamName};
|
||||
use hir::map::Map;
|
||||
use hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, ParamName, Node};
|
||||
use ty::{self, TyCtxt, GenericParamDefKind};
|
||||
|
||||
use errors::DiagnosticBuilder;
|
||||
|
@ -1440,10 +1440,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
debug!("node id first={:?}", node_id);
|
||||
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Lifetime(hir_lifetime) => {
|
||||
Node::Lifetime(hir_lifetime) => {
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
|
||||
}
|
||||
NodeKind::GenericParam(param) => {
|
||||
Node::GenericParam(param) => {
|
||||
Some((param.id, param.span, param.name.ident()))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1466,10 +1466,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
None => {
|
||||
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Lifetime(hir_lifetime) => {
|
||||
Node::Lifetime(hir_lifetime) => {
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
|
||||
}
|
||||
NodeKind::GenericParam(param) => {
|
||||
Node::GenericParam(param) => {
|
||||
Some((param.id, param.span, param.name.ident()))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1643,15 +1643,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
} else if let Some(body_id) = outermost_body {
|
||||
let fn_id = self.tcx.hir.body_owner(body_id);
|
||||
match self.tcx.hir.get(fn_id) {
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Fn(..),
|
||||
..
|
||||
})
|
||||
| NodeKind::TraitItem(&hir::TraitItem {
|
||||
| Node::TraitItem(&hir::TraitItem {
|
||||
node: hir::TraitItemKind::Method(..),
|
||||
..
|
||||
})
|
||||
| NodeKind::ImplItem(&hir::ImplItem {
|
||||
| Node::ImplItem(&hir::ImplItem {
|
||||
node: hir::ImplItemKind::Method(..),
|
||||
..
|
||||
}) => {
|
||||
|
@ -1868,12 +1868,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
let parent = self.tcx.hir.get_parent_node(output.id);
|
||||
let body = match self.tcx.hir.get(parent) {
|
||||
// `fn` definitions and methods.
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Fn(.., body),
|
||||
..
|
||||
}) => Some(body),
|
||||
|
||||
NodeKind::TraitItem(&hir::TraitItem {
|
||||
Node::TraitItem(&hir::TraitItem {
|
||||
node: hir::TraitItemKind::Method(_, ref m),
|
||||
..
|
||||
}) => {
|
||||
|
@ -1896,7 +1896,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ImplItem(&hir::ImplItem {
|
||||
Node::ImplItem(&hir::ImplItem {
|
||||
node: hir::ImplItemKind::Method(_, body),
|
||||
..
|
||||
}) => {
|
||||
|
@ -1918,7 +1918,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Foreign functions, `fn(...) -> R` and `Trait(...) -> R` (both types and bounds).
|
||||
NodeKind::ForeignItem(_) | NodeKind::Ty(_) | NodeKind::TraitRef(_) => None,
|
||||
Node::ForeignItem(_) | Node::Ty(_) | Node::TraitRef(_) => None,
|
||||
// Everything else (only closures?) doesn't
|
||||
// actually enjoy elision in return types.
|
||||
_ => {
|
||||
|
|
|
@ -29,7 +29,7 @@ use super::{
|
|||
|
||||
use errors::{Applicability, DiagnosticBuilder};
|
||||
use hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::def_id::DefId;
|
||||
use infer::{self, InferCtxt};
|
||||
use infer::type_variable::TypeVariableOrigin;
|
||||
|
@ -865,7 +865,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
err: &mut DiagnosticBuilder<'tcx>) {
|
||||
if let &ObligationCauseCode::VariableType(node_id) = code {
|
||||
let parent_node = self.tcx.hir.get_parent_node(node_id);
|
||||
if let Some(NodeKind::Local(ref local)) = self.tcx.hir.find(parent_node) {
|
||||
if let Some(Node::Local(ref local)) = self.tcx.hir.find(parent_node) {
|
||||
if let Some(ref expr) = local.init {
|
||||
if let hir::ExprKind::Index(_, _) = expr.node {
|
||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
|
||||
|
@ -933,9 +933,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
/// returns a span and `ArgKind` information that describes the
|
||||
/// arguments it expects. This can be supplied to
|
||||
/// `report_arg_count_mismatch`.
|
||||
pub fn get_fn_like_arguments(&self, node: NodeKind) -> (Span, Vec<ArgKind>) {
|
||||
pub fn get_fn_like_arguments(&self, node: Node) -> (Span, Vec<ArgKind>) {
|
||||
match node {
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(_, ref _decl, id, span, _),
|
||||
..
|
||||
}) => {
|
||||
|
@ -962,17 +962,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
})
|
||||
.collect::<Vec<ArgKind>>())
|
||||
}
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
span,
|
||||
node: hir::ItemKind::Fn(ref decl, ..),
|
||||
..
|
||||
}) |
|
||||
NodeKind::ImplItem(&hir::ImplItem {
|
||||
Node::ImplItem(&hir::ImplItem {
|
||||
span,
|
||||
node: hir::ImplItemKind::Method(hir::MethodSig { ref decl, .. }, _),
|
||||
..
|
||||
}) |
|
||||
NodeKind::TraitItem(&hir::TraitItem {
|
||||
Node::TraitItem(&hir::TraitItem {
|
||||
span,
|
||||
node: hir::TraitItemKind::Method(hir::MethodSig { ref decl, .. }, _),
|
||||
..
|
||||
|
@ -988,7 +988,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
_ => ArgKind::Arg("_".to_owned(), "_".to_owned())
|
||||
}).collect::<Vec<ArgKind>>())
|
||||
}
|
||||
NodeKind::Variant(&hir::Variant {
|
||||
Node::Variant(&hir::Variant {
|
||||
span,
|
||||
node: hir::VariantKind {
|
||||
data: hir::VariantData::Tuple(ref fields, _),
|
||||
|
@ -1001,7 +1001,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
ArgKind::Arg(field.ident.to_string(), "_".to_string())
|
||||
}).collect::<Vec<_>>())
|
||||
}
|
||||
NodeKind::StructCtor(ref variant_data) => {
|
||||
Node::StructCtor(ref variant_data) => {
|
||||
(self.tcx.sess.source_map().def_span(self.tcx.hir.span(variant_data.id())),
|
||||
variant_data.fields()
|
||||
.iter().map(|_| ArgKind::Arg("_".to_owned(), "_".to_owned()))
|
||||
|
|
|
@ -15,7 +15,7 @@ pub use self::IntVarValue::*;
|
|||
pub use self::fold::TypeFoldable;
|
||||
|
||||
use hir::{map as hir_map, FreevarMap, TraitMap};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use hir::def::{Def, CtorKind, ExportMap};
|
||||
use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use hir::map::DefPathData;
|
||||
|
@ -2479,7 +2479,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
pub fn expr_span(self, id: NodeId) -> Span {
|
||||
match self.hir.find(id) {
|
||||
Some(NodeKind::Expr(e)) => {
|
||||
Some(Node::Expr(e)) => {
|
||||
e.span
|
||||
}
|
||||
Some(f) => {
|
||||
|
@ -2506,7 +2506,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssociatedItem> {
|
||||
let is_associated_item = if let Some(node_id) = self.hir.as_local_node_id(def_id) {
|
||||
match self.hir.get(node_id) {
|
||||
NodeKind::TraitItem(_) | NodeKind::ImplItem(_) => true,
|
||||
Node::TraitItem(_) | Node::ImplItem(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
|
@ -2896,7 +2896,7 @@ fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option
|
|||
/// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition
|
||||
pub fn is_impl_trait_defn(tcx: TyCtxt, def_id: DefId) -> Option<DefId> {
|
||||
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
|
||||
if let NodeKind::Item(item) = tcx.hir.get(node_id) {
|
||||
if let Node::Item(item) = tcx.hir.get(node_id) {
|
||||
if let hir::ItemKind::Existential(ref exist_ty) = item.node {
|
||||
return exist_ty.impl_trait_fn;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
use hir::def::Def;
|
||||
use hir::def_id::DefId;
|
||||
use hir::map::{DefPathData, NodeKind};
|
||||
use hir;
|
||||
use hir::map::DefPathData;
|
||||
use hir::{self, Node};
|
||||
use ich::NodeIdHashingMode;
|
||||
use traits::{self, ObligationCause};
|
||||
use ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
|
||||
|
@ -604,10 +604,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> {
|
||||
if let Some(node) = self.hir.get_if_local(def_id) {
|
||||
match node {
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Static(_, mutbl, _), ..
|
||||
}) => Some(mutbl),
|
||||
NodeKind::ForeignItem(&hir::ForeignItem {
|
||||
Node::ForeignItem(&hir::ForeignItem {
|
||||
node: hir::ForeignItemKind::Static(_, is_mutbl), ..
|
||||
}) =>
|
||||
Some(if is_mutbl {
|
||||
|
|
|
@ -30,7 +30,7 @@ use rustc::ty::{self, TyCtxt, RegionKind};
|
|||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
|
||||
|
||||
use std::rc::Rc;
|
||||
|
@ -203,7 +203,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
|||
|
||||
let node_id = bccx.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
let movable_generator = !match bccx.tcx.hir.get(node_id) {
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
|
||||
..
|
||||
}) => true,
|
||||
|
|
|
@ -24,7 +24,7 @@ use std::rc::Rc;
|
|||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
|
||||
struct GatherMoveInfo<'c, 'tcx: 'c> {
|
||||
id: hir::ItemLocalId,
|
||||
|
@ -60,7 +60,7 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte
|
|||
let parent = tcx.hir.get_parent_node(pat.id);
|
||||
|
||||
match tcx.hir.get(parent) {
|
||||
NodeKind::Expr(ref e) => {
|
||||
Node::Expr(ref e) => {
|
||||
// the enclosing expression must be a `match` or something else
|
||||
assert!(match e.node {
|
||||
ExprKind::Match(..) => true,
|
||||
|
@ -68,7 +68,7 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte
|
|||
});
|
||||
PatternSource::MatchExpr(e)
|
||||
}
|
||||
NodeKind::Local(local) => PatternSource::LetDecl(local),
|
||||
Node::Local(local) => PatternSource::LetDecl(local),
|
||||
_ => return PatternSource::Other,
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub use self::MovedValueUseKind::*;
|
|||
use self::InteriorKind::*;
|
||||
|
||||
use rustc::hir::HirId;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::map::blocks::FnLikeNode;
|
||||
use rustc::cfg;
|
||||
use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
|
||||
|
@ -95,8 +95,8 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
|
|||
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
|
||||
|
||||
match tcx.hir.get(owner_id) {
|
||||
NodeKind::StructCtor(_) |
|
||||
NodeKind::Variant(_) => {
|
||||
Node::StructCtor(_) |
|
||||
Node::Variant(_) => {
|
||||
// We get invoked with anything that has MIR, but some of
|
||||
// those things (notably the synthesized constructors from
|
||||
// tuple structs/variants) do not have an associated body
|
||||
|
@ -419,7 +419,7 @@ fn closure_to_block(closure_id: LocalDefId,
|
|||
tcx: TyCtxt) -> ast::NodeId {
|
||||
let closure_id = tcx.hir.local_def_id_to_node_id(closure_id);
|
||||
match tcx.hir.get(closure_id) {
|
||||
NodeKind::Expr(expr) => match expr.node {
|
||||
Node::Expr(expr) => match expr.node {
|
||||
hir::ExprKind::Closure(.., body_id, _, _) => {
|
||||
body_id.node_id
|
||||
}
|
||||
|
@ -908,7 +908,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
let node = self.tcx.hir.get(node_id);
|
||||
|
||||
// This pattern probably always matches.
|
||||
if let NodeKind::Expr(
|
||||
if let Node::Expr(
|
||||
hir::Expr { node: hir::ExprKind::Index(lhs, _), ..}
|
||||
) = node {
|
||||
let ty = self.tables.expr_ty(lhs);
|
||||
|
@ -1032,7 +1032,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
if let ty::ReScope(scope) = *super_scope {
|
||||
let node_id = scope.node_id(self.tcx, &self.region_scope_tree);
|
||||
match self.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Stmt(_)) => {
|
||||
Some(Node::Stmt(_)) => {
|
||||
if *sub_scope != ty::ReStatic {
|
||||
db.note("consider using a `let` binding to increase its lifetime");
|
||||
}
|
||||
|
@ -1183,7 +1183,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
|
||||
fn local_binding_mode(&self, node_id: ast::NodeId) -> ty::BindingMode {
|
||||
let pat = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Binding(pat) => pat,
|
||||
Node::Binding(pat) => pat,
|
||||
node => bug!("bad node for local: {:?}", node)
|
||||
};
|
||||
|
||||
|
@ -1259,7 +1259,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
None => return
|
||||
};
|
||||
|
||||
if let NodeKind::Field(ref field) = self.tcx.hir.get(node_id) {
|
||||
if let Node::Field(ref field) = self.tcx.hir.get(node_id) {
|
||||
if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) {
|
||||
db.span_label(field.ty.span, msg);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::sync::Arc;
|
|||
|
||||
use monomorphize::Instance;
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::CodegenFnAttrFlags;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
@ -95,7 +95,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// 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.hir.get(node_id) {
|
||||
NodeKind::ForeignItem(..) => {
|
||||
Node::ForeignItem(..) => {
|
||||
let def_id = tcx.hir.local_def_id(node_id);
|
||||
if tcx.is_statically_included_foreign_item(def_id) {
|
||||
Some(def_id)
|
||||
|
@ -105,14 +105,14 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
|
||||
// Only consider nodes that actually have exported symbols.
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Static(..),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Fn(..), ..
|
||||
}) |
|
||||
NodeKind::ImplItem(&hir::ImplItem {
|
||||
Node::ImplItem(&hir::ImplItem {
|
||||
node: hir::ImplItemKind::Method(..),
|
||||
..
|
||||
}) => {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use libc::c_uint;
|
||||
use llvm::{self, SetUnnamedAddr, True};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use debuginfo;
|
||||
use base;
|
||||
use monomorphize::MonoItem;
|
||||
|
@ -135,7 +135,7 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value {
|
|||
|
||||
let llty = cx.layout_of(ty).llvm_type(cx);
|
||||
let (g, attrs) = match cx.tcx.hir.get(id) {
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
ref attrs, span, node: hir::ItemKind::Static(..), ..
|
||||
}) => {
|
||||
if declare::get_declared_value(cx, &sym[..]).is_some() {
|
||||
|
@ -153,7 +153,7 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value {
|
|||
(g, attrs)
|
||||
}
|
||||
|
||||
NodeKind::ForeignItem(&hir::ForeignItem {
|
||||
Node::ForeignItem(&hir::ForeignItem {
|
||||
ref attrs, span, node: hir::ForeignItemKind::Static(..), ..
|
||||
}) => {
|
||||
let fn_attrs = cx.tcx.codegen_fn_attrs(def_id);
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
//! DefPaths which are much more robust in the face of changes to the code base.
|
||||
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::CodegenFnAttrFlags;
|
||||
use rustc::hir::map::definitions::DefPathData;
|
||||
use rustc::ich::NodeIdHashingMode;
|
||||
|
@ -261,7 +261,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
|
|||
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
|
||||
let is_foreign = if let Some(id) = node_id {
|
||||
match tcx.hir.get(id) {
|
||||
NodeKind::ForeignItem(_) => true,
|
||||
Node::ForeignItem(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -30,7 +30,7 @@ use std::vec::Vec;
|
|||
use rustc::dep_graph::{DepNode, label_strs};
|
||||
use rustc::hir;
|
||||
use rustc::hir::{ItemKind as HirItem, ImplItemKind, TraitItemKind};
|
||||
use rustc::hir::map::NodeKind as HirNode;
|
||||
use rustc::hir::Node as HirNode;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc::hir::intravisit;
|
||||
|
@ -400,7 +400,7 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
|
|||
attr.span,
|
||||
&format!(
|
||||
"clean/dirty auto-assertions not yet defined \
|
||||
for NodeKind::Item.node={:?}",
|
||||
for Node::Item.node={:?}",
|
||||
item.node
|
||||
)
|
||||
),
|
||||
|
@ -408,14 +408,14 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
|
|||
},
|
||||
HirNode::TraitItem(item) => {
|
||||
match item.node {
|
||||
TraitItemKind::Method(..) => ("NodeKind::TraitItem", LABELS_FN_IN_TRAIT),
|
||||
TraitItemKind::Method(..) => ("Node::TraitItem", LABELS_FN_IN_TRAIT),
|
||||
TraitItemKind::Const(..) => ("NodeTraitConst", LABELS_CONST_IN_TRAIT),
|
||||
TraitItemKind::Type(..) => ("NodeTraitType", LABELS_CONST_IN_TRAIT),
|
||||
}
|
||||
},
|
||||
HirNode::ImplItem(item) => {
|
||||
match item.node {
|
||||
ImplItemKind::Method(..) => ("NodeKind::ImplItem", LABELS_FN_IN_IMPL),
|
||||
ImplItemKind::Method(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
|
||||
ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL),
|
||||
ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
|
||||
ImplItemKind::Existential(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
|
||||
|
|
|
@ -34,7 +34,7 @@ use rustc::cfg;
|
|||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::traits;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use util::nodemap::NodeSet;
|
||||
use lint::{LateContext, LintContext, LintArray};
|
||||
use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
|
||||
|
@ -427,7 +427,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
|||
let real_trait = trait_ref.path.def.def_id();
|
||||
if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
|
||||
match cx.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(item)) => {
|
||||
Some(Node::Item(item)) => {
|
||||
if let hir::VisibilityKind::Inherited = item.vis.node {
|
||||
for impl_item_ref in impl_item_refs {
|
||||
self.private_traits.insert(impl_item_ref.id.node_id);
|
||||
|
@ -981,7 +981,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
|
|||
|
||||
fn expr_refers_to_this_fn(cx: &LateContext, fn_id: ast::NodeId, id: ast::NodeId) -> bool {
|
||||
match cx.tcx.hir.get(id) {
|
||||
NodeKind::Expr(&hir::Expr { node: hir::ExprKind::Call(ref callee, _), .. }) => {
|
||||
Node::Expr(&hir::Expr { node: hir::ExprKind::Call(ref callee, _), .. }) => {
|
||||
let def = if let hir::ExprKind::Path(ref qpath) = callee.node {
|
||||
cx.tables.qpath_def(qpath, callee.hir_id)
|
||||
} else {
|
||||
|
@ -1004,7 +1004,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
|
|||
use rustc::ty::adjustment::*;
|
||||
|
||||
// Ignore non-expressions.
|
||||
let expr = if let NodeKind::Expr(e) = cx.tcx.hir.get(id) {
|
||||
let expr = if let Node::Expr(e) = cx.tcx.hir.get(id) {
|
||||
e
|
||||
} else {
|
||||
return false;
|
||||
|
@ -1864,7 +1864,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestFunctions {
|
|||
if attr.name() == "test" {
|
||||
let parent = cx.tcx.hir.get_parent(it.id);
|
||||
match cx.tcx.hir.find(parent) {
|
||||
Some(NodeKind::Item(hir::Item {node: hir::ItemKind::Mod(_), ..})) |
|
||||
Some(Node::Item(hir::Item {node: hir::ItemKind::Mod(_), ..})) |
|
||||
None => {}
|
||||
_ => {
|
||||
cx.struct_span_lint(
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
|
||||
use rustc::ty::layout::{self, IntegerExt, LayoutOf};
|
||||
|
@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
let parent_id = cx.tcx.hir.get_parent_node(e.id);
|
||||
if let NodeKind::Expr(parent_expr) = cx.tcx.hir.get(parent_id) {
|
||||
if let Node::Expr(parent_expr) = cx.tcx.hir.get(parent_id) {
|
||||
if let hir::ExprKind::Cast(..) = parent_expr.node {
|
||||
if let ty::Char = cx.tables.expr_ty(parent_expr).sty {
|
||||
let mut err = cx.struct_span_lint(
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
use borrow_check::nll::region_infer::RegionInferenceContext;
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::definitions::DefPathData;
|
||||
use rustc::infer::InferCtxt;
|
||||
|
@ -233,7 +233,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
|
|||
));
|
||||
|
||||
let movable_generator = match tcx.hir.get(id) {
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
|
||||
..
|
||||
}) => false,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::mir::{self, BindingForm, ClearCrossCrate, Local, Location, Mir};
|
||||
use rustc::mir::{Mutability, Place, Projection, ProjectionElem, Static};
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
|
@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
|||
.var_hir_id
|
||||
.assert_crate_local();
|
||||
let upvar_node_id = self.tcx.hir.hir_to_node_id(upvar_hir_id);
|
||||
if let Some(NodeKind::Binding(pat)) = self.tcx.hir.find(upvar_node_id) {
|
||||
if let Some(Node::Binding(pat)) = self.tcx.hir.find(upvar_node_id) {
|
||||
if let hir::PatKind::Binding(
|
||||
hir::BindingAnnotation::Unannotated,
|
||||
_,
|
||||
|
|
|
@ -14,7 +14,7 @@ use build::scope::{CachedBlock, DropKind};
|
|||
use hair::cx::Cx;
|
||||
use hair::{LintLevel, BindingMode, PatternKind};
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::{DefId, LocalDefId};
|
||||
use rustc::middle::region;
|
||||
use rustc::mir::*;
|
||||
|
@ -41,9 +41,9 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
|
|||
|
||||
// Figure out what primary body this item has.
|
||||
let body_id = match tcx.hir.get(id) {
|
||||
NodeKind::Variant(variant) =>
|
||||
Node::Variant(variant) =>
|
||||
return create_constructor_shim(tcx, id, &variant.node.data),
|
||||
NodeKind::StructCtor(ctor) =>
|
||||
Node::StructCtor(ctor) =>
|
||||
return create_constructor_shim(tcx, id, ctor),
|
||||
|
||||
_ => match tcx.hir.maybe_body_owned_by(id) {
|
||||
|
@ -521,7 +521,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
|
|||
by_ref,
|
||||
mutability: Mutability::Not,
|
||||
};
|
||||
if let Some(NodeKind::Binding(pat)) = tcx.hir.find(var_id) {
|
||||
if let Some(Node::Binding(pat)) = tcx.hir.find(var_id) {
|
||||
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
|
||||
decl.debug_name = ident.name;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ use hair::*;
|
|||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::hir::map::blocks::FnLikeNode;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::middle::region;
|
||||
use rustc::infer::InferCtxt;
|
||||
use rustc::ty::subst::Subst;
|
||||
|
@ -203,7 +203,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
|
|||
pub fn pattern_from_hir(&mut self, p: &hir::Pat) -> Pattern<'tcx> {
|
||||
let tcx = self.tcx.global_tcx();
|
||||
let p = match tcx.hir.get(p.id) {
|
||||
NodeKind::Pat(p) | NodeKind::Binding(p) => p,
|
||||
Node::Pat(p) | Node::Binding(p) => p,
|
||||
node => bug!("pattern became {:?}", node)
|
||||
};
|
||||
Pattern::from_hir(tcx,
|
||||
|
|
|
@ -191,7 +191,7 @@
|
|||
use rustc::hir::{self, CodegenFnAttrFlags};
|
||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::mir::interpret::{AllocId, ConstValue, ScalarMaybeUndef};
|
||||
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
|
||||
|
@ -740,7 +740,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
|
|||
};
|
||||
|
||||
return match tcx.hir.get_if_local(def_id) {
|
||||
Some(NodeKind::ForeignItem(..)) => {
|
||||
Some(Node::ForeignItem(..)) => {
|
||||
false // foreign items are linked against, not codegened.
|
||||
}
|
||||
Some(_) => true,
|
||||
|
|
|
@ -85,7 +85,7 @@ fn place_context<'a, 'tcx, D>(
|
|||
fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) -> bool {
|
||||
use rustc::hir::intravisit::{self, Visitor, FnKind};
|
||||
use rustc::hir::map::blocks::FnLikeNode;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
|
||||
/// Decide if this is an unsafe block
|
||||
fn block_is_unsafe(block: &hir::Block) -> bool {
|
||||
|
@ -142,13 +142,13 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
|
|||
}
|
||||
// Check if this is an unsafe block, or an item
|
||||
match node {
|
||||
NodeKind::Expr(&hir::Expr { node: hir::ExprKind::Block(ref block, _), ..}) => {
|
||||
Node::Expr(&hir::Expr { node: hir::ExprKind::Block(ref block, _), ..}) => {
|
||||
if block_is_unsafe(&*block) {
|
||||
// Found an unsafe block, we can bail out here.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
NodeKind::Item(..) => {
|
||||
Node::Item(..) => {
|
||||
// No walking up beyond items. This makes sure the loop always terminates.
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::sync::Lrc;
|
|||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::hir;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
|
||||
use rustc::mir::*;
|
||||
|
@ -408,7 +408,7 @@ fn is_enclosed(tcx: TyCtxt,
|
|||
if parent_id != id {
|
||||
if used_unsafe.contains(&parent_id) {
|
||||
Some(("block".to_string(), parent_id))
|
||||
} else if let Some(NodeKind::Item(&hir::Item {
|
||||
} else if let Some(Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Fn(_, header, _, _),
|
||||
..
|
||||
})) = tcx.hir.find(parent_id) {
|
||||
|
|
|
@ -11,9 +11,9 @@ use self::Context::*;
|
|||
|
||||
use rustc::session::Session;
|
||||
|
||||
use rustc::hir::map::{Map, NodeKind};
|
||||
use rustc::hir::map::Map;
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use rustc::hir::{self, Destination};
|
||||
use rustc::hir::{self, Node, Destination};
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
|
||||
|
@ -115,7 +115,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
|||
|
||||
if loop_id != ast::DUMMY_NODE_ID {
|
||||
match self.hir_map.find(loop_id).unwrap() {
|
||||
NodeKind::Block(_) => return,
|
||||
Node::Block(_) => return,
|
||||
_=> (),
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
|||
|
||||
match label.target_id {
|
||||
Ok(loop_id) => {
|
||||
if let NodeKind::Block(block) = self.hir_map.find(loop_id).unwrap() {
|
||||
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
|
||||
struct_span_err!(self.sess, e.span, E0696,
|
||||
"`continue` pointing to a labeled block")
|
||||
.span_label(e.span,
|
||||
|
|
|
@ -25,7 +25,7 @@ extern crate syntax_pos;
|
|||
extern crate rustc_data_structures;
|
||||
|
||||
use rustc::hir::{self, PatKind};
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
|
@ -660,17 +660,17 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
|
|||
match self.tcx.hir.as_local_node_id(did) {
|
||||
Some(node_id) => {
|
||||
let vis = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Item(item) => &item.vis,
|
||||
NodeKind::ForeignItem(foreign_item) => &foreign_item.vis,
|
||||
NodeKind::ImplItem(impl_item) => &impl_item.vis,
|
||||
NodeKind::TraitItem(..) |
|
||||
NodeKind::Variant(..) => {
|
||||
Node::Item(item) => &item.vis,
|
||||
Node::ForeignItem(foreign_item) => &foreign_item.vis,
|
||||
Node::ImplItem(impl_item) => &impl_item.vis,
|
||||
Node::TraitItem(..) |
|
||||
Node::Variant(..) => {
|
||||
return self.def_id_visibility(self.tcx.hir.get_parent_did(node_id));
|
||||
}
|
||||
NodeKind::StructCtor(vdata) => {
|
||||
Node::StructCtor(vdata) => {
|
||||
let struct_node_id = self.tcx.hir.get_parent(node_id);
|
||||
let struct_vis = match self.tcx.hir.get(struct_node_id) {
|
||||
NodeKind::Item(item) => &item.vis,
|
||||
Node::Item(item) => &item.vis,
|
||||
node => bug!("unexpected node kind: {:?}", node),
|
||||
};
|
||||
let mut ctor_vis
|
||||
|
@ -1038,7 +1038,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
|||
// .. and it corresponds to a private type in the AST (this returns
|
||||
// None for type parameters)
|
||||
match self.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(ref item)) => !item.vis.node.is_pub(),
|
||||
Some(Node::Item(ref item)) => !item.vis.node.is_pub(),
|
||||
Some(_) | None => false,
|
||||
}
|
||||
} else {
|
||||
|
@ -1470,8 +1470,8 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
|
|||
// Non-local means public (private items can't leave their crate, modulo bugs)
|
||||
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
|
||||
let hir_vis = match self.tcx.hir.find(node_id) {
|
||||
Some(NodeKind::Item(item)) => &item.vis,
|
||||
Some(NodeKind::ForeignItem(item)) => &item.vis,
|
||||
Some(Node::Item(item)) => &item.vis,
|
||||
Some(Node::ForeignItem(item)) => &item.vis,
|
||||
_ => bug!("expected item of foreign item"),
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ mod sig;
|
|||
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Def as HirDef;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::middle::cstore::ExternCrate;
|
||||
use rustc::session::config::CrateType;
|
||||
|
@ -420,7 +420,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
let (qualname, parent_scope, decl_id, docs, attributes) =
|
||||
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(NodeKind::Item(item)) => match item.node {
|
||||
Some(Node::Item(item)) => match item.node {
|
||||
hir::ItemKind::Impl(.., ref ty, _) => {
|
||||
let mut qualname = String::from("<");
|
||||
qualname.push_str(&self.tcx.hir.node_to_pretty_string(ty.id));
|
||||
|
@ -429,7 +429,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
let mut decl_id = None;
|
||||
let mut docs = String::new();
|
||||
let mut attrs = vec![];
|
||||
if let Some(NodeKind::ImplItem(item)) = self.tcx.hir.find(id) {
|
||||
if let Some(Node::ImplItem(item)) = self.tcx.hir.find(id) {
|
||||
docs = self.docs_for_attrs(&item.attrs);
|
||||
attrs = item.attrs.to_vec();
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
let mut docs = String::new();
|
||||
let mut attrs = vec![];
|
||||
|
||||
if let Some(NodeKind::TraitItem(item)) = self.tcx.hir.find(id) {
|
||||
if let Some(Node::TraitItem(item)) = self.tcx.hir.find(id) {
|
||||
docs = self.docs_for_attrs(&item.attrs);
|
||||
attrs = item.attrs.to_vec();
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
match expr.node {
|
||||
ast::ExprKind::Field(ref sub_ex, ident) => {
|
||||
let hir_node = match self.tcx.hir.find(sub_ex.id) {
|
||||
Some(NodeKind::Expr(expr)) => expr,
|
||||
Some(Node::Expr(expr)) => expr,
|
||||
_ => {
|
||||
debug!(
|
||||
"Missing or weird node for sub-expression {} in {:?}",
|
||||
|
@ -628,32 +628,32 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
|
||||
pub fn get_path_def(&self, id: NodeId) -> HirDef {
|
||||
match self.tcx.hir.get(id) {
|
||||
NodeKind::TraitRef(tr) => tr.path.def,
|
||||
Node::TraitRef(tr) => tr.path.def,
|
||||
|
||||
NodeKind::Item(&hir::Item {
|
||||
Node::Item(&hir::Item {
|
||||
node: hir::ItemKind::Use(ref path, _),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Visibility(&Spanned {
|
||||
Node::Visibility(&Spanned {
|
||||
node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def,
|
||||
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Struct(ref qpath, ..),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Path(ref qpath),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Pat(&hir::Pat {
|
||||
Node::Pat(&hir::Pat {
|
||||
node: hir::PatKind::Path(ref qpath),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Pat(&hir::Pat {
|
||||
Node::Pat(&hir::Pat {
|
||||
node: hir::PatKind::Struct(ref qpath, ..),
|
||||
..
|
||||
}) |
|
||||
NodeKind::Pat(&hir::Pat {
|
||||
Node::Pat(&hir::Pat {
|
||||
node: hir::PatKind::TupleStruct(ref qpath, ..),
|
||||
..
|
||||
}) => {
|
||||
|
@ -661,12 +661,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
self.tables.qpath_def(qpath, hir_id)
|
||||
}
|
||||
|
||||
NodeKind::Binding(&hir::Pat {
|
||||
Node::Binding(&hir::Pat {
|
||||
node: hir::PatKind::Binding(_, canonical_id, ..),
|
||||
..
|
||||
}) => HirDef::Local(canonical_id),
|
||||
|
||||
NodeKind::Ty(ty) => if let hir::Ty {
|
||||
Node::Ty(ty) => if let hir::Ty {
|
||||
node: hir::TyKind::Path(ref qpath),
|
||||
..
|
||||
} = *ty
|
||||
|
|
|
@ -17,7 +17,7 @@ use syntax::util::parser::PREC_POSTFIX;
|
|||
use syntax_pos::Span;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::{Item, ItemKind, print};
|
||||
use rustc::ty::{self, Ty, AssociatedItem};
|
||||
use rustc::ty::adjustment::AllowTwoPhase;
|
||||
|
@ -199,13 +199,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = expr.node {
|
||||
if let hir::def::Def::Local(id) = path.def {
|
||||
let parent = self.tcx.hir.get_parent_node(id);
|
||||
if let Some(NodeKind::Expr(hir::Expr {
|
||||
if let Some(Node::Expr(hir::Expr {
|
||||
id,
|
||||
node: hir::ExprKind::Closure(_, decl, ..),
|
||||
..
|
||||
})) = self.tcx.hir.find(parent) {
|
||||
let parent = self.tcx.hir.get_parent_node(*id);
|
||||
if let (Some(NodeKind::Expr(hir::Expr {
|
||||
if let (Some(Node::Expr(hir::Expr {
|
||||
node: hir::ExprKind::MethodCall(path, span, expr),
|
||||
..
|
||||
})), 1) = (self.tcx.hir.find(parent), decl.inputs.len()) {
|
||||
|
@ -377,7 +377,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
match self.tcx.hir.find(parent_id) {
|
||||
Some(parent) => {
|
||||
// Shouldn't suggest `.into()` on `const`s.
|
||||
if let NodeKind::Item(Item { node: ItemKind::Const(_, _), .. }) = parent {
|
||||
if let Node::Item(Item { node: ItemKind::Const(_, _), .. }) = parent {
|
||||
// FIXME(estebank): modify once we decide to suggest `as` casts
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
use check::FnCtxt;
|
||||
use rustc::hir::map as hir_map;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc::ty::{self, Ty, TyCtxt, ToPolyTraitRef, ToPredicate, TypeFoldable};
|
||||
use hir::def::Def;
|
||||
|
@ -276,7 +276,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
);
|
||||
|
||||
match (filename, parent_node) {
|
||||
(FileName::Real(_), NodeKind::Local(hir::Local {
|
||||
(FileName::Real(_), Node::Local(hir::Local {
|
||||
source: hir::LocalSource::Normal,
|
||||
ty,
|
||||
..
|
||||
|
|
|
@ -132,7 +132,7 @@ use syntax_pos::{self, BytePos, Span, MultiSpan};
|
|||
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::{self, PatKind, ItemKind};
|
||||
use rustc::middle::lang_items;
|
||||
|
||||
|
@ -761,7 +761,7 @@ fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
-> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)>
|
||||
{
|
||||
match tcx.hir.get(id) {
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
hir::ItemKind::Const(_, body) |
|
||||
hir::ItemKind::Static(_, _, body) =>
|
||||
|
@ -772,7 +772,7 @@ fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
None,
|
||||
}
|
||||
}
|
||||
NodeKind::TraitItem(item) => {
|
||||
Node::TraitItem(item) => {
|
||||
match item.node {
|
||||
hir::TraitItemKind::Const(_, Some(body)) =>
|
||||
Some((body, None)),
|
||||
|
@ -782,7 +782,7 @@ fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
None,
|
||||
}
|
||||
}
|
||||
NodeKind::ImplItem(item) => {
|
||||
Node::ImplItem(item) => {
|
||||
match item.node {
|
||||
hir::ImplItemKind::Const(_, body) =>
|
||||
Some((body, None)),
|
||||
|
@ -792,7 +792,7 @@ fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
None,
|
||||
}
|
||||
}
|
||||
NodeKind::AnonConst(constant) => Some((constant.body, None)),
|
||||
Node::AnonConst(constant) => Some((constant.body, None)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -1167,7 +1167,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
|||
);
|
||||
}
|
||||
|
||||
if let NodeKind::Item(item) = fcx.tcx.hir.get(fn_id) {
|
||||
if let Node::Item(item) = fcx.tcx.hir.get(fn_id) {
|
||||
if let ItemKind::Fn(_, _, ref generics, _) = item.node {
|
||||
if !generics.params.is_empty() {
|
||||
fcx.tcx.sess.span_err(
|
||||
|
@ -1214,7 +1214,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
|||
);
|
||||
}
|
||||
|
||||
if let NodeKind::Item(item) = fcx.tcx.hir.get(fn_id) {
|
||||
if let Node::Item(item) = fcx.tcx.hir.get(fn_id) {
|
||||
if let ItemKind::Fn(_, _, ref generics, _) = item.node {
|
||||
if !generics.params.is_empty() {
|
||||
fcx.tcx.sess.span_err(
|
||||
|
@ -4646,7 +4646,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
if let Some(fn_id) = self.tcx.hir.get_return_block(blk_id) {
|
||||
let parent = self.tcx.hir.get(fn_id);
|
||||
|
||||
if let NodeKind::Item(&hir::Item {
|
||||
if let Node::Item(&hir::Item {
|
||||
name, node: hir::ItemKind::Fn(ref decl, ..), ..
|
||||
}) = parent {
|
||||
decl.clone().and_then(|decl| {
|
||||
|
@ -4655,7 +4655,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// but it will still present it as the reason for the expected type.
|
||||
Some((decl, name != Symbol::intern("main")))
|
||||
})
|
||||
} else if let NodeKind::TraitItem(&hir::TraitItem {
|
||||
} else if let Node::TraitItem(&hir::TraitItem {
|
||||
node: hir::TraitItemKind::Method(hir::MethodSig {
|
||||
ref decl, ..
|
||||
}, ..), ..
|
||||
|
@ -4663,7 +4663,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
decl.clone().and_then(|decl| {
|
||||
Some((decl, true))
|
||||
})
|
||||
} else if let NodeKind::ImplItem(&hir::ImplItem {
|
||||
} else if let Node::ImplItem(&hir::ImplItem {
|
||||
node: hir::ImplItemKind::Method(hir::MethodSig {
|
||||
ref decl, ..
|
||||
}, ..), ..
|
||||
|
@ -5174,7 +5174,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// If our calling expression is indeed the function itself, we're good!
|
||||
// If not, generate an error that this can only be called directly.
|
||||
match self.tcx.hir.get(self.tcx.hir.get_parent_node(node_id)) {
|
||||
NodeKind::Expr(expr) => {
|
||||
Node::Expr(expr) => {
|
||||
match expr.node {
|
||||
hir::ExprKind::Call(ref callee, ..) => {
|
||||
if callee.id == node_id {
|
||||
|
|
|
@ -23,7 +23,7 @@ use rustc::ty::util::CopyImplementationError;
|
|||
use rustc::infer;
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::hir::{self, ItemKind};
|
||||
|
||||
pub fn check_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_def_id: DefId) {
|
||||
|
@ -60,7 +60,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
|
|||
// Destructors only work on nominal types.
|
||||
if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_did) {
|
||||
match tcx.hir.find(impl_node_id) {
|
||||
Some(NodeKind::Item(item)) => {
|
||||
Some(Node::Item(item)) => {
|
||||
let span = match item.node {
|
||||
ItemKind::Impl(.., ref ty, _) => ty.span,
|
||||
_ => item.span,
|
||||
|
|
|
@ -50,7 +50,7 @@ use syntax::symbol::{keywords, Symbol};
|
|||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
use rustc::hir::def::{CtorKind, Def};
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc::hir::GenericParamKind;
|
||||
|
@ -239,7 +239,6 @@ fn type_param_predicates<'a, 'tcx>(
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
(item_def_id, def_id): (DefId, DefId),
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
// In the AST, bounds can derive from two places. Either
|
||||
|
@ -273,11 +272,11 @@ fn type_param_predicates<'a, 'tcx>(
|
|||
|
||||
let item_node_id = tcx.hir.as_local_node_id(item_def_id).unwrap();
|
||||
let ast_generics = match tcx.hir.get(item_node_id) {
|
||||
NodeKind::TraitItem(item) => &item.generics,
|
||||
Node::TraitItem(item) => &item.generics,
|
||||
|
||||
NodeKind::ImplItem(item) => &item.generics,
|
||||
Node::ImplItem(item) => &item.generics,
|
||||
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Fn(.., ref generics, _)
|
||||
| ItemKind::Impl(_, _, _, ref generics, ..)
|
||||
|
@ -303,7 +302,7 @@ fn type_param_predicates<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ForeignItem(item) => match item.node {
|
||||
Node::ForeignItem(item) => match item.node {
|
||||
ForeignItemKind::Fn(_, _, ref generics) => generics,
|
||||
_ => return result,
|
||||
},
|
||||
|
@ -596,12 +595,11 @@ fn convert_struct_variant<'a, 'tcx>(
|
|||
}
|
||||
|
||||
fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::AdtDef {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
let item = match tcx.hir.get(node_id) {
|
||||
NodeKind::Item(item) => item,
|
||||
Node::Item(item) => item,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
|
@ -672,7 +670,7 @@ fn super_predicates_of<'a, 'tcx>(
|
|||
let trait_node_id = tcx.hir.as_local_node_id(trait_def_id).unwrap();
|
||||
|
||||
let item = match tcx.hir.get(trait_node_id) {
|
||||
NodeKind::Item(item) => item,
|
||||
Node::Item(item) => item,
|
||||
_ => bug!("trait_node_id {} is not an item", trait_node_id),
|
||||
};
|
||||
|
||||
|
@ -741,7 +739,7 @@ fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::
|
|||
|
||||
fn has_late_bound_regions<'a, 'tcx>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
node: NodeKind<'tcx>,
|
||||
node: Node<'tcx>,
|
||||
) -> Option<Span> {
|
||||
struct LateBoundRegionsDetector<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
@ -827,25 +825,25 @@ fn has_late_bound_regions<'a, 'tcx>(
|
|||
}
|
||||
|
||||
match node {
|
||||
NodeKind::TraitItem(item) => match item.node {
|
||||
Node::TraitItem(item) => match item.node {
|
||||
hir::TraitItemKind::Method(ref sig, _) => {
|
||||
has_late_bound_regions(tcx, &item.generics, &sig.decl)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
NodeKind::ImplItem(item) => match item.node {
|
||||
Node::ImplItem(item) => match item.node {
|
||||
hir::ImplItemKind::Method(ref sig, _) => {
|
||||
has_late_bound_regions(tcx, &item.generics, &sig.decl)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
NodeKind::ForeignItem(item) => match item.node {
|
||||
Node::ForeignItem(item) => match item.node {
|
||||
hir::ForeignItemKind::Fn(ref fn_decl, _, ref generics) => {
|
||||
has_late_bound_regions(tcx, generics, fn_decl)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
NodeKind::Item(item) => match item.node {
|
||||
Node::Item(item) => match item.node {
|
||||
hir::ItemKind::Fn(ref fn_decl, .., ref generics, _) => {
|
||||
has_late_bound_regions(tcx, generics, fn_decl)
|
||||
}
|
||||
|
@ -856,23 +854,22 @@ fn has_late_bound_regions<'a, 'tcx>(
|
|||
}
|
||||
|
||||
fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Generics {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
|
||||
let node = tcx.hir.get(node_id);
|
||||
let parent_def_id = match node {
|
||||
NodeKind::ImplItem(_) | NodeKind::TraitItem(_) | NodeKind::Variant(_)
|
||||
| NodeKind::StructCtor(_) | NodeKind::Field(_) => {
|
||||
Node::ImplItem(_) | Node::TraitItem(_) | Node::Variant(_)
|
||||
| Node::StructCtor(_) | Node::Field(_) => {
|
||||
let parent_id = tcx.hir.get_parent(node_id);
|
||||
Some(tcx.hir.local_def_id(parent_id))
|
||||
}
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(..),
|
||||
..
|
||||
}) => Some(tcx.closure_base_def_id(def_id)),
|
||||
NodeKind::Item(item) => match item.node {
|
||||
Node::Item(item) => match item.node {
|
||||
ItemKind::Existential(hir::ExistTy { impl_trait_fn, .. }) => impl_trait_fn,
|
||||
_ => None,
|
||||
},
|
||||
|
@ -884,11 +881,11 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
|
||||
let no_generics = hir::Generics::empty();
|
||||
let ast_generics = match node {
|
||||
NodeKind::TraitItem(item) => &item.generics,
|
||||
Node::TraitItem(item) => &item.generics,
|
||||
|
||||
NodeKind::ImplItem(item) => &item.generics,
|
||||
Node::ImplItem(item) => &item.generics,
|
||||
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) => {
|
||||
generics
|
||||
|
@ -931,7 +928,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ForeignItem(item) => match item.node {
|
||||
Node::ForeignItem(item) => match item.node {
|
||||
ForeignItemKind::Static(..) => &no_generics,
|
||||
ForeignItemKind::Fn(_, _, ref generics) => generics,
|
||||
ForeignItemKind::Type => &no_generics,
|
||||
|
@ -1026,7 +1023,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
// provide junk type parameter defs - the only place that
|
||||
// cares about anything but the length is instantiation,
|
||||
// and we don't do that for closures.
|
||||
if let NodeKind::Expr(&hir::Expr {
|
||||
if let Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(.., gen),
|
||||
..
|
||||
}) = node
|
||||
|
@ -1096,7 +1093,6 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span:
|
|||
}
|
||||
|
||||
fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
|
@ -1104,7 +1100,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
match tcx.hir.get(node_id) {
|
||||
NodeKind::TraitItem(item) => match item.node {
|
||||
Node::TraitItem(item) => match item.node {
|
||||
TraitItemKind::Method(..) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id, substs)
|
||||
|
@ -1115,7 +1111,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
}
|
||||
},
|
||||
|
||||
NodeKind::ImplItem(item) => match item.node {
|
||||
Node::ImplItem(item) => match item.node {
|
||||
ImplItemKind::Method(..) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id, substs)
|
||||
|
@ -1143,7 +1139,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
}
|
||||
},
|
||||
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Static(ref t, ..)
|
||||
| ItemKind::Const(ref t, _)
|
||||
|
@ -1201,7 +1197,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ForeignItem(foreign_item) => match foreign_item.node {
|
||||
Node::ForeignItem(foreign_item) => match foreign_item.node {
|
||||
ForeignItemKind::Fn(..) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id, substs)
|
||||
|
@ -1210,8 +1206,8 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
ForeignItemKind::Type => tcx.mk_foreign(def_id),
|
||||
},
|
||||
|
||||
NodeKind::StructCtor(&ref def)
|
||||
| NodeKind::Variant(&Spanned {
|
||||
Node::StructCtor(&ref def)
|
||||
| Node::Variant(&Spanned {
|
||||
node: hir::VariantKind { data: ref def, .. },
|
||||
..
|
||||
}) => match *def {
|
||||
|
@ -1224,9 +1220,9 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
}
|
||||
},
|
||||
|
||||
NodeKind::Field(field) => icx.to_ty(&field.ty),
|
||||
Node::Field(field) => icx.to_ty(&field.ty),
|
||||
|
||||
NodeKind::Expr(&hir::Expr {
|
||||
Node::Expr(&hir::Expr {
|
||||
node: hir::ExprKind::Closure(.., gen),
|
||||
..
|
||||
}) => {
|
||||
|
@ -1242,16 +1238,16 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
tcx.mk_closure(def_id, substs)
|
||||
}
|
||||
|
||||
NodeKind::AnonConst(_) => match tcx.hir.get(tcx.hir.get_parent_node(node_id)) {
|
||||
NodeKind::Ty(&hir::Ty {
|
||||
Node::AnonConst(_) => match tcx.hir.get(tcx.hir.get_parent_node(node_id)) {
|
||||
Node::Ty(&hir::Ty {
|
||||
node: hir::TyKind::Array(_, ref constant),
|
||||
..
|
||||
})
|
||||
| NodeKind::Ty(&hir::Ty {
|
||||
| Node::Ty(&hir::Ty {
|
||||
node: hir::TyKind::Typeof(ref constant),
|
||||
..
|
||||
})
|
||||
| NodeKind::Expr(&hir::Expr {
|
||||
| Node::Expr(&hir::Expr {
|
||||
node: ExprKind::Repeat(_, ref constant),
|
||||
..
|
||||
}) if constant.id == node_id =>
|
||||
|
@ -1259,7 +1255,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
tcx.types.usize
|
||||
}
|
||||
|
||||
NodeKind::Variant(&Spanned {
|
||||
Node::Variant(&Spanned {
|
||||
node:
|
||||
VariantKind {
|
||||
disr_expr: Some(ref e),
|
||||
|
@ -1279,7 +1275,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
|
|||
}
|
||||
},
|
||||
|
||||
NodeKind::GenericParam(param) => match param.kind {
|
||||
Node::GenericParam(param) => match param.kind {
|
||||
hir::GenericParamKind::Type {
|
||||
default: Some(ref ty),
|
||||
..
|
||||
|
@ -1297,7 +1293,6 @@ fn find_existential_constraints<'a, 'tcx>(
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId,
|
||||
) -> ty::Ty<'tcx> {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
struct ConstraintLocator<'a, 'tcx: 'a> {
|
||||
|
@ -1377,9 +1372,9 @@ fn find_existential_constraints<'a, 'tcx>(
|
|||
} else {
|
||||
trace!("parent: {:?}", tcx.hir.get(parent));
|
||||
match tcx.hir.get(parent) {
|
||||
NodeKind::Item(ref it) => intravisit::walk_item(&mut locator, it),
|
||||
NodeKind::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it),
|
||||
NodeKind::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it),
|
||||
Node::Item(ref it) => intravisit::walk_item(&mut locator, it),
|
||||
Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it),
|
||||
Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it),
|
||||
other => bug!(
|
||||
"{:?} is not a valid parent of an existential type item",
|
||||
other
|
||||
|
@ -1398,7 +1393,7 @@ fn find_existential_constraints<'a, 'tcx>(
|
|||
|
||||
fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> {
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::map::NodeKind::*;
|
||||
use rustc::hir::Node::*;
|
||||
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
|
||||
|
@ -1627,7 +1622,6 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::*;
|
||||
|
||||
debug!("explicit_predicates_of(def_id={:?})", def_id);
|
||||
|
@ -1644,9 +1638,9 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
let mut predicates = vec![];
|
||||
|
||||
let ast_generics = match node {
|
||||
NodeKind::TraitItem(item) => &item.generics,
|
||||
Node::TraitItem(item) => &item.generics,
|
||||
|
||||
NodeKind::ImplItem(item) => match item.node {
|
||||
Node::ImplItem(item) => match item.node {
|
||||
ImplItemKind::Existential(ref bounds) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
let anon_ty = tcx.mk_anon(def_id, substs);
|
||||
|
@ -1666,7 +1660,7 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
_ => &item.generics,
|
||||
},
|
||||
|
||||
NodeKind::Item(item) => {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Impl(_, _, defaultness, ref generics, ..) => {
|
||||
if defaultness.is_default() {
|
||||
|
@ -1718,7 +1712,7 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
NodeKind::ForeignItem(item) => match item.node {
|
||||
Node::ForeignItem(item) => match item.node {
|
||||
ForeignItemKind::Static(..) => &no_generics,
|
||||
ForeignItemKind::Fn(_, _, ref generics) => generics,
|
||||
ForeignItemKind::Type => &no_generics,
|
||||
|
@ -1878,7 +1872,7 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
// before uses of `U`. This avoids false ambiguity errors
|
||||
// in trait checking. See `setup_constraining_predicates`
|
||||
// for details.
|
||||
if let NodeKind::Item(&Item {
|
||||
if let Node::Item(&Item {
|
||||
node: ItemKind::Impl(..),
|
||||
..
|
||||
}) = node
|
||||
|
@ -2028,7 +2022,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>(
|
|||
|
||||
fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
|
||||
match tcx.hir.get_if_local(def_id) {
|
||||
Some(NodeKind::ForeignItem(..)) => true,
|
||||
Some(Node::ForeignItem(..)) => true,
|
||||
Some(_) => false,
|
||||
_ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id),
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ use rustc::middle;
|
|||
use rustc::session;
|
||||
use rustc::util;
|
||||
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::infer::InferOk;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
|
@ -187,7 +187,7 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
match main_t.sty {
|
||||
ty::FnDef(..) => {
|
||||
match tcx.hir.find(main_id) {
|
||||
Some(NodeKind::Item(it)) => {
|
||||
Some(Node::Item(it)) => {
|
||||
match it.node {
|
||||
hir::ItemKind::Fn(.., ref generics, _) => {
|
||||
let mut error = false;
|
||||
|
@ -259,7 +259,7 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
match start_t.sty {
|
||||
ty::FnDef(..) => {
|
||||
match tcx.hir.find(start_id) {
|
||||
Some(NodeKind::Item(it)) => {
|
||||
Some(Node::Item(it)) => {
|
||||
match it.node {
|
||||
hir::ItemKind::Fn(.., ref generics, _) => {
|
||||
let mut error = false;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use rustc::hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc::ty::subst::{Kind, Subst, UnpackedKind};
|
||||
|
@ -71,7 +71,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
|
|||
.as_local_node_id(item_did)
|
||||
.expect("expected local def-id");
|
||||
let item = match self.tcx.hir.get(node_id) {
|
||||
NodeKind::Item(item) => item,
|
||||
Node::Item(item) => item,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc::ty::query::Providers;
|
||||
|
@ -40,7 +40,7 @@ fn inferred_outlives_of<'a, 'tcx>(
|
|||
.expect("expected local def-id");
|
||||
|
||||
match tcx.hir.get(id) {
|
||||
NodeKind::Item(item) => match item.node {
|
||||
Node::Item(item) => match item.node {
|
||||
hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => {
|
||||
let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
use arena;
|
||||
use rustc::hir;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc::ty::{self, CrateVariancesMap, TyCtxt};
|
||||
use rustc::ty::query::Providers;
|
||||
|
@ -62,7 +62,7 @@ fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
|
|||
span_bug!(tcx.hir.span(id), "asked to compute variance for wrong kind of item")
|
||||
};
|
||||
match tcx.hir.get(id) {
|
||||
NodeKind::Item(item) => match item.node {
|
||||
Node::Item(item) => match item.node {
|
||||
hir::ItemKind::Enum(..) |
|
||||
hir::ItemKind::Struct(..) |
|
||||
hir::ItemKind::Union(..) |
|
||||
|
@ -71,25 +71,25 @@ fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
|
|||
_ => unsupported()
|
||||
},
|
||||
|
||||
NodeKind::TraitItem(item) => match item.node {
|
||||
Node::TraitItem(item) => match item.node {
|
||||
hir::TraitItemKind::Method(..) => {}
|
||||
|
||||
_ => unsupported()
|
||||
},
|
||||
|
||||
NodeKind::ImplItem(item) => match item.node {
|
||||
Node::ImplItem(item) => match item.node {
|
||||
hir::ImplItemKind::Method(..) => {}
|
||||
|
||||
_ => unsupported()
|
||||
},
|
||||
|
||||
NodeKind::ForeignItem(item) => match item.node {
|
||||
Node::ForeignItem(item) => match item.node {
|
||||
hir::ForeignItemKind::Fn(..) => {}
|
||||
|
||||
_ => unsupported()
|
||||
},
|
||||
|
||||
NodeKind::Variant(_) | NodeKind::StructCtor(_) => {}
|
||||
Node::Variant(_) | Node::StructCtor(_) => {}
|
||||
|
||||
_ => unsupported()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use syntax::attr;
|
|||
use syntax::source_map::Spanned;
|
||||
use syntax_pos::{self, Span};
|
||||
|
||||
use rustc::hir::map::NodeKind;
|
||||
use rustc::hir::Node;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::middle::privacy::AccessLevel;
|
||||
|
@ -295,7 +295,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
|
|||
if !self.view_item_stack.insert(def_node_id) { return false }
|
||||
|
||||
let ret = match tcx.hir.get(def_node_id) {
|
||||
NodeKind::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
|
||||
Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
|
||||
let prev = mem::replace(&mut self.inlining, true);
|
||||
for i in &m.item_ids {
|
||||
let i = self.cx.tcx.hir.expect_item(i.id);
|
||||
|
@ -304,13 +304,13 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
|
|||
self.inlining = prev;
|
||||
true
|
||||
}
|
||||
NodeKind::Item(it) if !glob => {
|
||||
Node::Item(it) if !glob => {
|
||||
let prev = mem::replace(&mut self.inlining, true);
|
||||
self.visit_item(it, renamed, om);
|
||||
self.inlining = prev;
|
||||
true
|
||||
}
|
||||
NodeKind::ForeignItem(it) if !glob => {
|
||||
Node::ForeignItem(it) if !glob => {
|
||||
// generate a fresh `extern {}` block if we want to inline a foreign item.
|
||||
om.foreigns.push(hir::ForeignMod {
|
||||
abi: tcx.hir.get_foreign_abi(it.id),
|
||||
|
|
|
@ -27,7 +27,7 @@ use syntax::symbol::Symbol;
|
|||
use rustc::hir;
|
||||
use rustc::hir::intravisit;
|
||||
use rustc::hir::map as hir_map;
|
||||
use hir::map::NodeKind;
|
||||
use hir::Node;
|
||||
use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext};
|
||||
use rustc::ty;
|
||||
use syntax::{ast, source_map};
|
||||
|
@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
|
|||
id: ast::NodeId) {
|
||||
|
||||
let item = match cx.tcx.hir.get(id) {
|
||||
NodeKind::Item(item) => item,
|
||||
Node::Item(item) => item,
|
||||
_ => cx.tcx.hir.expect_item(cx.tcx.hir.get_parent(id)),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue