diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 978d20ea94789..9cee05d2553f5 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -43,7 +43,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let body_exit; // Find the tables for this body. - let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id())); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(tcx.hir().body_owner(body.id())); let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { @@ -99,15 +99,15 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex { - let hir_id = self.tcx.hir().node_to_hir_id(stmt.node.id()); + let hir_id = stmt.node.hir_id(); match stmt.node { - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { let exit = self.decl(&decl, pred); self.add_ast_node(hir_id.local_id, &[exit]) } - hir::StmtKind::Expr(ref expr, _) | - hir::StmtKind::Semi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, ..) | + hir::StmtKind::Semi(ref expr, ..) => { let exit = self.expr(&expr, pred); self.add_ast_node(hir_id.local_id, &[exit]) } @@ -406,7 +406,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { args: I) -> CFGIndex { let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let ret = self.straightline(call_expr, func_or_rcvr_exit, args); - let m = self.tcx.hir().get_module_parent(call_expr.id); + let m = self.tcx.hir().get_module_parent(call_expr.hir_id); if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) { self.add_unreachable_node() } else { diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index b4a00715c0f22..ff10614788a0c 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -95,7 +95,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { /// Check any attribute. fn check_attributes(&self, item: &hir::Item, target: Target) { if target == Target::Fn || target == Target::Const { - self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.id)); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); + self.tcx.codegen_fn_attrs(def_id); } else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) { self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function") .span_label(item.span, "not a function") @@ -283,7 +284,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { fn check_stmt_attributes(&self, stmt: &hir::Stmt) { // When checking statements ignore expressions, they will be checked later - if let hir::StmtKind::Decl(_, _) = stmt.node { + if let hir::StmtKind::Decl(_, ..) = stmt.node { for attr in stmt.node.attrs() { if attr.check_name("inline") { self.check_inline(attr, &stmt.span, Target::Statement); diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 8a74c51d3f723..2140ff23400dc 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -65,10 +65,10 @@ pub enum Def { Method(DefId), AssociatedConst(DefId), - Local(ast::NodeId), - Upvar(ast::NodeId, // `NodeId` of closed over local - usize, // index in the `freevars` list of the closure - ast::NodeId), // expr node that creates the closure + Local(hir::HirId), + Upvar(hir::HirId, // `HirId` of closed over local + usize, // index in the `freevars` list of the closure + hir::HirId), // expr node that creates the closure Label(ast::NodeId), // Macro namespace diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index f633703be56d4..ad54ab0dc43f5 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -31,7 +31,7 @@ //! This order consistency is required in a few places in rustc, for //! example generator inference, and possibly also HIR borrowck. -use syntax::ast::{NodeId, CRATE_NODE_ID, Ident, Name, Attribute}; +use syntax::ast::{Ident, Name, Attribute}; use syntax_pos::Span; use hir::*; use hir::def::Def; @@ -227,7 +227,7 @@ pub trait Visitor<'v> : Sized { /////////////////////////////////////////////////////////////////////////// - fn visit_id(&mut self, _node_id: NodeId) { + fn visit_id(&mut self, _hir_id: HirId) { // Nothing to do. } fn visit_def_mention(&mut self, _def: Def) { @@ -239,8 +239,8 @@ pub trait Visitor<'v> : Sized { fn visit_ident(&mut self, ident: Ident) { walk_ident(self, ident) } - fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: NodeId) { - walk_mod(self, m, n) + fn visit_mod(&mut self, m: &'v Mod, _s: Span, h: HirId) { + walk_mod(self, m, h) } fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) @@ -284,11 +284,11 @@ pub trait Visitor<'v> : Sized { fn visit_fn_decl(&mut self, fd: &'v FnDecl) { walk_fn_decl(self, fd) } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: BodyId, s: Span, id: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: BodyId, s: Span, id: HirId) { walk_fn(self, fk, fd, b, s, id) } - fn visit_use(&mut self, path: &'v Path, id: NodeId, hir_id: HirId) { - walk_use(self, path, id, hir_id) + fn visit_use(&mut self, path: &'v Path, hir_id: HirId) { + walk_use(self, path, hir_id) } fn visit_trait_item(&mut self, ti: &'v TraitItem) { walk_trait_item(self, ti) @@ -315,7 +315,7 @@ pub trait Visitor<'v> : Sized { s: &'v VariantData, _: Name, _: &'v Generics, - _parent_id: NodeId, + _parent_id: HirId, _: Span) { walk_struct_def(self, s) } @@ -325,11 +325,11 @@ pub trait Visitor<'v> : Sized { fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, generics: &'v Generics, - item_id: NodeId, + item_id: HirId, _: Span) { walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: HirId) { walk_variant(self, v, g, item_id) } fn visit_label(&mut self, label: &'v Label) { @@ -377,19 +377,19 @@ pub trait Visitor<'v> : Sized { /// Walks the contents of a crate. See also `Crate::visit_all_items`. pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) { - visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); + visitor.visit_mod(&krate.module, krate.span, CRATE_HIR_ID); walk_list!(visitor, visit_attribute, &krate.attrs); walk_list!(visitor, visit_macro_def, &krate.exported_macros); } pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) { - visitor.visit_id(macro_def.id); + visitor.visit_id(macro_def.hir_id); visitor.visit_name(macro_def.span, macro_def.name); walk_list!(visitor, visit_attribute, ¯o_def.attrs); } -pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_node_id: NodeId) { - visitor.visit_id(mod_node_id); +pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_hir_id: HirId) { + visitor.visit_id(mod_hir_id); for &item_id in &module.item_ids { visitor.visit_nested_item(item_id); } @@ -397,7 +397,7 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_node_i pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) { for argument in &body.arguments { - visitor.visit_id(argument.id); + visitor.visit_id(argument.hir_id); visitor.visit_pat(&argument.pat); } visitor.visit_expr(&body.value); @@ -408,7 +408,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { // dominates the local's definition. walk_list!(visitor, visit_expr, &local.init); walk_list!(visitor, visit_attribute, local.attrs.iter()); - visitor.visit_id(local.id); + visitor.visit_id(local.hir_id); visitor.visit_pat(&local.pat); walk_list!(visitor, visit_ty, &local.ty); } @@ -422,7 +422,7 @@ pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) { } pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) { - visitor.visit_id(lifetime.id); + visitor.visit_id(lifetime.hir_id); match lifetime.name { LifetimeName::Param(ParamName::Plain(ident)) => { visitor.visit_ident(ident); @@ -448,7 +448,7 @@ pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V, pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef) where V: Visitor<'v> { - visitor.visit_id(trait_ref.ref_id); + visitor.visit_id(trait_ref.hir_ref_id); visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id) } @@ -457,17 +457,17 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ident(item.ident); match item.node { ItemKind::ExternCrate(orig_name) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); if let Some(orig_name) = orig_name { visitor.visit_name(item.span, orig_name); } } ItemKind::Use(ref path, _) => { - visitor.visit_use(path, item.id, item.hir_id); + visitor.visit_use(path, item.hir_id); } ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); visitor.visit_ty(typ); visitor.visit_nested_body(body); } @@ -480,26 +480,26 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { declaration, body_id, item.span, - item.id) + item.hir_id) } ItemKind::Mod(ref module) => { // `visit_mod()` takes care of visiting the `Item`'s `NodeId`. - visitor.visit_mod(module, item.span, item.id) + visitor.visit_mod(module, item.span, item.hir_id) } ItemKind::ForeignMod(ref foreign_module) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); walk_list!(visitor, visit_foreign_item, &foreign_module.items); } ItemKind::GlobalAsm(_) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); } ItemKind::Ty(ref typ, ref type_parameters) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); visitor.visit_ty(typ); visitor.visit_generics(type_parameters) } ItemKind::Existential(ExistTy {ref generics, ref bounds, impl_trait_fn}) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); walk_generics(visitor, generics); walk_list!(visitor, visit_param_bound, bounds); if let Some(impl_trait_fn) = impl_trait_fn { @@ -508,8 +508,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { } ItemKind::Enum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters); - // `visit_enum_def()` takes care of visiting the `Item`'s `NodeId`. - visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span) + // `visit_enum_def()` takes care of visiting the `Item`'s `HirId`. + visitor.visit_enum_def(enum_definition, type_parameters, item.hir_id, item.span) } ItemKind::Impl( .., @@ -518,7 +518,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ref typ, ref impl_item_refs ) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); visitor.visit_generics(type_parameters); walk_list!(visitor, visit_trait_ref, opt_trait_reference); visitor.visit_ty(typ); @@ -527,18 +527,18 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ItemKind::Struct(ref struct_definition, ref generics) | ItemKind::Union(ref struct_definition, ref generics) => { visitor.visit_generics(generics); - visitor.visit_id(item.id); - visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.id, + visitor.visit_id(item.hir_id); + visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.hir_id, item.span); } ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_trait_item_ref, trait_item_refs); } ItemKind::TraitAlias(ref generics, ref bounds) => { - visitor.visit_id(item.id); + visitor.visit_id(item.hir_id); visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); } @@ -548,16 +548,15 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path, - item_id: NodeId, hir_id: HirId) { - visitor.visit_id(item_id); + visitor.visit_id(hir_id); visitor.visit_path(path, hir_id); } pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, enum_definition: &'v EnumDef, generics: &'v Generics, - item_id: NodeId) { + item_id: HirId) { visitor.visit_id(item_id); walk_list!(visitor, visit_variant, @@ -569,7 +568,7 @@ pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant, generics: &'v Generics, - parent_item_id: NodeId) { + parent_item_id: HirId) { visitor.visit_ident(variant.node.ident); visitor.visit_variant_data(&variant.node.data, variant.node.ident.name, @@ -581,7 +580,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { - visitor.visit_id(typ.id); + visitor.visit_id(typ.hir_id); match typ.node { TyKind::Slice(ref ty) => { @@ -652,8 +651,8 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, segment: &'v PathSegment) { visitor.visit_ident(segment.ident); - if let Some(id) = segment.id { - visitor.visit_id(id); + if let Some(hir_id) = segment.hir_id { + visitor.visit_id(hir_id); } if let Some(ref args) = segment.args { visitor.visit_generic_args(path_span, args); @@ -669,13 +668,13 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, type_binding: &'v TypeBinding) { - visitor.visit_id(type_binding.id); + visitor.visit_id(type_binding.hir_id); visitor.visit_ident(type_binding.ident); visitor.visit_ty(&type_binding.ty); } pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { - visitor.visit_id(pattern.id); + visitor.visit_id(pattern.hir_id); match pattern.node { PatKind::TupleStruct(ref qpath, ref children, _) => { visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); @@ -687,7 +686,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { PatKind::Struct(ref qpath, ref fields, _) => { visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); for field in fields { - visitor.visit_id(field.node.id); + visitor.visit_id(field.node.hir_id); visitor.visit_ident(field.node.ident); visitor.visit_pat(&field.node.pat) } @@ -719,7 +718,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { } pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) { - visitor.visit_id(foreign_item.id); + visitor.visit_id(foreign_item.hir_id); visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.ident); @@ -748,7 +747,7 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB } pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) { - visitor.visit_id(param.id); + visitor.visit_id(param.hir_id); walk_list!(visitor, visit_attribute, ¶m.attrs); match param.name { ParamName::Plain(ident) => visitor.visit_ident(ident), @@ -763,7 +762,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { walk_list!(visitor, visit_generic_param, &generics.params); - visitor.visit_id(generics.where_clause.id); + visitor.visit_id(generics.where_clause.hir_id); walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates); } @@ -786,11 +785,11 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>( visitor.visit_lifetime(lifetime); walk_list!(visitor, visit_param_bound, bounds); } - &WherePredicate::EqPredicate(WhereEqPredicate{id, + &WherePredicate::EqPredicate(WhereEqPredicate{hir_id, ref lhs_ty, ref rhs_ty, ..}) => { - visitor.visit_id(id); + visitor.visit_id(hir_id); visitor.visit_ty(lhs_ty); visitor.visit_ty(rhs_ty); } @@ -825,7 +824,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl, body_id: BodyId, _span: Span, - id: NodeId) { + id: HirId) { visitor.visit_id(id); visitor.visit_fn_decl(function_declaration); walk_fn_kind(visitor, function_kind); @@ -838,12 +837,12 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai visitor.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, default) => { - visitor.visit_id(trait_item.id); + visitor.visit_id(trait_item.hir_id); visitor.visit_ty(ty); walk_list!(visitor, visit_nested_body, default); } TraitItemKind::Method(ref sig, TraitMethod::Required(ref param_names)) => { - visitor.visit_id(trait_item.id); + visitor.visit_id(trait_item.hir_id); visitor.visit_fn_decl(&sig.decl); for ¶m_name in param_names { visitor.visit_ident(param_name); @@ -857,10 +856,10 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai &sig.decl, body_id, trait_item.span, - trait_item.id); + trait_item.hir_id); } TraitItemKind::Type(ref bounds, ref default) => { - visitor.visit_id(trait_item.id); + visitor.visit_id(trait_item.hir_id); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, default); } @@ -879,7 +878,6 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItem { - id: _, hir_id: _, ident, ref vis, @@ -897,7 +895,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_generics(generics); match *node { ImplItemKind::Const(ref ty, body) => { - visitor.visit_id(impl_item.id); + visitor.visit_id(impl_item.hir_id); visitor.visit_ty(ty); visitor.visit_nested_body(body); } @@ -909,14 +907,14 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt &sig.decl, body_id, impl_item.span, - impl_item.id); + impl_item.hir_id); } ImplItemKind::Type(ref ty) => { - visitor.visit_id(impl_item.id); + visitor.visit_id(impl_item.hir_id); visitor.visit_ty(ty); } ImplItemKind::Existential(ref bounds) => { - visitor.visit_id(impl_item.id); + visitor.visit_id(impl_item.hir_id); walk_list!(visitor, visit_param_bound, bounds); } } @@ -934,12 +932,12 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &' pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) { - visitor.visit_id(struct_definition.id()); + visitor.visit_id(struct_definition.hir_id()); walk_list!(visitor, visit_struct_field, struct_definition.fields()); } pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) { - visitor.visit_id(struct_field.id); + visitor.visit_id(struct_field.hir_id); visitor.visit_vis(&struct_field.vis); visitor.visit_ident(struct_field.ident); visitor.visit_ty(&struct_field.ty); @@ -947,20 +945,20 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v } pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { - visitor.visit_id(block.id); + visitor.visit_id(block.hir_id); walk_list!(visitor, visit_stmt, &block.stmts); walk_list!(visitor, visit_expr, &block.expr); } pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { match statement.node { - StmtKind::Decl(ref declaration, id) => { - visitor.visit_id(id); + StmtKind::Decl(ref declaration, hir_id) => { + visitor.visit_id(hir_id); visitor.visit_decl(declaration) } - StmtKind::Expr(ref expression, id) | - StmtKind::Semi(ref expression, id) => { - visitor.visit_id(id); + StmtKind::Expr(ref expression, hir_id) | + StmtKind::Semi(ref expression, hir_id) => { + visitor.visit_id(hir_id); visitor.visit_expr(expression) } } @@ -974,12 +972,12 @@ pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { } pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) { - visitor.visit_id(constant.id); + visitor.visit_id(constant.hir_id); visitor.visit_nested_body(constant.body); } pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { - visitor.visit_id(expression.id); + visitor.visit_id(expression.hir_id); walk_list!(visitor, visit_attribute, expression.attrs.iter()); match expression.node { ExprKind::Box(ref subexpression) => { @@ -995,7 +993,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprKind::Struct(ref qpath, ref fields, ref optional_base) => { visitor.visit_qpath(qpath, expression.hir_id, expression.span); for field in fields { - visitor.visit_id(field.id); + visitor.visit_id(field.hir_id); visitor.visit_ident(field.ident); visitor.visit_expr(&field.expr) } @@ -1047,7 +1045,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { function_declaration, body, expression.span, - expression.id) + expression.hir_id) } ExprKind::Block(ref block, ref opt_label) => { walk_list!(visitor, visit_label, opt_label); @@ -1116,8 +1114,8 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { } pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) { - if let VisibilityKind::Restricted { ref path, id, hir_id } = vis.node { - visitor.visit_id(id); + if let VisibilityKind::Restricted { ref path, hir_id, .. } = vis.node { + visitor.visit_id(hir_id); visitor.visit_path(path, hir_id) } } @@ -1136,33 +1134,33 @@ pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) { #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] pub struct IdRange { - pub min: NodeId, - pub max: NodeId, + pub min: HirId, + pub max: HirId, } impl IdRange { pub fn max() -> IdRange { IdRange { - min: NodeId::MAX, - max: NodeId::from_u32(0), + min: HirId { owner: CRATE_DEF_INDEX, local_id: ItemLocalId::MAX }, + max: HirId { owner: CRATE_DEF_INDEX, local_id: ItemLocalId::from_u32_const(0) }, } } pub fn empty(&self) -> bool { - self.min >= self.max + self.min.local_id >= self.max.local_id } - pub fn contains(&self, id: NodeId) -> bool { - id >= self.min && id < self.max + pub fn contains(&self, id: HirId) -> bool { + id.local_id >= self.min.local_id && id.local_id < self.max.local_id } - pub fn add(&mut self, id: NodeId) { - self.min = cmp::min(self.min, id); - self.max = cmp::max(self.max, NodeId::from_u32(id.as_u32() + 1)); + pub fn add(&mut self, id: HirId) { + self.min.local_id = cmp::min(self.min.local_id, id.local_id); + self.max.local_id = cmp::max(self.max.local_id, + ItemLocalId::from_u32_const(id.local_id.as_u32() + 1)); } } - pub struct IdRangeComputingVisitor<'a, 'hir: 'a> { result: IdRange, map: &'a map::Map<'hir>, @@ -1183,7 +1181,7 @@ impl<'a, 'hir> Visitor<'hir> for IdRangeComputingVisitor<'a, 'hir> { NestedVisitorMap::OnlyBodies(&self.map) } - fn visit_id(&mut self, id: NodeId) { + fn visit_id(&mut self, id: HirId) { self.result.add(id); } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 8badcbfc1b301..58aefafd0ff53 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -740,7 +740,7 @@ impl<'a> LoweringContext<'a> { let params = lifetimes_to_define .into_iter() .map(|(span, hir_name)| { - let def_node_id = self.next_id().node_id; + let LoweredNodeId { node_id, hir_id } = self.next_id(); // Get the name we'll use to make the def-path. Note // that collisions are ok here and this shouldn't @@ -763,7 +763,7 @@ impl<'a> LoweringContext<'a> { // Add a definition for the in-band lifetime def. self.resolver.definitions().create_def_with_parent( parent_id.index, - def_node_id, + node_id, DefPathData::LifetimeParam(str_name), DefIndexAddressSpace::High, Mark::root(), @@ -771,7 +771,7 @@ impl<'a> LoweringContext<'a> { ); hir::GenericParam { - id: def_node_id, + hir_id, name: hir_name, attrs: hir_vec![], bounds: hir_vec![], @@ -954,7 +954,6 @@ impl<'a> LoweringContext<'a> { let closure_hir_id = self.lower_node_id(closure_node_id).hir_id; let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None); let generator = hir::Expr { - id: closure_node_id, hir_id: closure_hir_id, node: hir::ExprKind::Closure(capture_clause, decl, body_id, span, Some(hir::GeneratorMovability::Static)), @@ -1138,7 +1137,7 @@ impl<'a> LoweringContext<'a> { fn lower_ty_binding(&mut self, b: &TypeBinding, itctx: ImplTraitContext<'_>) -> hir::TypeBinding { hir::TypeBinding { - id: self.lower_node_id(b.id).node_id, + hir_id: self.lower_node_id(b.id).hir_id, ident: b.ident, ty: self.lower_ty(&b.ty, itctx), span: b.span, @@ -1260,7 +1259,7 @@ impl<'a> LoweringContext<'a> { ) } ImplTraitContext::Universal(in_band_ty_params) => { - self.lower_node_id(def_node_id); + let hir_id = self.lower_node_id(def_node_id).hir_id; // Add a definition for the in-band `Param`. let def_index = self .resolver @@ -1275,7 +1274,7 @@ impl<'a> LoweringContext<'a> { // Set the name to `impl Bound1 + Bound2`. let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span); in_band_ty_params.push(hir::GenericParam { - id: def_node_id, + hir_id, name: ParamName::Plain(ident), pure_wrt_drop: false, attrs: hir_vec![], @@ -1324,12 +1323,10 @@ impl<'a> LoweringContext<'a> { TyKind::Mac(_) => panic!("TyMac should have been expanded by now."), }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id); hir::Ty { - id: node_id, node: kind, span: t.span, - hir_id, + hir_id: self.lower_node_id(t.id).hir_id, } } @@ -1371,7 +1368,7 @@ impl<'a> LoweringContext<'a> { generics: hir::Generics { params: lifetime_defs, where_clause: hir::WhereClause { - id: lctx.next_id().node_id, + hir_id: lctx.next_id().hir_id, predicates: Vec::new().into(), }, span, @@ -1385,7 +1382,6 @@ impl<'a> LoweringContext<'a> { trace!("exist ty def index: {:#?}", exist_ty_def_index); let exist_ty_item = hir::Item { - id: exist_ty_id.node_id, hir_id: exist_ty_id.hir_id, ident: keywords::Invalid.ident(), attrs: Default::default(), @@ -1505,7 +1501,7 @@ impl<'a> LoweringContext<'a> { self.already_defined_lifetimes.insert(name); self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: self.context.next_id().node_id, + hir_id: self.context.next_id().hir_id, span: lifetime.span, name, })); @@ -1537,7 +1533,7 @@ impl<'a> LoweringContext<'a> { }; self.output_lifetime_params.push(hir::GenericParam { - id: def_node_id, + hir_id: self.context.next_id().hir_id, name, span: lifetime.span, pure_wrt_drop: false, @@ -1875,19 +1871,20 @@ impl<'a> LoweringContext<'a> { } let def = self.expect_full_def(segment.id); - let id = if let Some(owner) = explicit_owner { + let lowered_id = if let Some(owner) = explicit_owner { self.lower_node_id_with_owner(segment.id, owner) } else { self.lower_node_id(segment.id) }; debug!( "lower_path_segment: ident={:?} original-id={:?} new-id={:?}", - segment.ident, segment.id, id, + segment.ident, segment.id, lowered_id, ); hir::PathSegment::new( segment.ident, - Some(id.node_id), + Some(lowered_id.node_id), + Some(lowered_id.hir_id), Some(def), generic_args, infer_types, @@ -1931,8 +1928,7 @@ impl<'a> LoweringContext<'a> { .map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())) .collect(); let mk_tup = |this: &mut Self, tys, span| { - let LoweredNodeId { node_id, hir_id } = this.next_id(); - hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span } + hir::Ty { node: hir::TyKind::Tup(tys), hir_id: this.next_id().hir_id, span } }; ( @@ -1940,7 +1936,7 @@ impl<'a> LoweringContext<'a> { args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))], bindings: hir_vec![ hir::TypeBinding { - id: this.next_id().node_id, + hir_id: this.next_id().hir_id, ident: Ident::from_str(FN_OUTPUT_NAME), ty: output .as_ref() @@ -1958,7 +1954,6 @@ impl<'a> LoweringContext<'a> { } fn lower_local(&mut self, l: &Local) -> (P, SmallVec<[hir::ItemId; 1]>) { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id); let mut ids = SmallVec::<[hir::ItemId; 1]>::new(); if self.sess.features_untracked().impl_trait_in_bindings { if let Some(ref ty) = l.ty { @@ -1968,8 +1963,7 @@ impl<'a> LoweringContext<'a> { } let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0); (P(hir::Local { - id: node_id, - hir_id, + hir_id: self.lower_node_id(l.id).hir_id, ty: l.ty .as_ref() .map(|t| self.lower_ty(t, @@ -1995,10 +1989,8 @@ impl<'a> LoweringContext<'a> { } fn lower_arg(&mut self, arg: &Arg) -> hir::Arg { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(arg.id); hir::Arg { - id: node_id, - hir_id, + hir_id: self.lower_node_id(arg.id).hir_id, pat: self.lower_pat(&arg.pat), } } @@ -2267,10 +2259,8 @@ impl<'a> LoweringContext<'a> { this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id))) } FunctionRetTy::Default(span) => { - let LoweredNodeId { node_id, hir_id } = this.next_id(); P(hir::Ty { - id: node_id, - hir_id: hir_id, + hir_id: this.next_id().hir_id, node: hir::TyKind::Tup(hir_vec![]), span: *span, }) @@ -2283,7 +2273,7 @@ impl<'a> LoweringContext<'a> { bindings: hir_vec![hir::TypeBinding { ident: Ident::from_str(FN_OUTPUT_NAME), ty: output_ty, - id: this.next_id().node_id, + hir_id: this.next_id().hir_id, span, }], parenthesized: false, @@ -2292,14 +2282,12 @@ impl<'a> LoweringContext<'a> { let future_path = this.std_path(span, &["future", "Future"], Some(future_params), false); - let LoweredNodeId { node_id, hir_id } = this.next_id(); let mut bounds = vec![ hir::GenericBound::Trait( hir::PolyTraitRef { trait_ref: hir::TraitRef { path: future_path, - ref_id: node_id, - hir_ref_id: hir_id, + hir_ref_id: this.next_id().hir_id, }, bound_generic_params: hir_vec![], span, @@ -2310,18 +2298,16 @@ impl<'a> LoweringContext<'a> { if let Some((name, span)) = bound_lifetime { bounds.push(hir::GenericBound::Outlives( - hir::Lifetime { id: this.next_id().node_id, name, span })); + hir::Lifetime { hir_id: this.next_id().hir_id, name, span })); } hir::HirVec::from(bounds) }); - let LoweredNodeId { node_id, hir_id } = self.next_id(); let impl_trait_ty = P(hir::Ty { - id: node_id, node: impl_trait_ty, span, - hir_id, + hir_id: self.next_id().hir_id, }); hir::FunctionRetTy::Return(impl_trait_ty) @@ -2378,7 +2364,7 @@ impl<'a> LoweringContext<'a> { name: hir::LifetimeName, ) -> hir::Lifetime { hir::Lifetime { - id: self.lower_node_id(id).node_id, + hir_id: self.lower_node_id(id).hir_id, span, name: name, } @@ -2422,7 +2408,7 @@ impl<'a> LoweringContext<'a> { hir::LifetimeName::Error => ParamName::Error, }; let param = hir::GenericParam { - id: lt.id, + hir_id: lt.hir_id, name: param_name, span: lt.span, pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), @@ -2456,7 +2442,7 @@ impl<'a> LoweringContext<'a> { } hir::GenericParam { - id: self.lower_node_id(param.id).node_id, + hir_id: self.lower_node_id(param.id).hir_id, name: hir::ParamName::Plain(ident), pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), attrs: self.lower_attrs(¶m.attrs), @@ -2547,7 +2533,7 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::ReportError, |this| { hir::WhereClause { - id: this.lower_node_id(wc.id).node_id, + hir_id: this.lower_node_id(wc.id).hir_id, predicates: wc.predicates .iter() .map(|predicate| this.lower_where_predicate(predicate)) @@ -2607,7 +2593,7 @@ impl<'a> LoweringContext<'a> { ref rhs_ty, span, }) => hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { - id: self.lower_node_id(id).node_id, + hir_id: self.lower_node_id(id).hir_id, lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()), rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()), span, @@ -2623,7 +2609,7 @@ impl<'a> LoweringContext<'a> { .enumerate() .map(|f| self.lower_struct_field(f)) .collect(), - self.lower_node_id(id).node_id, + self.lower_node_id(id).hir_id ), VariantData::Tuple(ref fields, id) => hir::VariantData::Tuple( fields @@ -2631,9 +2617,9 @@ impl<'a> LoweringContext<'a> { .enumerate() .map(|f| self.lower_struct_field(f)) .collect(), - self.lower_node_id(id).node_id, + self.lower_node_id(id).hir_id ), - VariantData::Unit(id) => hir::VariantData::Unit(self.lower_node_id(id).node_id), + VariantData::Unit(id) => hir::VariantData::Unit(self.lower_node_id(id).hir_id), } } @@ -2642,11 +2628,10 @@ impl<'a> LoweringContext<'a> { hir::QPath::Resolved(None, path) => path.and_then(|path| path), qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath), }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id); + hir::TraitRef { path, - ref_id: node_id, - hir_ref_id: hir_id, + hir_ref_id: self.lower_node_id(p.ref_id).hir_id, } } @@ -2675,7 +2660,7 @@ impl<'a> LoweringContext<'a> { fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField { hir::StructField { span: f.span, - id: self.lower_node_id(f.id).node_id, + hir_id: self.lower_node_id(f.id).hir_id, ident: match f.ident { Some(ident) => ident, // FIXME(jseyfried): positional field hygiene @@ -2689,7 +2674,7 @@ impl<'a> LoweringContext<'a> { fn lower_field(&mut self, f: &Field) -> hir::Field { hir::Field { - id: self.next_id().node_id, + hir_id: self.next_id().hir_id, ident: f.ident, expr: P(self.lower_expr(&f.expr)), span: f.span, @@ -2726,11 +2711,8 @@ impl<'a> LoweringContext<'a> { } } - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id); - P(hir::Block { - id: node_id, - hir_id, + hir_id: self.lower_node_id(b.id).hir_id, stmts: stmts.into(), expr, rules: self.lower_block_check_mode(&b.rules), @@ -3041,13 +3023,11 @@ impl<'a> LoweringContext<'a> { hir::VisibilityKind::Public => hir::VisibilityKind::Public, hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, - hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => { - let id = this.next_id(); + hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { let path = this.renumber_segment_ids(path); hir::VisibilityKind::Restricted { path, - id: id.node_id, - hir_id: id.hir_id, + hir_id: this.next_id().hir_id, } } }; @@ -3056,7 +3036,6 @@ impl<'a> LoweringContext<'a> { this.insert_item( new_id.node_id, hir::Item { - id: new_id.node_id, hir_id: new_id.hir_id, ident, attrs: attrs.clone(), @@ -3148,13 +3127,11 @@ impl<'a> LoweringContext<'a> { hir::VisibilityKind::Public => hir::VisibilityKind::Public, hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, - hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => { - let id = this.next_id(); + hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { let path = this.renumber_segment_ids(path); hir::VisibilityKind::Restricted { path: path, - id: id.node_id, - hir_id: id.hir_id, + hir_id: this.next_id().hir_id, } } }; @@ -3163,7 +3140,6 @@ impl<'a> LoweringContext<'a> { this.insert_item( new_id, hir::Item { - id: new_id, hir_id: new_hir_id, ident, attrs: attrs.clone(), @@ -3269,7 +3245,6 @@ impl<'a> LoweringContext<'a> { }; hir::TraitItem { - id: node_id, hir_id, ident: i.ident, attrs: self.lower_attrs(&i.attrs), @@ -3345,7 +3320,6 @@ impl<'a> LoweringContext<'a> { }; hir::ImplItem { - id: node_id, hir_id, ident: i.ident, attrs: self.lower_attrs(&i.attrs), @@ -3443,15 +3417,17 @@ impl<'a> LoweringContext<'a> { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); let attrs = self.lower_attrs(&i.attrs); + if let ItemKind::MacroDef(ref def) = i.node { if !def.legacy || attr::contains_name(&i.attrs, "macro_export") || attr::contains_name(&i.attrs, "rustc_doc_only_macro") { let body = self.lower_token_stream(def.stream()); + let hir_id = self.lower_node_id(i.id).hir_id; self.exported_macros.push(hir::MacroDef { name: ident.name, vis, attrs, - id: i.id, + hir_id, span: i.span, body, legacy: def.legacy, @@ -3462,11 +3438,8 @@ impl<'a> LoweringContext<'a> { let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node); - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); - Some(hir::Item { - id: node_id, - hir_id, + hir_id: self.lower_node_id(i.id).hir_id, ident, attrs, node, @@ -3476,10 +3449,11 @@ impl<'a> LoweringContext<'a> { } fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem { - let node_id = self.lower_node_id(i.id).node_id; + let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); let def_id = self.resolver.definitions().local_def_id(node_id); + hir::ForeignItem { - id: node_id, + hir_id, ident: i.ident, attrs: self.lower_attrs(&i.attrs), node: match i.node { @@ -3606,6 +3580,8 @@ impl<'a> LoweringContext<'a> { } fn lower_pat(&mut self, p: &Pat) -> P { + let hir_id = self.lower_node_id(p.id).hir_id; + let node = match p.node { PatKind::Wild => hir::PatKind::Wild, PatKind::Ident(ref binding_mode, ident, ref sub) => { @@ -3614,7 +3590,7 @@ impl<'a> LoweringContext<'a> { def @ None | def @ Some(Def::Local(_)) => { let canonical_id = match def { Some(Def::Local(id)) => id, - _ => p.id, + _ => hir_id, }; hir::PatKind::Binding( self.lower_binding_mode(binding_mode), @@ -3672,7 +3648,7 @@ impl<'a> LoweringContext<'a> { .map(|f| Spanned { span: f.span, node: hir::FieldPat { - id: self.next_id().node_id, + hir_id: self.next_id().hir_id, ident: f.node.ident, pat: self.lower_pat(&f.node.pat), is_shorthand: f.node.is_shorthand, @@ -3702,9 +3678,7 @@ impl<'a> LoweringContext<'a> { PatKind::Mac(_) => panic!("Shouldn't exist here"), }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id); P(hir::Pat { - id: node_id, hir_id, node, span: p.span, @@ -3720,10 +3694,8 @@ impl<'a> LoweringContext<'a> { fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst { self.with_new_scopes(|this| { - let LoweredNodeId { node_id, hir_id } = this.lower_node_id(c.id); hir::AnonConst { - id: node_id, - hir_id, + hir_id: this.lower_node_id(c.id).hir_id, body: this.lower_body(None, |this| this.lower_expr(&c.value)), } }) @@ -3798,12 +3770,10 @@ impl<'a> LoweringContext<'a> { // Wrap the `if let` expr in a block. let span = els.span; let els = P(self.lower_expr(els)); - let LoweredNodeId { node_id, hir_id } = self.next_id(); let blk = P(hir::Block { stmts: hir_vec![], expr: Some(els), - id: node_id, - hir_id, + hir_id: self.next_id().hir_id, rules: hir::DefaultBlock, span, targeted_by_break: false, @@ -3840,14 +3810,12 @@ impl<'a> LoweringContext<'a> { let mut block = this.lower_block(body, true).into_inner(); let tail = block.expr.take().map_or_else( || { - let LoweredNodeId { node_id, hir_id } = this.next_id(); let span = this.sess.source_map().end_point(unstable_span); hir::Expr { - id: node_id, span, node: hir::ExprKind::Tup(hir_vec![]), attrs: ThinVec::new(), - hir_id, + hir_id: this.next_id().hir_id, } }, |x: P| x.into_inner(), @@ -4028,11 +3996,8 @@ impl<'a> LoweringContext<'a> { let struct_path = self.std_path(e.span, &struct_path, None, is_unit); let struct_path = hir::QPath::Resolved(None, P(struct_path)); - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); - return hir::Expr { - id: node_id, - hir_id, + hir_id: self.lower_node_id(e.id).hir_id, node: if is_unit { hir::ExprKind::Path(struct_path) } else { @@ -4286,8 +4251,8 @@ impl<'a> LoweringContext<'a> { let pat_arm = { let val_ident = self.str_to_ident("val"); let val_pat = self.pat_ident(pat.span, val_ident); - let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id)); - let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id)); + let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.hir_id)); + let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.hir_id)); let assign = P(self.expr( pat.span, hir::ExprKind::Assign(next_expr, val_expr), @@ -4314,7 +4279,7 @@ impl<'a> LoweringContext<'a> { // `match ::std::iter::Iterator::next(&mut iter) { ... }` let match_expr = { - let iter = P(self.expr_ident(head_sp, iter, iter_pat.id)); + let iter = P(self.expr_ident(head_sp, iter, iter_pat.hir_id)); let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter); let next_path = &["iter", "Iterator", "next"]; let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new())); @@ -4331,12 +4296,13 @@ impl<'a> LoweringContext<'a> { ThinVec::new(), )) }; + let match_stmt = respan( head_sp, - hir::StmtKind::Expr(match_expr, self.next_id().node_id) + hir::StmtKind::Expr(match_expr, self.next_id().hir_id) ); - let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id)); + let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.hir_id)); // `let mut __next` let next_let = self.stmt_let_pat( @@ -4357,9 +4323,10 @@ impl<'a> LoweringContext<'a> { let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false)); let body_expr = P(self.expr_block(body_block, ThinVec::new())); + let body_stmt = respan( body.span, - hir::StmtKind::Expr(body_expr, self.next_id().node_id) + hir::StmtKind::Expr(body_expr, self.next_id().hir_id) ); let loop_block = P(self.block_all( @@ -4374,10 +4341,9 @@ impl<'a> LoweringContext<'a> { self.lower_label(opt_label), hir::LoopSource::ForLoop, ); - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); + let loop_expr = P(hir::Expr { - id: node_id, - hir_id, + hir_id: self.lower_node_id(e.id).hir_id, node: loop_expr, span: e.span, attrs: ThinVec::new(), @@ -4461,7 +4427,7 @@ impl<'a> LoweringContext<'a> { let val_expr = P(self.expr_ident_with_attrs( e.span, val_ident, - val_pat.id, + val_pat.hir_id, ThinVec::from(attrs.clone()), )); let ok_pat = self.pat_ok(e.span, val_pat); @@ -4478,7 +4444,7 @@ impl<'a> LoweringContext<'a> { let path = &["convert", "From", "from"]; let from = P(self.expr_std_path( e.span, path, None, ThinVec::new())); - let err_expr = self.expr_ident(e.span, err_ident, err_local.id); + let err_expr = self.expr_ident(e.span, err_ident, err_local.hir_id); self.expr_call(e.span, from, hir_vec![err_expr]) }; @@ -4516,11 +4482,8 @@ impl<'a> LoweringContext<'a> { ExprKind::Mac(_) => panic!("Shouldn't exist here"), }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); - hir::Expr { - id: node_id, - hir_id, + hir_id: self.lower_node_id(e.id).hir_id, node: kind, span: e.span, attrs: e.attrs.clone(), @@ -4539,18 +4502,19 @@ impl<'a> LoweringContext<'a> { node: hir::DeclKind::Item(item_id), span: s.span, }), - self.next_id().node_id, + self.next_id().hir_id ), span: s.span, }) .collect(); + ids.push(Spanned { node: hir::StmtKind::Decl( P(Spanned { node: hir::DeclKind::Local(l), span: s.span, }), - self.lower_node_id(s.id).node_id, + self.lower_node_id(s.id).hir_id ), span: s.span, }); @@ -4568,19 +4532,19 @@ impl<'a> LoweringContext<'a> { span: s.span, }), id.take() - .map(|id| self.lower_node_id(id).node_id) - .unwrap_or_else(|| self.next_id().node_id), + .map(|id| self.lower_node_id(id).hir_id) + .unwrap_or_else(|| self.next_id().hir_id) ), span: s.span, }) .collect(); } StmtKind::Expr(ref e) => Spanned { - node: hir::StmtKind::Expr(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Expr(P(self.lower_expr(e)), self.lower_node_id(s.id).hir_id), span: s.span, }, StmtKind::Semi(ref e) => Spanned { - node: hir::StmtKind::Semi(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Semi(P(self.lower_expr(e)), self.lower_node_id(s.id).hir_id), span: s.span, }, StmtKind::Mac(..) => panic!("Shouldn't exist here"), @@ -4622,7 +4586,6 @@ impl<'a> LoweringContext<'a> { ParamMode::Explicit, explicit_owner, )), - id: lowered_id.node_id, hir_id: lowered_id.hir_id, } }, @@ -4693,7 +4656,7 @@ impl<'a> LoweringContext<'a> { fn field(&mut self, ident: Ident, expr: P, span: Span) -> hir::Field { hir::Field { - id: self.next_id().node_id, + hir_id: self.next_id().hir_id, ident, span, expr, @@ -4715,7 +4678,7 @@ impl<'a> LoweringContext<'a> { self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new()) } - fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr { + fn expr_ident(&mut self, span: Span, ident: Ident, binding: hir::HirId) -> hir::Expr { self.expr_ident_with_attrs(span, ident, binding, ThinVec::new()) } @@ -4723,7 +4686,7 @@ impl<'a> LoweringContext<'a> { &mut self, span: Span, ident: Ident, - binding: NodeId, + binding: hir::HirId, attrs: ThinVec, ) -> hir::Expr { let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( @@ -4776,10 +4739,8 @@ impl<'a> LoweringContext<'a> { } fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec) -> hir::Expr { - let LoweredNodeId { node_id, hir_id } = self.next_id(); hir::Expr { - id: node_id, - hir_id, + hir_id: self.next_id().hir_id, node, span, attrs, @@ -4793,20 +4754,17 @@ impl<'a> LoweringContext<'a> { pat: P, source: hir::LocalSource, ) -> hir::Stmt { - let LoweredNodeId { node_id, hir_id } = self.next_id(); - let local = P(hir::Local { pat, ty: None, init: ex, - id: node_id, - hir_id, + hir_id: self.next_id().hir_id, span: sp, attrs: ThinVec::new(), source, }); let decl = respan(sp, hir::DeclKind::Local(local)); - respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id)) + respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().hir_id)) } fn stmt_let( @@ -4815,13 +4773,13 @@ impl<'a> LoweringContext<'a> { mutbl: bool, ident: Ident, ex: P, - ) -> (hir::Stmt, NodeId) { + ) -> (hir::Stmt, hir::HirId) { let pat = if mutbl { self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable) } else { self.pat_ident(sp, ident) }; - let pat_id = pat.id; + let pat_id = pat.hir_id; ( self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal), pat_id, @@ -4838,13 +4796,10 @@ impl<'a> LoweringContext<'a> { stmts: hir::HirVec, expr: Option>, ) -> hir::Block { - let LoweredNodeId { node_id, hir_id } = self.next_id(); - hir::Block { stmts, expr, - id: node_id, - hir_id, + hir_id: self.next_id().hir_id, rules: hir::DefaultBlock, span, targeted_by_break: false, @@ -4893,12 +4848,11 @@ impl<'a> LoweringContext<'a> { ident: Ident, bm: hir::BindingAnnotation, ) -> P { - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let hir_id = self.next_id().hir_id; P(hir::Pat { - id: node_id, hir_id, - node: hir::PatKind::Binding(bm, node_id, ident.with_span_pos(span), None), + node: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None), span, }) } @@ -4908,10 +4862,8 @@ impl<'a> LoweringContext<'a> { } fn pat(&mut self, span: Span, pat: hir::PatKind) -> P { - let LoweredNodeId { node_id, hir_id } = self.next_id(); P(hir::Pat { - id: node_id, - hir_id, + hir_id: self.next_id().hir_id, node: pat, span, }) @@ -4951,7 +4903,6 @@ impl<'a> LoweringContext<'a> { bound_generic_params: hir::HirVec::new(), trait_ref: hir::TraitRef { path: path.and_then(|path| path), - ref_id: id.node_id, hir_ref_id: id.hir_id, }, span, @@ -4968,7 +4919,6 @@ impl<'a> LoweringContext<'a> { _ => hir::TyKind::Path(qpath), }; hir::Ty { - id: id.node_id, hir_id: id.hir_id, node, span, @@ -4984,8 +4934,9 @@ impl<'a> LoweringContext<'a> { // `'f`. AnonymousLifetimeMode::CreateParameter => { let fresh_name = self.collect_fresh_in_band_lifetime(span); + hir::Lifetime { - id: self.next_id().node_id, + hir_id: self.next_id().hir_id, span, name: hir::LifetimeName::Param(fresh_name), } @@ -5086,7 +5037,7 @@ impl<'a> LoweringContext<'a> { fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime { hir::Lifetime { - id: self.next_id().node_id, + hir_id: self.next_id().hir_id, span, name: hir::LifetimeName::Implicit, } diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index f61b8551927bb..ae28fe6ae2a27 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -13,9 +13,9 @@ use hir as ast; use hir::map; -use hir::{Expr, FnDecl, Node}; +use hir::{Expr, FnDecl, HirId, Node}; use hir::intravisit::FnKind; -use syntax::ast::{Attribute, Ident, NodeId}; +use syntax::ast::{Attribute, Ident}; use syntax_pos::Span; /// An FnLikeNode is a Node that is like a fn, in that it has a decl @@ -75,16 +75,16 @@ pub enum Code<'a> { } impl<'a> Code<'a> { - pub fn id(&self) -> NodeId { + pub fn id(&self) -> HirId { match *self { Code::FnLike(node) => node.id(), - Code::Expr(block) => block.id, + Code::Expr(block) => block.hir_id, } } /// Attempts to construct a Code from presumed FnLike or Expr node input. - pub fn from_node(map: &map::Map<'a>, id: NodeId) -> Option> { - match map.get(id) { + pub fn from_node(map: &map::Map<'a>, id: HirId) -> Option> { + match map.get_by_hir_id(id) { map::Node::Block(_) => { // Use the parent, hopefully an expression node. Code::from_node(map, map.get_parent_node(id)) @@ -104,7 +104,7 @@ struct ItemFnParts<'a> { vis: &'a ast::Visibility, generics: &'a ast::Generics, body: ast::BodyId, - id: NodeId, + id: HirId, span: Span, attrs: &'a [Attribute], } @@ -114,13 +114,13 @@ struct ItemFnParts<'a> { struct ClosureParts<'a> { decl: &'a FnDecl, body: ast::BodyId, - id: NodeId, + id: HirId, span: Span, attrs: &'a [Attribute], } impl<'a> ClosureParts<'a> { - fn new(d: &'a FnDecl, b: ast::BodyId, id: NodeId, s: Span, attrs: &'a [Attribute]) -> Self { + fn new(d: &'a FnDecl, b: ast::BodyId, id: HirId, s: Span, attrs: &'a [Attribute]) -> Self { ClosureParts { decl: d, body: b, @@ -168,7 +168,7 @@ impl<'a> FnLikeNode<'a> { |c: ClosureParts<'_>| c.span) } - pub fn id(self) -> NodeId { + pub fn id(self) -> HirId { self.handle(|i: ItemFnParts<'_>| i.id, |id, _, _: &'a ast::MethodSig, _, _, _, _| id, |c: ClosureParts<'_>| c.id) @@ -213,7 +213,7 @@ impl<'a> FnLikeNode<'a> { fn handle(self, item_fn: I, method: M, closure: C) -> A where I: FnOnce(ItemFnParts<'a>) -> A, - M: FnOnce(NodeId, + M: FnOnce(HirId, Ident, &'a ast::MethodSig, Option<&'a ast::Visibility>, @@ -227,7 +227,7 @@ impl<'a> FnLikeNode<'a> { map::Node::Item(i) => match i.node { ast::ItemKind::Fn(ref decl, header, ref generics, block) => item_fn(ItemFnParts { - id: i.id, + id: i.hir_id, ident: i.ident, decl: &decl, body: block, @@ -241,21 +241,21 @@ impl<'a> FnLikeNode<'a> { }, 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) + method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs) } _ => bug!("trait method FnLikeNode that is not fn-like"), }, 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) + method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs) } _ => bug!("impl method FnLikeNode that is not fn-like") } }, 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)), + closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)), _ => bug!("expr FnLikeNode that is not fn-like"), }, _ => bug!("other FnLikeNode that is not fn-like"), diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index ae9bb37842990..90976e4346868 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -8,7 +8,6 @@ use middle::cstore::CrateStore; use session::CrateDisambiguator; use session::Session; use std::iter::repeat; -use syntax::ast::{NodeId, CRATE_NODE_ID}; use syntax::source_map::SourceMap; use syntax_pos::Span; @@ -26,7 +25,7 @@ pub(super) struct NodeCollector<'a, 'hir> { /// The node map map: Vec>>, /// The parent of this node - parent_node: NodeId, + parent_hir: HirId, // These fields keep track of the currently relevant DepNodes during // the visitor's traversal. @@ -144,7 +143,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { krate, source_map: sess.source_map(), map: repeat(None).take(sess.current_node_id_count()).collect(), - parent_node: CRATE_NODE_ID, + parent_hir: CRATE_HIR_ID, current_signature_dep_index: root_mod_sig_dep_index, current_full_dep_index: root_mod_full_dep_index, current_dep_node_owner: CRATE_DEF_INDEX, @@ -154,8 +153,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { hcx, hir_body_nodes, }; - collector.insert_entry(CRATE_NODE_ID, Entry { - parent: CRATE_NODE_ID, + collector.insert_entry(CRATE_HIR_ID, Entry { + parent_hir: CRATE_HIR_ID, dep_node: root_mod_sig_dep_index, node: Node::Crate, }); @@ -218,14 +217,15 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { (self.map, svh) } - fn insert_entry(&mut self, id: NodeId, entry: Entry<'hir>) { + fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) { debug!("hir_map: {:?} => {:?}", id, entry); - self.map[id.as_usize()] = Some(entry); + + self.map[id.local_id.as_usize()] = Some(entry); } - fn insert(&mut self, span: Span, id: NodeId, node: Node<'hir>) { + fn insert(&mut self, span: Span, id: HirId, node: Node<'hir>) { let entry = Entry { - parent: self.parent_node, + parent_hir: self.parent_hir, dep_node: if self.currently_in_body { self.current_full_dep_index } else { @@ -237,47 +237,30 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { // Make sure that the DepNode of some node coincides with the HirId // owner of that node. if cfg!(debug_assertions) { - let hir_id = self.definitions.node_to_hir_id(id); - - if hir_id.owner != self.current_dep_node_owner { - let node_str = match self.definitions.opt_def_index(id) { - Some(def_index) => { - self.definitions.def_path(def_index).to_string_no_crate() - } - None => format!("{:?}", node) - }; - - let forgot_str = if hir_id == ::hir::DUMMY_HIR_ID { - format!("\nMaybe you forgot to lower the node id {:?}?", id) - } else { - String::new() - }; - + if id.owner != self.current_dep_node_owner { span_bug!( span, - "inconsistent DepNode at `{:?}` for `{}`: \ - current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}", + "inconsistent DepNode at `{:?}` for `{:?}`: \ + current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", self.source_map.span_to_string(span), - node_str, + id, self.definitions .def_path(self.current_dep_node_owner) .to_string_no_crate(), self.current_dep_node_owner, - self.definitions.def_path(hir_id.owner).to_string_no_crate(), - hir_id.owner, - forgot_str, + self.definitions.def_path(id.owner).to_string_no_crate(), + id.owner, ) } } - self.insert_entry(id, entry); } - fn with_parent(&mut self, parent_id: NodeId, f: F) { - let parent_node = self.parent_node; - self.parent_node = parent_id; + fn with_parent(&mut self, parent_id: HirId, f: F) { + let parent_hir = self.parent_hir; + self.parent_hir = parent_id; f(self); - self.parent_node = parent_node; + self.parent_hir = parent_hir; } fn with_dep_node_owner>, @@ -343,15 +326,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { fn visit_item(&mut self, i: &'hir Item) { debug!("visit_item: {:?}", i); - 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.span, i.id, Node::Item(i)); - this.with_parent(i.id, |this| { + this.insert(i.span, i.hir_id, Node::Item(i)); + this.with_parent(i.hir_id, |this| { if let ItemKind::Struct(ref struct_def, _) = i.node { // If this is a tuple-like struct, register the constructor. if !struct_def.is_struct() { - this.insert(i.span, struct_def.id(), Node::StructCtor(struct_def)); + this.insert(i.span, struct_def.hir_id(), Node::StructCtor(struct_def)); } } intravisit::walk_item(this, i); @@ -360,37 +341,33 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) { - self.insert(foreign_item.span, foreign_item.id, Node::ForeignItem(foreign_item)); + self.insert(foreign_item.span, foreign_item.hir_id, Node::ForeignItem(foreign_item)); - self.with_parent(foreign_item.id, |this| { + self.with_parent(foreign_item.hir_id, |this| { intravisit::walk_foreign_item(this, foreign_item); }); } fn visit_generic_param(&mut self, param: &'hir GenericParam) { - self.insert(param.span, param.id, Node::GenericParam(param)); + self.insert(param.span, param.hir_id, Node::GenericParam(param)); intravisit::walk_generic_param(self, param); } fn visit_trait_item(&mut self, ti: &'hir TraitItem) { - 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.span, ti.id, Node::TraitItem(ti)); + this.insert(ti.span, ti.hir_id, Node::TraitItem(ti)); - this.with_parent(ti.id, |this| { + this.with_parent(ti.hir_id, |this| { intravisit::walk_trait_item(this, ti); }); }); } fn visit_impl_item(&mut self, ii: &'hir ImplItem) { - 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.span, ii.id, Node::ImplItem(ii)); + this.insert(ii.span, ii.hir_id, Node::ImplItem(ii)); - this.with_parent(ii.id, |this| { + this.with_parent(ii.hir_id, |this| { intravisit::walk_impl_item(this, ii); }); }); @@ -402,31 +379,31 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } else { Node::Pat(pat) }; - self.insert(pat.span, pat.id, node); + self.insert(pat.span, pat.hir_id, node); - self.with_parent(pat.id, |this| { + self.with_parent(pat.hir_id, |this| { intravisit::walk_pat(this, pat); }); } fn visit_anon_const(&mut self, constant: &'hir AnonConst) { - self.insert(DUMMY_SP, constant.id, Node::AnonConst(constant)); + self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant)); - self.with_parent(constant.id, |this| { + self.with_parent(constant.hir_id, |this| { intravisit::walk_anon_const(this, constant); }); } fn visit_expr(&mut self, expr: &'hir Expr) { - self.insert(expr.span, expr.id, Node::Expr(expr)); + self.insert(expr.span, expr.hir_id, Node::Expr(expr)); - self.with_parent(expr.id, |this| { + self.with_parent(expr.hir_id, |this| { intravisit::walk_expr(this, expr); }); } fn visit_stmt(&mut self, stmt: &'hir Stmt) { - let id = stmt.node.id(); + let id = stmt.node.hir_id(); self.insert(stmt.span, id, Node::Stmt(stmt)); self.with_parent(id, |this| { @@ -435,50 +412,50 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment) { - if let Some(id) = path_segment.id { + if let Some(id) = path_segment.hir_id { self.insert(path_span, id, Node::PathSegment(path_segment)); } intravisit::walk_path_segment(self, path_span, path_segment); } fn visit_ty(&mut self, ty: &'hir Ty) { - self.insert(ty.span, ty.id, Node::Ty(ty)); + self.insert(ty.span, ty.hir_id, Node::Ty(ty)); - self.with_parent(ty.id, |this| { + self.with_parent(ty.hir_id, |this| { intravisit::walk_ty(this, ty); }); } fn visit_trait_ref(&mut self, tr: &'hir TraitRef) { - self.insert(tr.path.span, tr.ref_id, Node::TraitRef(tr)); + self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr)); - self.with_parent(tr.ref_id, |this| { + self.with_parent(tr.hir_ref_id, |this| { intravisit::walk_trait_ref(this, tr); }); } fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl, - b: BodyId, s: Span, id: NodeId) { - assert_eq!(self.parent_node, id); + b: BodyId, s: Span, id: HirId) { + assert_eq!(self.parent_hir, id); intravisit::walk_fn(self, fk, fd, b, s, id); } fn visit_block(&mut self, block: &'hir Block) { - self.insert(block.span, block.id, Node::Block(block)); - self.with_parent(block.id, |this| { + self.insert(block.span, block.hir_id, Node::Block(block)); + self.with_parent(block.hir_id, |this| { intravisit::walk_block(this, block); }); } fn visit_local(&mut self, l: &'hir Local) { - self.insert(l.span, l.id, Node::Local(l)); - self.with_parent(l.id, |this| { + self.insert(l.span, l.hir_id, Node::Local(l)); + self.with_parent(l.hir_id, |this| { intravisit::walk_local(this, l) }) } fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) { - self.insert(lifetime.span, lifetime.id, Node::Lifetime(lifetime)); + self.insert(lifetime.span, lifetime.hir_id, Node::Lifetime(lifetime)); } fn visit_vis(&mut self, visibility: &'hir Visibility) { @@ -486,9 +463,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {} - VisibilityKind::Restricted { id, .. } => { - self.insert(visibility.span, id, Node::Visibility(visibility)); - self.with_parent(id, |this| { + VisibilityKind::Restricted { hir_id, .. } => { + self.insert(visibility.span, hir_id, Node::Visibility(visibility)); + self.with_parent(hir_id, |this| { intravisit::walk_vis(this, visibility); }); } @@ -496,15 +473,15 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) { - let def_index = self.definitions.opt_def_index(macro_def.id).unwrap(); + let def_index = macro_def.hir_id.owner; self.with_dep_node_owner(def_index, macro_def, |this| { - this.insert(macro_def.span, macro_def.id, Node::MacroDef(macro_def)); + this.insert(macro_def.span, macro_def.hir_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(); + fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: HirId) { + let id = v.node.data.hir_id(); self.insert(v.span, id, Node::Variant(v)); self.with_parent(id, |this| { intravisit::walk_variant(this, v, g, item_id); @@ -512,8 +489,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_struct_field(&mut self, field: &'hir StructField) { - self.insert(field.span, field.id, Node::Field(field)); - self.with_parent(field.id, |this| { + self.insert(field.span, field.hir_id, Node::Field(field)); + self.with_parent(field.hir_id, |this| { intravisit::walk_struct_field(this, field); }); } diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 6b707dd2dcc80..1bbbd29e573e2 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -449,6 +449,16 @@ impl Definitions { self.opt_local_def_id(node).unwrap() } + #[inline] + pub fn local_def_id_from_hir_id(&self, node: hir::HirId) -> DefId { + for (node_id, hir_id) in self.node_to_hir_id.iter_enumerated() { + if node == *hir_id { + return self.local_def_id(node_id); + } + } + unreachable!() + } + #[inline] pub fn as_local_node_id(&self, def_id: DefId) -> Option { if def_id.krate == LOCAL_CRATE { @@ -465,6 +475,20 @@ impl Definitions { } } + #[inline] + pub fn as_local_hir_id(&self, def_id: DefId) -> Option { + if def_id.krate == LOCAL_CRATE { + let hir_id = self.def_index_to_hir_id(def_id.index); + if hir_id != hir::DUMMY_HIR_ID { + Some(hir_id) + } else { + None + } + } else { + None + } + } + #[inline] pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId { self.node_to_hir_id[node_id] diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 91c8c29144406..8aed4c396f190 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -30,7 +30,7 @@ pub fn check_crate<'hir>(hir_map: &hir::map::Map<'hir>) { struct HirIdValidator<'a, 'hir: 'a> { hir_map: &'a hir::map::Map<'hir>, owner_def_index: Option, - hir_ids_seen: FxHashMap, + hir_ids_seen: FxHashMap, errors: &'a Lock>, } @@ -55,17 +55,17 @@ impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> { impl<'a, 'hir: 'a> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { fn visit_item(&mut self, i: &'hir hir::Item) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); - inner_visitor.check(i.id, |this| intravisit::walk_item(this, i)); + inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i)); } fn visit_trait_item(&mut self, i: &'hir hir::TraitItem) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); - inner_visitor.check(i.id, |this| intravisit::walk_trait_item(this, i)); + inner_visitor.check(i.hir_id, |this| intravisit::walk_trait_item(this, i)); } fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); - inner_visitor.check(i.id, |this| intravisit::walk_impl_item(this, i)); + inner_visitor.check(i.hir_id, |this| intravisit::walk_impl_item(this, i)); } } @@ -77,10 +77,10 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { } fn check)>(&mut self, - node_id: NodeId, + hir_id: HirId, walk: F) { assert!(self.owner_def_index.is_none()); - let owner_def_index = self.hir_map.local_def_id(node_id).index; + let owner_def_index = self.hir_map.local_def_id_from_hir_id(hir_id).index; self.owner_def_index = Some(owner_def_index); walk(self); @@ -134,7 +134,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { missing_items, self.hir_ids_seen .values() - .map(|n| format!("({:?} {})", n, self.hir_map.node_to_string(*n))) + .map(|n| format!("({:?} {})", n, self.hir_map.hir_to_string(*n))) .collect::>())); } } @@ -147,33 +147,31 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { intravisit::NestedVisitorMap::OnlyBodies(self.hir_map) } - fn visit_id(&mut self, node_id: NodeId) { + fn visit_id(&mut self, hir_id: HirId) { let owner = self.owner_def_index.expect("no owner_def_index"); - let stable_id = self.hir_map.definitions().node_to_hir_id[node_id]; - if stable_id == hir::DUMMY_HIR_ID { - self.error(|| format!("HirIdValidator: No HirId assigned for NodeId {}: {:?}", - node_id, - self.hir_map.node_to_string(node_id))); + if hir_id == hir::DUMMY_HIR_ID { + self.error(|| format!("HirIdValidator: HirId {:?} is invalid", + self.hir_map.hir_to_string(hir_id))); return; } - if owner != stable_id.owner { + if owner != hir_id.owner { self.error(|| format!( "HirIdValidator: The recorded owner of {} is {} instead of {}", - self.hir_map.node_to_string(node_id), - self.hir_map.def_path(DefId::local(stable_id.owner)).to_string_no_crate(), + self.hir_map.hir_to_string(hir_id), + self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(), self.hir_map.def_path(DefId::local(owner)).to_string_no_crate())); } - if let Some(prev) = self.hir_ids_seen.insert(stable_id.local_id, node_id) { - if prev != node_id { + if let Some(prev) = self.hir_ids_seen.insert(hir_id.local_id, hir_id) { + if prev != hir_id { self.error(|| format!( "HirIdValidator: Same HirId {}/{} assigned for nodes {} and {}", - self.hir_map.def_path(DefId::local(stable_id.owner)).to_string_no_crate(), - stable_id.local_id.as_usize(), - self.hir_map.node_to_string(prev), - self.hir_map.node_to_string(node_id))); + self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(), + hir_id.local_id.as_usize(), + self.hir_map.hir_to_string(prev), + self.hir_map.hir_to_string(hir_id))); } } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 869baef1f5afc..6bef2256c3eb6 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -12,7 +12,7 @@ use middle::cstore::CrateStoreDyn; use rustc_target::spec::abi::Abi; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::join; -use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID}; +use syntax::ast::{self, Name, NodeId}; use syntax::source_map::Spanned; use syntax::ext::base::MacroKind; use syntax_pos::{Span, DUMMY_SP}; @@ -39,16 +39,16 @@ pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High; /// Represents an entry and its parent NodeId. #[derive(Copy, Clone, Debug)] pub struct Entry<'hir> { - parent: NodeId, + parent_hir: HirId, dep_node: DepNodeIndex, node: Node<'hir>, } impl<'hir> Entry<'hir> { - fn parent_node(self) -> Option { + fn parent_hir(self) -> Option { match self.node { Node::Crate | Node::MacroDef(_) => None, - _ => Some(self.parent), + _ => Some(self.parent_hir), } } @@ -126,12 +126,16 @@ impl<'hir> Entry<'hir> { } } - fn is_body_owner(self, node_id: NodeId) -> bool { + fn is_body_owner(self, hir_id: HirId) -> bool { match self.associated_body() { - Some(b) => b.node_id == node_id, + Some(b) => b.hir_id == hir_id, None => false, } } + + fn hir_id(&self) -> HirId { + self.node.hir_id() + } } /// Stores a crate and any number of inlined items from other crates. @@ -208,6 +212,15 @@ impl<'hir> Map<'hir> { } } + // can replace Map::read when no longer needed + pub fn read_by_hir_id(&self, hir_id: HirId) { + if let Some(entry) = self.find_entry_by_hir_id(hir_id) { + self.dep_graph.read_index(entry.dep_node); + } else { + bug!("called `HirMap::read_by_hir_id()` with invalid `HirId`: {:?}", hir_id) + } + } + #[inline] pub fn definitions(&self) -> &'hir Definitions { self.definitions @@ -224,6 +237,10 @@ impl<'hir> Map<'hir> { }) } + pub fn def_path_from_hir_id(&self, id: HirId) -> DefPath { + self.def_path(self.local_def_id_from_hir_id(id)) + } + pub fn def_path(&self, def_id: DefId) -> DefPath { assert!(def_id.is_local()); self.definitions.def_path(def_id.index) @@ -237,6 +254,15 @@ impl<'hir> Map<'hir> { }) } + #[inline] + pub fn local_def_id_from_hir_id(&self, hir_id: HirId) -> DefId { + let node = self.hir_to_node_id(hir_id); + self.opt_local_def_id(node).unwrap_or_else(|| { + bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`", + node, self.find_entry(node)) + }) + } + #[inline] pub fn opt_local_def_id(&self, node: NodeId) -> Option { self.definitions.opt_local_def_id(node) @@ -247,6 +273,11 @@ impl<'hir> Map<'hir> { self.definitions.as_local_node_id(def_id) } + #[inline] + pub fn as_local_hir_id(&self, def_id: DefId) -> Option { + self.definitions.as_local_hir_id(def_id) + } + #[inline] pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId { self.hir_to_node_id[&hir_id] @@ -286,7 +317,7 @@ impl<'hir> Map<'hir> { match node { Node::Item(item) => { - let def_id = || self.local_def_id(item.id); + let def_id = || self.definitions.local_def_id_from_hir_id(item.hir_id); match item.node { ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)), @@ -308,7 +339,7 @@ impl<'hir> Map<'hir> { } } Node::ForeignItem(item) => { - let def_id = self.local_def_id(item.id); + let def_id = self.definitions.local_def_id_from_hir_id(item.hir_id); match item.node { ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)), ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)), @@ -316,7 +347,7 @@ impl<'hir> Map<'hir> { } } Node::TraitItem(item) => { - let def_id = self.local_def_id(item.id); + let def_id = self.definitions.local_def_id_from_hir_id(item.hir_id); match item.node { TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)), TraitItemKind::Method(..) => Some(Def::Method(def_id)), @@ -324,7 +355,7 @@ impl<'hir> Map<'hir> { } } Node::ImplItem(item) => { - let def_id = self.local_def_id(item.id); + let def_id = self.definitions.local_def_id_from_hir_id(item.hir_id); match item.node { ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)), ImplItemKind::Method(..) => Some(Def::Method(def_id)), @@ -333,7 +364,7 @@ impl<'hir> Map<'hir> { } } Node::Variant(variant) => { - let def_id = self.local_def_id(variant.node.data.id()); + let def_id = self.definitions.local_def_id_from_hir_id(variant.node.data.hir_id()); Some(Def::Variant(def_id)) } Node::Field(_) | @@ -351,16 +382,18 @@ impl<'hir> Map<'hir> { Node::Block(_) | Node::Crate => None, Node::Local(local) => { - Some(Def::Local(local.id)) + Some(Def::Local(local.hir_id)) } Node::MacroDef(macro_def) => { - Some(Def::Macro(self.local_def_id(macro_def.id), - MacroKind::Bang)) + let def_id = self.definitions.local_def_id_from_hir_id(macro_def.hir_id); + Some(Def::Macro(def_id, MacroKind::Bang)) } Node::GenericParam(param) => { Some(match param.kind { - GenericParamKind::Lifetime { .. } => Def::Local(param.id), - GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)), + GenericParamKind::Lifetime { .. } => + Def::Local(param.hir_id), + GenericParamKind::Type { .. } => + Def::TyParam(self.definitions.local_def_id_from_hir_id(param.hir_id)), }) } } @@ -374,6 +407,11 @@ impl<'hir> Map<'hir> { self.map.get(id.as_usize()).cloned().unwrap_or(None) } + // can replace Map::find_entry when no longer needed + fn find_entry_by_hir_id(&self, hir_id: HirId) -> Option> { + self.map.iter().filter_map(|&entry| entry).find(|&entry| entry.hir_id() == hir_id) + } + pub fn krate(&self) -> &'hir Crate { self.forest.krate() } @@ -395,60 +433,61 @@ impl<'hir> Map<'hir> { } pub fn body(&self, id: BodyId) -> &'hir Body { - self.read(id.node_id); + self.read_by_hir_id(id.hir_id); // N.B., intentionally bypass `self.forest.krate()` so that we // do not trigger a read of the whole krate here self.forest.krate.body(id) } - pub fn fn_decl(&self, node_id: ast::NodeId) -> Option { - if let Some(entry) = self.find_entry(node_id) { + pub fn fn_decl(&self, hir_id: HirId) -> Option { + if let Some(entry) = self.find_entry_by_hir_id(hir_id) { entry.fn_decl().cloned() } else { - bug!("no entry for node_id `{}`", node_id) + bug!("no entry for hir_id `{:?}`", hir_id) } } /// Returns the `NodeId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. - pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId { - let parent = self.get_parent_node(node_id); - assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id))); + pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { + let parent = self.get_parent_node(hir_id); + assert!(self.map[parent.local_id.as_usize()] + .map_or(false, |e| e.is_body_owner(hir_id))); parent } pub fn body_owner_def_id(&self, id: BodyId) -> DefId { - self.local_def_id(self.body_owner(id)) + self.local_def_id_from_hir_id(self.body_owner(id)) } - /// Given a node id, returns the `BodyId` associated with it, + /// Given a hir id, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. - pub fn maybe_body_owned_by(&self, id: NodeId) -> Option { - if let Some(entry) = self.find_entry(id) { + pub fn maybe_body_owned_by(&self, id: HirId) -> Option { + if let Some(entry) = self.find_entry_by_hir_id(id) { if self.dep_graph.is_fully_enabled() { - let hir_id_owner = self.node_to_hir_id(id).owner; + let hir_id_owner = id.owner; let def_path_hash = self.definitions.def_path_hash(hir_id_owner); self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody)); } entry.associated_body() } else { - bug!("no entry for id `{}`", id) + bug!("no entry for id `{:?}`", id) } } /// Given a body owner's id, returns the `BodyId` associated with it. - pub fn body_owned_by(&self, id: NodeId) -> BodyId { + pub fn body_owned_by(&self, id: HirId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { span_bug!(self.span(id), "body_owned_by: {} has no associated body", - self.node_to_string(id)); + self.hir_to_string(id)); }) } - pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind { - match self.get(id) { + pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { + match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) | Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) | @@ -463,19 +502,19 @@ impl<'hir> Map<'hir> { } } - pub fn ty_param_owner(&self, id: NodeId) -> NodeId { - match self.get(id) { + pub fn ty_param_owner(&self, id: HirId) -> HirId { + match self.get_by_hir_id(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)) + _ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id)) } } - pub fn ty_param_name(&self, id: NodeId) -> Name { - match self.get(id) { + pub fn ty_param_name(&self, id: HirId) -> Name { + match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(), Node::GenericParam(param) => param.name.ident().name, - _ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)), + _ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)), } } @@ -542,6 +581,12 @@ impl<'hir> Map<'hir> { self.find(id).unwrap_or_else(|| bug!("couldn't find node id {} in the AST map", id)) } + pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> { + // read recorded by `find` + self.find_by_hir_id(id).unwrap_or_else(|| + bug!("couldn't find id {:?} in the HIR map", id)) + } + pub fn get_if_local(&self, id: DefId) -> Option> { self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` } @@ -589,34 +634,49 @@ impl<'hir> Map<'hir> { result } + // can replace Map::find when no longer needed + pub fn find_by_hir_id(&self, hir_id: HirId) -> Option> { + let result = self.find_entry_by_hir_id(hir_id).and_then(|entry| { + if let Node::Crate = entry.node { + None + } else { + Some(entry.node) + } + }); + if result.is_some() { + self.read_by_hir_id(hir_id); + } + result + } + /// Similar to `get_parent`; returns the parent node-id, or own `id` if there is - /// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself + /// no parent. Note that the parent may be `CRATE_HIR_ID`, which is not itself /// present in the map -- so passing the return value of get_parent_node to /// get may actually panic. - /// This function returns the immediate parent in the AST, whereas get_parent + /// This function returns the immediate parent in the HIR, whereas get_parent /// returns the enclosing item. Note that this might not be the actual parent /// node in the AST - some kinds of nodes are not in the map and these will /// never appear as the parent_node. So you can always walk the `parent_nodes` /// from a node to the root of the ast (unless you get the same id back here /// that can happen if the id is not in the map itself or is just weird). - pub fn get_parent_node(&self, id: NodeId) -> NodeId { + pub fn get_parent_node(&self, id: HirId) -> HirId { if self.dep_graph.is_fully_enabled() { - let hir_id_owner = self.node_to_hir_id(id).owner; + let hir_id_owner = id.owner; let def_path_hash = self.definitions.def_path_hash(hir_id_owner); self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody)); } - self.find_entry(id).and_then(|x| x.parent_node()).unwrap_or(id) + self.find_entry_by_hir_id(id).and_then(|x| x.parent_hir()).unwrap_or(id) } /// Check if the node is an argument. An argument is a local variable whose /// immediate parent is an item or a closure. - pub fn is_argument(&self, id: NodeId) -> bool { - match self.find(id) { + pub fn is_argument(&self, id: HirId) -> bool { + match self.find_by_hir_id(id) { Some(Node::Binding(_)) => (), _ => return false, } - match self.find(self.get_parent_node(id)) { + match self.find_by_hir_id(self.get_parent_node(id)) { Some(Node::Item(_)) | Some(Node::TraitItem(_)) | Some(Node::ImplItem(_)) => true, @@ -636,23 +696,23 @@ impl<'hir> Map<'hir> { /// is not an error, since items in the crate module have the crate root as /// parent. fn walk_parent_nodes(&self, - start_id: NodeId, - found: F, - bail_early: F2) - -> Result + start_id: HirId, + found: F, + bail_early: F2) + -> Result where F: Fn(&Node<'hir>) -> bool, F2: Fn(&Node<'hir>) -> bool { let mut id = start_id; loop { let parent_node = self.get_parent_node(id); - if parent_node == CRATE_NODE_ID { - return Ok(CRATE_NODE_ID); + if parent_node == CRATE_HIR_ID { + return Ok(CRATE_HIR_ID); } if parent_node == id { return Err(id); } - if let Some(entry) = self.find_entry(parent_node) { + if let Some(entry) = self.find_entry_by_hir_id(parent_node) { if let Node::Crate = entry.node { return Err(id); } @@ -668,7 +728,7 @@ impl<'hir> Map<'hir> { } } - /// Retrieve the `NodeId` for `id`'s enclosing method, unless there's a + /// Retrieve the `HirId` for `id`'s enclosing method, unless there's a /// `while` or `loop` before reaching it, as block tail returns are not /// available in them. /// @@ -676,7 +736,7 @@ impl<'hir> Map<'hir> { /// fn foo(x: usize) -> bool { /// if x == 1 { /// true // `get_return_block` gets passed the `id` corresponding - /// } else { // to this, it will return `foo`'s `NodeId`. + /// } else { // to this, it will return `foo`'s `HirId`. /// false /// } /// } @@ -690,7 +750,7 @@ impl<'hir> Map<'hir> { /// false /// } /// ``` - pub fn get_return_block(&self, id: NodeId) -> Option { + pub fn get_return_block(&self, id: HirId) -> Option { let match_fn = |node: &Node<'_>| { match *node { Node::Item(_) | @@ -716,11 +776,11 @@ impl<'hir> Map<'hir> { self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok() } - /// Retrieve the `NodeId` for `id`'s parent item, or `id` itself if no + /// Retrieve the `HirId` for `id`'s parent item, or `id` itself if no /// parent item is in this map. The "parent item" is the closest parent node /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. - pub fn get_parent(&self, id: NodeId) -> NodeId { + pub fn get_parent(&self, id: HirId) -> HirId { match self.walk_parent_nodes(id, |node| match *node { Node::Item(_) | Node::ForeignItem(_) | @@ -735,13 +795,13 @@ impl<'hir> Map<'hir> { /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent(&self, id: NodeId) -> DefId { - self.local_def_id(self.get_module_parent_node(id)) + pub fn get_module_parent(&self, id: HirId) -> DefId { + self.local_def_id_from_hir_id(self.get_module_parent_node(id)) } - /// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no + /// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent_node(&self, id: NodeId) -> NodeId { + pub fn get_module_parent_node(&self, id: HirId) -> HirId { match self.walk_parent_nodes(id, |node| match *node { Node::Item(&Item { node: ItemKind::Mod(_), .. }) => true, _ => false, @@ -755,7 +815,7 @@ impl<'hir> Map<'hir> { /// FIXME: it is not clear to me that all items qualify as scopes -- statics /// and associated types probably shouldn't, for example. Behavior in this /// regard should be expected to be highly unstable. - pub fn get_enclosing_scope(&self, id: NodeId) -> Option { + pub fn get_enclosing_scope(&self, id: HirId) -> Option { self.walk_parent_nodes(id, |node| match *node { Node::Item(_) | Node::ForeignItem(_) | @@ -766,21 +826,21 @@ impl<'hir> Map<'hir> { }, |_| false).ok() } - pub fn get_parent_did(&self, id: NodeId) -> DefId { - self.local_def_id(self.get_parent(id)) + pub fn get_parent_did(&self, id: HirId) -> DefId { + self.local_def_id_from_hir_id(self.get_parent(id)) } - pub fn get_foreign_abi(&self, id: NodeId) -> Abi { + pub fn get_foreign_abi(&self, id: HirId) -> Abi { let parent = self.get_parent(id); - if let Some(entry) = self.find_entry(parent) { + if let Some(entry) = self.find_entry_by_hir_id(parent) { if let Entry { node: Node::Item(Item { node: ItemKind::ForeignMod(ref nm), .. }), .. } = entry { - self.read(id); // reveals some of the content of a node + self.read_by_hir_id(id); // reveals some of the content of a node return nm.abi; } } - bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent)) + bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) } pub fn expect_item(&self, id: NodeId) -> &'hir Item { @@ -790,6 +850,13 @@ impl<'hir> Map<'hir> { } } + pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { + match self.find_by_hir_id(id) { // read recorded by `find` + Some(Node::Item(item)) => item, + _ => bug!("expected item, found {}", self.hir_to_string(id)) + } + } + pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem { match self.find(id) { Some(Node::ImplItem(item)) => item, @@ -797,6 +864,13 @@ impl<'hir> Map<'hir> { } } + pub fn expect_impl_item_by_hir_id(&self, id: HirId) -> &'hir ImplItem { + match self.find_by_hir_id(id) { + Some(Node::ImplItem(item)) => item, + _ => bug!("expected impl item, found {}", self.hir_to_string(id)) + } + } + pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem { match self.find(id) { Some(Node::TraitItem(item)) => item, @@ -804,45 +878,52 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData { - match self.find(id) { + pub fn expect_trait_item_by_hir_id(&self, id: HirId) -> &'hir TraitItem { + match self.find_by_hir_id(id) { + Some(Node::TraitItem(item)) => item, + _ => bug!("expected trait item, found {}", self.hir_to_string(id)) + } + } + + pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData { + match self.find_by_hir_id(id) { Some(Node::Item(i)) => { match i.node { ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => struct_def, - _ => bug!("struct ID bound to non-struct {}", self.node_to_string(id)) + _ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id)) } } Some(Node::StructCtor(data)) => data, Some(Node::Variant(variant)) => &variant.node.data, - _ => bug!("expected struct or variant, found {}", self.node_to_string(id)) + _ => bug!("expected struct or variant, found {}", self.hir_to_string(id)) } } - pub fn expect_variant(&self, id: NodeId) -> &'hir Variant { - match self.find(id) { + pub fn expect_variant(&self, id: HirId) -> &'hir Variant { + match self.find_by_hir_id(id) { Some(Node::Variant(variant)) => variant, - _ => bug!("expected variant, found {}", self.node_to_string(id)), + _ => bug!("expected variant, found {}", self.hir_to_string(id)), } } - pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem { - match self.find(id) { + pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { + match self.find_by_hir_id(id) { Some(Node::ForeignItem(item)) => item, - _ => bug!("expected foreign item, found {}", self.node_to_string(id)) + _ => bug!("expected foreign item, found {}", self.hir_to_string(id)) } } - pub fn expect_expr(&self, id: NodeId) -> &'hir Expr { - match self.find(id) { // read recorded by find + pub fn expect_expr(&self, id: HirId) -> &'hir Expr { + match self.find_by_hir_id(id) { // read recorded by find Some(Node::Expr(expr)) => expr, - _ => bug!("expected expr, found {}", self.node_to_string(id)) + _ => bug!("expected expr, found {}", self.hir_to_string(id)) } } /// Returns the name associated with the given NodeId's AST. - pub fn name(&self, id: NodeId) -> Name { - match self.get(id) { + pub fn name(&self, id: HirId) -> Name { + match self.get_by_hir_id(id) { Node::Item(i) => i.ident.name, Node::ForeignItem(fi) => fi.ident.name, Node::ImplItem(ii) => ii.ident.name, @@ -853,15 +934,15 @@ impl<'hir> Map<'hir> { 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)) + _ => bug!("no name for {}", self.hir_to_string(id)) } } /// Given a node ID, get a list of attributes associated with the AST /// 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) { + pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] { + self.read_by_hir_id(id); // reveals attributes on the node + let attrs = match self.find_by_hir_id(id) { Some(Node::Item(i)) => Some(&i.attrs[..]), Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]), Some(Node::TraitItem(ref ti)) => Some(&ti.attrs[..]), @@ -892,13 +973,13 @@ impl<'hir> Map<'hir> { map: self, item_name: parts.last().unwrap(), in_which: &parts[..parts.len() - 1], - idx: CRATE_NODE_ID, + idx: CRATE_HIR_ID, } } - pub fn span(&self, id: NodeId) -> Span { - self.read(id); // reveals span from node - match self.find_entry(id).map(|entry| entry.node) { + pub fn span(&self, id: HirId) -> Span { + self.read_by_hir_id(id); // reveals span from node + match self.find_entry_by_hir_id(id).map(|entry| entry.node) { Some(Node::Item(item)) => item.span, Some(Node::ForeignItem(foreign_item)) => foreign_item.span, Some(Node::TraitItem(trait_method)) => trait_method.span, @@ -914,7 +995,8 @@ impl<'hir> Map<'hir> { 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::StructCtor(_)) => + self.expect_item_by_hir_id(self.get_parent(id)).span, Some(Node::Lifetime(lifetime)) => lifetime.span, Some(Node::GenericParam(param)) => param.span, Some(Node::Visibility(&Spanned { @@ -929,27 +1011,39 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - self.as_local_node_id(id).map(|id| self.span(id)) + self.as_local_hir_id(id).map(|id| self.span(id)) } pub fn node_to_string(&self, id: NodeId) -> String { node_id_to_string(self, id, true) } + pub fn hir_to_string(&self, id: HirId) -> String { + hir_id_to_string(self, id, true) + } + pub fn node_to_user_string(&self, id: NodeId) -> String { node_id_to_string(self, id, false) } + pub fn hir_to_user_string(&self, id: HirId) -> String { + hir_id_to_string(self, id, false) + } + pub fn node_to_pretty_string(&self, id: NodeId) -> String { print::to_string(self, |s| s.print_node(self.get(id))) } + + pub fn node_to_pretty_string_by_hir_id(&self, id: HirId) -> String { + print::to_string(self, |s| s.print_node(self.get_by_hir_id(id))) + } } pub struct NodesMatchingSuffix<'a, 'hir:'a> { map: &'a Map<'hir>, item_name: &'a String, in_which: &'a [String], - idx: NodeId, + idx: HirId, } impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { @@ -959,12 +1053,12 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { /// In other words: let `[x_0,x_1,...,x_k]` be `self.in_which`; /// returns true if parent's path ends with the suffix /// `x_0::x_1::...::x_k`. - fn suffix_matches(&self, parent: NodeId) -> bool { + fn suffix_matches(&self, parent: HirId) -> bool { let mut cursor = parent; for part in self.in_which.iter().rev() { let (mod_id, mod_name) = match find_first_mod_parent(self.map, cursor) { None => return false, - Some((node_id, name)) => (node_id, name), + Some((hir_id, name)) => (hir_id, name), }; if mod_name != &**part { return false; @@ -979,9 +1073,9 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { // If `id` itself is a mod named `m` with parent `p`, then // returns `Some(id, m, p)`. If `id` has no mod in its parent // chain, then returns `None`. - fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: NodeId) -> Option<(NodeId, Name)> { + fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: HirId) -> Option<(HirId, Name)> { loop { - if let Node::Item(item) = map.find(id)? { + if let Node::Item(item) = map.find_by_hir_id(id)? { if item_is_mod(&item) { return Some((id, item.ident.name)) } @@ -1002,22 +1096,23 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { // We are looking at some node `n` with a given name and parent // id; do their names match what I am seeking? - fn matches_names(&self, parent_of_n: NodeId, name: Name) -> bool { + fn matches_names(&self, parent_of_n: HirId, name: Name) -> bool { name == &**self.item_name && self.suffix_matches(parent_of_n) } } impl<'a, 'hir> Iterator for NodesMatchingSuffix<'a, 'hir> { - type Item = NodeId; + type Item = HirId; - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { loop { let idx = self.idx; - if idx.as_usize() >= self.map.entry_count() { + if idx.local_id.as_usize() >= self.map.entry_count() { return None; } - self.idx = NodeId::from_u32(self.idx.as_u32() + 1); - let name = match self.map.find_entry(idx).map(|entry| entry.node) { + let node_id = self.map.hir_to_node_id(idx); + self.idx = self.map.node_to_hir_id(NodeId::from_u32(node_id.as_u32() + 1)); + let name = match self.map.find_entry_by_hir_id(idx).map(|entry| entry.node) { Some(Node::Item(n)) => n.name(), Some(Node::ForeignItem(n)) => n.name(), Some(Node::TraitItem(n)) => n.name(), @@ -1286,6 +1381,135 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String { } } +fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { + let id_str = format!(" (id={:?})", id); + let id_str = if include_id { &id_str[..] } else { "" }; + + let path_str = || { + // This functionality is used for debugging, try to use TyCtxt to get + // the user-friendly path, otherwise fall back to stringifying DefPath. + ::ty::tls::with_opt(|tcx| { + if let Some(tcx) = tcx { + tcx.hir_path_str(id) + } else { + let path = map.def_path_from_hir_id(id); + path.data.into_iter().map(|elem| { + elem.data.to_string() + }).collect::>().join("::") + } + }) + }; + + match map.find_by_hir_id(id) { + Some(Node::Item(item)) => { + let item_str = match item.node { + ItemKind::ExternCrate(..) => "extern crate", + ItemKind::Use(..) => "use", + ItemKind::Static(..) => "static", + ItemKind::Const(..) => "const", + ItemKind::Fn(..) => "fn", + ItemKind::Mod(..) => "mod", + ItemKind::ForeignMod(..) => "foreign mod", + ItemKind::GlobalAsm(..) => "global asm", + ItemKind::Ty(..) => "ty", + ItemKind::Existential(..) => "existential type", + ItemKind::Enum(..) => "enum", + ItemKind::Struct(..) => "struct", + ItemKind::Union(..) => "union", + ItemKind::Trait(..) => "trait", + ItemKind::TraitAlias(..) => "trait alias", + ItemKind::Impl(..) => "impl", + }; + format!("{} {}{}", item_str, path_str(), id_str) + } + Some(Node::ForeignItem(_)) => { + format!("foreign item {}{}", path_str(), id_str) + } + Some(Node::ImplItem(ii)) => { + match ii.node { + ImplItemKind::Const(..) => { + format!("assoc const {} in {}{}", ii.ident, path_str(), id_str) + } + ImplItemKind::Method(..) => { + format!("method {} in {}{}", ii.ident, path_str(), id_str) + } + ImplItemKind::Type(_) => { + format!("assoc type {} in {}{}", ii.ident, path_str(), id_str) + } + ImplItemKind::Existential(_) => { + format!("assoc existential type {} in {}{}", ii.ident, path_str(), id_str) + } + } + } + Some(Node::TraitItem(ti)) => { + let kind = match ti.node { + TraitItemKind::Const(..) => "assoc constant", + TraitItemKind::Method(..) => "trait method", + TraitItemKind::Type(..) => "assoc type", + }; + + format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str) + } + Some(Node::Variant(ref variant)) => { + format!("variant {} in {}{}", + variant.node.ident, + path_str(), id_str) + } + Some(Node::Field(ref field)) => { + format!("field {} in {}{}", + field.ident, + path_str(), id_str) + } + Some(Node::AnonConst(_)) => { + format!("const {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Expr(_)) => { + format!("expr {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Stmt(_)) => { + format!("stmt {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::PathSegment(_)) => { + format!("path segment {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Ty(_)) => { + format!("type {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::TraitRef(_)) => { + format!("trait_ref {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Binding(_)) => { + format!("local {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Pat(_)) => { + format!("pat {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Block(_)) => { + format!("block {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::Local(_)) => { + format!("local {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::StructCtor(_)) => { + format!("struct_ctor {}{}", path_str(), id_str) + } + Some(Node::Lifetime(_)) => { + format!("lifetime {}{}", map.node_to_pretty_string_by_hir_id(id), id_str) + } + Some(Node::GenericParam(ref param)) => { + format!("generic_param {:?}{}", param, id_str) + } + Some(Node::Visibility(ref vis)) => { + format!("visibility {:?}{}", vis, id_str) + } + Some(Node::MacroDef(_)) => { + format!("macro {}{}", path_str(), id_str) + } + Some(Node::Crate) => String::from("root_crate"), + None => format!("unknown node{}", id_str), + } +} + pub fn describe_def(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option { if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { tcx.hir().describe_def(node_id) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index fc4bd05476f6c..31fc06df73663 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -12,13 +12,13 @@ pub use self::UnsafeSource::*; use hir::def::Def; use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; -use util::nodemap::{NodeMap, FxHashSet}; +use util::nodemap::{HirIdMap, NodeMap, FxHashSet}; use mir::mono::Linkage; use syntax_pos::{Span, DUMMY_SP, symbol::InternedString}; use syntax::source_map::{self, Spanned}; use rustc_target::spec::abi::Abi; -use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect}; +use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy}; use syntax::attr::InlineAttr; use syntax::ext::hygiene::SyntaxContext; @@ -71,7 +71,7 @@ pub mod print; /// the local_id part of the HirId changing, which is a very useful property in /// incremental compilation where we have to persist things through changes to /// the code base. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct HirId { pub owner: DefIndex, pub local_id: ItemLocalId, @@ -155,7 +155,7 @@ impl fmt::Debug for Label { #[derive(Clone, RustcEncodable, RustcDecodable, Copy)] pub struct Lifetime { - pub id: NodeId, + pub hir_id: HirId, pub span: Span, /// Either "'a", referring to a named lifetime definition, @@ -273,8 +273,8 @@ impl fmt::Display for Lifetime { impl fmt::Debug for Lifetime { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, - "lifetime({}: {})", - self.id, + "lifetime({:?}: {})", + self.hir_id, print::to_string(print::NO_ANN, |s| s.print_lifetime(self))) } } @@ -331,6 +331,7 @@ pub struct PathSegment { // affected. (In general, we don't bother to get the defs for synthesized // segments, only for segments which have come from the AST). pub id: Option, + pub hir_id: Option, pub def: Option, /// Type/lifetime parameters attached to this path. They come in @@ -353,6 +354,7 @@ impl PathSegment { PathSegment { ident, id: None, + hir_id: None, def: None, infer_types: true, args: None, @@ -362,6 +364,7 @@ impl PathSegment { pub fn new( ident: Ident, id: Option, + hir_id: Option, def: Option, args: GenericArgs, infer_types: bool, @@ -369,6 +372,7 @@ impl PathSegment { PathSegment { ident, id, + hir_id, def, infer_types, args: if args.is_empty() { @@ -407,10 +411,10 @@ impl GenericArg { } } - pub fn id(&self) -> NodeId { + pub fn hir_id(&self) -> HirId { match self { - GenericArg::Lifetime(l) => l.id, - GenericArg::Type(t) => t.id, + GenericArg::Lifetime(l) => l.hir_id, + GenericArg::Type(t) => t.hir_id, } } } @@ -537,7 +541,7 @@ pub enum GenericParamKind { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct GenericParam { - pub id: NodeId, + pub hir_id: HirId, pub name: ParamName, pub attrs: HirVec, pub bounds: GenericBounds, @@ -567,7 +571,7 @@ impl Generics { Generics { params: HirVec::new(), where_clause: WhereClause { - id: DUMMY_NODE_ID, + hir_id: DUMMY_HIR_ID, predicates: HirVec::new(), }, span: DUMMY_SP, @@ -610,7 +614,7 @@ pub enum SyntheticTyParamKind { /// A `where` clause in a definition #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereClause { - pub id: NodeId, + pub hir_id: HirId, pub predicates: HirVec, } @@ -670,7 +674,7 @@ pub struct WhereRegionPredicate { /// An equality predicate (unsupported), e.g., `T=int` #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereEqPredicate { - pub id: NodeId, + pub hir_id: HirId, pub span: Span, pub lhs_ty: P, pub rhs_ty: P, @@ -798,7 +802,7 @@ pub struct MacroDef { pub name: Name, pub vis: Visibility, pub attrs: HirVec, - pub id: NodeId, + pub hir_id: HirId, pub span: Span, pub body: TokenStream, pub legacy: bool, @@ -811,7 +815,6 @@ pub struct Block { /// An expression at the end of the block /// without a semicolon, if any pub expr: Option>, - pub id: NodeId, pub hir_id: HirId, /// Distinguishes between `unsafe { ... }` and `{ ... }` pub rules: BlockCheckMode, @@ -824,7 +827,6 @@ pub struct Block { #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Pat { - pub id: NodeId, pub hir_id: HirId, pub node: PatKind, pub span: Span, @@ -832,7 +834,7 @@ pub struct Pat { impl fmt::Debug for Pat { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "pat({}: {})", self.id, + write!(f, "pat({:?}: {})", self.hir_id, print::to_string(print::NO_ANN, |s| s.print_pat(self))) } } @@ -887,7 +889,7 @@ impl Pat { /// except is_shorthand is true #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct FieldPat { - pub id: NodeId, + pub hir_id: HirId, /// The identifier for the field pub ident: Ident, /// The pattern the field is destructured to @@ -931,10 +933,10 @@ pub enum PatKind { Wild, /// A fresh binding `ref mut binding @ OPT_SUBPATTERN`. - /// The `NodeId` is the canonical ID for the variable being bound, + /// The `HirId` is the canonical ID for the variable being bound, /// e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID, /// which is the pattern ID of the first `x`. - Binding(BindingAnnotation, NodeId, Ident, Option>), + Binding(BindingAnnotation, HirId, Ident, Option>), /// A struct or struct variant pattern, e.g., `Variant {x, y, ..}`. /// The `bool` is `true` in the presence of a `..`. @@ -1151,8 +1153,8 @@ impl fmt::Debug for StmtKind { // Sadness. let spanned = source_map::dummy_spanned(self.clone()); write!(f, - "stmt({}: {})", - spanned.node.id(), + "stmt({:?}: {})", + spanned.node.hir_id(), print::to_string(print::NO_ANN, |s| s.print_stmt(&spanned))) } } @@ -1160,13 +1162,13 @@ impl fmt::Debug for StmtKind { #[derive(Clone, RustcEncodable, RustcDecodable)] pub enum StmtKind { /// Could be an item or a local (let) binding: - Decl(P, NodeId), + Decl(P, HirId), /// Expr without trailing semi-colon (must have unit type): - Expr(P, NodeId), + Expr(P, HirId), /// Expr with trailing semi-colon (may have any type): - Semi(P, NodeId), + Semi(P, HirId), } impl StmtKind { @@ -1178,11 +1180,11 @@ impl StmtKind { } } - pub fn id(&self) -> NodeId { + pub fn hir_id(&self) -> HirId { match *self { - StmtKind::Decl(_, id) | - StmtKind::Expr(_, id) | - StmtKind::Semi(_, id) => id, + StmtKind::Decl(_, hir_id) | + StmtKind::Expr(_, hir_id) | + StmtKind::Semi(_, hir_id) => hir_id, } } } @@ -1194,7 +1196,6 @@ pub struct Local { pub ty: Option>, /// Initializer expression to set the value, if any pub init: Option>, - pub id: NodeId, pub hir_id: HirId, pub span: Span, pub attrs: ThinVec, @@ -1243,7 +1244,7 @@ pub enum Guard { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Field { - pub id: NodeId, + pub hir_id: HirId, pub ident: Ident, pub expr: P, pub span: Span, @@ -1266,7 +1267,7 @@ pub enum UnsafeSource { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct BodyId { - pub node_id: NodeId, + pub hir_id: HirId, } /// The body of a function, closure, or constant value. In the case of @@ -1300,7 +1301,7 @@ pub struct Body { impl Body { pub fn id(&self) -> BodyId { BodyId { - node_id: self.value.id + hir_id: self.value.hir_id } } } @@ -1324,7 +1325,6 @@ pub enum BodyOwnerKind { /// explicit discriminant values for enum variants. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] pub struct AnonConst { - pub id: NodeId, pub hir_id: HirId, pub body: BodyId, } @@ -1332,7 +1332,6 @@ pub struct AnonConst { /// An expression #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Expr { - pub id: NodeId, pub span: Span, pub node: ExprKind, pub attrs: ThinVec, @@ -1431,7 +1430,7 @@ impl Expr { impl fmt::Debug for Expr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "expr({}: {})", self.id, + write!(f, "expr({:?}: {})", self.hir_id, print::to_string(print::NO_ANN, |s| s.print_expr(self))) } } @@ -1667,7 +1666,6 @@ pub struct TraitItemId { /// signature) or provided (meaning it has a default implementation). #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct TraitItem { - pub id: NodeId, pub ident: Ident, pub hir_id: HirId, pub attrs: HirVec, @@ -1710,7 +1708,6 @@ pub struct ImplItemId { /// Represents anything within an `impl` block #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct ImplItem { - pub id: NodeId, pub ident: Ident, pub hir_id: HirId, pub vis: Visibility, @@ -1738,7 +1735,7 @@ pub enum ImplItemKind { // Bind a type to an associated type: `A=Foo`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct TypeBinding { - pub id: NodeId, + pub hir_id: HirId, pub ident: Ident, pub ty: P, pub span: Span, @@ -1746,7 +1743,6 @@ pub struct TypeBinding { #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Ty { - pub id: NodeId, pub node: TyKind, pub span: Span, pub hir_id: HirId, @@ -1851,7 +1847,6 @@ pub struct InlineAsm { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Arg { pub pat: P, - pub id: NodeId, pub hir_id: HirId, } @@ -2062,7 +2057,6 @@ pub enum UseKind { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct TraitRef { pub path: Path, - pub ref_id: NodeId, pub hir_ref_id: HirId, } @@ -2083,7 +2077,7 @@ pub type Visibility = Spanned; pub enum VisibilityKind { Public, Crate(CrateSugar), - Restricted { path: P, id: NodeId, hir_id: HirId }, + Restricted { path: P, hir_id: HirId }, Inherited, } @@ -2119,7 +2113,7 @@ pub struct StructField { pub span: Span, pub ident: Ident, pub vis: Visibility, - pub id: NodeId, + pub hir_id: HirId, pub ty: P, pub attrs: HirVec, } @@ -2145,9 +2139,9 @@ impl StructField { /// Id of the whole struct lives in `Item`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum VariantData { - Struct(HirVec, NodeId), - Tuple(HirVec, NodeId), - Unit(NodeId), + Struct(HirVec, HirId), + Tuple(HirVec, HirId), + Unit(HirId), } impl VariantData { @@ -2157,9 +2151,11 @@ impl VariantData { _ => &[], } } - pub fn id(&self) -> NodeId { + pub fn hir_id(&self) -> HirId { match *self { - VariantData::Struct(_, id) | VariantData::Tuple(_, id) | VariantData::Unit(id) => id, + VariantData::Struct(_, hir_id) + | VariantData::Tuple(_, hir_id) + | VariantData::Unit(hir_id) => hir_id, } } pub fn is_struct(&self) -> bool { @@ -2199,7 +2195,6 @@ pub struct ItemId { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Item { pub ident: Ident, - pub id: NodeId, pub hir_id: HirId, pub attrs: HirVec, pub node: ItemKind, @@ -2356,7 +2351,7 @@ pub struct ForeignItem { pub ident: Ident, pub attrs: HirVec, pub node: ForeignItemKind, - pub id: NodeId, + pub hir_id: HirId, pub span: Span, pub vis: Visibility, } @@ -2394,7 +2389,7 @@ pub struct Freevar { } impl Freevar { - pub fn var_id(&self) -> NodeId { + pub fn var_id(&self) -> HirId { match self.def { Def::Local(id) | Def::Upvar(id, ..) => id, _ => bug!("Freevar::var_id: bad def ({:?})", self.def) @@ -2402,7 +2397,7 @@ impl Freevar { } } -pub type FreevarMap = NodeMap>; +pub type FreevarMap = HirIdMap>; pub type CaptureModeMap = NodeMap; @@ -2554,3 +2549,35 @@ pub enum Node<'hir> { Crate, } + +impl<'hir> Node<'hir> { + pub fn hir_id(&self) -> HirId { + match *self { + Node::Item(item) => item.hir_id, + Node::ForeignItem(foreign_item) => foreign_item.hir_id, + Node::TraitItem(trait_method) => trait_method.hir_id, + Node::ImplItem(impl_item) => impl_item.hir_id, + Node::Variant(spanned) => spanned.node.data.hir_id(), + Node::Field(field) => field.hir_id, + Node::AnonConst(constant) => constant.hir_id, + Node::Expr(expr) => expr.hir_id, + Node::Stmt(spanned) => spanned.node.hir_id(), + Node::PathSegment(seg) => seg.hir_id.unwrap(), // is None possible here? + Node::Ty(ty) => ty.hir_id, + Node::TraitRef(tr) => tr.hir_ref_id, + Node::Binding(pat) => pat.hir_id, + Node::Pat(pat) => pat.hir_id, + Node::Block(block) => block.hir_id, + Node::StructCtor(variant_data) => variant_data.hir_id(), + Node::Lifetime(lifetime) => lifetime.hir_id, + Node::GenericParam(param) => param.hir_id, + Node::Visibility(&Spanned { + node: VisibilityKind::Restricted { hir_id, .. }, .. + }) => hir_id, + Node::Visibility(v) => bug!("unexpected Visibility {:?}", v), + Node::Local(local) => local.hir_id, + Node::MacroDef(macro_def) => macro_def.hir_id, + Node::Crate => CRATE_HIR_ID, + } + } +} diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index d7acdefcc7d71..6b59ec45ba80d 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -25,7 +25,7 @@ pub enum AnnNode<'a> { Name(&'a ast::Name), Block(&'a hir::Block), Item(&'a hir::Item), - SubItem(ast::NodeId), + SubItem(hir::HirId), Expr(&'a hir::Expr), Pat(&'a hir::Pat), } @@ -924,7 +924,7 @@ impl<'a> State<'a> { } pub fn print_trait_item(&mut self, ti: &hir::TraitItem) -> io::Result<()> { - self.ann.pre(self, AnnNode::SubItem(ti.id))?; + self.ann.pre(self, AnnNode::SubItem(ti.hir_id))?; self.hardbreak_if_not_bol()?; self.maybe_print_comment(ti.span.lo())?; self.print_outer_attributes(&ti.attrs)?; @@ -956,11 +956,11 @@ impl<'a> State<'a> { default.as_ref().map(|ty| &**ty))?; } } - self.ann.post(self, AnnNode::SubItem(ti.id)) + self.ann.post(self, AnnNode::SubItem(ti.hir_id)) } pub fn print_impl_item(&mut self, ii: &hir::ImplItem) -> io::Result<()> { - self.ann.pre(self, AnnNode::SubItem(ii.id))?; + self.ann.pre(self, AnnNode::SubItem(ii.hir_id))?; self.hardbreak_if_not_bol()?; self.maybe_print_comment(ii.span.lo())?; self.print_outer_attributes(&ii.attrs)?; @@ -986,7 +986,7 @@ impl<'a> State<'a> { self.print_associated_type(ii.ident, Some(bounds), None)?; } } - self.ann.post(self, AnnNode::SubItem(ii.id)) + self.ann.post(self, AnnNode::SubItem(ii.hir_id)) } pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> { @@ -2254,7 +2254,7 @@ impl<'a> State<'a> { let generics = hir::Generics { params: hir::HirVec::new(), where_clause: hir::WhereClause { - id: ast::DUMMY_NODE_ID, + hir_id: hir::DUMMY_HIR_ID, predicates: hir::HirVec::new(), }, span: syntax_pos::DUMMY_SP, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 8ff60e5f56225..6832a54141925 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -158,7 +158,7 @@ impl_stable_hash_for!(struct hir::Label { }); impl_stable_hash_for!(struct hir::Lifetime { - id, + hir_id, span, name }); @@ -172,6 +172,7 @@ impl_stable_hash_for!(struct hir::Path { impl_stable_hash_for!(struct hir::PathSegment { ident -> (ident.name), id, + hir_id, def, infer_types, args @@ -199,7 +200,7 @@ impl_stable_hash_for!(enum hir::TraitBoundModifier { }); impl_stable_hash_for!(struct hir::GenericParam { - id, + hir_id, name, pure_wrt_drop, attrs, @@ -243,7 +244,7 @@ impl_stable_hash_for!(enum hir::SyntheticTyParamKind { }); impl_stable_hash_for!(struct hir::WhereClause { - id, + hir_id, predicates }); @@ -267,7 +268,7 @@ impl_stable_hash_for!(struct hir::WhereRegionPredicate { }); impl_stable_hash_for!(struct hir::WhereEqPredicate { - id, + hir_id, span, lhs_ty, rhs_ty @@ -284,7 +285,7 @@ impl_stable_hash_for!(struct hir::MethodSig { }); impl_stable_hash_for!(struct hir::TypeBinding { - id, + hir_id, ident -> (ident.name), ty, span @@ -303,7 +304,6 @@ impl<'a> HashStable> for hir::Ty { hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Ty { - id: _, hir_id: _, ref node, ref span, @@ -375,8 +375,7 @@ impl_stable_hash_for!(enum hir::ImplicitSelfKind { }); impl_stable_hash_for!(struct hir::TraitRef { - // Don't hash the ref_id. It is tracked via the thing it is used to access - ref_id -> _, + // Don't hash the hir_ref_id. It is tracked via the thing it is used to access hir_ref_id -> _, path, }); @@ -396,7 +395,7 @@ impl_stable_hash_for!(struct hir::MacroDef { name, vis, attrs, - id, + hir_id, span, legacy, body @@ -405,7 +404,6 @@ impl_stable_hash_for!(struct hir::MacroDef { impl_stable_hash_for!(struct hir::Block { stmts, expr, - id -> _, hir_id -> _, rules, span, @@ -413,7 +411,6 @@ impl_stable_hash_for!(struct hir::Block { }); impl_stable_hash_for!(struct hir::Pat { - id -> _, hir_id -> _, node, span, @@ -422,7 +419,7 @@ impl_stable_hash_for!(struct hir::Pat { impl_stable_hash_for_spanned!(hir::FieldPat); impl_stable_hash_for!(struct hir::FieldPat { - id -> _, + hir_id -> _, ident -> (ident.name), pat, is_shorthand, @@ -489,7 +486,6 @@ impl_stable_hash_for!(struct hir::Local { pat, ty, init, - id, hir_id, span, attrs, @@ -514,7 +510,7 @@ impl_stable_hash_for!(enum hir::Guard { }); impl_stable_hash_for!(struct hir::Field { - id -> _, + hir_id -> _, ident, expr, span, @@ -537,7 +533,6 @@ impl_stable_hash_for!(enum hir::UnsafeSource { }); impl_stable_hash_for!(struct hir::AnonConst { - id, hir_id, body }); @@ -548,7 +543,6 @@ impl<'a> HashStable> for hir::Expr { hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Expr { - id: _, hir_id: _, ref span, ref node, @@ -662,7 +656,6 @@ impl<'a> HashStable> for hir::TraitItem { hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::TraitItem { - id: _, hir_id: _, ident, ref attrs, @@ -697,7 +690,6 @@ impl<'a> HashStable> for hir::ImplItem { hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::ImplItem { - id: _, hir_id: _, ident, ref vis, @@ -745,9 +737,8 @@ impl<'a> HashStable> for hir::VisibilityKind { hir::VisibilityKind::Crate(sugar) => { sugar.hash_stable(hcx, hasher); } - hir::VisibilityKind::Restricted { ref path, id, hir_id } => { + hir::VisibilityKind::Restricted { ref path, hir_id } => { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - id.hash_stable(hcx, hasher); hir_id.hash_stable(hcx, hasher); }); path.hash_stable(hcx, hasher); @@ -836,15 +827,15 @@ impl_stable_hash_for!(struct hir::StructField { span, ident -> (ident.name), vis, - id, + hir_id, ty, attrs }); impl_stable_hash_for!(enum hir::VariantData { - Struct(fields, id), - Tuple(fields, id), - Unit(id) + Struct(fields, hir_id), + Tuple(fields, hir_id), + Unit(hir_id) }); impl<'a> HashStable> for hir::Item { @@ -854,7 +845,6 @@ impl<'a> HashStable> for hir::Item { let hir::Item { ident, ref attrs, - id: _, hir_id: _, ref node, ref vis, @@ -929,7 +919,7 @@ impl_stable_hash_for!(struct hir::ForeignItem { ident -> (ident.name), attrs, node, - id, + hir_id, span, vis }); @@ -941,14 +931,13 @@ impl_stable_hash_for!(enum hir::ForeignItemKind { }); impl_stable_hash_for!(enum hir::StmtKind { - Decl(decl, id), - Expr(expr, id), - Semi(expr, id) + Decl(decl, hir_id), + Expr(expr, hir_id), + Semi(expr, hir_id) }); impl_stable_hash_for!(struct hir::Arg { pat, - id, hir_id }); @@ -977,8 +966,8 @@ impl<'a> ToStableHashKey> for hir::BodyId { fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> (DefPathHash, hir::ItemLocalId) { - let hir::BodyId { node_id } = *self; - node_id.to_stable_hash_key(hcx) + let hir::BodyId { hir_id } = *self; + hir_id.to_stable_hash_key(hcx) } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 2995b25308d4c..c754007d9dbbb 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -56,7 +56,6 @@ use hir::def_id::DefId; use hir::Node; use middle::region; use std::{cmp, fmt}; -use syntax::ast::DUMMY_NODE_ID; use syntax_pos::{Pos, Span}; use traits::{ObligationCause, ObligationCauseCode}; use ty::error::TypeError; @@ -87,7 +86,7 @@ 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)) { + let tag = match self.hir().find_by_hir_id(scope.hir_id(self, region_scope_tree)) { Some(Node::Block(_)) => "block", Some(Node::Expr(expr)) => match expr.node { hir::ExprKind::Call(..) => "call", @@ -182,8 +181,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let cm = self.sess.source_map(); 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) { + let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); + let tag = match self.hir().find_by_hir_id(node) { 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), @@ -1184,12 +1183,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if !param.is_self() { let type_param = generics.type_param(param, self.tcx); let hir = &self.tcx.hir(); - hir.as_local_node_id(type_param.def_id).map(|id| { + hir.as_local_hir_id(type_param.def_id).map(|id| { // Get the `hir::Param` to verify whether it already has any bounds. // 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 Node::GenericParam(ref param) = hir.get(id) { + if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { has_bounds = !param.bounds.is_empty(); } let sp = hir.span(id); @@ -1434,8 +1433,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { format!(" for lifetime parameter `{}` in coherence check", name) } infer::UpvarRegion(ref upvar_id, _) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) } infer::NLL(..) => bug!("NLL variable found in lexical phase"), diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 8ee367c87c3ea..2ab99ba5f37b2 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -16,9 +16,9 @@ struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { } impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> { - fn node_matches_type(&mut self, node_id: HirId) -> bool { + fn node_matches_type(&mut self, hir_id: HirId) -> bool { let ty_opt = self.infcx.in_progress_tables.and_then(|tables| { - tables.borrow().node_id_to_type_opt(node_id) + tables.borrow().hir_id_to_type_opt(hir_id) }); match ty_opt { Some(ty) => { @@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }; if let Some(body_id) = body_id { - let expr = self.tcx.hir().expect_expr(body_id.node_id); + let expr = self.tcx.hir().expect_expr(body_id.hir_id); local_visitor.visit_expr(expr); } diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs index bfb5b61d0aa1f..4dc96047f7653 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) { (None, None) => { - let (main_label_1, span_label_1) = if ty_sup.id == ty_sub.id { + let (main_label_1, span_label_1) = if ty_sup.hir_id == ty_sub.hir_id { ( "this type is declared with multiple lifetimes...".to_owned(), "...but data with one lifetime flows into the other here".to_owned() diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index d230ce55471e9..6d61a8e85f16d 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -114,7 +114,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { hir::TyKind::Rptr(ref lifetime, _) => { // the lifetime of the TyRptr - let hir_id = self.tcx.hir().node_to_hir_id(lifetime.id); + let hir_id = lifetime.hir_id; match (self.tcx.named_region(hir_id), self.bound_region) { // Find the index of the anonymous region that was part of the // error. We will then search the function parameters for a bound @@ -221,7 +221,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> { } fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) { - let hir_id = self.tcx.hir().node_to_hir_id(lifetime.id); + let hir_id = lifetime.hir_id; match (self.tcx.named_region(hir_id), self.bound_region) { // the lifetime of the TyPath! (Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)), ty::BrAnon(br_index)) => { diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 43590a606ae90..c5564795d4084 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -51,8 +51,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { }; let hir = &self.tcx.hir(); - if let Some(node_id) = hir.as_local_node_id(id) { - if let Some(body_id) = hir.maybe_body_owned_by(node_id) { + if let Some(hir_id) = hir.as_local_hir_id(id) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); let fn_decl = hir.fn_decl(owner_id).unwrap(); @@ -63,8 +63,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { .filter_map(|(index, arg)| { // May return None; sometimes the tables are not yet populated. let ty_hir_id = fn_decl.inputs[index].hir_id; - let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id)); - let ty = tables.node_id_to_type_opt(arg.hir_id)?; + let arg_ty_span = hir.span(ty_hir_id); + let ty = tables.hir_id_to_type_opt(arg.hir_id)?; let mut found_anon_region = false; let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| { if *r == *anon_region { diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index e45a4b17cdd9c..3b42aab4a9b06 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -31,8 +31,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "...so that reference does not outlive borrowed content"); } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); err.span_note(span, &format!("...so that closure can access `{}`", var_name)); } @@ -48,10 +47,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "...so that pointer is not dereferenced outside its lifetime"); } infer::FreeVariable(span, id) => { + let hir_id = self.tcx.hir().node_to_hir_id(id); err.span_note(span, &format!("...so that captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name(id))); + self.tcx.hir().name(hir_id))); } infer::IndexSlice(span) => { err.span_note(span, "...so that slice is not indexed outside the lifetime"); @@ -164,8 +164,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); let mut err = struct_span_err!(self.tcx.sess, span, E0313, @@ -217,12 +216,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } infer::FreeVariable(span, id) => { + let hir_id = self.tcx.hir().node_to_hir_id(id); let mut err = struct_span_err!(self.tcx.sess, span, E0474, "captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name(id)); + self.tcx.hir().name(hir_id)); self.tcx.note_and_explain_region(region_scope_tree, &mut err, "captured variable is valid for ", sup, ""); self.tcx.note_and_explain_region(region_scope_tree, &mut err, diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 958982545750f..f4bbd5cf08ee2 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -9,6 +9,7 @@ pub use ty::IntVarValue; use arena::SyncDroplessArena; use errors::DiagnosticBuilder; +use hir; use hir::def_id::DefId; use infer::canonical::{Canonical, CanonicalVarValues}; use middle::free_region::RegionRelations; @@ -202,7 +203,7 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { // for each body-id in this map, which will process the // obligations within. This is expected to be done 'late enough' // that all type inference variables have been bound and so forth. - pub region_obligations: RefCell)>>, + pub region_obligations: RefCell)>>, /// What is the innermost universe we have created? Starts out as /// `UniverseIndex::root()` but grows from there as we enter @@ -1440,7 +1441,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn partially_normalize_associated_types_in( &self, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T, ) -> InferOk<'tcx, T> diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 5e94bb1f877fb..04ff374ebf156 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -4,7 +4,6 @@ use hir::Node; use infer::{self, InferCtxt, InferOk, TypeVariableOrigin}; use infer::outlives::free_region_map::FreeRegionRelations; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; use traits::{self, PredicateObligation}; use ty::{self, Ty, TyCtxt, GenericParamDefKind}; use ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder}; @@ -98,7 +97,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn instantiate_opaque_types>( &self, parent_def_id: DefId, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T, ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> { @@ -632,7 +631,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx> struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, parent_def_id: DefId, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, opaque_types: OpaqueTypeMap<'tcx>, obligations: Vec>, @@ -681,13 +680,14 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { // let x = || foo(); // returns the Opaque assoc with `foo` // } // ``` - if let Some(opaque_node_id) = tcx.hir().as_local_node_id(def_id) { + if let Some(opaque_hir_id) = tcx.hir().as_local_hir_id(def_id) { let parent_def_id = self.parent_def_id; let def_scope_default = || { - let opaque_parent_node_id = tcx.hir().get_parent(opaque_node_id); - parent_def_id == tcx.hir().local_def_id(opaque_parent_node_id) + let opaque_parent_hir_id = tcx.hir().get_parent(opaque_hir_id); + parent_def_id == tcx.hir().local_def_id_from_hir_id( + opaque_parent_hir_id) }; - let in_definition_scope = match tcx.hir().find(opaque_node_id) { + let in_definition_scope = match tcx.hir().find_by_hir_id(opaque_hir_id) { Some(Node::Item(item)) => match item.node { // impl trait hir::ItemKind::Existential(hir::ExistTy { @@ -701,7 +701,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { }) => may_define_existential_type( tcx, self.parent_def_id, - opaque_node_id, + opaque_hir_id, ), _ => def_scope_default(), }, @@ -709,13 +709,13 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { hir::ImplItemKind::Existential(_) => may_define_existential_type( tcx, self.parent_def_id, - opaque_node_id, + opaque_hir_id, ), _ => def_scope_default(), }, _ => bug!( "expected (impl) item, found {}", - tcx.hir().node_to_string(opaque_node_id), + tcx.hir().hir_to_string(opaque_hir_id), ), }; if in_definition_scope { @@ -813,7 +813,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { } } -/// Whether `opaque_node_id` is a sibling or a child of a sibling of `def_id` +/// Whether `opaque_hir_id` is a sibling or a child of a sibling of `def_id` /// /// ```rust /// pub mod foo { @@ -828,27 +828,27 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { /// ``` /// /// Here, `def_id` will be the `DefId` of the existential type `Baz`. -/// `opaque_node_id` is the `NodeId` of the reference to Baz -- +/// `opaque_hir_id` is the `HirId` of the reference to Baz -- /// so either the return type of f1 or f2. /// We will return true if the reference is within the same module as the existential type /// So true for f1, false for f2. pub fn may_define_existential_type( tcx: TyCtxt<'_, '_, '_>, def_id: DefId, - opaque_node_id: ast::NodeId, + opaque_hir_id: hir::HirId, ) -> bool { - let mut node_id = tcx + let mut hir_id = tcx .hir() - .as_local_node_id(def_id) + .as_local_hir_id(def_id) .unwrap(); // named existential types can be defined by any siblings or // children of siblings - let mod_id = tcx.hir().get_parent(opaque_node_id); + let mod_id = tcx.hir().get_parent(opaque_hir_id); // so we walk up the node tree until we hit the root or the parent // of the opaque type - while node_id != mod_id && node_id != ast::CRATE_NODE_ID { - node_id = tcx.hir().get_parent(node_id); + while hir_id != mod_id && hir_id != hir::CRATE_HIR_ID { + hir_id = tcx.hir().get_parent(hir_id); } // syntactically we are allowed to define the concrete type - node_id == mod_id + hir_id == mod_id } diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs index 677b6136ea03b..c9ad4da92a780 100644 --- a/src/librustc/infer/outlives/env.rs +++ b/src/librustc/infer/outlives/env.rs @@ -1,7 +1,7 @@ +use hir; use infer::outlives::free_region_map::FreeRegionMap; use infer::{GenericKind, InferCtxt}; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; use syntax_pos::Span; use traits::query::outlives_bounds::{self, OutlivesBound}; use ty::{self, Ty}; @@ -55,7 +55,7 @@ pub struct OutlivesEnvironment<'tcx> { // results when proving outlives obligations like `T: 'x` later // (e.g., if `T: 'x` must be proven within the body B1, then we // know it is true if either `'a: 'x` or `'b: 'x`). - region_bound_pairs_map: FxHashMap>, + region_bound_pairs_map: FxHashMap>, // Used to compute `region_bound_pairs_map`: contains the set of // in-scope region-bound pairs thus far. @@ -87,7 +87,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { } /// Borrows current value of the `region_bound_pairs`. - pub fn region_bound_pairs_map(&self) -> &FxHashMap> { + pub fn region_bound_pairs_map(&self) -> &FxHashMap> { &self.region_bound_pairs_map } @@ -162,7 +162,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { &mut self, infcx: &InferCtxt<'a, 'gcx, 'tcx>, fn_sig_tys: &[Ty<'tcx>], - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, ) { debug!("add_implied_bounds()"); @@ -176,7 +176,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { } /// Save the current set of region-bound pairs under the given `body_id`. - pub fn save_implied_bounds(&mut self, body_id: ast::NodeId) { + pub fn save_implied_bounds(&mut self, body_id: hir::HirId) { let old = self.region_bound_pairs_map.insert( body_id, self.region_bound_pairs_accum.clone(), diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index abe835c9211a5..c9e0a1c212db8 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -63,7 +63,7 @@ use infer::outlives::env::RegionBoundPairs; use infer::outlives::verify::VerifyBoundCx; use infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound}; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; +use hir; use traits::ObligationCause; use ty::outlives::Component; use ty::{self, Region, Ty, TyCtxt, TypeFoldable}; @@ -76,7 +76,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// information). pub fn register_region_obligation( &self, - body_id: ast::NodeId, + body_id: hir::HirId, obligation: RegionObligation<'tcx>, ) { debug!( @@ -110,7 +110,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { } /// Trait queries just want to pass back type obligations "as is" - pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> { + pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> { ::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![]) } @@ -149,7 +149,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// processed. pub fn process_registered_region_obligations( &self, - region_bound_pairs_map: &FxHashMap>, + region_bound_pairs_map: &FxHashMap>, implicit_region_bound: Option>, param_env: ty::ParamEnv<'tcx>, ) { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f5a7919ef09c8..38089e6423bea 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -514,6 +514,8 @@ pub struct LateContext<'a, 'tcx: 'a> { last_ast_node_with_lint_attrs: ast::NodeId, + last_hir_node_with_lint_attrs: hir::HirId, + /// Generic type parameters in scope for the item we are in. pub generics: Option<&'tcx hir::Generics>, } @@ -552,6 +554,10 @@ impl LintPassObject for EarlyLintPassObject {} impl LintPassObject for LateLintPassObject {} +pub enum ItemId { + Early(ast::NodeId), + Late(hir::HirId) +} pub trait LintContext<'tcx>: Sized { type PassObject: LintPassObject; @@ -629,7 +635,7 @@ pub trait LintContext<'tcx>: Sized { /// current lint context, call the provided function, then reset the /// lints in effect to their previous state. fn with_lint_attrs(&mut self, - id: ast::NodeId, + id: ItemId, attrs: &'tcx [ast::Attribute], f: F) where F: FnOnce(&mut Self); @@ -700,7 +706,7 @@ impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> { span: Option, msg: &str) -> DiagnosticBuilder<'_> { - let id = self.last_ast_node_with_lint_attrs; + let id = self.last_hir_node_with_lint_attrs; match span { Some(s) => self.tcx.struct_span_lint_node(lint, id, s, msg), None => self.tcx.struct_lint_node(lint, id, msg), @@ -708,13 +714,18 @@ impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> { } fn with_lint_attrs(&mut self, - id: ast::NodeId, + id: ItemId, attrs: &'tcx [ast::Attribute], f: F) where F: FnOnce(&mut Self) { + let id = match id { + ItemId::Early(_) => panic!("NodeId is not available in early lint context!"), + ItemId::Late(hir_id) => hir_id + }; + let prev = self.last_ast_node_with_lint_attrs; - self.last_ast_node_with_lint_attrs = id; + self.last_hir_node_with_lint_attrs = id; self.enter_attrs(attrs); f(self); self.exit_attrs(attrs); @@ -761,11 +772,16 @@ impl<'a> LintContext<'a> for EarlyContext<'a> { } fn with_lint_attrs(&mut self, - id: ast::NodeId, + id: ItemId, attrs: &'a [ast::Attribute], f: F) where F: FnOnce(&mut Self) { + let id = match id { + ItemId::Early(node_id) => node_id, + ItemId::Late(_) => panic!("HirId is not available in early lint context!") + }; + let push = self.builder.push(attrs); self.check_id(id); self.enter_attrs(attrs); @@ -776,16 +792,16 @@ impl<'a> LintContext<'a> for EarlyContext<'a> { } impl<'a, 'tcx> LateContext<'a, 'tcx> { - fn with_param_env(&mut self, id: ast::NodeId, f: F) + fn with_param_env(&mut self, id: hir::HirId, f: F) where F: FnOnce(&mut Self), { let old_param_env = self.param_env; - self.param_env = self.tcx.param_env(self.tcx.hir().local_def_id(id)); + self.param_env = self.tcx.param_env(self.tcx.hir().local_def_id_from_hir_id(id)); f(self); self.param_env = old_param_env; } - pub fn current_lint_root(&self) -> ast::NodeId { - self.last_ast_node_with_lint_attrs + pub fn current_lint_root(&self) -> hir::HirId { + self.last_hir_node_with_lint_attrs } } @@ -823,8 +839,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { fn visit_item(&mut self, it: &'tcx hir::Item) { let generics = self.generics.take(); self.generics = it.node.generics(); - self.with_lint_attrs(it.id, &it.attrs, |cx| { - cx.with_param_env(it.id, |cx| { + self.with_lint_attrs(ItemId::Late(it.hir_id), &it.attrs, |cx| { + cx.with_param_env(it.hir_id, |cx| { run_lints!(cx, check_item, it); hir_visit::walk_item(cx, it); run_lints!(cx, check_item_post, it); @@ -834,8 +850,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { - self.with_lint_attrs(it.id, &it.attrs, |cx| { - cx.with_param_env(it.id, |cx| { + self.with_lint_attrs(ItemId::Late(it.hir_id), &it.attrs, |cx| { + cx.with_param_env(it.hir_id, |cx| { run_lints!(cx, check_foreign_item, it); hir_visit::walk_foreign_item(cx, it); run_lints!(cx, check_foreign_item_post, it); @@ -849,7 +865,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_expr(&mut self, e: &'tcx hir::Expr) { - self.with_lint_attrs(e.id, &e.attrs, |cx| { + self.with_lint_attrs(ItemId::Late(e.hir_id), &e.attrs, |cx| { run_lints!(cx, check_expr, e); hir_visit::walk_expr(cx, e); run_lints!(cx, check_expr_post, e); @@ -867,7 +883,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_fn(&mut self, fk: hir_visit::FnKind<'tcx>, decl: &'tcx hir::FnDecl, - body_id: hir::BodyId, span: Span, id: ast::NodeId) { + body_id: hir::BodyId, span: Span, id: hir::HirId) { // Wrap in tables here, not just in visit_nested_body, // in order for `check_fn` to be able to use them. let old_tables = self.tables; @@ -883,7 +899,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { s: &'tcx hir::VariantData, name: ast::Name, g: &'tcx hir::Generics, - item_id: ast::NodeId, + item_id: hir::HirId, _: Span) { run_lints!(self, check_struct_def, s, name, g, item_id); hir_visit::walk_struct_def(self, s); @@ -891,7 +907,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { - self.with_lint_attrs(s.id, &s.attrs, |cx| { + self.with_lint_attrs(ItemId::Late(s.hir_id), &s.attrs, |cx| { run_lints!(cx, check_struct_field, s); hir_visit::walk_struct_field(cx, s); }) @@ -900,8 +916,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { fn visit_variant(&mut self, v: &'tcx hir::Variant, g: &'tcx hir::Generics, - item_id: ast::NodeId) { - self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |cx| { + item_id: hir::HirId) { + self.with_lint_attrs(ItemId::Late(v.node.data.hir_id()), &v.node.attrs, |cx| { run_lints!(cx, check_variant, v, g); hir_visit::walk_variant(cx, v, g, item_id); run_lints!(cx, check_variant_post, v, g); @@ -917,14 +933,14 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { run_lints!(self, check_name, sp, name); } - fn visit_mod(&mut self, m: &'tcx hir::Mod, s: Span, n: ast::NodeId) { - run_lints!(self, check_mod, m, s, n); - hir_visit::walk_mod(self, m, n); - run_lints!(self, check_mod_post, m, s, n); + fn visit_mod(&mut self, m: &'tcx hir::Mod, s: Span, h: hir::HirId) { + run_lints!(self, check_mod, m, s, h); + hir_visit::walk_mod(self, m, h); + run_lints!(self, check_mod_post, m, s, h); } fn visit_local(&mut self, l: &'tcx hir::Local) { - self.with_lint_attrs(l.id, &l.attrs, |cx| { + self.with_lint_attrs(ItemId::Late(l.hir_id), &l.attrs, |cx| { run_lints!(cx, check_local, l); hir_visit::walk_local(cx, l); }) @@ -970,8 +986,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { let generics = self.generics.take(); self.generics = Some(&trait_item.generics); - self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| { - cx.with_param_env(trait_item.id, |cx| { + self.with_lint_attrs(ItemId::Late(trait_item.hir_id), &trait_item.attrs, |cx| { + cx.with_param_env(trait_item.hir_id, |cx| { run_lints!(cx, check_trait_item, trait_item); hir_visit::walk_trait_item(cx, trait_item); run_lints!(cx, check_trait_item_post, trait_item); @@ -983,8 +999,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { let generics = self.generics.take(); self.generics = Some(&impl_item.generics); - self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| { - cx.with_param_env(impl_item.id, |cx| { + self.with_lint_attrs(ItemId::Late(impl_item.hir_id), &impl_item.attrs, |cx| { + cx.with_param_env(impl_item.hir_id, |cx| { run_lints!(cx, check_impl_item, impl_item); hir_visit::walk_impl_item(cx, impl_item); run_lints!(cx, check_impl_item_post, impl_item); @@ -1010,7 +1026,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { fn visit_item(&mut self, it: &'a ast::Item) { - self.with_lint_attrs(it.id, &it.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(it.id), &it.attrs, |cx| { run_lints!(cx, check_item, it); ast_visit::walk_item(cx, it); run_lints!(cx, check_item_post, it); @@ -1018,7 +1034,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) { - self.with_lint_attrs(it.id, &it.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(it.id), &it.attrs, |cx| { run_lints!(cx, check_foreign_item, it); ast_visit::walk_foreign_item(cx, it); run_lints!(cx, check_foreign_item_post, it); @@ -1035,7 +1051,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_expr(&mut self, e: &'a ast::Expr) { - self.with_lint_attrs(e.id, &e.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(e.id), &e.attrs, |cx| { run_lints!(cx, check_expr, e); ast_visit::walk_expr(cx, e); }) @@ -1068,14 +1084,14 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_struct_field(&mut self, s: &'a ast::StructField) { - self.with_lint_attrs(s.id, &s.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(s.id), &s.attrs, |cx| { run_lints!(cx, check_struct_field, s); ast_visit::walk_struct_field(cx, s); }) } fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) { - self.with_lint_attrs(item_id, &v.node.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(item_id), &v.node.attrs, |cx| { run_lints!(cx, check_variant, v, g); ast_visit::walk_variant(cx, v, g, item_id); run_lints!(cx, check_variant_post, v, g); @@ -1100,7 +1116,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_local(&mut self, l: &'a ast::Local) { - self.with_lint_attrs(l.id, &l.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(l.id), &l.attrs, |cx| { run_lints!(cx, check_local, l); ast_visit::walk_local(cx, l); }) @@ -1143,7 +1159,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) { - self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(trait_item.id), &trait_item.attrs, |cx| { run_lints!(cx, check_trait_item, trait_item); ast_visit::walk_trait_item(cx, trait_item); run_lints!(cx, check_trait_item_post, trait_item); @@ -1151,7 +1167,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) { - self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| { + self.with_lint_attrs(ItemId::Early(impl_item.id), &impl_item.attrs, |cx| { run_lints!(cx, check_impl_item, impl_item); ast_visit::walk_impl_item(cx, impl_item); run_lints!(cx, check_impl_item_post, impl_item); @@ -1211,11 +1227,12 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { lints: tcx.sess.lint_store.borrow(), }, last_ast_node_with_lint_attrs: ast::CRATE_NODE_ID, + last_hir_node_with_lint_attrs: hir::CRATE_HIR_ID, generics: None, }; // Visit the whole crate. - cx.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |cx| { + cx.with_lint_attrs(ItemId::Early(ast::CRATE_NODE_ID), &krate.attrs, |cx| { // since the root module isn't visited as an item (because it isn't an // item), warn for it here. run_lints!(cx, check_crate, krate); @@ -1251,7 +1268,7 @@ pub fn check_ast_crate( let mut cx = EarlyContext::new(sess, krate, passes, buffered); // Visit the whole crate. - cx.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |cx| { + cx.with_lint_attrs(ItemId::Early(ast::CRATE_NODE_ID), &krate.attrs, |cx| { // since the root module isn't visited as an item (because it isn't an // item), warn for it here. run_lints!(cx, check_crate, krate); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 730ce919bd295..f04145642cb4d 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -180,8 +180,8 @@ macro_rules! late_lint_methods { fn check_name(a: Span, b: ast::Name); fn check_crate(a: &$hir hir::Crate); fn check_crate_post(a: &$hir hir::Crate); - fn check_mod(a: &$hir hir::Mod, b: Span, c: ast::NodeId); - fn check_mod_post(a: &$hir hir::Mod, b: Span, c: ast::NodeId); + fn check_mod(a: &$hir hir::Mod, b: Span, c: hir::HirId); + fn check_mod_post(a: &$hir hir::Mod, b: Span, c: hir::HirId); fn check_foreign_item(a: &$hir hir::ForeignItem); fn check_foreign_item_post(a: &$hir hir::ForeignItem); fn check_item(a: &$hir hir::Item); @@ -205,13 +205,13 @@ macro_rules! late_lint_methods { b: &$hir hir::FnDecl, c: &$hir hir::Body, d: Span, - e: ast::NodeId); + e: hir::HirId); fn check_fn_post( a: hir::intravisit::FnKind<$hir>, b: &$hir hir::FnDecl, c: &$hir hir::Body, d: Span, - e: ast::NodeId + e: hir::HirId ); fn check_trait_item(a: &$hir hir::TraitItem); fn check_trait_item_post(a: &$hir hir::TraitItem); @@ -221,13 +221,13 @@ macro_rules! late_lint_methods { a: &$hir hir::VariantData, b: ast::Name, c: &$hir hir::Generics, - d: ast::NodeId + d: hir::HirId ); fn check_struct_def_post( a: &$hir hir::VariantData, b: ast::Name, c: &$hir hir::Generics, - d: ast::NodeId + d: hir::HirId ); fn check_struct_field(a: &$hir hir::StructField); fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics); @@ -636,7 +636,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum) }; let krate = tcx.hir().krate(); - builder.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |builder| { + builder.with_lint_attrs(hir::CRATE_HIR_ID, &krate.attrs, |builder| { intravisit::walk_crate(builder, krate); }); @@ -650,13 +650,13 @@ struct LintLevelMapBuilder<'a, 'tcx: 'a> { impl<'a, 'tcx> LintLevelMapBuilder<'a, 'tcx> { fn with_lint_attrs(&mut self, - id: ast::NodeId, + hir_id: hir::HirId, attrs: &[ast::Attribute], f: F) where F: FnOnce(&mut Self) { let push = self.levels.push(attrs); - self.levels.register_id(self.tcx.hir().definitions().node_to_hir_id(id)); + self.levels.register_id(hir_id); f(self); self.levels.pop(push); } @@ -668,25 +668,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> { } fn visit_item(&mut self, it: &'tcx hir::Item) { - self.with_lint_attrs(it.id, &it.attrs, |builder| { + self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_item(builder, it); }); } fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { - self.with_lint_attrs(it.id, &it.attrs, |builder| { + self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_foreign_item(builder, it); }) } fn visit_expr(&mut self, e: &'tcx hir::Expr) { - self.with_lint_attrs(e.id, &e.attrs, |builder| { + self.with_lint_attrs(e.hir_id, &e.attrs, |builder| { intravisit::walk_expr(builder, e); }) } fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { - self.with_lint_attrs(s.id, &s.attrs, |builder| { + self.with_lint_attrs(s.hir_id, &s.attrs, |builder| { intravisit::walk_struct_field(builder, s); }) } @@ -694,26 +694,26 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> { fn visit_variant(&mut self, v: &'tcx hir::Variant, g: &'tcx hir::Generics, - item_id: ast::NodeId) { - self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |builder| { + item_id: hir::HirId) { + self.with_lint_attrs(v.node.data.hir_id(), &v.node.attrs, |builder| { intravisit::walk_variant(builder, v, g, item_id); }) } fn visit_local(&mut self, l: &'tcx hir::Local) { - self.with_lint_attrs(l.id, &l.attrs, |builder| { + self.with_lint_attrs(l.hir_id, &l.attrs, |builder| { intravisit::walk_local(builder, l); }) } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - self.with_lint_attrs(trait_item.id, &trait_item.attrs, |builder| { + self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| { intravisit::walk_trait_item(builder, trait_item); }); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - self.with_lint_attrs(impl_item.id, &impl_item.attrs, |builder| { + self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| { intravisit::walk_impl_item(builder, impl_item); }); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0c769c91801b8..d36f8eefadc0e 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -26,8 +26,8 @@ use syntax_pos; // 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) { + hir_id: hir::HirId) -> bool { + match tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(..)) | Some(Node::ImplItem(..)) | Some(Node::ForeignItem(..)) | @@ -39,33 +39,33 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } struct MarkSymbolVisitor<'a, 'tcx: 'a> { - worklist: Vec, + worklist: Vec, tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, - live_symbols: FxHashSet, + live_symbols: FxHashSet, repr_has_repr_c: bool, in_pat: bool, inherited_pub_visibility: bool, ignore_variant_stack: Vec, // maps from tuple struct constructors to tuple struct items - struct_constructors: FxHashMap, + struct_constructors: FxHashMap, } impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn check_def_id(&mut self, def_id: DefId) { - if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { - if should_explore(self.tcx, node_id) || - self.struct_constructors.contains_key(&node_id) { - self.worklist.push(node_id); + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { + if should_explore(self.tcx, hir_id) || + self.struct_constructors.contains_key(&hir_id) { + self.worklist.push(hir_id); } - self.live_symbols.insert(node_id); + self.live_symbols.insert(hir_id); } } fn insert_def_id(&mut self, def_id: DefId) { - if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { - debug_assert!(!should_explore(self.tcx, node_id)); - self.live_symbols.insert(node_id); + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { + debug_assert!(!should_explore(self.tcx, hir_id)); + self.live_symbols.insert(hir_id); } } @@ -99,10 +99,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } } - fn handle_field_access(&mut self, lhs: &hir::Expr, node_id: ast::NodeId) { + fn handle_field_access(&mut self, lhs: &hir::Expr, hir_id: hir::HirId) { match self.tables.expr_ty_adjusted(lhs).sty { ty::Adt(def, _) => { - let index = self.tcx.field_index(node_id, self.tables); + let index = self.tcx.field_index(hir_id, self.tables); self.insert_def_id(def.non_enum_variant().fields[index].did); } ty::Tuple(..) => {} @@ -112,7 +112,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def, pats: &[source_map::Spanned]) { - let variant = match self.tables.node_id_to_type(lhs.hir_id).sty { + let variant = match self.tables.hir_id_to_type(lhs.hir_id).sty { ty::Adt(adt, _) => adt.variant_of_def(def), _ => span_bug!(lhs.span, "non-ADT in struct pattern") }; @@ -120,7 +120,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { if let PatKind::Wild = pat.node.pat.node { continue; } - let index = self.tcx.field_index(pat.node.id, self.tables); + let index = self.tcx.field_index(pat.node.hir_id, self.tables); self.insert_def_id(variant.fields[index].did); } } @@ -136,7 +136,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { // tuple struct constructor function let id = self.struct_constructors.get(&id).cloned().unwrap_or(id); - if let Some(node) = self.tcx.hir().find(id) { + if let Some(node) = self.tcx.hir().find_by_hir_id(id) { self.live_symbols.insert(id); self.visit_node(node); } @@ -152,7 +152,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { Node::Item(item) => { match item.node { hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let def = self.tcx.adt_def(def_id); self.repr_has_repr_c = def.repr.c(); @@ -190,7 +190,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &hir::HirVec) { if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() { for field in fields { - let index = self.tcx.field_index(field.id, self.tables); + let index = self.tcx.field_index(field.hir_id, self.tables); self.insert_def_id(adt.non_enum_variant().fields[index].did); } } @@ -211,13 +211,13 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { } fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name, - _: &hir::Generics, _: ast::NodeId, _: syntax_pos::Span) { + _: &hir::Generics, _: hir::HirId, _: syntax_pos::Span) { let has_repr_c = self.repr_has_repr_c; let inherited_pub_visibility = self.inherited_pub_visibility; let live_fields = def.fields().iter().filter(|f| { has_repr_c || inherited_pub_visibility || f.vis.node.is_pub() }); - self.live_symbols.extend(live_fields.map(|f| f.id)); + self.live_symbols.extend(live_fields.map(|f| f.hir_id)); intravisit::walk_struct_def(self, def); } @@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { self.lookup_and_handle_method(expr.hir_id); } hir::ExprKind::Field(ref lhs, ..) => { - self.handle_field_access(&lhs, expr.id); + self.handle_field_access(&lhs, expr.hir_id); } hir::ExprKind::Struct(_, ref fields, _) => { if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).sty { @@ -285,7 +285,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { } fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, - id: ast::NodeId, + id: hir::HirId, attrs: &[ast::Attribute]) -> bool { if attr::contains_name(attrs, "lang") { return true; @@ -306,7 +306,7 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, return true; } - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); let cg_attrs = tcx.codegen_fn_attrs(def_id); // #[used], #[no_mangle], #[export_name], etc also keeps the item alive @@ -333,25 +333,25 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, // 2) We are not sure to be live or not // * Implementation of a trait method struct LifeSeeder<'k, 'tcx: 'k> { - worklist: Vec, + worklist: Vec, krate: &'k hir::Crate, tcx: TyCtxt<'k, 'tcx, 'tcx>, // see `MarkSymbolVisitor::struct_constructors` - struct_constructors: FxHashMap, + struct_constructors: FxHashMap, } impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, - item.id, + item.hir_id, &item.attrs); if allow_dead_code { - self.worklist.push(item.id); + self.worklist.push(item.hir_id); } match item.node { hir::ItemKind::Enum(ref enum_def, _) if allow_dead_code => { self.worklist.extend(enum_def.variants.iter() - .map(|variant| variant.node.data.id())); + .map(|variant| variant.node.data.hir_id())); } hir::ItemKind::Trait(.., ref trait_item_refs) => { for trait_item_ref in trait_item_refs { @@ -360,9 +360,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { hir::TraitItemKind::Const(_, Some(_)) | hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => { if has_allow_dead_code_or_lang_attr(self.tcx, - trait_item.id, + trait_item.hir_id, &trait_item.attrs) { - self.worklist.push(trait_item.id); + self.worklist.push(trait_item.hir_id); } } _ => {} @@ -374,14 +374,14 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { let impl_item = self.krate.impl_item(impl_item_ref.id); if opt_trait.is_some() || has_allow_dead_code_or_lang_attr(self.tcx, - impl_item.id, + impl_item.hir_id, &impl_item.attrs) { - self.worklist.push(impl_item_ref.id.node_id); + self.worklist.push(impl_item.hir_id); } } } hir::ItemKind::Struct(ref variant_data, _) => { - self.struct_constructors.insert(variant_data.id(), item.id); + self.struct_constructors.insert(variant_data.hir_id(), item.hir_id); } _ => () } @@ -400,10 +400,11 @@ fn create_and_seed_worklist<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &privacy::AccessLevels, krate: &hir::Crate, -) -> (Vec, FxHashMap) { +) -> (Vec, FxHashMap) { let worklist = access_levels.map.iter().filter_map(|(&id, level)| { if level >= &privacy::AccessLevel::Reachable { - Some(id) + let hir_id = tcx.hir().node_to_hir_id(id); + Some(hir_id) } else { None } @@ -427,7 +428,7 @@ fn create_and_seed_worklist<'a, 'tcx>( fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &privacy::AccessLevels, krate: &hir::Crate) - -> FxHashSet { + -> FxHashSet { let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate); let mut symbol_visitor = MarkSymbolVisitor { worklist, @@ -446,7 +447,7 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, struct DeadVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - live_symbols: FxHashSet, + live_symbols: FxHashSet, } impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { @@ -461,33 +462,33 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { | hir::ItemKind::Union(..) => true, _ => false }; - should_warn && !self.symbol_is_live(item.id) + should_warn && !self.symbol_is_live(item.hir_id) } fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool { - let field_type = self.tcx.type_of(self.tcx.hir().local_def_id(field.id)); + let field_type = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id)); !field.is_positional() - && !self.symbol_is_live(field.id) + && !self.symbol_is_live(field.hir_id) && !field_type.is_phantom_data() - && !has_allow_dead_code_or_lang_attr(self.tcx, field.id, &field.attrs) + && !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id, &field.attrs) } fn should_warn_about_variant(&mut self, variant: &hir::VariantKind) -> bool { - !self.symbol_is_live(variant.data.id()) + !self.symbol_is_live(variant.data.hir_id()) && !has_allow_dead_code_or_lang_attr(self.tcx, - variant.data.id(), + variant.data.hir_id(), &variant.attrs) } fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem) -> bool { - !self.symbol_is_live(fi.id) - && !has_allow_dead_code_or_lang_attr(self.tcx, fi.id, &fi.attrs) + !self.symbol_is_live(fi.hir_id) + && !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id, &fi.attrs) } // id := node id of an item's definition. fn symbol_is_live( &mut self, - id: ast::NodeId, + id: hir::HirId, ) -> bool { if self.live_symbols.contains(&id) { return true; @@ -496,12 +497,12 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { // This is done to handle the case where, for example, the static // method of a private type is used, but the type itself is never // called directly. - let def_id = self.tcx.hir().local_def_id(id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(id); let inherent_impls = self.tcx.inherent_impls(def_id); for &impl_did in inherent_impls.iter() { for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] { - if let Some(item_node_id) = self.tcx.hir().as_local_node_id(item_did) { - if self.live_symbols.contains(&item_node_id) { + if let Some(item_hir_id) = self.tcx.hir().as_local_hir_id(item_did) { + if self.live_symbols.contains(&item_hir_id) { return true; } } @@ -511,7 +512,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { } fn warn_dead_code(&mut self, - id: ast::NodeId, + id: hir::HirId, span: syntax_pos::Span, name: ast::Name, node_type: &str, @@ -555,7 +556,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { _ => "used" }; self.warn_dead_code( - item.id, + item.hir_id, span, item.ident.name, item.node.descriptive_variant(), @@ -570,9 +571,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { fn visit_variant(&mut self, variant: &'tcx hir::Variant, g: &'tcx hir::Generics, - id: ast::NodeId) { + id: hir::HirId) { if self.should_warn_about_variant(&variant.node) { - self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.ident.name, + self.warn_dead_code(variant.node.data.hir_id(), variant.span, variant.node.ident.name, "variant", "constructed"); } else { intravisit::walk_variant(self, variant, g, id); @@ -581,7 +582,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) { if self.should_warn_about_foreign_item(fi) { - self.warn_dead_code(fi.id, fi.span, fi.ident.name, + self.warn_dead_code(fi.hir_id, fi.span, fi.ident.name, fi.node.descriptive_variant(), "used"); } intravisit::walk_foreign_item(self, fi); @@ -589,7 +590,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { fn visit_struct_field(&mut self, field: &'tcx hir::StructField) { if self.should_warn_about_field(&field) { - self.warn_dead_code(field.id, field.span, field.ident.name, "field", "used"); + self.warn_dead_code(field.hir_id, field.span, field.ident.name, "field", "used"); } intravisit::walk_struct_field(self, field); } @@ -597,8 +598,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { match impl_item.node { hir::ImplItemKind::Const(_, body_id) => { - if !self.symbol_is_live(impl_item.id) { - self.warn_dead_code(impl_item.id, + if !self.symbol_is_live(impl_item.hir_id) { + self.warn_dead_code(impl_item.hir_id, impl_item.span, impl_item.ident.name, "associated const", @@ -607,9 +608,10 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { self.visit_nested_body(body_id) } hir::ImplItemKind::Method(_, body_id) => { - if !self.symbol_is_live(impl_item.id) { + if !self.symbol_is_live(impl_item.hir_id) { let span = self.tcx.sess.source_map().def_span(impl_item.span); - self.warn_dead_code(impl_item.id, span, impl_item.ident.name, "method", "used"); + self.warn_dead_code(impl_item.hir_id, span, impl_item.ident.name, "method", + "used"); } self.visit_nested_body(body_id) } diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 6b593a1a9f9b2..cf612d46be24b 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -1,8 +1,8 @@ use hir::map as hir_map; use hir::def_id::{CRATE_DEF_INDEX}; +use hir::HirId; use session::{config, Session}; use session::config::EntryFnType; -use syntax::ast::NodeId; use syntax::attr; use syntax::entry::EntryPointType; use syntax_pos::Span; @@ -15,22 +15,22 @@ struct EntryContext<'a, 'tcx: 'a> { map: &'a hir_map::Map<'tcx>, // The top-level function called 'main' - main_fn: Option<(NodeId, Span)>, + main_fn: Option<(HirId, Span)>, // The function that has attribute named 'main' - attr_main_fn: Option<(NodeId, Span)>, + attr_main_fn: Option<(HirId, Span)>, // The function that has the attribute 'start' on it - start_fn: Option<(NodeId, Span)>, + start_fn: Option<(HirId, Span)>, // The functions that one might think are 'main' but aren't, e.g. // main functions not defined at the top level. For diagnostics. - non_main_fns: Vec<(NodeId, Span)> , + non_main_fns: Vec<(HirId, Span)> , } impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx Item) { - let def_id = self.map.local_def_id(item.id); + let def_id = self.map.local_def_id_from_hir_id(item.hir_id); let def_key = self.map.def_key(def_id); let at_root = def_key.parent == Some(CRATE_DEF_INDEX); find_item(item, self, at_root); @@ -106,18 +106,18 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { match entry_point_type(item, at_root) { EntryPointType::MainNamed => { if ctxt.main_fn.is_none() { - ctxt.main_fn = Some((item.id, item.span)); + ctxt.main_fn = Some((item.hir_id, item.span)); } else { span_err!(ctxt.session, item.span, E0136, "multiple 'main' functions"); } }, EntryPointType::OtherMain => { - ctxt.non_main_fns.push((item.id, item.span)); + ctxt.non_main_fns.push((item.hir_id, item.span)); }, EntryPointType::MainAttr => { if ctxt.attr_main_fn.is_none() { - ctxt.attr_main_fn = Some((item.id, item.span)); + ctxt.attr_main_fn = Some((item.hir_id, item.span)); } else { struct_span_err!(ctxt.session, item.span, E0137, "multiple functions with a #[main] attribute") @@ -128,7 +128,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { }, EntryPointType::Start => { if ctxt.start_fn.is_none() { - ctxt.start_fn = Some((item.id, item.span)); + ctxt.start_fn = Some((item.hir_id, item.span)); } else { struct_span_err!(ctxt.session, item.span, E0138, "multiple 'start' functions") .span_label(ctxt.start_fn.unwrap().1, "previous `start` function here") diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index c1aa25b6b75c2..488abc65fd506 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -19,7 +19,6 @@ use ty::{self, TyCtxt, adjustment}; use hir::{self, PatKind}; use rustc_data_structures::sync::Lrc; use std::rc::Rc; -use syntax::ast; use syntax::ptr::P; use syntax_pos::Span; use util::nodemap::ItemLocalSet; @@ -33,7 +32,7 @@ pub trait Delegate<'tcx> { // The value found at `cmt` is either copied or moved, depending // on mode. fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: ConsumeMode); @@ -65,7 +64,7 @@ pub trait Delegate<'tcx> { // The value found at `borrow` is being borrowed at the point // `borrow_id` for the region `loan_region` with kind `bk`. fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, @@ -74,12 +73,12 @@ pub trait Delegate<'tcx> { // The local variable `id` is declared but not initialized. fn decl_without_init(&mut self, - id: ast::NodeId, + id: hir::HirId, span: Span); // The path at `cmt` is being assigned to. fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, mode: MutateMode); @@ -329,10 +328,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } fn delegate_consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>) { - debug!("delegate_consume(consume_id={}, cmt={:?})", + debug!("delegate_consume(consume_id={:?}, cmt={:?})", consume_id, cmt); let mode = copy_or_move(&self.mc, self.param_env, cmt, DirectRefMove); @@ -349,7 +348,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { debug!("consume_expr(expr={:?})", expr); let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate_consume(expr.id, expr.span, &cmt); + self.delegate_consume(expr.hir_id, expr.span, &cmt); self.walk_expr(expr); } @@ -359,7 +358,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr: &hir::Expr, mode: MutateMode) { let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate.mutate(assignment_expr.id, span, &cmt, mode); + self.delegate.mutate(assignment_expr.hir_id, span, &cmt, mode); self.walk_expr(expr); } @@ -372,7 +371,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr, r, bk); let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate.borrow(expr.id, expr.span, &cmt, r, bk, cause); + self.delegate.borrow(expr.hir_id, expr.span, &cmt, r, bk, cause); self.walk_expr(expr) } @@ -589,7 +588,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { fn walk_stmt(&mut self, stmt: &hir::Stmt) { match stmt.node { - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { match decl.node { hir::DeclKind::Local(ref local) => { self.walk_local(&local); @@ -602,8 +601,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - hir::StmtKind::Expr(ref expr, _) | - hir::StmtKind::Semi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, ..) | + hir::StmtKind::Semi(ref expr, ..) => { self.consume_expr(&expr); } } @@ -613,8 +612,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { match local.init { None => { local.pat.each_binding(|_, hir_id, span, _| { - let node_id = self.mc.tcx.hir().hir_to_node_id(hir_id); - self.delegate.decl_without_init(node_id, span); + self.delegate.decl_without_init(hir_id, span); }) } @@ -633,7 +631,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// Indicates that the value of `blk` will be consumed, meaning either copied or moved /// depending on its type. fn walk_block(&mut self, blk: &hir::Block) { - debug!("walk_block(blk.id={})", blk.id); + debug!("walk_block(blk.hir_id={:?})", blk.hir_id); for stmt in &blk.stmts { self.walk_stmt(stmt); @@ -666,7 +664,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // Consume those fields of the with expression that are needed. for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() { let is_mentioned = fields.iter().any(|f| { - self.tcx().field_index(f.id, self.mc.tables) == f_index + self.tcx().field_index(f.hir_id, self.mc.tables) == f_index }); if !is_mentioned { let cmt_field = self.mc.cat_field( @@ -676,7 +674,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { with_field.ident, with_field.ty(self.tcx(), substs) ); - self.delegate_consume(with_expr.id, with_expr.span, &cmt_field); + self.delegate_consume(with_expr.hir_id, with_expr.span, &cmt_field); } } } @@ -715,7 +713,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { adjustment::Adjust::Unsize => { // Creating a closure/fn-pointer or unsizing consumes // the input and stores it into the resulting rvalue. - self.delegate_consume(expr.id, expr.span, &cmt); + self.delegate_consume(expr.hir_id, expr.span, &cmt); } adjustment::Adjust::Deref(None) => {} @@ -727,7 +725,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // this is an autoref of `x`. adjustment::Adjust::Deref(Some(ref deref)) => { let bk = ty::BorrowKind::from_mutbl(deref.mutbl); - self.delegate.borrow(expr.id, expr.span, &cmt, deref.region, bk, AutoRef); + self.delegate.borrow(expr.hir_id, expr.span, &cmt, deref.region, bk, AutoRef); } adjustment::Adjust::Borrow(ref autoref) => { @@ -745,14 +743,14 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr: &hir::Expr, cmt_base: &mc::cmt_<'tcx>, autoref: &adjustment::AutoBorrow<'tcx>) { - debug!("walk_autoref(expr.id={} cmt_base={:?} autoref={:?})", - expr.id, + debug!("walk_autoref(expr.id={:?} cmt_base={:?} autoref={:?})", + expr.hir_id, cmt_base, autoref); match *autoref { adjustment::AutoBorrow::Ref(r, m) => { - self.delegate.borrow(expr.id, + self.delegate.borrow(expr.hir_id, expr.span, cmt_base, r, @@ -761,8 +759,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } adjustment::AutoBorrow::RawPtr(m) => { - debug!("walk_autoref: expr.id={} cmt_base={:?}", - expr.id, + debug!("walk_autoref: expr.id={:?} cmt_base={:?}", + expr.hir_id, cmt_base); // Converting from a &T to *T (or &mut T to *mut T) is @@ -774,7 +772,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { data: region::ScopeData::Node })); - self.delegate.borrow(expr.id, + self.delegate.borrow(expr.hir_id, expr.span, cmt_base, r, @@ -868,7 +866,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // binding being produced. let def = Def::Local(canonical_id); if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) { - delegate.mutate(pat.id, pat.span, binding_cmt, MutateMode::Init); + delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init); } // It is also a borrow or copy/move of the value being matched. @@ -876,7 +874,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { ty::BindByReference(m) => { if let ty::Ref(r, _, _) = pat_ty.sty { let bk = ty::BorrowKind::from_mutbl(m); - delegate.borrow(pat.id, pat.span, &cmt_pat, r, bk, RefBinding); + delegate.borrow(pat.hir_id, pat.span, &cmt_pat, r, bk, RefBinding); } } ty::BindByValue(..) => { @@ -924,10 +922,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) { debug!("walk_captures({:?})", closure_expr); - self.tcx().with_freevars(closure_expr.id, |freevars| { + self.tcx().with_freevars(closure_expr.hir_id, |freevars| { for freevar in freevars { - let var_hir_id = self.tcx().hir().node_to_hir_id(freevar.var_id()); - let closure_def_id = self.tcx().hir().local_def_id(closure_expr.id); + let var_hir_id = freevar.var_id(); + let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id.to_local(), @@ -942,10 +940,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { self.param_env, &cmt_var, CaptureMove); - self.delegate.consume(closure_expr.id, freevar.span, &cmt_var, mode); + self.delegate.consume(closure_expr.hir_id, freevar.span, &cmt_var, mode); } ty::UpvarCapture::ByRef(upvar_borrow) => { - self.delegate.borrow(closure_expr.id, + self.delegate.borrow(closure_expr.hir_id, fn_decl_span, &cmt_var, upvar_borrow.region, @@ -964,7 +962,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { -> mc::McResult> { // Create the cmt for the variable being borrowed, from the // caller's perspective - let var_hir_id = self.tcx().hir().node_to_hir_id(upvar.var_id()); + let var_hir_id = upvar.var_id(); let var_ty = self.mc.node_ty(var_hir_id)?; self.mc.cat_def(closure_hir_id, closure_span, var_ty, upvar.def) } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 1716daaa107c4..78ad2d209f44e 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -151,7 +151,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { }; if let Def::Fn(did) = def { if self.def_id_is_transmute(did) { - let typ = self.tables.node_id_to_type(expr.hir_id); + let typ = self.tables.hir_id_to_type(expr.hir_id); let sig = typ.fn_sig(self.tcx); let from = sig.inputs().skip_binder()[0]; let to = *sig.output().skip_binder(); diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index c203ea96f3d64..282afa79572ce 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -98,7 +98,7 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> { match self.item_refs.get(&*value.as_str()).cloned() { // Known lang item with attribute on correct target. Some((item_index, expected_target)) if actual_target == expected_target => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); self.collect_item(item_index, def_id); }, // Known lang item with attribute on incorrect target. diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index a78cf1a471b4b..fa1dcf2b1c0e2 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -102,14 +102,14 @@ use hir::Node; use ty::{self, TyCtxt}; use lint; use errors::Applicability; -use util::nodemap::{NodeMap, HirIdMap, HirIdSet}; +use util::nodemap::{HirIdMap, HirIdSet}; use std::collections::VecDeque; use std::{fmt, u32}; use std::io::prelude::*; use std::io; use std::rc::Rc; -use syntax::ast::{self, NodeId}; +use syntax::ast; use syntax::ptr::P; use syntax::symbol::keywords; use syntax_pos::Span; @@ -170,7 +170,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> { } fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl, - b: hir::BodyId, s: Span, id: NodeId) { + b: hir::BodyId, s: Span, id: HirId) { visit_fn(self, fk, fd, b, s, id); } @@ -251,7 +251,7 @@ struct IrMaps<'a, 'tcx: 'a> { num_vars: usize, live_node_map: HirIdMap, variable_map: HirIdMap, - capture_info_map: NodeMap>>, + capture_info_map: HirIdMap>>, var_kinds: Vec, lnks: Vec, } @@ -330,8 +330,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> { } } - fn set_captures(&mut self, node_id: NodeId, cs: Vec) { - self.capture_info_map.insert(node_id, Rc::new(cs)); + fn set_captures(&mut self, hir_id: hir::HirId, cs: Vec) { + self.capture_info_map.insert(hir_id, Rc::new(cs)); } fn lnk(&self, ln: LiveNode) -> LiveNodeKind { @@ -344,7 +344,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>, decl: &'tcx hir::FnDecl, body_id: hir::BodyId, sp: Span, - id: ast::NodeId) { + id: hir::HirId) { debug!("visit_fn"); // swap in a new set of IR maps for this function body: @@ -353,7 +353,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(Node::Item(i)) = ir.tcx.hir().find(parent) { + if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) { if i.attrs.iter().any(|a| a.check_name("automatically_derived")) { return; } @@ -446,7 +446,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) { match expr.node { // live nodes required for uses or definitions of variables: hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => { - debug!("expr {}: path that leads to {:?}", expr.id, path.def); + debug!("expr {:?}: path that leads to {:?}", expr.hir_id, path.def); if let Def::Local(..) = path.def { ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span)); } @@ -462,18 +462,17 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) { // in better error messages than just pointing at the closure // construction site. let mut call_caps = Vec::new(); - ir.tcx.with_freevars(expr.id, |freevars| { + ir.tcx.with_freevars(expr.hir_id, |freevars| { call_caps.extend(freevars.iter().filter_map(|fv| { if let Def::Local(rv) = fv.def { let fv_ln = ir.add_live_node(FreeVarNode(fv.span)); - let var_hid = ir.tcx.hir().node_to_hir_id(rv); - Some(CaptureInfo { ln: fv_ln, var_hid }) + Some(CaptureInfo { ln: fv_ln, var_hid: rv }) } else { None } })); }); - ir.set_captures(expr.id, call_caps); + ir.set_captures(expr.hir_id, call_caps); intravisit::walk_expr(ir, expr); } @@ -655,8 +654,8 @@ struct Liveness<'a, 'tcx: 'a> { // mappings from loop node ID to LiveNode // ("break" label should map to loop node ID, // it probably doesn't now) - break_ln: NodeMap, - cont_ln: NodeMap, + break_ln: HirIdMap, + cont_ln: HirIdMap, } impl<'a, 'tcx> Liveness<'a, 'tcx> { @@ -915,12 +914,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // effectively a return---this only occurs in `for` loops, // where the body is really a closure. - debug!("compute: using id for body, {}", self.ir.tcx.hir().node_to_pretty_string(body.id)); + debug!("compute: using id for body, {}", + self.ir.tcx.hir().node_to_pretty_string_by_hir_id(body.hir_id)); let exit_ln = self.s.exit_ln; - self.break_ln.insert(body.id, exit_ln); - self.cont_ln.insert(body.id, exit_ln); + self.break_ln.insert(body.hir_id, exit_ln); + self.cont_ln.insert(body.hir_id, exit_ln); // the fallthrough exit is only for those cases where we do not // explicitly return: @@ -931,11 +931,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let entry_ln = self.propagate_through_expr(body, s.fallthrough_ln); // hack to skip the loop unless debug! is enabled: - debug!("^^ liveness computation results for body {} (entry={:?})", { + debug!("^^ liveness computation results for body {:?} (entry={:?})", { for ln_idx in 0..self.ir.num_live_nodes { debug!("{:?}", self.ln_str(LiveNode(ln_idx as u32))); } - body.id + body.hir_id }, entry_ln); @@ -945,7 +945,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode) -> LiveNode { if blk.targeted_by_break { - self.break_ln.insert(blk.id, succ); + self.break_ln.insert(blk.hir_id, succ); } let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ); blk.stmts.iter().rev().fold(succ, |succ, stmt| { @@ -956,11 +956,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_stmt(&mut self, stmt: &hir::Stmt, succ: LiveNode) -> LiveNode { match stmt.node { - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { self.propagate_through_decl(&decl, succ) } - hir::StmtKind::Expr(ref expr, _) | hir::StmtKind::Semi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, ..) | hir::StmtKind::Semi(ref expr, ..) => { self.propagate_through_expr(&expr, succ) } } @@ -1012,7 +1012,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode) -> LiveNode { - debug!("propagate_through_expr: {}", self.ir.tcx.hir().node_to_pretty_string(expr.id)); + debug!("propagate_through_expr: {}", + self.ir.tcx.hir().node_to_pretty_string_by_hir_id(expr.hir_id)); match expr.node { // Interesting cases with control flow or which gen/kill @@ -1026,7 +1027,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Closure(.., blk_id, _, _) => { debug!("{} is an ExprKind::Closure", - self.ir.tcx.hir().node_to_pretty_string(expr.id)); + self.ir.tcx.hir().node_to_pretty_string_by_hir_id(expr.hir_id)); // The next-node for a break is the successor of the entire // loop. The next-node for a continue is the top of this loop. @@ -1034,12 +1035,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let break_ln = succ; let cont_ln = node; - self.break_ln.insert(blk_id.node_id, break_ln); - self.cont_ln.insert(blk_id.node_id, cont_ln); + self.break_ln.insert(blk_id.hir_id, break_ln); + self.cont_ln.insert(blk_id.hir_id, cont_ln); // the construction of a closure itself is not important, // but we have to consider the closed over variables. - let caps = self.ir.capture_info_map.get(&expr.id).cloned().unwrap_or_else(|| + let caps = self.ir.capture_info_map.get(&expr.hir_id) + .cloned() + .unwrap_or_else(|| span_bug!(expr.span, "no registered caps")); caps.iter().rev().fold(succ, |succ, cap| { @@ -1128,7 +1131,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Break(label, ref opt_expr) => { // Find which label this break jumps to let target = match label.target_id { - Ok(node_id) => self.break_ln.get(&node_id), + Ok(node_id) => { + let hir_id = self.ir.tcx.hir().node_to_hir_id(node_id); + self.break_ln.get(&hir_id) + }, Err(err) => span_bug!(expr.span, "loop scope error: {}", err), }.cloned(); @@ -1148,7 +1154,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Now that we know the label we're going to, // look it up in the continue loop nodes table - self.cont_ln.get(&sc).cloned().unwrap_or_else(|| + let hir_id = self.ir.tcx.hir().node_to_hir_id(sc); + self.cont_ln.get(&hir_id).cloned().unwrap_or_else(|| span_bug!(expr.span, "continue to unknown label")) } @@ -1188,7 +1195,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Call(ref f, ref args) => { - let m = self.ir.tcx.hir().get_module_parent(expr.id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1199,7 +1206,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::MethodCall(.., ref args) => { - let m = self.ir.tcx.hir().get_module_parent(expr.id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1343,12 +1350,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - fn access_var(&mut self, hir_id: HirId, nid: NodeId, succ: LiveNode, acc: u32, span: Span) + fn access_var(&mut self, hir_id: HirId, var_hid: HirId, succ: LiveNode, acc: u32, span: Span) -> LiveNode { let ln = self.live_node(hir_id, span); if acc != 0 { self.init_from_succ(ln, succ); - let var_hid = self.ir.tcx.hir().node_to_hir_id(nid); let var = self.variable(var_hid, span); self.acc(ln, var, acc); } @@ -1358,8 +1364,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn access_path(&mut self, hir_id: HirId, path: &hir::Path, succ: LiveNode, acc: u32) -> LiveNode { match path.def { - Def::Local(nid) => { - self.access_var(hir_id, nid, succ, acc, path.span) + Def::Local(hid) => { + self.access_var(hir_id, hid, succ, acc, path.span) } _ => succ } @@ -1404,13 +1410,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { first_merge = false; } } - debug!("propagate_through_loop: using id for loop body {} {}", - expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id)); + debug!("propagate_through_loop: using id for loop body {:?} {}", + expr.hir_id, self.ir.tcx.hir().node_to_pretty_string_by_hir_id(body.hir_id)); let break_ln = succ; let cont_ln = ln; - self.break_ln.insert(expr.id, break_ln); - self.cont_ln.insert(expr.id, cont_ln); + self.break_ln.insert(expr.hir_id, break_ln); + self.cont_ln.insert(expr.hir_id, cont_ln); let cond_ln = match kind { LoopLoop => ln, @@ -1533,13 +1539,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn check_place(&mut self, expr: &'tcx Expr) { match expr.node { hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => { - if let Def::Local(nid) = path.def { + if let Def::Local(var_hid) = path.def { // Assignment to an immutable variable or argument: only legal // if there is no later assignment. If this local is actually // mutable, then check for a reassignment to flag the mutability // as being used. let ln = self.live_node(expr.hir_id, expr.span); - let var_hid = self.ir.tcx.hir().node_to_hir_id(nid); let var = self.variable(var_hid, expr.span); self.warn_about_dead_assign(expr.span, expr.hir_id, ln, var); } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 370f0d1a6c6d7..09de7a6143516 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -88,7 +88,7 @@ pub enum Categorization<'tcx> { ThreadLocal(ty::Region<'tcx>), // value that cannot move, but still restricted in scope StaticItem, Upvar(Upvar), // upvar referenced by closure env - Local(ast::NodeId), // local variable + Local(hir::HirId), // local variable Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1) @@ -198,9 +198,9 @@ pub struct cmt_<'tcx> { pub type cmt<'tcx> = Rc>; pub enum ImmutabilityBlame<'tcx> { - ImmLocal(ast::NodeId), + ImmLocal(hir::HirId), ClosureEnv(LocalDefId), - LocalDeref(ast::NodeId), + LocalDeref(hir::HirId), AdtFieldDeref(&'tcx ty::AdtDef, &'tcx ty::FieldDef) } @@ -337,8 +337,8 @@ impl MutabilityCategory { } fn from_local(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, - id: ast::NodeId) -> MutabilityCategory { - let ret = match tcx.hir().get(id) { + id: hir::HirId) -> MutabilityCategory { + let ret = match tcx.hir().get_by_hir_id(id) { Node::Binding(p) => match p.node { PatKind::Binding(..) => { let bm = *tables.pat_binding_modes() @@ -486,9 +486,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { // FIXME None if self.is_tainted_by_errors() => Err(()), None => { - let id = self.tcx.hir().hir_to_node_id(id); - bug!("no type for node {}: {} in mem_categorization", - id, self.tcx.hir().node_to_string(id)); + bug!("no type for node {:?}: {} in mem_categorization", + id, self.tcx.hir().hir_to_string(id)); } } } @@ -497,7 +496,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { hir_id: hir::HirId) -> McResult> { self.resolve_type_vars_or_error(hir_id, - self.tables.node_id_to_type_opt(hir_id)) + Some(self.tables.hir_id_to_type(hir_id))) } pub fn expr_ty(&self, expr: &hir::Expr) -> McResult> { @@ -632,7 +631,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { } pub fn cat_expr_unadjusted(&self, expr: &hir::Expr) -> McResult> { - debug!("cat_expr: id={} expr={:?}", expr.id, expr); + debug!("cat_expr: id={:?} expr={:?}", expr.hir_id, expr); let expr_ty = self.expr_ty(expr)?; match expr.node { @@ -647,11 +646,11 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { hir::ExprKind::Field(ref base, f_ident) => { let base_cmt = Rc::new(self.cat_expr(&base)?); - debug!("cat_expr(cat_field): id={} expr={:?} base={:?}", - expr.id, + debug!("cat_expr(cat_field): id={:?} expr={:?} base={:?}", + expr.hir_id, expr, base_cmt); - let f_index = self.tcx.field_index(expr.id, self.tables); + let f_index = self.tcx.field_index(expr.hir_id, self.tables); Ok(self.cat_field(expr, base_cmt, f_index, f_ident, expr_ty)) } @@ -757,12 +756,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { fn cat_upvar(&self, hir_id: hir::HirId, span: Span, - var_id: ast::NodeId, - fn_node_id: ast::NodeId) + var_hir_id: hir::HirId, + fn_hir_id: hir::HirId) -> McResult> { - let fn_hir_id = self.tcx.hir().node_to_hir_id(fn_node_id); - // An upvar can have up to 3 components. We translate first to a // `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the // field from the environment. @@ -806,8 +803,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { ref t => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", t), }; - let closure_expr_def_id = self.tcx.hir().local_def_id(fn_node_id); - let var_hir_id = self.tcx.hir().node_to_hir_id(var_id); + let closure_expr_def_id = self.tcx.hir().local_def_id_from_hir_id(fn_hir_id); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_expr_def_id.to_local(), @@ -816,7 +812,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { let var_ty = self.node_ty(var_hir_id)?; // Mutability of original variable itself - let var_mutbl = MutabilityCategory::from_local(self.tcx, self.tables, var_id); + let var_mutbl = MutabilityCategory::from_local(self.tcx, self.tables, var_hir_id); // Construct the upvar. This represents access to the field // from the environment (perhaps we should eventually desugar @@ -1321,7 +1317,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { for fp in field_pats { let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2) - let f_index = self.tcx.field_index(fp.node.id, self.tables); + let f_index = self.tcx.field_index(fp.node.hir_id, self.tables); let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index, fp.node.ident, field_ty)); self.cat_pattern_(cmt_field, &fp.node.pat, op)?; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 10deca836fff3..0fd2833f549db 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -14,10 +14,9 @@ use ty::{self, TyCtxt}; use ty::query::Providers; use middle::privacy; use session::config; -use util::nodemap::{NodeSet, FxHashSet}; +use util::nodemap::{HirIdSet, FxHashSet}; use rustc_target::spec::abi::Abi; -use syntax::ast; use hir; use hir::def_id::LOCAL_CRATE; use hir::intravisit::{Visitor, NestedVisitorMap}; @@ -37,7 +36,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'a, 'tcx, 'tcx>, match item.node { hir::ItemKind::Impl(..) | hir::ItemKind::Fn(..) => { - let generics = tcx.generics_of(tcx.hir().local_def_id(item.id)); + let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(item.hir_id)); generics.requires_monomorphization(tcx) } _ => false, @@ -48,7 +47,7 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item: &hir::ImplItem, impl_src: DefId) -> bool { let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id()); - let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.id)); + let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(impl_item.hir_id)); if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) { return true } @@ -70,10 +69,10 @@ struct ReachableContext<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, // The set of items which must be exported in the linkage sense. - reachable_symbols: NodeSet, + reachable_symbols: HirIdSet, // A worklist of item IDs. Each item ID in this worklist will be inlined // and will be scanned for further references. - worklist: Vec, + worklist: Vec, // Whether any output of this compilation is a library any_library: bool, } @@ -103,28 +102,28 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> { }; match def { - Some(Def::Local(node_id)) | Some(Def::Upvar(node_id, ..)) => { - self.reachable_symbols.insert(node_id); + Some(Def::Local(hir_id)) | Some(Def::Upvar(hir_id, ..)) => { + self.reachable_symbols.insert(hir_id); } Some(def) => { - if let Some((node_id, def_id)) = def.opt_def_id().and_then(|def_id| { - self.tcx.hir().as_local_node_id(def_id).map(|node_id| (node_id, def_id)) + if let Some((hir_id, def_id)) = def.opt_def_id().and_then(|def_id| { + self.tcx.hir().as_local_hir_id(def_id).map(|hir_id| (hir_id, def_id)) }) { if self.def_id_represents_local_inlined_item(def_id) { - self.worklist.push(node_id); + self.worklist.push(hir_id); } else { match def { // If this path leads to a constant, then we need to // recurse into the constant to continue finding // items that are reachable. Def::Const(..) | Def::AssociatedConst(..) => { - self.worklist.push(node_id); + self.worklist.push(hir_id); } // If this wasn't a static, then the destination is // surely reachable. _ => { - self.reachable_symbols.insert(node_id); + self.reachable_symbols.insert(hir_id); } } } @@ -171,14 +170,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { if generics.requires_monomorphization(self.tcx) || attrs.requests_inline() { true } else { + let impl_hir_id = impl_item.hir_id; let impl_did = self.tcx .hir() - .get_parent_did(node_id); + .get_parent_did(impl_hir_id); // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. - let impl_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap(); - match self.tcx.hir().expect_item(impl_node_id).node { + match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node { hir::ItemKind::Impl(..) => { let generics = self.tcx.generics_of(impl_did); generics.requires_monomorphization(self.tcx) @@ -204,14 +203,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { continue } - if let Some(ref item) = self.tcx.hir().find(search_item) { + if let Some(ref item) = self.tcx.hir().find_by_hir_id(search_item) { self.propagate_node(item, search_item); } } } fn propagate_node(&mut self, node: &Node<'tcx>, - search_item: ast::NodeId) { + search_hir_id: hir::HirId) { if !self.any_library { // If we are building an executable, only explicitly extern // types need to be exported. @@ -221,13 +220,13 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } else { false }; - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let codegen_attrs = self.tcx.codegen_fn_attrs(def_id); let is_extern = codegen_attrs.contains_extern_indicator(); let std_internal = codegen_attrs.flags.contains( CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL); if reachable || is_extern || std_internal { - self.reachable_symbols.insert(search_item); + self.reachable_symbols.insert(search_hir_id); } } } else { @@ -235,14 +234,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // continue to participate in linkage after this product is // produced. In this case, we traverse the ast node, recursing on // all reachable nodes from this one. - self.reachable_symbols.insert(search_item); + self.reachable_symbols.insert(search_hir_id); } match *node { Node::Item(item) => { match item.node { hir::ItemKind::Fn(.., body) => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); if item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id)) { @@ -295,7 +294,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { self.visit_nested_body(body); } hir::ImplItemKind::Method(_, body) => { - let did = self.tcx.hir().get_parent_did(search_item); + let did = self.tcx.hir().get_parent_did(search_hir_id); if method_might_be_inlined(self.tcx, impl_item, did) { self.visit_nested_body(body) } @@ -315,8 +314,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { Node::Ty(_) | Node::MacroDef(_) => {} _ => { - bug!("found unexpected thingy in worklist: {}", - self.tcx.hir().node_to_string(search_item)) + bug!("found unexpected thingy in worklist: {:?}", search_hir_id) } } } @@ -333,7 +331,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &'a privacy::AccessLevels, - worklist: &'a mut Vec, + worklist: &'a mut Vec, } impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> { @@ -341,17 +339,20 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, // Anything which has custom linkage gets thrown on the worklist no // matter where it is in the crate, along with "special std symbols" // which are currently akin to allocator symbols. - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let codegen_attrs = self.tcx.codegen_fn_attrs(def_id); if codegen_attrs.contains_extern_indicator() || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) { - self.worklist.push(item.id); + self.worklist.push(item.hir_id); } // We need only trait impls here, not inherent impls, and only non-exported ones if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node { - if !self.access_levels.is_reachable(item.id) { - self.worklist.extend(impl_item_refs.iter().map(|r| r.id.node_id)); + let item_node_id = self.tcx.hir().hir_to_node_id(item.hir_id); + if !self.access_levels.is_reachable(item_node_id) { + let hir_refs = impl_item_refs.iter().map(|r| + self.tcx.hir().node_to_hir_id(r.id.node_id)).collect::>(); + self.worklist.extend(hir_refs.into_iter()); let trait_def_id = match trait_ref.path.def { Def::Trait(def_id) => def_id, @@ -365,11 +366,11 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, let provided_trait_methods = self.tcx.provided_trait_methods(trait_def_id); self.worklist.reserve(provided_trait_methods.len()); for default_method in provided_trait_methods { - let node_id = self.tcx - .hir() - .as_local_node_id(default_method.def_id) - .unwrap(); - self.worklist.push(node_id); + let hir_id = self.tcx + .hir() + .as_local_hir_id(default_method.def_id) + .unwrap(); + self.worklist.push(hir_id); } } } @@ -385,7 +386,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, // We introduce a new-type here, so we can have a specialized HashStable // implementation for it. #[derive(Clone)] -pub struct ReachableSet(pub Lrc); +pub struct ReachableSet(pub Lrc); fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet { debug_assert!(crate_num == LOCAL_CRATE); @@ -409,11 +410,12 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> // If other crates link to us, they're going to expect to be able to // use the lang items, so we need to be sure to mark them as // exported. - reachable_context.worklist.extend(access_levels.map.iter().map(|(id, _)| *id)); + let hir_ids = access_levels.map.iter().map(|(&node_id, _)| tcx.hir().node_to_hir_id(node_id)); + reachable_context.worklist.extend(hir_ids); for item in tcx.lang_items().items().iter() { if let Some(did) = *item { - if let Some(node_id) = tcx.hir().as_local_node_id(did) { - reachable_context.worklist.push(node_id); + if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { + reachable_context.worklist.push(hir_id); } } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index ce2a348950622..c6f5d55587628 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -14,7 +14,6 @@ use std::mem; use std::fmt; use rustc_data_structures::sync::Lrc; use syntax::source_map; -use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; use ty::TyCtxt; use ty::query::Providers; @@ -168,15 +167,13 @@ impl Scope { self.id } - pub fn node_id(&self, tcx: TyCtxt<'_, '_, '_>, scope_tree: &ScopeTree) -> ast::NodeId { + pub fn hir_id(&self, _tcx: TyCtxt<'_, '_, '_>, scope_tree: &ScopeTree) -> hir::HirId { match scope_tree.root_body { - Some(hir_id) => { - tcx.hir().hir_to_node_id(hir::HirId { - owner: hir_id.owner, - local_id: self.item_local_id() - }) - } - None => ast::DUMMY_NODE_ID + Some(hir_id) => hir::HirId { + owner: hir_id.owner, + local_id: self.item_local_id() + }, + None => hir::DUMMY_HIR_ID } } @@ -184,13 +181,13 @@ impl Scope { /// returned span may not correspond to the span of any node id in /// the AST. pub fn span(&self, tcx: TyCtxt<'_, '_, '_>, scope_tree: &ScopeTree) -> Span { - let node_id = self.node_id(tcx, scope_tree); - if node_id == ast::DUMMY_NODE_ID { + let hir_id = self.hir_id(tcx, scope_tree); + if hir_id == hir::DUMMY_HIR_ID { return DUMMY_SP; } - let span = tcx.hir().span(node_id); + let span = tcx.hir().span(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { - if let Node::Block(ref blk) = tcx.hir().get(node_id) { + if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { // Want span for scope starting after the // indexed statement and ending at end of // `blk`; reuse span of `blk` and shift `lo` @@ -223,7 +220,7 @@ pub struct ScopeTree { /// The parent of the root body owner, if the latter is an /// an associated const or method, as impls/traits can also /// have lifetime parameters free in this body. - root_parent: Option, + root_parent: Option, /// `parent_map` maps from a scope id to the enclosing scope id; /// this is usually corresponding to the lexical nesting, though @@ -650,7 +647,7 @@ impl<'tcx> ScopeTree { -> Scope { let param_owner = tcx.parent_def_id(br.def_id).unwrap(); - let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap(); + let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| { tcx.hir().body(body_id).value.hir_id.local_id }).unwrap_or_else(|| { @@ -661,7 +658,7 @@ impl<'tcx> ScopeTree { "free_scope: {:?} not recognized by the \ region scope tree for {:?} / {:?}", param_owner, - self.root_parent.map(|id| tcx.hir().local_def_id(id)), + self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)), self.root_body.map(|hir_id| DefId::local(hir_id.owner))); // The trait/impl lifetime is in scope for the method's body. @@ -686,7 +683,7 @@ impl<'tcx> ScopeTree { // on the same function that they ended up being freed in. assert_eq!(param_owner, fr.scope); - let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap(); + let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); let body_id = tcx.hir().body_owned_by(param_owner_id); Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite } } @@ -745,7 +742,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_, '_>, } fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: &'tcx hir::Block) { - debug!("resolve_block(blk.id={:?})", blk.id); + debug!("resolve_block(blk.hir_id={:?})", blk.hir_id); let prev_cx = visitor.cx; @@ -835,7 +832,7 @@ fn resolve_pat<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, pat: & } fn resolve_stmt<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, stmt: &'tcx hir::Stmt) { - let stmt_id = visitor.tcx.hir().node_to_hir_id(stmt.node.id()).local_id; + let stmt_id = stmt.node.hir_id().local_id; debug!("resolve_stmt(stmt.id={:?})", stmt_id); // Every statement will clean up the temporaries created during @@ -1323,7 +1320,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) return tcx.region_scope_tree(closure_base_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) { let mut visitor = RegionResolutionVisitor { tcx, @@ -1343,7 +1340,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // If the item is an associated const or a method, // record its impl/trait parent, as it can also have // lifetime parameters free in this body. - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::ImplItem(_) | Node::TraitItem(_) => { visitor.scope_tree.root_parent = Some(tcx.hir().get_parent(id)); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 2d3653464d538..888d7bcca250b 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -6,9 +6,9 @@ //! way. Therefore we break lifetime name resolution into a separate pass. use hir::def::Def; -use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use hir::map::Map; -use hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName}; +use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName}; use ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; use errors::{Applicability, DiagnosticBuilder}; @@ -23,7 +23,7 @@ use syntax::attr; use syntax::ptr::P; use syntax::symbol::keywords; use syntax_pos::Span; -use util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; +use util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet, ItemLocalMap, ItemLocalSet}; use hir::intravisit::{self, NestedVisitorMap, Visitor}; use hir::{self, GenericParamKind, LifetimeParamKind}; @@ -83,7 +83,7 @@ impl Region { fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam) -> (ParamName, Region) { let i = *index; *index += 1; - let def_id = hir_map.local_def_id(param.id); + let def_id = hir_map.local_def_id_from_hir_id(param.hir_id); let origin = LifetimeDefOrigin::from_param(param); debug!("Region::early: index={} def_id={:?}", i, def_id); (param.name.modern(), Region::EarlyBound(i, def_id, origin)) @@ -91,7 +91,7 @@ impl Region { fn late(hir_map: &Map<'_>, param: &GenericParam) -> (ParamName, Region) { let depth = ty::INNERMOST; - let def_id = hir_map.local_def_id(param.id); + let def_id = hir_map.local_def_id_from_hir_id(param.hir_id); let origin = LifetimeDefOrigin::from_param(param); debug!( "Region::late: param={:?} depth={:?} def_id={:?} origin={:?}", @@ -151,7 +151,7 @@ impl Region { if let Region::EarlyBound(index, _, _) = self { params .nth(index as usize) - .and_then(|lifetime| map.defs.get(&lifetime.id).cloned()) + .and_then(|lifetime| map.defs.get(&lifetime.hir_id).cloned()) } else { Some(self) } @@ -195,25 +195,25 @@ pub type ObjectLifetimeDefault = Set1; struct NamedRegionMap { // maps from every use of a named (not anonymous) lifetime to a // `Region` describing how that region is bound - pub defs: NodeMap, + pub defs: HirIdMap, // the set of lifetime def ids that are late-bound; a region can // be late-bound if (a) it does NOT appear in a where-clause and // (b) it DOES appear in the arguments. - pub late_bound: NodeSet, + pub late_bound: HirIdSet, // For each type and trait definition, maps type parameters // to the trait object lifetime defaults computed from them. - pub object_lifetime_defaults: NodeMap>, + pub object_lifetime_defaults: HirIdMap>, } /// See `NamedRegionMap`. #[derive(Default)] pub struct ResolveLifetimes { - defs: FxHashMap>>, - late_bound: FxHashMap>>, + defs: FxHashMap>>, + late_bound: FxHashMap>, object_lifetime_defaults: - FxHashMap>>>>, + FxHashMap>>>>, } impl_stable_hash_for!(struct ::middle::resolve_lifetime::ResolveLifetimes { @@ -387,20 +387,17 @@ fn resolve_lifetimes<'tcx>( let mut rl = ResolveLifetimes::default(); - for (k, v) in named_region_map.defs { - let hir_id = tcx.hir().node_to_hir_id(k); + for (hir_id, v) in named_region_map.defs { let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default(); Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v); } - for k in named_region_map.late_bound { - let hir_id = tcx.hir().node_to_hir_id(k); + for hir_id in named_region_map.late_bound { let map = rl.late_bound .entry(hir_id.owner_local_def_id()) .or_default(); Lrc::get_mut(map).unwrap().insert(hir_id.local_id); } - for (k, v) in named_region_map.object_lifetime_defaults { - let hir_id = tcx.hir().node_to_hir_id(k); + for (hir_id, v) in named_region_map.object_lifetime_defaults { let map = rl.object_lifetime_defaults .entry(hir_id.owner_local_def_id()) .or_default(); @@ -575,7 +572,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } fn visit_ty(&mut self, ty: &'tcx hir::Ty) { - debug!("visit_ty: id={:?} ty={:?}", ty.id, ty); + debug!("visit_ty: id={:?} ty={:?}", ty.hir_id, ty); match ty.node { hir::TyKind::BareFn(ref c) => { let next_early_index = self.next_early_index(); @@ -634,7 +631,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { hir::TyKind::Rptr(ref lifetime_ref, ref mt) => { self.visit_lifetime(lifetime_ref); let scope = Scope::ObjectLifetimeDefault { - lifetime: self.map.defs.get(&lifetime_ref.id).cloned(), + lifetime: self.map.defs.get(&lifetime_ref.hir_id).cloned(), s: self.scope, }; self.with(scope, |_, this| this.visit_ty(&mt.ty)); @@ -677,15 +674,16 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // and ban them. Type variables instantiated inside binders aren't // well-supported at the moment, so this doesn't work. // In the future, this should be fixed and this error should be removed. - let def = self.map.defs.get(&lifetime.id).cloned(); + let def = self.map.defs.get(&lifetime.hir_id).cloned(); if let Some(Region::LateBound(_, def_id, _)) = def { - if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { // Ensure that the parent of the def is an item, not HRTB - let parent_id = self.tcx.hir().get_parent_node(node_id); - let parent_impl_id = hir::ImplItemId { node_id: parent_id }; - let parent_trait_id = hir::TraitItemId { node_id: parent_id }; + let parent_id = self.tcx.hir().get_parent_node(hir_id); + let parent_node_id = self.tcx.hir().hir_to_node_id(parent_id); + let parent_impl_id = hir::ImplItemId { node_id: parent_node_id }; + let parent_trait_id = hir::TraitItemId { node_id: parent_node_id }; let krate = self.tcx.hir().forest.krate(); - if !(krate.items.contains_key(&parent_id) + if !(krate.items.contains_key(&parent_node_id) || krate.impl_items.contains_key(&parent_impl_id) || krate.trait_items.contains_key(&parent_trait_id)) { @@ -780,7 +778,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { Method(ref sig, _) => { let tcx = self.tcx; self.visit_early_late( - Some(tcx.hir().get_parent(trait_item.id)), + Some(tcx.hir().get_parent(trait_item.hir_id)), &sig.decl, &trait_item.generics, |this| intravisit::walk_trait_item(this, trait_item), @@ -835,7 +833,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { Method(ref sig, _) => { let tcx = self.tcx; self.visit_early_late( - Some(tcx.hir().get_parent(impl_item.id)), + Some(tcx.hir().get_parent(impl_item.hir_id)), &sig.decl, &impl_item.generics, |this| intravisit::walk_impl_item(this, impl_item), @@ -1248,12 +1246,12 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { } => { // FIXME (#24278): non-hygienic comparison if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) { - let node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span(node_id)), + original_lifetime(tcx.hir().span(hir_id)), shadower_label(label.span), ); return; @@ -1267,8 +1265,8 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { fn compute_object_lifetime_defaults( tcx: TyCtxt<'_, '_, '_>, -) -> NodeMap> { - let mut map = NodeMap::default(); +) -> HirIdMap> { + let mut map = HirIdMap::default(); for item in tcx.hir().krate().items.values() { match item.node { hir::ItemKind::Struct(_, ref generics) @@ -1312,7 +1310,7 @@ fn compute_object_lifetime_defaults( tcx.sess.span_err(item.span, &object_lifetime_default_reprs); } - map.insert(item.id, result); + map.insert(item.hir_id, result); } _ => {} } @@ -1345,7 +1343,7 @@ fn object_lifetime_defaults_for_item( add_bounds(&mut set, ¶m.bounds); - let param_def_id = tcx.hir().local_def_id(param.id); + let param_def_id = tcx.hir().local_def_id_from_hir_id(param.hir_id); for predicate in &generics.where_clause.predicates { // Look for `type: ...` where clauses. let data = match *predicate { @@ -1380,7 +1378,7 @@ fn object_lifetime_defaults_for_item( .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => Some(( - param.id, + param.hir_id, hir::LifetimeName::Param(param.name), LifetimeDefOrigin::from_param(param), )), @@ -1389,7 +1387,7 @@ fn object_lifetime_defaults_for_item( .enumerate() .find(|&(_, (_, lt_name, _))| lt_name == name) .map_or(Set1::Many, |(i, (id, _, origin))| { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); Set1::One(Region::EarlyBound(i as u32, def_id, origin)) }) } @@ -1503,8 +1501,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } } }; - if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.id) { - if let Some(parent) = self.tcx.hir().find(self.tcx.hir().get_parent(hir_lifetime.id)) { + if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) { + if let Some(parent) = self.tcx.hir().find_by_hir_id( + self.tcx.hir().get_parent(hir_lifetime.hir_id)) + { match parent { Node::Item(item) => { if let hir::ItemKind::Fn(decl, _, _, _) = &item.node { @@ -1581,19 +1581,20 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { match lifetimeuseset { Some(LifetimeUseSet::One(lifetime)) => { 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) { + let hir_id = self.tcx.hir().node_to_hir_id(node_id); + debug!("node id first={:?}", hir_id); + if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) { Node::Lifetime(hir_lifetime) => Some(( - hir_lifetime.id, + hir_lifetime.hir_id, hir_lifetime.span, hir_lifetime.name.ident(), )), Node::GenericParam(param) => { - Some((param.id, param.span, param.name.ident())) + Some((param.hir_id, param.span, param.name.ident())) } _ => None, } { - debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name); + debug!("id = {:?} span = {:?} name = {:?}", hir_id, span, name); if name == keywords::UnderscoreLifetime.ident() { continue; @@ -1622,18 +1623,19 @@ 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) { + let hir_id = self.tcx.hir().node_to_hir_id(node_id); + if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) { Node::Lifetime(hir_lifetime) => Some(( - hir_lifetime.id, + hir_lifetime.hir_id, hir_lifetime.span, hir_lifetime.name.ident(), )), Node::GenericParam(param) => { - Some((param.id, param.span, param.name.ident())) + Some((param.hir_id, param.span, param.name.ident())) } _ => None, } { - debug!("id ={:?} span = {:?} name = {:?}", node_id, span, name); + debug!("id ={:?} span = {:?} name = {:?}", hir_id, span, name); let mut err = self.tcx.struct_span_lint_node( lint::builtin::UNUSED_LIFETIMES, id, @@ -1680,7 +1682,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { /// ordering is not important there. fn visit_early_late( &mut self, - parent_id: Option, + parent_id: Option, decl: &'tcx hir::FnDecl, generics: &'tcx hir::Generics, walk: F, @@ -1692,7 +1694,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Find the start of nested early scopes, e.g., in methods. let mut index = 0; if let Some(parent_id) = parent_id { - let parent = self.tcx.hir().expect_item(parent_id); + let parent = self.tcx.hir().expect_item_by_hir_id(parent_id); if sub_items_have_self_param(&parent.node) { index += 1; // Self comes before lifetimes } @@ -1711,7 +1713,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => { - if self.map.late_bound.contains(¶m.id) { + if self.map.late_bound.contains(¶m.hir_id) { Some(Region::late(&self.tcx.hir(), param)) } else { Some(Region::early(&self.tcx.hir(), &mut index, param)) @@ -1828,7 +1830,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Do not free early-bound regions, only late-bound ones. } 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) { + match self.tcx.hir().get_by_hir_id(fn_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(..), .. @@ -1841,7 +1843,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { node: hir::ImplItemKind::Method(..), .. }) => { - let scope = self.tcx.hir().local_def_id(fn_id); + let scope = self.tcx.hir().local_def_id_from_hir_id(fn_id); def = Region::Free(scope, def.id().unwrap()); } _ => {} @@ -1957,8 +1959,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }; let map = &self.map; - let unsubst = if let Some(id) = self.tcx.hir().as_local_node_id(def_id) { - &map.object_lifetime_defaults[&id] + let hir = self.tcx.hir(); + let unsubst = if let Some(node_id) = hir.as_local_node_id(def_id) { + let hir_id = hir.definitions().node_to_hir_id(node_id); + &map.object_lifetime_defaults[&hir_id] } else { let tcx = self.tcx; self.xcrate_object_lifetime_defaults @@ -2051,8 +2055,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // and whether there's a `self` argument (treated specially). let mut assoc_item_kind = None; let mut impl_self = None; - let parent = self.tcx.hir().get_parent_node(output.id); - let body = match self.tcx.hir().get(parent) { + let parent = self.tcx.hir().get_parent_node(output.hir_id); + let body = match self.tcx.hir().get_by_hir_id(parent) { // `fn` definitions and methods. Node::Item(&hir::Item { node: hir::ItemKind::Fn(.., body), @@ -2065,12 +2069,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx .hir() - .expect_item(self.tcx.hir().get_parent(parent)) + .expect_item_by_hir_id(self.tcx.hir().get_parent(parent)) .node { assoc_item_kind = trait_items .iter() - .find(|ti| ti.id.node_id == parent) + .find(|ti| ti.id.node_id == self.tcx.hir().hir_to_node_id(parent)) .map(|ti| ti.kind); } match *m { @@ -2085,13 +2089,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx .hir() - .expect_item(self.tcx.hir().get_parent(parent)) + .expect_item_by_hir_id(self.tcx.hir().get_parent(parent)) .node { impl_self = Some(self_ty); assoc_item_kind = impl_items .iter() - .find(|ii| ii.id.node_id == parent) + .find(|ii| ii.id.node_id == self.tcx.hir().hir_to_node_id(parent)) .map(|ii| ii.kind); } Some(body) @@ -2145,7 +2149,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let hir::TyKind::Rptr(lifetime_ref, ref mt) = inputs[0].node { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.node { if is_self_ty(path.def) { - if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) { + if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) { let scope = Scope::Elision { elide: Elide::Exact(lifetime), s: self.scope, @@ -2264,7 +2268,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) { - if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) { + if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) { match lifetime { Region::LateBound(debruijn, _, _) | Region::LateBoundAnon(debruijn, _) if debruijn < self.outer_index => @@ -2387,7 +2391,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let help_name = if let Some(body) = parent { let arg = &self.tcx.hir().body(body).arguments[index]; - format!("`{}`", self.tcx.hir().node_to_pretty_string(arg.pat.id)) + format!("`{}`", self.tcx.hir().node_to_pretty_string_by_hir_id(arg.pat.hir_id)) } else { format!("argument {}", index + 1) }; @@ -2593,12 +2597,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { ref lifetimes, s, .. } => { if let Some(&def) = lifetimes.get(¶m.name.modern()) { - let node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span(node_id)), + original_lifetime(self.tcx.hir().span(hir_id)), shadower_lifetime(¶m), ); return; @@ -2655,7 +2659,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: Region) { - if lifetime_ref.id == ast::DUMMY_NODE_ID { + if lifetime_ref.hir_id == hir::DUMMY_HIR_ID { span_bug!( lifetime_ref.span, "lifetime reference not renumbered, \ @@ -2665,11 +2669,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!( "insert_lifetime: {} resolved to {:?} span={:?}", - self.tcx.hir().node_to_string(lifetime_ref.id), + self.tcx.hir().hir_to_string(lifetime_ref.hir_id), def, self.tcx.sess.source_map().span_to_string(lifetime_ref.span) ); - self.map.defs.insert(lifetime_ref.id, def); + self.map.defs.insert(lifetime_ref.hir_id, def); match def { Region::LateBoundAnon(..) | Region::Static => { @@ -2701,7 +2705,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { /// error (esp. around impl trait). In that case, we remove the /// entry into `map.defs` so as not to confuse later code. fn uninsert_lifetime_on_error(&mut self, lifetime_ref: &'tcx hir::Lifetime, bad_def: Region) { - let old_value = self.map.defs.remove(&lifetime_ref.id); + let old_value = self.map.defs.remove(&lifetime_ref.hir_id); assert_eq!(old_value, Some(bad_def)); } } @@ -2790,11 +2794,11 @@ fn insert_late_bound_lifetimes( debug!( "insert_late_bound_lifetimes: lifetime {:?} with id {:?} is late-bound", param.name.ident(), - param.id + param.hir_id ); - let inserted = map.late_bound.insert(param.id); - assert!(inserted, "visited lifetime {:?} twice", param.id); + let inserted = map.late_bound.insert(param.hir_id); + assert!(inserted, "visited lifetime {:?} twice", param.hir_id); } return; diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 918e286c435bc..f386b8bc0b5cb 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -14,8 +14,7 @@ use middle::privacy::AccessLevels; use session::{DiagnosticMessageId, Session}; use syntax::symbol::Symbol; use syntax_pos::{Span, MultiSpan}; -use syntax::ast; -use syntax::ast::{NodeId, Attribute}; +use syntax::ast::Attribute; use syntax::feature_gate::{GateIssue, emit_feature_err}; use syntax::attr::{self, Stability, Deprecation}; use ty::{self, TyCtxt}; @@ -117,7 +116,7 @@ struct Annotator<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { // Determine the stability for a node based on its attributes and inherited // stability. The stability is recorded in the index and used as the parent. - fn annotate(&mut self, id: NodeId, attrs: &[Attribute], + fn annotate(&mut self, id: HirId, attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, visit_children: F) where F: FnOnce(&mut Self) { @@ -178,8 +177,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } } - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.index.stab_map.insert(hir_id, stab); + self.index.stab_map.insert(id, stab); let orig_parent_stab = replace(&mut self.parent_stab, Some(stab)); visit_children(self); @@ -188,8 +186,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { debug!("annotate: not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { if stab.level.is_unstable() { - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.index.stab_map.insert(hir_id, stab); + self.index.stab_map.insert(id, stab); } } visit_children(self); @@ -209,8 +206,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { if stab.level.is_unstable() { - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.index.stab_map.insert(hir_id, stab); + self.index.stab_map.insert(id, stab); } } @@ -220,17 +216,15 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } // `Deprecation` is just two pointers, no need to intern it - let hir_id = self.tcx.hir().node_to_hir_id(id); - let depr_entry = DeprecationEntry::local(depr, hir_id); - self.index.depr_map.insert(hir_id, depr_entry.clone()); + let depr_entry = DeprecationEntry::local(depr, id); + self.index.depr_map.insert(id, depr_entry.clone()); let orig_parent_depr = replace(&mut self.parent_depr, Some(depr_entry)); visit_children(self); self.parent_depr = orig_parent_depr; } else if let Some(parent_depr) = self.parent_depr.clone() { - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.index.depr_map.insert(hir_id, parent_depr); + self.index.depr_map.insert(id, parent_depr); visit_children(self); } else { visit_children(self); @@ -264,20 +258,20 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } hir::ItemKind::Struct(ref sd, _) => { if !sd.is_struct() { - self.annotate(sd.id(), &i.attrs, i.span, AnnotationKind::Required, |_| {}) + self.annotate(sd.hir_id(), &i.attrs, i.span, AnnotationKind::Required, |_| {}) } } _ => {} } - self.annotate(i.id, &i.attrs, i.span, kind, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| { intravisit::walk_item(v, i) }); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { - self.annotate(ti.id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { + self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { intravisit::walk_trait_item(v, ti); }); } @@ -288,31 +282,33 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } else { AnnotationKind::Required }; - self.annotate(ii.id, &ii.attrs, ii.span, kind, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| { intravisit::walk_impl_item(v, ii); }); } - fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: NodeId) { - self.annotate(var.node.data.id(), &var.node.attrs, var.span, AnnotationKind::Required, |v| { + fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { + self.annotate(var.node.data.hir_id(), &var.node.attrs, var.span, + AnnotationKind::Required, |v| + { intravisit::walk_variant(v, var, g, item_id); }) } fn visit_struct_field(&mut self, s: &'tcx StructField) { - self.annotate(s.id, &s.attrs, s.span, AnnotationKind::Required, |v| { + self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { intravisit::walk_struct_field(v, s); }); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { - self.annotate(i.id, &i.attrs, i.span, AnnotationKind::Required, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { intravisit::walk_foreign_item(v, i); }); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { - self.annotate(md.id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); + self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); } } @@ -322,12 +318,11 @@ struct MissingStabilityAnnotations<'a, 'tcx: 'a> { } impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> { - fn check_missing_stability(&self, id: NodeId, span: Span) { - let hir_id = self.tcx.hir().node_to_hir_id(id); + fn check_missing_stability(&self, hir_id: HirId, span: Span) { let stab = self.tcx.stability().local_stability(hir_id); let is_error = !self.tcx.sess.opts.test && stab.is_none() && - self.access_levels.is_reachable(id); + self.access_levels.is_reachable(self.tcx.hir().hir_to_node_id(hir_id)); if is_error { self.tcx.sess.span_err(span, "This node does not have a stability attribute"); } @@ -347,42 +342,43 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { // optional. They inherit stability from their parents when unannotated. hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {} - _ => self.check_missing_stability(i.id, i.span) + _ => self.check_missing_stability(i.hir_id, i.span) } intravisit::walk_item(self, i) } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { - self.check_missing_stability(ti.id, ti.span); + self.check_missing_stability(ti.hir_id, ti.span); intravisit::walk_trait_item(self, ti); } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { - let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id)); + let impl_def_id = self.tcx.hir().local_def_id_from_hir_id( + self.tcx.hir().get_parent(ii.hir_id)); if self.tcx.impl_trait_ref(impl_def_id).is_none() { - self.check_missing_stability(ii.id, ii.span); + self.check_missing_stability(ii.hir_id, ii.span); } intravisit::walk_impl_item(self, ii); } - fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: NodeId) { - self.check_missing_stability(var.node.data.id(), var.span); + fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { + self.check_missing_stability(var.node.data.hir_id(), var.span); intravisit::walk_variant(self, var, g, item_id); } fn visit_struct_field(&mut self, s: &'tcx StructField) { - self.check_missing_stability(s.id, s.span); + self.check_missing_stability(s.hir_id, s.span); intravisit::walk_struct_field(self, s); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { - self.check_missing_stability(i.id, i.span); + self.check_missing_stability(i.hir_id, i.span); intravisit::walk_foreign_item(self, i); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { - self.check_missing_stability(md.id, md.span); + self.check_missing_stability(md.hir_id, md.span); } } @@ -438,7 +434,7 @@ impl<'a, 'tcx> Index<'tcx> { annotator.parent_stab = Some(stability); } - annotator.annotate(ast::CRATE_NODE_ID, + annotator.annotate(hir::CRATE_HIR_ID, &krate.attrs, krate.span, AnnotationKind::Required, @@ -560,14 +556,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to /// `id`. - pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { + pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { if span.allows_unstable() { debug!("stability: skipping span={:?} since it is internal", span); return EvalResult::Allow; } let lint_deprecated = |def_id: DefId, - id: NodeId, + id: HirId, note: Option, message: &str, lint: &'static Lint| { @@ -578,7 +574,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { }; self.lint_node(lint, id, span, &msg); - if id == ast::DUMMY_NODE_ID { + if id == hir::DUMMY_HIR_ID { span_bug!(span, "emitted a {} lint with dummy node id: {:?}", lint.name, def_id); } }; @@ -599,7 +595,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { None }; - let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id)); + let parent_def_id = self.hir().local_def_id_from_hir_id(self.hir().get_parent(id)); let skip = self.lookup_deprecation_entry(parent_def_id) .map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry)); @@ -716,7 +712,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// /// Additionally, this function will also check if the item is deprecated. If so, and `id` is /// not `None`, a deprecated lint attached to `id` will be emitted. - pub fn check_stability(self, def_id: DefId, id: Option, span: Span) { + pub fn check_stability(self, def_id: DefId, id: Option, span: Span) { match self.eval_stability(def_id, id, span) { EvalResult::Allow => {} EvalResult::Deny { feature, reason, issue } => { @@ -768,13 +764,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // compiler-generated `extern crate` items have a dummy span. if item.span.is_dummy() { return } - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) { Some(cnum) => cnum, None => return, }; let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; - self.tcx.check_stability(def_id, Some(item.id), item.span); + self.tcx.check_stability(def_id, Some(item.hir_id), item.span); } // For implementations of traits, check the stability of each item @@ -798,7 +794,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // There's no good place to insert stability check for non-Copy unions, // so semi-randomly perform it here in stability.rs hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let adt_def = self.tcx.adt_def(def_id); let ty = self.tcx.type_of(def_id); @@ -822,7 +818,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { } fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) { - let id = self.tcx.hir().hir_to_node_id(id); if let Some(def_id) = path.def.opt_def_id() { self.tcx.check_stability(def_id, Some(id), path.span) } @@ -848,7 +843,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx, access_levels, }; - missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span); + missing.check_missing_stability(hir::CRATE_HIR_ID, krate.span); intravisit::walk_crate(&mut missing, krate); krate.visit_all_item_likes(&mut missing.as_deep_visitor()); } @@ -930,7 +925,7 @@ fn unnecessary_stable_feature_lint<'a, 'tcx>( since: Symbol ) { tcx.lint_node(lint::builtin::STABLE_FEATURES, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, span, &format!("the feature `{}` has been stable since {} and no longer requires \ an attribute to enable", feature, since)); diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index c3fe5d773ab16..14504f4be8e29 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -1,5 +1,6 @@ use std::{fmt, env}; +use hir; use hir::map::definitions::DefPathData; use mir; use ty::{self, Ty, layout}; @@ -14,7 +15,6 @@ use ty::query::TyCtxtAt; use errors::DiagnosticBuilder; use syntax_pos::{Pos, Span}; -use syntax::ast; use syntax::symbol::Symbol; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -50,7 +50,7 @@ pub struct ConstEvalErr<'tcx> { pub struct FrameInfo<'tcx> { pub call_site: Span, // this span is in the caller! pub instance: ty::Instance<'tcx>, - pub lint_root: Option, + pub lint_root: Option, } impl<'tcx> fmt::Display for FrameInfo<'tcx> { @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { pub fn report_as_lint(&self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, - lint_root: ast::NodeId, + lint_root: hir::HirId, ) -> ErrorHandled { let lint = self.struct_generic( tcx, @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { &self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, - lint_root: Option, + lint_root: Option, ) -> Result, ErrorHandled> { match self.error { EvalErrorKind::Layout(LayoutError::Unknown(_)) | @@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { } trace!("reporting const eval failure at {:?}", self.span); let mut err = if let Some(lint_root) = lint_root { - let node_id = self.stacktrace + let hir_id = self.stacktrace .iter() .rev() .filter_map(|frame| frame.lint_root) @@ -137,7 +137,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { .unwrap_or(lint_root); tcx.struct_span_lint_node( ::rustc::lint::builtin::CONST_ERR, - node_id, + hir_id, tcx.span, message, ) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index a1a6e890b1292..a11873145d213 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -413,7 +413,7 @@ pub enum Safety { /// Unsafe because of an unsafe fn FnUnsafe, /// Unsafe because of an `unsafe` block - ExplicitUnsafe(ast::NodeId), + ExplicitUnsafe(hir::HirId), } impl_stable_hash_for!(struct Mir<'tcx> { @@ -2099,7 +2099,7 @@ pub struct SourceScopeData { #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub struct SourceScopeLocalData { /// A NodeId with lint levels equivalent to this scope's lint levels. - pub lint_root: ast::NodeId, + pub lint_root: HirId, /// The unsafe block that contains this node. pub safety: Safety, } @@ -2391,17 +2391,18 @@ impl<'tcx> Debug for Rvalue<'tcx> { } AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| { - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { let name = if tcx.sess.opts.debugging_opts.span_free_formats { - format!("[closure@{:?}]", node_id) + format!("[closure@{:?}]", hir_id) } else { - format!("[closure@{:?}]", tcx.hir().span(node_id)) + format!("[closure@{:?}]", tcx.hir().span(hir_id)) }; let mut struct_fmt = fmt.debug_struct(&name); - tcx.with_freevars(node_id, |freevars| { + tcx.with_freevars(hir_id, |freevars| { for (freevar, place) in freevars.iter().zip(places) { - let var_name = tcx.hir().name(freevar.var_id()); + let var_hid = freevar.var_id(); + let var_name = tcx.hir().name(var_hid); struct_fmt.field(&var_name.as_str(), place); } }); @@ -2413,13 +2414,15 @@ impl<'tcx> Debug for Rvalue<'tcx> { }), AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - let name = format!("[generator@{:?}]", tcx.hir().span(node_id)); + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + let name = format!("[generator@{:?}]", tcx.hir() + .span(hir_id)); let mut struct_fmt = fmt.debug_struct(&name); - tcx.with_freevars(node_id, |freevars| { + tcx.with_freevars(hir_id, |freevars| { for (freevar, place) in freevars.iter().zip(places) { - let var_name = tcx.hir().name(freevar.var_id()); + let var_hid = freevar.var_id(); + let var_name = tcx.hir().name(var_hid); struct_fmt.field(&var_name.as_str(), place); } struct_fmt.field("$state", &places[freevars.len()]); @@ -2851,8 +2854,8 @@ pub enum UnsafetyViolationKind { General, /// Permitted in const fn and regular fns GeneralAndConstFn, - ExternStatic(ast::NodeId), - BorrowPacked(ast::NodeId), + ExternStatic(hir::HirId), + BorrowPacked(hir::HirId), } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] @@ -2869,7 +2872,7 @@ pub struct UnsafetyCheckResult { pub violations: Lrc<[UnsafetyViolation]>, /// unsafe blocks in this function, along with whether they are used. This is /// used for the "unused_unsafe" lint. - pub unsafe_blocks: Lrc<[(ast::NodeId, bool)]>, + pub unsafe_blocks: Lrc<[(hir::HirId, bool)]>, } /// The layout of generator state diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 55f5c36cde66d..e90a1e7019566 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -1,5 +1,5 @@ +use hir; use hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; -use syntax::ast::NodeId; use syntax::symbol::{Symbol, InternedString}; use ty::{Instance, TyCtxt}; use util::nodemap::FxHashMap; @@ -14,7 +14,7 @@ use std::hash::Hash; pub enum MonoItem<'tcx> { Fn(Instance<'tcx>), Static(DefId), - GlobalAsm(NodeId), + GlobalAsm(hir::HirId), } impl<'tcx> MonoItem<'tcx> { diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 7363b8b3a78fa..c6932b2b6dbcd 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -3,6 +3,7 @@ use self::code_stats::CodeStats; use dep_graph::cgu_reuse_tracker::CguReuseTracker; use hir::def_id::CrateNum; +use hir::HirId; use rustc_data_structures::fingerprint::Fingerprint; use lint; @@ -68,7 +69,7 @@ pub struct Session { pub target_tlib_path: Option, pub parse_sess: ParseSess, /// For a library crate, this is always none - pub entry_fn: Once>, + pub entry_fn: Once>, pub sysroot: PathBuf, /// The name of the root source file of the crate, in the local file system. /// `None` means that there is no source file. diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 92004ece26d00..d2d8b8f3a281d 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -202,7 +202,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { full_env, ty, trait_did, - ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID), + ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID), ); fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| { panic!( @@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { user_env.caller_bounds.iter().cloned().collect(); let mut new_env = param_env.clone(); - let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID); + let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); while let Some(pred) = predicates.pop_front() { infcx.clear_caches(); @@ -669,7 +669,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { select: &mut SelectionContext<'c, 'd, 'cx>, only_projections: bool, ) -> bool { - let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID); + let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); for (obligation, mut predicate) in nested .map(|o| (o.clone(), o.predicate.clone())) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 367a7eacdfcaf..d36daa6ada241 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -894,9 +894,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn suggest_borrow_on_unsized_slice(&self, code: &ObligationCauseCode<'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(Node::Local(ref local)) = self.tcx.hir().find(parent_node) { + if let &ObligationCauseCode::VariableType(hir_id) = code { + let parent_node = self.tcx.hir().get_parent_node(hir_id); + if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(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) { @@ -1031,7 +1031,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ).collect::>()) } Node::StructCtor(ref variant_data) => { - (self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())), + (self.tcx.sess.source_map().def_span(self.tcx.hir().span( + variant_data.hir_id())), vec![ArgKind::empty(); variant_data.fields().len()]) } _ => panic!("non-FnLike node found: {:?}", node), diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 68383bef37a6a..b40b0111ced2e 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -132,7 +132,7 @@ pub struct ObligationCause<'tcx> { // (in particular, closures can add new assumptions). See the // field `region_obligations` of the `FulfillmentContext` for more // information. - pub body_id: ast::NodeId, + pub body_id: hir::HirId, pub code: ObligationCauseCode<'tcx> } @@ -185,7 +185,7 @@ pub enum ObligationCauseCode<'tcx> { /// S { ... } must be Sized StructInitializerSized, /// Type of each variable must be Sized - VariableType(ast::NodeId), + VariableType(hir::HirId), /// Argument type must be Sized SizedArgumentType, /// Return type must be Sized @@ -254,10 +254,10 @@ pub enum ObligationCauseCode<'tcx> { ReturnNoExpression, /// `return` with an expression - ReturnType(ast::NodeId), + ReturnType(hir::HirId), /// Block implicit return - BlockTailExpression(ast::NodeId), + BlockTailExpression(hir::HirId), /// #[feature(trivial_bounds)] is not enabled TrivialBound, @@ -655,7 +655,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( }; let obligation = Obligation { param_env, - cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID), + cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID), recursion_depth: 0, predicate: trait_ref.to_predicate(), }; @@ -678,7 +678,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( // We can use a dummy node-id here because we won't pay any mind // to region obligations that arise (there shouldn't really be any // anyhow). - let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID); + let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID); fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause); @@ -1058,7 +1058,7 @@ impl<'tcx,O> Obligation<'tcx,O> { } pub fn misc(span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, trait_ref: O) -> Obligation<'tcx, O> { @@ -1076,18 +1076,18 @@ impl<'tcx,O> Obligation<'tcx,O> { impl<'tcx> ObligationCause<'tcx> { #[inline] pub fn new(span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> { ObligationCause { span: span, body_id: body_id, code: code } } - pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> { + pub fn misc(span: Span, body_id: hir::HirId) -> ObligationCause<'tcx> { ObligationCause { span: span, body_id: body_id, code: MiscObligation } } pub fn dummy() -> ObligationCause<'tcx> { - ObligationCause { span: DUMMY_SP, body_id: ast::CRATE_NODE_ID, code: MiscObligation } + ObligationCause { span: DUMMY_SP, body_id: hir::CRATE_HIR_ID, code: MiscObligation } } } diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index c37dc2a855ed0..1f96a3893b411 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -10,6 +10,7 @@ use super::elaborate_predicates; +use hir; use hir::def_id::DefId; use lint; use traits::{self, Obligation, ObligationCause}; @@ -129,7 +130,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { // It's also hard to get a use site span, so we use the method definition span. self.lint_node_note( lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, *span, &format!("the trait `{}` cannot be made into an object", self.item_path_str(trait_def_id)), diff --git a/src/librustc/traits/query/outlives_bounds.rs b/src/librustc/traits/query/outlives_bounds.rs index 1134cb1b2f5d0..31dfd8c6ebace 100644 --- a/src/librustc/traits/query/outlives_bounds.rs +++ b/src/librustc/traits/query/outlives_bounds.rs @@ -1,6 +1,6 @@ +use hir; use infer::InferCtxt; use infer::canonical::OriginalQueryValues; -use syntax::ast; use syntax::source_map::Span; use traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt}; use traits::query::NoSolution; @@ -89,7 +89,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { pub fn implied_outlives_bounds( &self, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, ty: Ty<'tcx>, span: Span, ) -> Vec> { diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index e5ed16e755860..76a544974b36c 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -334,9 +334,11 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>( FutureCompatOverlapErrorKind::Issue33140 => lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS, }; + let node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap(); + let hir_id = tcx.hir().node_to_hir_id(node_id); tcx.struct_span_lint_node( lint, - tcx.hir().as_local_node_id(impl_def_id).unwrap(), + hir_id, impl_span, &msg) } else { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index d69219efbd884..bbfbe2623c5fb 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -65,7 +65,7 @@ use std::sync::mpsc; use std::sync::Arc; use std::marker::PhantomData; use rustc_target::spec::abi; -use syntax::ast::{self, NodeId}; +use syntax::ast; use syntax::attr; use syntax::source_map::MultiSpan; use syntax::edition::Edition; @@ -242,11 +242,9 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option, if let Some(local_id_root) = local_id_root { if hir_id.owner != local_id_root.index { ty::tls::with(|tcx| { - let node_id = tcx.hir().hir_to_node_id(hir_id); - bug!("node {} with HirId::owner {:?} cannot be placed in \ TypeckTables with local_id_root {:?}", - tcx.hir().node_to_string(node_id), + tcx.hir().hir_to_string(hir_id), DefId::local(hir_id.owner), local_id_root) }); @@ -523,17 +521,16 @@ impl<'tcx> TypeckTables<'tcx> { } } - pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> { - self.node_id_to_type_opt(id).unwrap_or_else(|| + pub fn hir_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> { + self.hir_id_to_type_opt(id).unwrap_or_else(|| bug!("node_id_to_type: no type for node `{}`", tls::with(|tcx| { - let id = tcx.hir().hir_to_node_id(id); - tcx.hir().node_to_string(id) + tcx.hir().hir_to_string(id) })) ) } - pub fn node_id_to_type_opt(&self, id: hir::HirId) -> Option> { + pub fn hir_id_to_type_opt(&self, id: hir::HirId) -> Option> { validate_hir_id_for_typeck_tables(self.local_id_root, id, false); self.node_types.get(&id.local_id).cloned() } @@ -558,11 +555,11 @@ impl<'tcx> TypeckTables<'tcx> { // Returns the type of a pattern as a monotype. Like @expr_ty, this function // doesn't provide type parameter substitutions. pub fn pat_ty(&self, pat: &hir::Pat) -> Ty<'tcx> { - self.node_id_to_type(pat.hir_id) + self.hir_id_to_type(pat.hir_id) } pub fn pat_ty_opt(&self, pat: &hir::Pat) -> Option> { - self.node_id_to_type_opt(pat.hir_id) + self.hir_id_to_type_opt(pat.hir_id) } // Returns the type of an expression as a monotype. @@ -576,11 +573,11 @@ impl<'tcx> TypeckTables<'tcx> { // ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize" // instead of "fn(ty) -> T with T = isize". pub fn expr_ty(&self, expr: &hir::Expr) -> Ty<'tcx> { - self.node_id_to_type(expr.hir_id) + self.hir_id_to_type(expr.hir_id) } pub fn expr_ty_opt(&self, expr: &hir::Expr) -> Option> { - self.node_id_to_type_opt(expr.hir_id) + self.hir_id_to_type_opt(expr.hir_id) } pub fn adjustments(&self) -> LocalTableInContext<'_, Vec>> { @@ -1220,7 +1217,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { (k, Lrc::new(v)) }).collect(), freevars: resolutions.freevars.into_iter().map(|(k, v)| { - (hir.local_def_id(k), Lrc::new(v)) + (hir.local_def_id_from_hir_id(k), Lrc::new(v)) }).collect(), maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports @@ -2796,7 +2793,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn lint_node>(self, lint: &'static Lint, - id: NodeId, + id: HirId, span: S, msg: &str) { self.struct_span_lint_node(lint, id, span.into(), msg).emit() @@ -2815,7 +2812,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn lint_node_note>(self, lint: &'static Lint, - id: NodeId, + id: HirId, span: S, msg: &str, note: &str) { @@ -2824,7 +2821,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { err.emit() } - pub fn lint_level_at_node(self, lint: &'static Lint, mut id: NodeId) + pub fn lint_level_at_node(self, lint: &'static Lint, mut hir_id: hir::HirId) -> (lint::Level, lint::LintSource) { // Right now we insert a `with_ignore` node in the dep graph here to @@ -2838,15 +2835,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.dep_graph.with_ignore(|| { let sets = self.lint_levels(LOCAL_CRATE); loop { - let hir_id = self.hir().definitions().node_to_hir_id(id); if let Some(pair) = sets.level_and_source(lint, hir_id, self.sess) { return pair } - let next = self.hir().get_parent_node(id); - if next == id { + let next = self.hir().get_parent_node(hir_id); + if next == hir_id { bug!("lint traversal reached the root of the crate"); } - id = next; + hir_id = next; } }) } @@ -2858,14 +2854,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { msg: &str) -> DiagnosticBuilder<'tcx> { - let node_id = self.hir().hir_to_node_id(hir_id); - let (level, src) = self.lint_level_at_node(lint, node_id); + let (level, src) = self.lint_level_at_node(lint, hir_id); lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg) } pub fn struct_span_lint_node>(self, lint: &'static Lint, - id: NodeId, + id: HirId, span: S, msg: &str) -> DiagnosticBuilder<'tcx> @@ -2874,7 +2869,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg) } - pub fn struct_lint_node(self, lint: &'static Lint, id: NodeId, msg: &str) + pub fn struct_lint_node(self, lint: &'static Lint, id: HirId, msg: &str) -> DiagnosticBuilder<'tcx> { let (level, src) = self.lint_level_at_node(lint, id); diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 417e14054d24f..7faf7b04dec0e 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -1,3 +1,4 @@ +use hir; use hir::map::DefPathData; use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use ty::{self, DefIdTree, Ty, TyCtxt}; @@ -76,6 +77,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.item_path_str(self.hir().local_def_id(id)) } + pub fn hir_path_str(self, id: hir::HirId) -> String { + self.item_path_str(self.hir().local_def_id_from_hir_id(id)) + } + /// Returns a string identifying this def-id. This string is /// suitable for user output. It always begins with a crate identifier. pub fn absolute_item_path_str(self, def_id: DefId) -> String { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 26b4735d926a5..66f764aca1ad7 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -39,7 +39,7 @@ use std::ops::Deref; use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter}; use std::slice; use std::{mem, ptr}; -use syntax::ast::{self, DUMMY_NODE_ID, Name, Ident, NodeId}; +use syntax::ast::{self, Name, Ident, NodeId}; use syntax::attr; use syntax::ext::hygiene::Mark; use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString}; @@ -269,7 +269,7 @@ impl<'a, 'gcx, 'tcx> DefIdTree for TyCtxt<'a, 'gcx, 'tcx> { } impl Visibility { - pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt<'_, '_, '_>) -> Self { + pub fn from_hir(visibility: &hir::Visibility, id: hir::HirId, tcx: TyCtxt<'_, '_, '_>) -> Self { match visibility.node { hir::VisibilityKind::Public => Visibility::Public, hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)), @@ -2758,11 +2758,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"), }; + let hir_id = self.hir().node_to_hir_id(trait_item_ref.id.node_id); + AssociatedItem { ident: trait_item_ref.ident, kind, // Visibility of trait items is inherited from their traits. - vis: Visibility::from_hir(parent_vis, trait_item_ref.id.node_id, self), + vis: Visibility::from_hir(parent_vis, hir_id, self), defaultness: trait_item_ref.defaultness, def_id, container: TraitContainer(parent_def_id), @@ -2784,11 +2786,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false), }; + let hir_id = self.hir().node_to_hir_id(impl_item_ref.id.node_id); + AssociatedItem { ident: impl_item_ref.ident, kind, // Visibility of trait impl items doesn't matter. - vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.node_id, self), + vis: ty::Visibility::from_hir(&impl_item_ref.vis, hir_id, self), defaultness: impl_item_ref.defaultness, def_id, container: ImplContainer(parent_def_id), @@ -2796,14 +2800,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn field_index(self, node_id: NodeId, tables: &TypeckTables<'_>) -> usize { - let hir_id = self.hir().node_to_hir_id(node_id); + pub fn field_index(self, hir_id: hir::HirId, tables: &TypeckTables<'_>) -> usize { tables.field_indices().get(hir_id).cloned().expect("no index for a field") } pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option { variant.fields.iter().position(|field| { - self.adjust_ident(ident, variant.did, DUMMY_NODE_ID).0 == field.ident.modern() + self.adjust_ident(ident, variant.did, hir::DUMMY_HIR_ID).0 == field.ident.modern() }) } @@ -2958,7 +2961,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Get the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'gcx> { - if let Some(id) = self.hir().as_local_node_id(did) { + if let Some(id) = self.hir().as_local_hir_id(did) { Attributes::Borrowed(self.hir().attrs(id)) } else { Attributes::Owned(self.item_attrs(did)) @@ -3010,8 +3013,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// with the name of the crate containing the impl. pub fn span_of_impl(self, impl_did: DefId) -> Result { if impl_did.is_local() { - let node_id = self.hir().as_local_node_id(impl_did).unwrap(); - Ok(self.hir().span(node_id)) + let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); + Ok(self.hir().span(hir_id)) } else { Err(self.crate_name(impl_did.krate)) } @@ -3021,10 +3024,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // supposed definition name (`def_name`). The method also needs `DefId` of the supposed // definition's parent/scope to perform comparison. pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool { - self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern() + self.adjust_ident(use_name, def_parent_def_id, hir::DUMMY_HIR_ID).0 == def_name.modern() } - pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) { + pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: hir::HirId) -> (Ident, DefId) { ident = ident.modern(); let target_expansion = match scope.krate { LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index), @@ -3033,7 +3036,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let scope = match ident.span.adjust(target_expansion) { Some(actual_expansion) => self.hir().definitions().parent_module_of_macro_def(actual_expansion), - None if block == DUMMY_NODE_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId + None if block == hir::DUMMY_HIR_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId None => self.hir().get_module_parent(block), }; (ident, scope) @@ -3057,10 +3060,10 @@ impl Iterator for AssociatedItemsIterator<'_, '_, '_> { } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { - pub fn with_freevars(self, fid: NodeId, f: F) -> T where + pub fn with_freevars(self, fid: hir::HirId, f: F) -> T where F: FnOnce(&[hir::Freevar]) -> T, { - let def_id = self.hir().local_def_id(fid); + let def_id = self.hir().local_def_id_from_hir_id(fid); match self.freevars(def_id) { None => f(&[]), Some(d) => f(&d), @@ -3069,13 +3072,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssociatedItem { - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let parent_id = tcx.hir().get_parent(id); - let parent_def_id = tcx.hir().local_def_id(parent_id); - let parent_item = tcx.hir().expect_item(parent_id); + let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id); + let parent_item = tcx.hir().expect_item_by_hir_id(parent_id); match parent_item.node { hir::ItemKind::Impl(.., ref impl_item_refs) => { - if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.node_id == id) { + let node_id = tcx.hir().hir_to_node_id(id); + if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.node_id == node_id) { let assoc_item = tcx.associated_item_from_impl_item_ref(parent_def_id, impl_item_ref); debug_assert_eq!(assoc_item.def_id, def_id); @@ -3084,7 +3088,8 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Asso } hir::ItemKind::Trait(.., ref trait_item_refs) => { - if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.node_id == id) { + let node_id = tcx.hir().hir_to_node_id(id); + if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.node_id == node_id) { let assoc_item = tcx.associated_item_from_trait_item_ref(parent_def_id, &parent_item.vis, trait_item_ref); @@ -3223,8 +3228,8 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None } ); - let body_id = tcx.hir().as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| { - tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.node_id) + let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { + tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id) }); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index ca5d1f6bd3203..68e4d38e8ec15 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -271,7 +271,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> { fn describe(tcx: TyCtxt<'_, '_, '_>, (_, def_id): (DefId, DefId)) -> Cow<'static, str> { - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); format!("computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(id)).into() } diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index ef68394029680..da2608dd08155 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -1,10 +1,10 @@ +use hir; use hir::def_id::DefId; use infer::InferCtxt; use ty::subst::Substs; use traits; use ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable}; use std::iter::once; -use syntax::ast; use syntax_pos::Span; use middle::lang_items; @@ -16,7 +16,7 @@ use middle::lang_items; /// say "$0 is WF if $0 is WF". pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, ty: Ty<'tcx>, span: Span) -> Option>> @@ -42,7 +42,7 @@ pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, /// if `Bar: Eq`. pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, trait_ref: &ty::TraitRef<'tcx>, span: Span) -> Vec> @@ -54,7 +54,7 @@ pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, predicate: &ty::Predicate<'tcx>, span: Span) -> Vec> @@ -103,7 +103,7 @@ pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, struct WfPredicates<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, out: Vec>, } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 04e571863d42f..34cd1ae350c51 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -800,7 +800,7 @@ impl fmt::Debug for ty::UpvarId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, - ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))), + ty::tls::with(|tcx| tcx.hir().name(self.var_path.hir_id)), self.closure_expr_id) } } @@ -1362,15 +1362,16 @@ define_print! { write!(f, "[static generator")?; } - if let Some(node_id) = tcx.hir().as_local_node_id(did) { - write!(f, "@{:?}", tcx.hir().span(node_id))?; + if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { + write!(f, "@{:?}", tcx.hir().span(hir_id))?; let mut sep = " "; - tcx.with_freevars(node_id, |freevars| { + tcx.with_freevars(hir_id, |freevars| { for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) { + let var_hir_id = freevar.var_id(); print!(f, cx, write("{}{}:", sep, - tcx.hir().name(freevar.var_id())), + tcx.hir().name(var_hir_id)), print(upvar_ty))?; sep = ", "; } @@ -1398,19 +1399,20 @@ define_print! { let upvar_tys = substs.upvar_tys(did, tcx); write!(f, "[closure")?; - if let Some(node_id) = tcx.hir().as_local_node_id(did) { + if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { if tcx.sess.opts.debugging_opts.span_free_formats { - write!(f, "@{:?}", node_id)?; + write!(f, "@{:?}", hir_id)?; } else { - write!(f, "@{:?}", tcx.hir().span(node_id))?; + write!(f, "@{:?}", tcx.hir().span(hir_id))?; } let mut sep = " "; - tcx.with_freevars(node_id, |freevars| { + tcx.with_freevars(hir_id, |freevars| { for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) { + let var_hir_id = freevar.var_id(); print!(f, cx, write("{}{}:", sep, - tcx.hir().name(freevar.var_id())), + tcx.hir().name(var_hir_id)), print(upvar_ty))?; sep = ", "; } diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index cafb29ed99a41..139c73c6e2230 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -17,7 +17,6 @@ use rustc::middle::mem_categorization as mc; use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty::{self, TyCtxt, RegionKind}; -use syntax::ast; use syntax_pos::Span; use rustc::hir; use rustc::hir::Node; @@ -88,15 +87,14 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { - debug!("consume(consume_id={}, cmt={:?}, mode={:?})", + debug!("consume(consume_id={:?}, cmt={:?}, mode={:?})", consume_id, cmt, mode); - let hir_id = self.tcx().hir().node_to_hir_id(consume_id); - self.consume_common(hir_id.local_id, consume_span, cmt, mode); + self.consume_common(consume_id.local_id, consume_span, cmt, mode); } fn matched_pat(&mut self, @@ -117,39 +115,38 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { } fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, bk: ty::BorrowKind, loan_cause: euv::LoanCause) { - debug!("borrow(borrow_id={}, cmt={:?}, loan_region={:?}, \ + debug!("borrow(borrow_id={:?}, cmt={:?}, loan_region={:?}, \ bk={:?}, loan_cause={:?})", borrow_id, cmt, loan_region, bk, loan_cause); - let hir_id = self.tcx().hir().node_to_hir_id(borrow_id); if let Some(lp) = opt_loan_path(cmt) { let moved_value_use_kind = match loan_cause { euv::ClosureCapture(_) => MovedInCapture, _ => MovedInUse, }; - self.check_if_path_is_moved(hir_id.local_id, borrow_span, moved_value_use_kind, &lp); + self.check_if_path_is_moved(borrow_id.local_id, borrow_span, moved_value_use_kind, &lp); } - self.check_for_conflicting_loans(hir_id.local_id); + self.check_for_conflicting_loans(borrow_id.local_id); self.check_for_loans_across_yields(cmt, loan_region, borrow_span); } fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, mode: euv::MutateMode) { - debug!("mutate(assignment_id={}, assignee_cmt={:?})", + debug!("mutate(assignment_id={:?}, assignee_cmt={:?})", assignment_id, assignee_cmt); if let Some(lp) = opt_loan_path(assignee_cmt) { @@ -175,11 +172,10 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { } } } - self.check_assignment(self.tcx().hir().node_to_hir_id(assignment_id).local_id, - assignment_span, assignee_cmt); + self.check_assignment(assignment_id.local_id, assignment_span, assignee_cmt); } - fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { } + fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) { } } pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, @@ -187,7 +183,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_data: &move_data::FlowedMoveData<'c, 'tcx>, all_loans: &[Loan<'tcx>], body: &hir::Body) { - debug!("check_loans(body id={})", body.value.id); + debug!("check_loans(body id={:?})", body.value.hir_id); let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); @@ -893,7 +889,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { let lp = opt_loan_path(assignee_cmt).unwrap(); self.move_data.each_assignment_of(assignment_id, &lp, |assign| { if assignee_cmt.mutbl.is_mutable() { - let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id); + let hir_id = local_id; self.bccx.used_mut_nodes.borrow_mut().insert(hir_id); } else { self.bccx.report_reassigned_immutable_variable( diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 72437e270b092..e21d0f8985744 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -11,7 +11,6 @@ use rustc::middle::mem_categorization::InteriorOffsetKind as Kind; use rustc::ty::{self, Ty}; use std::rc::Rc; -use syntax::ast; use syntax_pos::Span; use rustc::hir::*; use rustc::hir::Node; @@ -47,9 +46,9 @@ pub enum PatternSource<'tcx> { /// with a reference to the let fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> PatternSource<'tcx> { - let parent = tcx.hir().get_parent_node(pat.id); + let parent = tcx.hir().get_parent_node(pat.hir_id); - match tcx.hir().get(parent) { + match tcx.hir().get_by_hir_id(parent) { Node::Expr(ref e) => { // the enclosing expression must be a `match` or something else assert!(match e.node { @@ -66,11 +65,10 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte pub fn gather_decl<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_data: &MoveData<'tcx>, - var_id: ast::NodeId, + var_id: hir::HirId, var_ty: Ty<'tcx>) { let loan_path = Rc::new(LoanPath::new(LpVar(var_id), var_ty)); - let hir_id = bccx.tcx.hir().node_to_hir_id(var_id); - move_data.add_move(bccx.tcx, loan_path, hir_id.local_id, Declared); + move_data.add_move(bccx.tcx, loan_path, var_id.local_id, Declared); } pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 8fc0a3d63384a..5a303e03538d2 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -103,8 +103,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { Categorization::Upvar(..) => { self.bccx.tcx.mk_region(ty::ReScope(self.item_scope)) } - Categorization::Local(local_id) => { - let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id); + Categorization::Local(hir_id) => { self.bccx.tcx.mk_region(ty::ReScope( self.bccx.region_scope_tree.var_scope(hir_id.local_id))) } diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index d681c771d2fa9..bb9b4ce9db94b 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -14,7 +14,6 @@ use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty::{self, TyCtxt}; -use syntax::ast; use syntax_pos::Span; use rustc::hir; @@ -67,18 +66,18 @@ struct GatherLoanCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, _consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { - debug!("consume(consume_id={}, cmt={:?}, mode={:?})", + debug!("consume(consume_id={:?}, cmt={:?}, mode={:?})", consume_id, cmt, mode); match mode { euv::Move(move_reason) => { gather_moves::gather_move_from_expr( self.bccx, &self.move_data, &mut self.move_error_collector, - self.bccx.tcx.hir().node_to_hir_id(consume_id).local_id, cmt, move_reason); + consume_id.local_id, cmt, move_reason); } euv::Copy => { } } @@ -114,19 +113,19 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { } fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, bk: ty::BorrowKind, loan_cause: euv::LoanCause) { - debug!("borrow(borrow_id={}, cmt={:?}, loan_region={:?}, \ + debug!("borrow(borrow_id={:?}, cmt={:?}, loan_region={:?}, \ bk={:?}, loan_cause={:?})", borrow_id, cmt, loan_region, bk, loan_cause); - let hir_id = self.bccx.tcx.hir().node_to_hir_id(borrow_id); - self.guarantee_valid(hir_id.local_id, + + self.guarantee_valid(borrow_id.local_id, borrow_span, cmt, bk, @@ -135,7 +134,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { } fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, _: euv::MutateMode) @@ -145,10 +144,10 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { assignee_cmt); } - fn decl_without_init(&mut self, id: ast::NodeId, _span: Span) { + fn decl_without_init(&mut self, id: hir::HirId, _span: Span) { let ty = self.bccx .tables - .node_id_to_type(self.bccx.tcx.hir().node_to_hir_id(id)); + .hir_id_to_type(id); gather_moves::gather_decl(self.bccx, &self.move_data, id, ty); } } @@ -236,12 +235,12 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { /// Guarantees that `cmt` is assignable, or reports an error. fn guarantee_assignment_valid(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, cmt: &mc::cmt_<'tcx>) { let opt_lp = opt_loan_path(cmt); - debug!("guarantee_assignment_valid(assignment_id={}, cmt={:?}) opt_lp={:?}", + debug!("guarantee_assignment_valid(assignment_id={:?}, cmt={:?}) opt_lp={:?}", assignment_id, cmt, opt_lp); if let Categorization::Local(..) = cmt.cat { @@ -270,8 +269,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { self.mark_loan_path_as_mutated(&lp); } gather_moves::gather_assignment(self.bccx, &self.move_data, - self.bccx.tcx.hir().node_to_hir_id(assignment_id) - .local_id, + assignment_id.local_id, assignment_span, lp); } @@ -436,9 +434,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { while let Some(current_path) = wrapped_path { wrapped_path = match current_path.kind { - LpVar(local_id) => { + LpVar(hir_id) => { if !through_borrow { - let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id); self.bccx.used_mut_nodes.borrow_mut().insert(hir_id); } None diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 588b2344a18e0..3ddf21f1ed61c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -87,8 +87,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr } } if let NoteClosureEnv(upvar_id) = error.move_from.note { - let var_node_id = bccx.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - err.span_label(bccx.tcx.hir().span(var_node_id), + err.span_label(bccx.tcx.hir().span(upvar_id.var_path.hir_id), "captured outer variable"); } err.emit(); diff --git a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs index a43a7f1e09ae1..272d6711c7d26 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs @@ -66,9 +66,9 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { RestrictionResult::Safe } - Categorization::Local(local_id) => { + Categorization::Local(hir_id) => { // R-Variable, locally declared - let lp = new_lp(LpVar(local_id)); + let lp = new_lp(LpVar(hir_id)); RestrictionResult::SafeIf(lp.clone(), vec![lp]) } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 66303ab71b25f..010a14500e94b 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -34,7 +34,6 @@ use std::fmt; use std::rc::Rc; use rustc_data_structures::sync::Lrc; use std::hash::{Hash, Hasher}; -use syntax::ast; use syntax_pos::{MultiSpan, Span}; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; @@ -83,9 +82,9 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) debug!("borrowck(body_owner_def_id={:?})", owner_def_id); - let owner_id = tcx.hir().as_local_node_id(owner_def_id).unwrap(); + let owner_id = tcx.hir().as_local_hir_id(owner_def_id).unwrap(); - match tcx.hir().get(owner_id) { + match tcx.hir().get_by_hir_id(owner_id) { Node::StructCtor(_) | Node::Variant(_) => { // We get invoked with anything that has MIR, but some of @@ -215,7 +214,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'a, 'tcx>) { let owner_id = tcx.hir().body_owner(body_id); - let owner_def_id = tcx.hir().local_def_id(owner_id); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_id); let tables = tcx.typeck_tables_of(owner_def_id); let region_scope_tree = tcx.region_scope_tree(owner_def_id); let body = tcx.hir().body(body_id); @@ -343,7 +342,7 @@ impl<'tcx> Hash for LoanPath<'tcx> { #[derive(PartialEq, Eq, Hash, Debug)] pub enum LoanPathKind<'tcx> { - LpVar(ast::NodeId), // `x` in README.md + LpVar(hir::HirId), // `x` in README.md LpUpvar(ty::UpvarId), // `x` captured by-value into closure LpDowncast(Rc>, DefId), // `x` downcast to particular enum variant LpExtend(Rc>, mc::MutabilityCategory, LoanPathElem<'tcx>) @@ -407,12 +406,12 @@ pub enum LoanPathElem<'tcx> { } fn closure_to_block(closure_id: LocalDefId, - tcx: TyCtxt) -> ast::NodeId { + tcx: TyCtxt) -> hir::HirId { let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { - body_id.node_id + body_id.hir_id } _ => { bug!("encountered non-closure id: {}", closure_id) @@ -425,14 +424,12 @@ fn closure_to_block(closure_id: LocalDefId, impl<'a, 'tcx> LoanPath<'tcx> { pub fn kill_scope(&self, bccx: &BorrowckCtxt<'a, 'tcx>) -> region::Scope { match self.kind { - LpVar(local_id) => { - let hir_id = bccx.tcx.hir().node_to_hir_id(local_id); + LpVar(hir_id) => { bccx.region_scope_tree.var_scope(hir_id.local_id) } LpUpvar(upvar_id) => { let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx); - let hir_id = bccx.tcx.hir().node_to_hir_id(block_id); - region::Scope { id: hir_id.local_id, data: region::ScopeData::Node } + region::Scope { id: block_id.local_id, data: region::ScopeData::Node } } LpDowncast(ref base, _) | LpExtend(ref base, ..) => base.kill_scope(bccx), @@ -711,20 +708,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { // Get type of value and span where it was previously // moved. - let node_id = self.tcx.hir().hir_to_node_id(hir::HirId { + let hir_id = hir::HirId { owner: self.body.value.hir_id.owner, local_id: the_move.id - }); + }; let (move_span, move_note) = match the_move.kind { move_data::Declared => { unreachable!(); } move_data::MoveExpr | - move_data::MovePat => (self.tcx.hir().span(node_id), ""), + move_data::MovePat => (self.tcx.hir().span(hir_id), ""), move_data::Captured => - (match self.tcx.hir().expect_expr(node_id).node { + (match self.tcx.hir().expect_expr(hir_id).node { hir::ExprKind::Closure(.., fn_decl_span, _) => fn_decl_span, ref r => bug!("Captured({:?}) maps to non-closure: {:?}", the_move.id, r), @@ -836,8 +833,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { MutabilityViolation => { let mut db = self.cannot_assign(error_span, &descr, Origin::Ast); if let mc::NoteClosureEnv(upvar_id) = err.cmt.note { - let node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let sp = self.tcx.hir().span(node_id); + let sp = self.tcx.hir().span(upvar_id.var_path.hir_id); let fn_closure_msg = "`Fn` closures cannot capture their enclosing \ environment for modifications"; match (self.tcx.sess.source_map().span_to_snippet(sp), &err.cmt.cat) { @@ -906,8 +902,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node_id = self.tcx.hir().hir_to_node_id(err.cmt.hir_id); - let node = self.tcx.hir().get(node_id); + let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr( @@ -927,7 +922,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.note_immutability_blame( &mut db, err.cmt.immutability_blame(), - self.tcx.hir().hir_to_node_id(err.cmt.hir_id) + err.cmt.hir_id ); db.emit(); self.signal_error(); @@ -1032,8 +1027,8 @@ 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) { + let hir_id = scope.hir_id(self.tcx, &self.region_scope_tree); + match self.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Stmt(_)) => { if *sub_scope != ty::ReStatic { db.note("consider using a `let` binding to increase its lifetime"); @@ -1128,8 +1123,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } else { "consider changing this closure to take self by mutable reference" }; - let node_id = self.tcx.hir().local_def_id_to_node_id(id); - let help_span = self.tcx.hir().span(node_id); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(id); + let help_span = self.tcx.hir().span(hir_id); self.cannot_act_on_capture_in_sharable_fn(span, prefix, (help_span, help_msg), @@ -1143,7 +1138,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.note_immutability_blame( &mut err, blame, - self.tcx.hir().hir_to_node_id(cmt.hir_id) + cmt.hir_id ); if is_closure { @@ -1183,8 +1178,8 @@ 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) { + fn local_binding_mode(&self, hir_id: hir::HirId) -> ty::BindingMode { + let pat = match self.tcx.hir().get_by_hir_id(hir_id) { Node::Binding(pat) => pat, node => bug!("bad node for local: {:?}", node) }; @@ -1200,16 +1195,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - fn local_ty(&self, node_id: ast::NodeId) -> (Option<&hir::Ty>, bool) { - let parent = self.tcx.hir().get_parent_node(node_id); - let parent_node = self.tcx.hir().get(parent); + fn local_ty(&self, hir_id: hir::HirId) -> (Option<&hir::Ty>, bool) { + let parent = self.tcx.hir().get_parent_node(hir_id); + let parent_node = self.tcx.hir().get_by_hir_id(parent); // The parent node is like a fn if let Some(fn_like) = FnLikeNode::from_node(parent_node) { // `nid`'s parent's `Body` let fn_body = self.tcx.hir().body(fn_like.body()); // Get the position of `node_id` in the arguments list - let arg_pos = fn_body.arguments.iter().position(|arg| arg.pat.id == node_id); + let arg_pos = fn_body.arguments.iter().position(|arg| arg.pat.hir_id == hir_id); if let Some(i) = arg_pos { // The argument's `Ty` (Some(&fn_like.decl().inputs[i]), @@ -1225,17 +1220,17 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { fn note_immutability_blame(&self, db: &mut DiagnosticBuilder, blame: Option, - error_node_id: ast::NodeId) { + error_hir_id: hir::HirId) { match blame { None => {} Some(ImmutabilityBlame::ClosureEnv(_)) => {} - Some(ImmutabilityBlame::ImmLocal(node_id)) => { - self.note_immutable_local(db, error_node_id, node_id) + Some(ImmutabilityBlame::ImmLocal(hir_id)) => { + self.note_immutable_local(db, error_hir_id, hir_id) } - Some(ImmutabilityBlame::LocalDeref(node_id)) => { - match self.local_binding_mode(node_id) { + Some(ImmutabilityBlame::LocalDeref(hir_id)) => { + match self.local_binding_mode(hir_id) { ty::BindByReference(..) => { - let let_span = self.tcx.hir().span(node_id); + let let_span = self.tcx.hir().span(hir_id); let suggestion = suggest_ref_mut(self.tcx, let_span); if let Some(replace_str) = suggestion { db.span_suggestion_with_applicability( @@ -1252,7 +1247,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } ty::BindByValue(..) => { - if let (Some(local_ty), is_implicit_self) = self.local_ty(node_id) { + if let (Some(local_ty), is_implicit_self) = self.local_ty(hir_id) { if let Some(msg) = self.suggest_mut_for_immutable(local_ty, is_implicit_self) { db.span_label(local_ty.span, msg); @@ -1281,12 +1276,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { // not a mutable reference) or to avoid borrowing altogether fn note_immutable_local(&self, db: &mut DiagnosticBuilder, - borrowed_node_id: ast::NodeId, - binding_node_id: ast::NodeId) { - let let_span = self.tcx.hir().span(binding_node_id); - if let ty::BindByValue(..) = self.local_binding_mode(binding_node_id) { + borrowed_hir_id: hir::HirId, + binding_hir_id: hir::HirId) { + let let_span = self.tcx.hir().span(binding_hir_id); + if let ty::BindByValue(..) = self.local_binding_mode(binding_hir_id) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(let_span) { - let (ty, is_implicit_self) = self.local_ty(binding_node_id); + let (ty, is_implicit_self) = self.local_ty(binding_hir_id); if is_implicit_self && snippet != "self" { // avoid suggesting `mut &self`. return @@ -1299,7 +1294,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { }, )) = ty.map(|t| &t.node) { - let borrow_expr_id = self.tcx.hir().get_parent_node(borrowed_node_id); + let borrow_expr_id = self.tcx.hir().get_parent_node(borrowed_hir_id); db.span_suggestion_with_applicability( self.tcx.hir().span(borrow_expr_id), "consider removing the `&mut`, as it is an \ @@ -1370,9 +1365,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { _ => bug!() }; if *kind == ty::ClosureKind::Fn { - let closure_node_id = - self.tcx.hir().local_def_id_to_node_id(upvar_id.closure_expr_id); - db.span_help(self.tcx.hir().span(closure_node_id), + let closure_hir_id = + self.tcx.hir().local_def_id_to_hir_id(upvar_id.closure_expr_id); + db.span_help(self.tcx.hir().span(closure_hir_id), "consider changing this closure to take \ self by mutable reference"); } @@ -1406,7 +1401,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { out: &mut String) { match loan_path.kind { LpUpvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id: id}, closure_expr_id: _ }) => { - out.push_str(&self.tcx.hir().name(self.tcx.hir().hir_to_node_id(id)).as_str()); + out.push_str(&self.tcx.hir().name(id).as_str()); } LpVar(id) => { out.push_str(&self.tcx.hir().name(id).as_str()); @@ -1520,13 +1515,12 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.kind { LpVar(id) => { - write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_string(id))) + write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().hir_to_string(id))) } LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(var_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(var_id) }); write!(f, "$({} captured by id={:?})", s, closure_expr_id) } @@ -1555,13 +1549,12 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.kind { LpVar(id) => { - write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_user_string(id))) + write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().hir_to_user_string(id))) } LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(hir_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(hir_id) }); write!(f, "$({} captured by closure)", s) } diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 2eab626ae8e6e..e38770ced1801 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let mut flags = DIFlags::FlagPrototyped; - let local_id = self.tcx().hir().as_local_node_id(def_id); + let local_id = self.tcx().hir().as_local_hir_id(def_id); if let Some((id, _, _)) = *self.sess().entry_fn.borrow() { if local_id == Some(id) { flags |= DIFlags::FlagMainSubprogram; diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index bf69089a254a4..6d39a9ce67534 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -69,7 +69,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut reachable_non_generics: DefIdMap<_> = tcx.reachable_set(LOCAL_CRATE).0 .iter() - .filter_map(|&node_id| { + .filter_map(|&hir_id| { // We want to ignore some FFI functions that are not exposed from // this crate. Reachable FFI functions can be lumped into two // categories: @@ -83,9 +83,9 @@ 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) { + match tcx.hir().get_by_hir_id(hir_id) { Node::ForeignItem(..) => { - let def_id = tcx.hir().local_def_id(node_id); + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); if tcx.is_statically_included_foreign_item(def_id) { Some(def_id) } else { @@ -105,7 +105,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node: hir::ImplItemKind::Method(..), .. }) => { - let def_id = tcx.hir().local_def_id(node_id); + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let generics = tcx.generics_of(def_id); if !generics.requires_monomorphization(tcx) && // Functions marked with #[inline] are only ever codegened @@ -343,8 +343,8 @@ fn upstream_monomorphizations_for_provider<'a, 'tcx>( } fn is_unreachable_local_definition_provider(tcx: TyCtxt, def_id: DefId) -> bool { - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - !tcx.reachable_set(LOCAL_CRATE).0.contains(&node_id) + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + !tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id) } else { bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id) diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index b88ec075653ba..fd5927b174469 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -443,7 +443,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( ) { let (main_def_id, span) = match *cx.sess().entry_fn.borrow() { Some((id, span, _)) => { - (cx.tcx().hir().local_def_id(id), span) + (cx.tcx().hir().local_def_id_from_hir_id(id), span) } None => return, }; diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index 21e0044759a5a..7a0076d2b4392 100644 --- a/src/librustc_codegen_ssa/mono_item.rs +++ b/src/librustc_codegen_ssa/mono_item.rs @@ -31,8 +31,8 @@ pub trait MonoItemExt<'a, 'tcx: 'a>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> { }; cx.codegen_static(def_id, is_mutable); } - MonoItem::GlobalAsm(node_id) => { - let item = cx.tcx().hir().expect_item(node_id); + MonoItem::GlobalAsm(hir_id) => { + let item = cx.tcx().hir().expect_item_by_hir_id(hir_id); if let hir::ItemKind::GlobalAsm(ref ga) = item.node { cx.codegen_global_asm(ga); } else { diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index b59bca0ae0edb..ed20b09cb98b5 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -43,7 +43,7 @@ pub mod symbol_names_test; /// reporting an error. pub fn check_for_rustc_errors_attr(tcx: TyCtxt) { if let Some((id, span, _)) = *tcx.sess.entry_fn.borrow() { - let main_def_id = tcx.hir().local_def_id(id); + let main_def_id = tcx.hir().local_def_id_from_hir_id(id); if tcx.has_attr(main_def_id, "rustc_error") { tcx.sess.span_fatal(span, "compilation successful"); diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 9267f14f24234..b4ca416cb249c 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -240,7 +240,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance debug!("symbol_name(def_id={:?}, substs={:?})", def_id, substs); - let node_id = tcx.hir().as_local_node_id(def_id); + let hir_id = tcx.hir().as_local_hir_id(def_id); if def_id.is_local() { if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) { @@ -254,8 +254,8 @@ 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) { + let is_foreign = if let Some(id) = hir_id { + match tcx.hir().get_by_hir_id(id) { Node::ForeignItem(_) => true, _ => false, } diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs index a11eb4da66ade..91ab1a8edb992 100644 --- a/src/librustc_codegen_utils/symbol_names_test.rs +++ b/src/librustc_codegen_utils/symbol_names_test.rs @@ -6,7 +6,6 @@ use rustc::hir; use rustc::ty::TyCtxt; -use syntax::ast; use rustc_mir::monomorphize::Instance; @@ -33,9 +32,9 @@ struct SymbolNamesTest<'a, 'tcx:'a> { impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> { fn process_attrs(&mut self, - node_id: ast::NodeId) { + hir_id: hir::HirId) { let tcx = self.tcx; - let def_id = tcx.hir().local_def_id(node_id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(hir_id); for attr in tcx.get_attrs(def_id).iter() { if attr.check_name(SYMBOL_NAME) { // for now, can only use on monomorphic names @@ -56,14 +55,14 @@ impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> { impl<'a, 'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { - self.process_attrs(item.id); + self.process_attrs(item.hir_id); } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - self.process_attrs(trait_item.id); + self.process_attrs(trait_item.hir_id); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - self.process_attrs(impl_item.id); + self.process_attrs(impl_item.hir_id); } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index a9ec99358c1b2..3b99659d1fbcf 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -273,8 +273,8 @@ trait HirPrinterSupport<'hir>: pprust_hir::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn; /// Computes an user-readable representation of a path, if possible. - fn node_path(&self, id: ast::NodeId) -> Option { - self.hir_map().and_then(|map| map.def_path_from_id(id)).map(|path| { + fn node_path(&self, id: hir::HirId) -> Option { + self.hir_map().map(|map| map.def_path_from_hir_id(id)).map(|path| { path.data .into_iter() .map(|elem| elem.data.to_string()) @@ -411,28 +411,24 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> { pprust_hir::AnnNode::Name(_) => Ok(()), pprust_hir::AnnNode::Item(item) => { s.s.space()?; - s.synth_comment(format!("node_id: {} hir local_id: {}", - item.id, item.hir_id.local_id.as_u32())) + s.synth_comment(format!("hir_id: {:?}", item.hir_id)) } - pprust_hir::AnnNode::SubItem(id) => { + pprust_hir::AnnNode::SubItem(hir_id) => { s.s.space()?; - s.synth_comment(id.to_string()) + s.synth_comment(format!("{:?}", hir_id)) } pprust_hir::AnnNode::Block(blk) => { s.s.space()?; - s.synth_comment(format!("block node_id: {} hir local_id: {}", - blk.id, blk.hir_id.local_id.as_u32())) + s.synth_comment(format!("block hir_id: {:?}", blk.hir_id)) } pprust_hir::AnnNode::Expr(expr) => { s.s.space()?; - s.synth_comment(format!("node_id: {} hir local_id: {}", - expr.id, expr.hir_id.local_id.as_u32()))?; + s.synth_comment(format!("hir_id: {:?}", expr.hir_id))?; s.pclose() } pprust_hir::AnnNode::Pat(pat) => { s.s.space()?; - s.synth_comment(format!("pat node_id: {} hir local_id: {}", - pat.id, pat.hir_id.local_id.as_u32())) + s.synth_comment(format!("pat hir_id: {:?}", pat.hir_id)) } } } @@ -489,8 +485,8 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { self } - fn node_path(&self, id: ast::NodeId) -> Option { - Some(self.tcx.node_path_str(id)) + fn node_path(&self, id: hir::HirId) -> Option { + Some(self.tcx.hir_path_str(id)) } } @@ -545,7 +541,7 @@ fn gather_flowgraph_variants(sess: &Session) -> Vec { #[derive(Clone, Debug)] pub enum UserIdentifiedItem { - ItemViaNode(ast::NodeId), + ItemViaNode(hir::HirId), ItemViaPath(Vec), } @@ -553,21 +549,23 @@ impl FromStr for UserIdentifiedItem { type Err = (); fn from_str(s: &str) -> Result { Ok(s.parse() - .map(ast::NodeId::from_u32) + .map(|n| { let mut hir_id = hir::CRATE_HIR_ID; + hir_id.local_id = hir::ItemLocalId::from_u32(n); + hir_id }) .map(ItemViaNode) .unwrap_or_else(|_| ItemViaPath(s.split("::").map(|s| s.to_string()).collect()))) } } enum NodesMatchingUII<'a, 'hir: 'a> { - NodesMatchingDirect(option::IntoIter), + NodesMatchingDirect(option::IntoIter), NodesMatchingSuffix(hir_map::NodesMatchingSuffix<'a, 'hir>), } impl<'a, 'hir> Iterator for NodesMatchingUII<'a, 'hir> { - type Item = ast::NodeId; + type Item = hir::HirId; - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { match self { &mut NodesMatchingDirect(ref mut iter) => iter.next(), &mut NodesMatchingSuffix(ref mut iter) => iter.next(), @@ -585,23 +583,23 @@ impl<'a, 'hir> Iterator for NodesMatchingUII<'a, 'hir> { impl UserIdentifiedItem { fn reconstructed_input(&self) -> String { match *self { - ItemViaNode(node_id) => node_id.to_string(), + ItemViaNode(hir_id) => format!("{:?}", hir_id), ItemViaPath(ref parts) => parts.join("::"), } } - fn all_matching_node_ids<'a, 'hir>(&'a self, - map: &'a hir_map::Map<'hir>) - -> NodesMatchingUII<'a, 'hir> { + fn all_matching_hir_ids<'a, 'hir>(&'a self, + map: &'a hir_map::Map<'hir>) + -> NodesMatchingUII<'a, 'hir> { match *self { - ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()), + ItemViaNode(hir_id) => NodesMatchingDirect(Some(hir_id).into_iter()), ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts)), } } - fn to_one_node_id(self, user_option: &str, sess: &Session, map: &hir_map::Map) -> ast::NodeId { + fn to_one_hir_id(self, user_option: &str, sess: &Session, map: &hir_map::Map) -> hir::HirId { let fail_because = |is_wrong_because| -> ast::NodeId { - let message = format!("{} needs NodeId (int) or unique path suffix (b::c::d); got \ + let message = format!("{} needs HirId (int) or unique path suffix (b::c::d); got \ {}, which {}", user_option, self.reconstructed_input(), @@ -609,9 +607,9 @@ impl UserIdentifiedItem { sess.fatal(&message) }; - let mut saw_node = ast::DUMMY_NODE_ID; + let mut saw_node = hir::DUMMY_HIR_ID; let mut seen = 0; - for node in self.all_matching_node_ids(map) { + for node in self.all_matching_hir_ids(map) { saw_node = node; seen += 1; if seen > 1 { @@ -834,15 +832,15 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec, let body_id = match code { blocks::Code::Expr(expr) => { // Find the function this expression is from. - let mut node_id = expr.id; + let mut hir_id = expr.hir_id; loop { - let node = tcx.hir().get(node_id); + let node = tcx.hir().get_by_hir_id(hir_id); if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) { break n.body(); } - let parent = tcx.hir().get_parent_node(node_id); - assert_ne!(node_id, parent); - node_id = parent; + let parent = tcx.hir().get_parent_node(hir_id); + assert_ne!(hir_id, parent); + hir_id = parent; } } blocks::Code::FnLike(fn_like) => fn_like.body(), @@ -853,7 +851,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec, let lcfg = LabelledCFG { tcx, cfg: &cfg, - name: format!("node_{}", code.id()), + name: format!("{:?}", code.id()), labelled_edges, }; @@ -1063,11 +1061,11 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, box out, annotation.pp_ann(), true); - for node_id in uii.all_matching_node_ids(hir_map) { - let node = hir_map.get(node_id); + for hir_id in uii.all_matching_hir_ids(hir_map) { + let node = hir_map.get_by_hir_id(hir_id); pp_state.print_node(node)?; pp_state.s.space()?; - let path = annotation.node_path(node_id) + let path = annotation.node_path(hir_id) .expect("-Z unpretty missing node paths"); pp_state.synth_comment(path)?; pp_state.s.hardbreak()?; @@ -1087,8 +1085,8 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, crate_name, move |_annotation, _krate| { debug!("pretty printing source code {:?}", s); - for node_id in uii.all_matching_node_ids(hir_map) { - let node = hir_map.get(node_id); + for hir_id in uii.all_matching_hir_ids(hir_map) { + let node = hir_map.get_by_hir_id(hir_id); write!(out, "{:#?}", node)?; } Ok(()) @@ -1116,9 +1114,9 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, ppm: PpMode, uii: Option, ofile: Option<&Path>) { - let nodeid = if let Some(uii) = uii { + let hir_id = if let Some(uii) = uii { debug!("pretty printing for {:?}", uii); - Some(uii.to_one_node_id("-Z unpretty", sess, &hir_map)) + Some(uii.to_one_hir_id("-Z unpretty", sess, &hir_map)) } else { debug!("pretty printing for whole crate"); None @@ -1142,8 +1140,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, |tcx, _, _, _| { match ppm { PpmMir | PpmMirCFG => { - if let Some(nodeid) = nodeid { - let def_id = tcx.hir().local_def_id(nodeid); + if let Some(hir_id) = hir_id { + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); match ppm { PpmMir => write_mir_pretty(tcx, Some(def_id), &mut out), PpmMirCFG => write_mir_graphviz(tcx, Some(def_id), &mut out), @@ -1159,14 +1157,14 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, Ok(()) } PpmFlowGraph(mode) => { - let nodeid = - nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \ + let hir_id = + hir_id.expect("`pretty flowgraph=..` needs HirId (int) or unique path \ suffix (b::c::d)"); - let node = tcx.hir().find(nodeid).unwrap_or_else(|| { - tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) + let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| { + tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {:?}", hir_id)) }); - match blocks::Code::from_node(&tcx.hir(), nodeid) { + match blocks::Code::from_node(&tcx.hir(), hir_id) { Some(code) => { let variants = gather_flowgraph_variants(tcx.sess); @@ -1179,7 +1177,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, got {:?}", node); - tcx.sess.span_fatal(tcx.hir().span(nodeid), &message) + tcx.sess.span_fatal(tcx.hir().span(hir_id), &message) } } } diff --git a/src/librustc_driver/proc_macro_decls.rs b/src/librustc_driver/proc_macro_decls.rs index 093d15b7e3c57..8ed03efd1a784 100644 --- a/src/librustc_driver/proc_macro_decls.rs +++ b/src/librustc_driver/proc_macro_decls.rs @@ -3,7 +3,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir; use rustc::ty::TyCtxt; use rustc::ty::query::Providers; -use syntax::ast; use syntax::attr; pub fn find<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option { @@ -19,17 +18,17 @@ fn proc_macro_decls_static<'tcx>( let mut finder = Finder { decls: None }; tcx.hir().krate().visit_all_item_likes(&mut finder); - finder.decls.map(|id| tcx.hir().local_def_id(id)) + finder.decls.map(|id| tcx.hir().local_def_id_from_hir_id(id)) } struct Finder { - decls: Option, + decls: Option, } impl<'v> ItemLikeVisitor<'v> for Finder { fn visit_item(&mut self, item: &hir::Item) { if attr::contains_name(&item.attrs, "rustc_proc_macro_decls") { - self.decls = Some(item.id); + self.decls = Some(item.hir_id); } } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 57ab48493fa93..54aa5c317afe9 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -69,7 +69,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let mut visitor = IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] }; - visitor.process_attrs(ast::CRATE_NODE_ID, &tcx.hir().krate().attrs); + visitor.process_attrs(hir::CRATE_HIR_ID, &tcx.hir().krate().attrs); tcx.hir().krate().visit_all_item_likes(&mut visitor.as_deep_visitor()); (visitor.if_this_changed, visitor.then_this_would_need) }; @@ -87,7 +87,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { } type Sources = Vec<(Span, DefId, DepNode)>; -type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode)>; +type Targets = Vec<(Span, ast::Name, hir::HirId, DepNode)>; struct IfThisChanged<'a, 'tcx:'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -110,8 +110,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { value } - fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) { - let def_id = self.tcx.hir().local_def_id(node_id); + fn process_attrs(&mut self, hir_id: hir::HirId, attrs: &[ast::Attribute]) { + let def_id = self.tcx.hir().local_def_id_from_hir_id(hir_id); let def_path_hash = self.tcx.def_path_hash(def_id); for attr in attrs { if attr.check_name(ATTR_IF_THIS_CHANGED) { @@ -151,7 +151,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { }; self.then_this_would_need.push((attr.span, dep_node_interned.unwrap(), - node_id, + hir_id, dep_node)); } } @@ -164,22 +164,22 @@ impl<'a, 'tcx> Visitor<'tcx> for IfThisChanged<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - self.process_attrs(item.id, &item.attrs); + self.process_attrs(item.hir_id, &item.attrs); intravisit::walk_item(self, item); } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - self.process_attrs(trait_item.id, &trait_item.attrs); + self.process_attrs(trait_item.hir_id, &trait_item.attrs); intravisit::walk_trait_item(self, trait_item); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - self.process_attrs(impl_item.id, &impl_item.attrs); + self.process_attrs(impl_item.hir_id, &impl_item.attrs); intravisit::walk_impl_item(self, impl_item); } fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { - self.process_attrs(s.id, &s.attrs); + self.process_attrs(s.hir_id, &s.attrs); intravisit::walk_struct_field(self, s); } } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index 3ff4d2ec38dff..279376304efe2 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -242,7 +242,7 @@ pub struct DirtyCleanVisitor<'a, 'tcx:'a> { impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> { /// Possibly "deserialize" the attribute into a clean/dirty assertion - fn assertion_maybe(&mut self, item_id: ast::NodeId, attr: &Attribute) + fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute) -> Option { let is_clean = if attr.check_name(ATTR_DIRTY) { @@ -270,7 +270,7 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> { } /// Get the "auto" assertion on pre-validated attr, along with the `except` labels - fn assertion_auto(&mut self, item_id: ast::NodeId, attr: &Attribute, is_clean: bool) + fn assertion_auto(&mut self, item_id: hir::HirId, attr: &Attribute, is_clean: bool) -> Assertion { let (name, mut auto) = self.auto_labels(item_id, attr); @@ -322,8 +322,8 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> { /// Return all DepNode labels that should be asserted for this item. /// index=0 is the "name" used for error messages - fn auto_labels(&mut self, item_id: ast::NodeId, attr: &Attribute) -> (&'static str, Labels) { - let node = self.tcx.hir().get(item_id); + fn auto_labels(&mut self, item_id: hir::HirId, attr: &Attribute) -> (&'static str, Labels) { + let node = self.tcx.hir().get_by_hir_id(item_id); let (name, labels) = match node { HirNode::Item(item) => { match item.node { @@ -500,8 +500,8 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> { } } - fn check_item(&mut self, item_id: ast::NodeId, item_span: Span) { - let def_id = self.tcx.hir().local_def_id(item_id); + fn check_item(&mut self, item_id: hir::HirId, item_span: Span) { + let def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); for attr in self.tcx.get_attrs(def_id).iter() { let assertion = match self.assertion_maybe(item_id, attr) { Some(a) => a, @@ -520,15 +520,15 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> { impl<'a, 'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { - self.check_item(item.id, item.span); + self.check_item(item.hir_id, item.span); } fn visit_trait_item(&mut self, item: &hir::TraitItem) { - self.check_item(item.id, item.span); + self.check_item(item.hir_id, item.span); } fn visit_impl_item(&mut self, item: &hir::ImplItem) { - self.check_item(item.id, item.span); + self.check_item(item.hir_id, item.span); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f895542e43ada..900021fb1ecd9 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -22,7 +22,7 @@ use rustc::hir::def::Def; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::ty::{self, Ty}; use hir::Node; -use util::nodemap::NodeSet; +use util::nodemap::HirIdSet; use lint::{LateContext, LintContext, LintArray}; use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext}; @@ -122,7 +122,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => { - let def_id = cx.tcx.hir().local_def_id(it.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id); self.check_heap_type(cx, it.span, cx.tcx.type_of(def_id)) } _ => () @@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { for struct_field in struct_def.fields() { - let def_id = cx.tcx.hir().local_def_id(struct_field.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(struct_field.hir_id); self.check_heap_type(cx, struct_field.span, cx.tcx.type_of(def_id)); } @@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { } fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { - let ty = cx.tables.node_id_to_type(e.hir_id); + let ty = cx.tables.hir_id_to_type(e.hir_id); self.check_heap_type(cx, e.span, ty); } } @@ -181,7 +181,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { } if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node { if cx.tcx.find_field_index(ident, &variant) == - Some(cx.tcx.field_index(fieldpat.node.id, cx.tables)) { + Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) { let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, &format!("the `{}:` in this pattern is redundant", ident)); @@ -302,7 +302,7 @@ pub struct MissingDoc { doc_hidden_stack: Vec, /// Private traits or trait items that leaked through. Don't check their methods. - private_traits: FxHashSet, + private_traits: FxHashSet, } fn has_doc(attr: &ast::Attribute) -> bool { @@ -339,7 +339,7 @@ impl MissingDoc { fn check_missing_docs_attrs(&self, cx: &LateContext, - id: Option, + id: Option, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { @@ -358,7 +358,8 @@ impl MissingDoc { // It's an option so the crate root can also use this function (it doesn't // have a NodeId). if let Some(id) = id { - if !cx.access_levels.is_exported(id) { + let node_id = cx.tcx.hir().hir_to_node_id(id); + if !cx.access_levels.is_exported(node_id) { return; } } @@ -418,9 +419,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { hir::ItemKind::Trait(.., ref trait_item_refs) => { // Issue #11592, traits are always considered exported, even when private. if let hir::VisibilityKind::Inherited = it.vis.node { - self.private_traits.insert(it.id); + self.private_traits.insert(it.hir_id); for trait_item_ref in trait_item_refs { - self.private_traits.insert(trait_item_ref.id.node_id); + let hir_id = cx.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id); + self.private_traits.insert(hir_id); } return; } @@ -436,7 +438,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { 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); + let hir_id = cx.tcx.hir().node_to_hir_id( + impl_item_ref.id.node_id); + self.private_traits.insert(hir_id); } } } @@ -450,11 +454,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { _ => return, }; - self.check_missing_docs_attrs(cx, Some(it.id), &it.attrs, it.span, desc); + self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, desc); } fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) { - if self.private_traits.contains(&trait_item.id) { + if self.private_traits.contains(&trait_item.hir_id) { return; } @@ -465,7 +469,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { }; self.check_missing_docs_attrs(cx, - Some(trait_item.id), + Some(trait_item.hir_id), &trait_item.attrs, trait_item.span, desc); @@ -473,7 +477,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) { // If the method is an impl for a trait, don't doc. - if method_context(cx, impl_item.id) == MethodLateContext::TraitImpl { + if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl { return; } @@ -484,7 +488,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { hir::ImplItemKind::Existential(_) => "an associated existential type", }; self.check_missing_docs_attrs(cx, - Some(impl_item.id), + Some(impl_item.hir_id), &impl_item.attrs, impl_item.span, desc); @@ -493,7 +497,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) { if !sf.is_positional() { self.check_missing_docs_attrs(cx, - Some(sf.id), + Some(sf.hir_id), &sf.attrs, sf.span, "a struct field") @@ -502,7 +506,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) { self.check_missing_docs_attrs(cx, - Some(v.node.data.id()), + Some(v.node.data.hir_id()), &v.node.attrs, v.span, "a variant"); @@ -526,7 +530,8 @@ impl LintPass for MissingCopyImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { - if !cx.access_levels.is_reachable(item.id) { + let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id); + if !cx.access_levels.is_reachable(node_id) { return; } let (def, ty) = match item.node { @@ -534,21 +539,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { if !ast_generics.params.is_empty() { return; } - let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } hir::ItemKind::Union(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } - let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } hir::ItemKind::Enum(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } - let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } _ => return, @@ -576,7 +581,7 @@ declare_lint! { } pub struct MissingDebugImplementations { - impling_types: Option, + impling_types: Option, } impl MissingDebugImplementations { @@ -593,7 +598,8 @@ impl LintPass for MissingDebugImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { - if !cx.access_levels.is_reachable(item.id) { + let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id); + if !cx.access_levels.is_reachable(node_id) { return; } @@ -610,11 +616,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { }; if self.impling_types.is_none() { - let mut impls = NodeSet::default(); + let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(debug, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { - if let Some(node_id) = cx.tcx.hir().as_local_node_id(ty_def.did) { - impls.insert(node_id); + if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(ty_def.did) { + impls.insert(hir_id); } } }); @@ -623,7 +629,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { debug!("{:?}", self.impling_types); } - if !self.impling_types.as_ref().unwrap().contains(&item.id) { + if !self.impling_types.as_ref().unwrap().contains(&item.hir_id) { cx.span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, "type does not implement `fmt::Debug`; consider adding #[derive(Debug)] \ @@ -804,7 +810,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary { _ => return, }; - let def_id = cx.tcx.hir().local_def_id(it.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id); let prfn = match cx.tcx.extern_mod_stmt_cnum(def_id) { Some(cnum) => cx.tcx.plugin_registrar_fn(cnum), None => { @@ -944,7 +950,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { if !def_id_is_transmute(cx, did) { return None; } - let sig = cx.tables.node_id_to_type(expr.hir_id).fn_sig(cx.tcx); + let sig = cx.tables.hir_id_to_type(expr.hir_id).fn_sig(cx.tcx); let from = sig.inputs().skip_binder()[0]; let to = *sig.output().skip_binder(); return Some((&from.sty, &to.sty)); @@ -1006,7 +1012,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields { fn check_item(&mut self, ctx: &LateContext, item: &hir::Item) { if let hir::ItemKind::Union(ref vdata, _) = item.node { for field in vdata.fields() { - let field_ty = ctx.tcx.type_of(ctx.tcx.hir().local_def_id(field.id)); + let field_ty = ctx.tcx.type_of( + ctx.tcx.hir().local_def_id_from_hir_id(field.hir_id)); if field_ty.needs_drop(ctx.tcx, ctx.param_env) { ctx.span_lint(UNIONS_WITH_DROP_FIELDS, field.span, @@ -1035,11 +1042,12 @@ impl LintPass for UnreachablePub { } impl UnreachablePub { - fn perform_lint(&self, cx: &LateContext, what: &str, id: ast::NodeId, + fn perform_lint(&self, cx: &LateContext, what: &str, id: hir::HirId, vis: &hir::Visibility, span: Span, exportable: bool) { let mut applicability = Applicability::MachineApplicable; - match vis.node { - hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => { + if let hir::VisibilityKind::Public = vis.node { + let node_id = cx.tcx.hir().hir_to_node_id(id); + if !cx.access_levels.is_reachable(node_id) { if span.ctxt().outer().expn_info().is_some() { applicability = Applicability::MaybeIncorrect; } @@ -1060,8 +1068,7 @@ impl UnreachablePub { err.help("or consider exporting it for use by other crates"); } err.emit(); - }, - _ => {} + } } } } @@ -1069,20 +1076,20 @@ impl UnreachablePub { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { - self.perform_lint(cx, "item", item.id, &item.vis, item.span, true); + self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true); } fn check_foreign_item(&mut self, cx: &LateContext, foreign_item: &hir::ForeignItem) { - self.perform_lint(cx, "item", foreign_item.id, &foreign_item.vis, + self.perform_lint(cx, "item", foreign_item.hir_id, &foreign_item.vis, foreign_item.span, true); } fn check_struct_field(&mut self, cx: &LateContext, field: &hir::StructField) { - self.perform_lint(cx, "field", field.id, &field.vis, field.span, false); + self.perform_lint(cx, "field", field.hir_id, &field.vis, field.span, false); } fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) { - self.perform_lint(cx, "item", impl_item.id, &impl_item.vis, impl_item.span, false); + self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false); } } @@ -1265,7 +1272,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { if cx.tcx.features().trivial_bounds { - let def_id = cx.tcx.hir().local_def_id(item.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let predicates = cx.tcx.predicates_of(def_id); for &(predicate, span) in &predicates.predicates { let predicate_kind_name = match predicate { @@ -1397,14 +1404,14 @@ declare_lint! { } pub struct UnnameableTestItems { - boundary: ast::NodeId, // NodeId of the item under which things are not nameable + boundary: hir::HirId, // HirId of the item under which things are not nameable items_nameable: bool, } impl UnnameableTestItems { pub fn new() -> Self { Self { - boundary: ast::DUMMY_NODE_ID, + boundary: hir::DUMMY_HIR_ID, items_nameable: true } } @@ -1422,7 +1429,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { if let hir::ItemKind::Mod(..) = it.node {} else { self.items_nameable = false; - self.boundary = it.id; + self.boundary = it.hir_id; } return; } @@ -1437,7 +1444,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { } fn check_item_post(&mut self, _cx: &LateContext, it: &hir::Item) { - if !self.items_nameable && self.boundary == it.id { + if !self.items_nameable && self.boundary == it.hir_id { self.items_nameable = true; } } @@ -1679,7 +1686,7 @@ impl ExplicitOutlivesRequirements { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { let infer_static = cx.tcx.features().infer_static_outlives_requirements; - let def_id = cx.tcx.hir().local_def_id(item.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); if let hir::ItemKind::Struct(_, ref generics) = item.node { let mut bound_count = 0; let mut lint_spans = Vec::new(); diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index a4a3fa552e988..a94b8f12f4552 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -17,8 +17,8 @@ pub enum MethodLateContext { PlainImpl, } -pub fn method_context(cx: &LateContext, id: ast::NodeId) -> MethodLateContext { - let def_id = cx.tcx.hir().local_def_id(id); +pub fn method_context(cx: &LateContext, id: hir::HirId) -> MethodLateContext { + let def_id = cx.tcx.hir().local_def_id_from_hir_id(id); let item = cx.tcx.associated_item(def_id); match item.container { ty::TraitContainer(..) => MethodLateContext::TraitAutoImpl, @@ -291,7 +291,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { _: &hir::FnDecl, _: &hir::Body, _: Span, - id: ast::NodeId, + id: hir::HirId ) { match &fk { FnKind::Method(ident, ..) => { @@ -343,7 +343,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { s: &hir::VariantData, _: ast::Name, _: &hir::Generics, - _: ast::NodeId, + _: hir::HirId ) { for sf in s.fields() { self.check_snake_case(cx, "structure field", &sf.ident); diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 642681a73a8a0..014832819806b 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -43,12 +43,12 @@ declare_lint! { #[derive(Copy, Clone)] pub struct TypeLimits { /// Id of the last visited negated expression - negated_expr_id: ast::NodeId, + negated_expr_id: hir::HirId, } impl TypeLimits { pub fn new() -> TypeLimits { - TypeLimits { negated_expr_id: ast::DUMMY_NODE_ID } + TypeLimits { negated_expr_id: hir::DUMMY_HIR_ID } } } @@ -64,8 +64,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { match e.node { hir::ExprKind::Unary(hir::UnNeg, ref expr) => { // propagate negation, if the negation itself isn't negated - if self.negated_expr_id != e.id { - self.negated_expr_id = expr.id; + if self.negated_expr_id != e.hir_id { + self.negated_expr_id = expr.hir_id; } } hir::ExprKind::Binary(binop, ref l, ref r) => { @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } } hir::ExprKind::Lit(ref lit) => { - match cx.tables.node_id_to_type(e.hir_id).sty { + match cx.tables.hir_id_to_type(e.hir_id).sty { ty::Int(t) => { match lit.node { ast::LitKind::Int(v, ast::LitIntType::Signed(_)) | @@ -88,7 +88,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { }; let (_, max) = int_ty_range(int_type); let max = max as u128; - let negative = self.negated_expr_id == e.id; + let negative = self.negated_expr_id == e.hir_id; // Detect literal value out of range [min, max] inclusive // avoiding use of -min to prevent overflow/panic @@ -129,8 +129,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { _ => bug!(), }; if lit_val < min || lit_val > max { - let parent_id = cx.tcx.hir().get_parent_node(e.id); - if let Node::Expr(parent_expr) = cx.tcx.hir().get(parent_id) { + let parent_id = cx.tcx.hir().get_parent_node(e.hir_id); + if let Node::Expr(parent_expr) = cx.tcx.hir().get_by_hir_id(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( @@ -248,7 +248,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { // Normalize the binop so that the literal is always on the RHS in // the comparison let norm_binop = if swap { rev_binop(binop) } else { binop }; - match cx.tables.node_id_to_type(expr.hir_id).sty { + match cx.tables.hir_id_to_type(expr.hir_id).sty { ty::Int(int_ty) => { let (min, max) = int_ty_range(int_ty); let lit_val: i128 = match lit.node { @@ -391,7 +391,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { repr_str, val, t, actually, t )); if let Some(sugg_ty) = - get_type_suggestion(&cx.tables.node_id_to_type(expr.hir_id).sty, val, negative) + get_type_suggestion(&cx.tables.hir_id_to_type(expr.hir_id).sty, val, negative) { if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') { let (sans_suffix, _) = repr_str.split_at(pos); @@ -755,8 +755,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } } - fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) { - let def_id = self.cx.tcx.hir().local_def_id(id); + fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) { + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id); let sig = self.cx.tcx.fn_sig(def_id); let sig = self.cx.tcx.erase_late_bound_regions(&sig); @@ -772,8 +772,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } } - fn check_foreign_static(&mut self, id: ast::NodeId, span: Span) { - let def_id = self.cx.tcx.hir().local_def_id(id); + fn check_foreign_static(&mut self, id: hir::HirId, span: Span) { + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id); let ty = self.cx.tcx.type_of(def_id); self.check_type_for_ffi_and_report_errors(span, ty); } @@ -791,14 +791,14 @@ impl LintPass for ImproperCTypes { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { fn check_foreign_item(&mut self, cx: &LateContext, it: &hir::ForeignItem) { let mut vis = ImproperCTypesVisitor { cx }; - let abi = cx.tcx.hir().get_foreign_abi(it.id); + let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic { match it.node { hir::ForeignItemKind::Fn(ref decl, _, _) => { - vis.check_foreign_fn(it.id, decl); + vis.check_foreign_fn(it.hir_id, decl); } hir::ForeignItemKind::Static(ref ty, _) => { - vis.check_foreign_static(it.id, ty.span); + vis.check_foreign_static(it.hir_id, ty.span); } hir::ForeignItemKind::Type => () } @@ -817,7 +817,7 @@ impl LintPass for VariantSizeDifferences { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { if let hir::ItemKind::Enum(ref enum_definition, _) = it.node { - let item_def_id = cx.tcx.hir().local_def_id(it.id); + let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id); let t = cx.tcx.type_of(item_def_id); let ty = cx.tcx.erase_regions(&t); match cx.layout_of(ty) { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index bc29020e79f2a..392e9fc83397b 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -41,7 +41,7 @@ impl LintPass for UnusedResults { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { let expr = match s.node { - hir::StmtKind::Semi(ref expr, _) => &**expr, + hir::StmtKind::Semi(ref expr, ..) => &**expr, _ => return, }; @@ -51,7 +51,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { let t = cx.tables.expr_ty(&expr); let type_permits_lack_of_use = if t.is_unit() - || cx.tcx.is_ty_uninhabited_from(cx.tcx.hir().get_module_parent(expr.id), t) { + || cx.tcx.is_ty_uninhabited_from(cx.tcx.hir().get_module_parent(expr.hir_id), + t) + { true } else { match t.sty { @@ -205,7 +207,7 @@ impl LintPass for PathStatements { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { - if let hir::StmtKind::Semi(ref expr, _) = s.node { + if let hir::StmtKind::Semi(ref expr, ..) = s.node { if let hir::ExprKind::Path(_) = expr.node { cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect"); } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 2de1637fb0d9d..2ffb6963e37b0 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -29,7 +29,7 @@ use std::hash::Hash; use std::path::Path; use rustc_data_structures::sync::Lrc; use std::u32; -use syntax::ast::{self, CRATE_NODE_ID}; +use syntax::ast; use syntax::attr; use syntax::source_map::Spanned; use syntax::symbol::keywords; @@ -313,7 +313,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public }; index.record(DefId::local(CRATE_DEF_INDEX), IsolatedEncoder::encode_info_for_mod, - FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &vis))); + FromId(hir::CRATE_HIR_ID, (&krate.module, &krate.attrs, &vis))); let mut visitor = EncodeVisitor { index }; krate.visit_all_item_likes(&mut visitor.as_deep_visitor()); for macro_def in &krate.exported_macros { @@ -587,8 +587,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { } }; - let enum_id = tcx.hir().as_local_node_id(enum_did).unwrap(); - let enum_vis = &tcx.hir().expect_item(enum_id).vis; + let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); + let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis; Entry { kind: EntryKind::Variant(self.lazy(&data)), @@ -623,7 +623,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { &hir::Visibility)>) -> Entry<'tcx> { let tcx = self.tcx; - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); debug!("IsolatedEncoder::encode_info_for_mod({:?})", def_id); let data = ModData { @@ -673,7 +673,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let def_id = field.did; debug!("IsolatedEncoder::encode_field({:?})", def_id); - let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap(); + let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap(); let variant_data = tcx.hir().expect_variant_data(variant_id); Entry { @@ -713,8 +713,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { } }; - let struct_id = tcx.hir().as_local_node_id(adt_def_id).unwrap(); - let struct_vis = &tcx.hir().expect_item(struct_id).vis; + let struct_id = tcx.hir().as_local_hir_id(adt_def_id).unwrap(); + let struct_vis = &tcx.hir().expect_item_by_hir_id(struct_id).vis; let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx); for field in &variant.fields { if ctor_vis.is_at_least(field.vis, tcx) { @@ -778,8 +778,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { debug!("IsolatedEncoder::encode_info_for_trait_item({:?})", def_id); let tcx = self.tcx; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let ast_item = tcx.hir().expect_trait_item(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let ast_item = tcx.hir().expect_trait_item_by_hir_id(hir_id); let trait_item = tcx.associated_item(def_id); let container = match trait_item.defaultness { @@ -888,8 +888,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { debug!("IsolatedEncoder::encode_info_for_impl_item({:?})", def_id); let tcx = self.tcx; - let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap(); - let ast_item = self.tcx.hir().expect_impl_item(node_id); + let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let ast_item = self.tcx.hir().expect_impl_item_by_hir_id(hir_id); let impl_item = self.tcx.associated_item(def_id); let container = match impl_item.defaultness { @@ -1054,7 +1054,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { EntryKind::Fn(self.lazy(&data)) } hir::ItemKind::Mod(ref m) => { - return self.encode_info_for_mod(FromId(item.id, (m, &item.attrs, &item.vis))); + return self.encode_info_for_mod(FromId(item.hir_id, (m, &item.attrs, &item.vis))); } hir::ItemKind::ForeignMod(_) => EntryKind::ForeignMod, hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm, @@ -1068,7 +1068,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { // for methods, write all the stuff get_trait_method // needs to know let struct_ctor = if !struct_def.is_struct() { - Some(tcx.hir().local_def_id(struct_def.id()).index) + Some(tcx.hir().local_def_id_from_hir_id(struct_def.hir_id()).index) } else { None }; @@ -1147,14 +1147,15 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { Entry { kind, - visibility: self.lazy(&ty::Visibility::from_hir(&item.vis, item.id, tcx)), + visibility: self.lazy(&ty::Visibility::from_hir(&item.vis, item.hir_id, tcx)), span: self.lazy(&item.span), attributes: self.encode_attributes(&item.attrs), children: match item.node { hir::ItemKind::ForeignMod(ref fm) => { self.lazy_seq(fm.items .iter() - .map(|foreign_item| tcx.hir().local_def_id(foreign_item.id).index)) + .map(|foreign_item| tcx.hir() + .local_def_id_from_hir_id(foreign_item.hir_id).index)) } hir::ItemKind::Enum(..) => { let def = self.tcx.adt_def(def_id); @@ -1269,7 +1270,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { /// Serialize the text of exported macros fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) -> Entry<'tcx> { use syntax::print::pprust; - let def_id = self.tcx.hir().local_def_id(macro_def.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(macro_def.hir_id); Entry { kind: EntryKind::MacroDef(self.lazy(&MacroDef { body: pprust::tts_to_string(¯o_def.body.trees().collect::>()), @@ -1326,9 +1327,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let tcx = self.tcx; let tables = self.tcx.typeck_tables_of(def_id); - let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap(); - let hir_id = self.tcx.hir().node_to_hir_id(node_id); - let kind = match tables.node_id_to_type(hir_id).sty { + let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let kind = match tables.hir_id_to_type(hir_id).sty { ty::Generator(def_id, ..) => { let layout = self.tcx.generator_layout(def_id); let data = GeneratorData { @@ -1369,7 +1369,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { fn encode_info_for_anon_const(&mut self, def_id: DefId) -> Entry<'tcx> { debug!("IsolatedEncoder::encode_info_for_anon_const({:?})", def_id); let tcx = self.tcx; - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let body_id = tcx.hir().body_owned_by(id); let const_data = self.encode_rendered_const_for_body(body_id); let mir = tcx.mir_const_qualif(def_id).0; @@ -1576,7 +1576,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { Entry { kind, - visibility: self.lazy(&ty::Visibility::from_hir(&nitem.vis, nitem.id, tcx)), + visibility: self.lazy(&ty::Visibility::from_hir(&nitem.vis, nitem.hir_id, tcx)), span: self.lazy(&nitem.span), attributes: self.encode_attributes(&nitem.attrs), children: LazySeq::empty(), @@ -1612,7 +1612,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { intravisit::walk_item(self, item); - let def_id = self.index.tcx.hir().local_def_id(item.id); + let def_id = self.index.tcx.hir().local_def_id_from_hir_id(item.hir_id); match item.node { hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => (), // ignore these @@ -1622,7 +1622,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> { } fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem) { intravisit::walk_foreign_item(self, ni); - let def_id = self.index.tcx.hir().local_def_id(ni.id); + let def_id = self.index.tcx.hir().local_def_id_from_hir_id(ni.hir_id); self.index.record(def_id, IsolatedEncoder::encode_info_for_foreign_item, (def_id, ni)); @@ -1630,11 +1630,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> { fn visit_variant(&mut self, v: &'tcx hir::Variant, g: &'tcx hir::Generics, - id: ast::NodeId) { + id: hir::HirId) { intravisit::walk_variant(self, v, g, id); if let Some(ref discr) = v.node.disr_expr { - let def_id = self.index.tcx.hir().local_def_id(discr.id); + let def_id = self.index.tcx.hir().local_def_id_from_hir_id(discr.hir_id);; self.index.record(def_id, IsolatedEncoder::encode_info_for_anon_const, def_id); } } @@ -1647,7 +1647,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> { self.index.encode_info_for_ty(ty); } fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) { - let def_id = self.index.tcx.hir().local_def_id(macro_def.id); + let def_id = self.index.tcx.hir().local_def_id_from_hir_id(macro_def.hir_id); self.index.record(def_id, IsolatedEncoder::encode_info_for_macro_def, macro_def); } } @@ -1669,7 +1669,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { match param.kind { hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Type { ref default, .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); let has_default = Untracked(default.is_some()); let encode_info = IsolatedEncoder::encode_info_for_ty_param; self.record(def_id, encode_info, (def_id, has_default)); @@ -1681,7 +1681,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { fn encode_info_for_ty(&mut self, ty: &hir::Ty) { match ty.node { hir::TyKind::Array(_, ref length) => { - let def_id = self.tcx.hir().local_def_id(length.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(length.hir_id); self.record(def_id, IsolatedEncoder::encode_info_for_anon_const, def_id); } _ => {} @@ -1691,7 +1691,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { fn encode_info_for_expr(&mut self, expr: &hir::Expr) { match expr.node { hir::ExprKind::Closure(..) => { - let def_id = self.tcx.hir().local_def_id(expr.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); self.record(def_id, IsolatedEncoder::encode_info_for_closure, def_id); } _ => {} @@ -1703,7 +1703,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { /// so it's easier to do that here then to wait until we would encounter /// normally in the visitor walk. fn encode_addl_info_for_item(&mut self, item: &hir::Item) { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); match item.node { hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | @@ -1733,7 +1733,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { // If the struct has a constructor, encode it. if !struct_def.is_struct() { - let ctor_def_id = self.tcx.hir().local_def_id(struct_def.id()); + let ctor_def_id = self.tcx.hir().local_def_id_from_hir_id(struct_def.hir_id()); self.record(ctor_def_id, IsolatedEncoder::encode_struct_ctor, (def_id, ctor_def_id)); @@ -1768,7 +1768,7 @@ struct ImplVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { if let hir::ItemKind::Impl(..) = item.node { - let impl_id = self.tcx.hir().local_def_id(item.id); + let impl_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) { self.impls .entry(trait_ref.def_id) diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index 2c03bd6659f27..284f6796145a8 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -25,11 +25,11 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for Collector<'a, 'tcx> { }; let foreign_items = fm.items.iter() - .map(|it| self.tcx.hir().local_def_id(it.id)) + .map(|it| self.tcx.hir().local_def_id_from_hir_id(it.hir_id)) .collect(); self.modules.push(ForeignModule { foreign_items, - def_id: self.tcx.hir().local_def_id(it.id), + def_id: self.tcx.hir().local_def_id_from_hir_id(it.hir_id), }); } diff --git a/src/librustc_metadata/index_builder.rs b/src/librustc_metadata/index_builder.rs index 3608b12aea934..ccfda7f37fd02 100644 --- a/src/librustc_metadata/index_builder.rs +++ b/src/librustc_metadata/index_builder.rs @@ -185,7 +185,7 @@ macro_rules! read_hir { ($t:ty) => { impl<'tcx> DepGraphRead for &'tcx $t { fn read(&self, tcx: TyCtxt) { - tcx.hir().read(self.id); + tcx.hir().read_by_hir_id(self.hir_id); } } } @@ -215,10 +215,10 @@ impl DepGraphRead for Untracked { /// HIR node that doesn't carry its own id. This will allow an /// arbitrary `T` to be passed in, but register a read on the given /// node-id. -pub struct FromId(pub ast::NodeId, pub T); +pub struct FromId(pub hir::HirId, pub T); impl DepGraphRead for FromId { fn read(&self, tcx: TyCtxt) { - tcx.hir().read(self.0); + tcx.hir().read_by_hir_id(self.0); } } diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index d35d64957b7b4..9da0f51553405 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -55,7 +55,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for Collector<'a, 'tcx> { name: None, kind: cstore::NativeUnknown, cfg: None, - foreign_module: Some(self.tcx.hir().local_def_id(it.id)), + foreign_module: Some(self.tcx.hir().local_def_id_from_hir_id(it.hir_id)), wasm_import_module: None, }; let mut kind_specified = false; diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 233db12b03001..df18d35079483 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -814,13 +814,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { format!("`{}` would have to be valid for `{}`...", name, region_name), ); - if let Some(fn_node_id) = self.infcx.tcx.hir().as_local_node_id(self.mir_def_id) { + if let Some(fn_hir_id) = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id) { err.span_label( drop_span, format!( "...but `{}` will be dropped here, when the function `{}` returns", name, - self.infcx.tcx.hir().name(fn_node_id), + self.infcx.tcx.hir().name(fn_hir_id), ), ); @@ -1159,7 +1159,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let escapes_from = if tcx.is_closure(self.mir_def_id) { let tables = tcx.typeck_tables_of(self.mir_def_id); let mir_hir_id = tcx.hir().def_index_to_hir_id(self.mir_def_id.index); - match tables.node_id_to_type(mir_hir_id).sty { + match tables.hir_id_to_type(mir_hir_id).sty { ty::Closure(..) => "closure", ty::Generator(..) => "generator", _ => bug!("Closure body doesn't have a closure or generator type"), @@ -1755,12 +1755,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // the local code in the current crate, so this returns an `Option` in case // the closure comes from another crate. But in that case we wouldn't // be borrowck'ing it, so we can just unwrap: - let node_id = self.infcx.tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id).unwrap(); let freevar = self.infcx .tcx - .with_freevars(node_id, |fv| fv[field.index()]); + .with_freevars(hir_id, |fv| fv[field.index()]); - self.infcx.tcx.hir().name(freevar.var_id()).to_string() + let freevar_hir_id = freevar.var_id(); + self.infcx.tcx.hir().name(freevar_hir_id).to_string() } _ => { // Might need a revision when the fields in trait RFC is implemented @@ -2065,8 +2066,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { ) -> Option { debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig); let is_closure = self.infcx.tcx.is_closure(did); - let fn_node_id = self.infcx.tcx.hir().as_local_node_id(did)?; - let fn_decl = self.infcx.tcx.hir().fn_decl(fn_node_id)?; + let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(did)?; + let fn_decl = self.infcx.tcx.hir().fn_decl(fn_hir_id)?; // We need to work out which arguments to highlight. We do this by looking // at the return type, where there are three cases: @@ -2512,14 +2513,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { "closure_span: def_id={:?} target_place={:?} places={:?}", def_id, target_place, places ); - let node_id = self.infcx.tcx.hir().as_local_node_id(def_id)?; - let expr = &self.infcx.tcx.hir().expect_expr(node_id).node; - debug!("closure_span: node_id={:?} expr={:?}", node_id, expr); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id)?; + let expr = &self.infcx.tcx.hir().expect_expr(hir_id).node; + debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr); if let hir::ExprKind::Closure( .., args_span, _ ) = expr { let var_span = self.infcx.tcx.with_freevars( - node_id, + hir_id, |freevars| { for (v, place) in freevars.iter().zip(places) { match place { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 45632245b61de..79af6e98d3f25 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -128,7 +128,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( let param_env = tcx.param_env(def_id); let id = tcx .hir() - .as_local_node_id(def_id) + .as_local_hir_id(def_id) .expect("do_mir_borrowck: non-local DefId"); // Replace all regions with fresh inference variables. This @@ -219,7 +219,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( |bd, i| DebugFormatted::new(&bd.move_data().inits[i]), )); - let movable_generator = match tcx.hir().get(id) { + let movable_generator = match tcx.hir().get_by_hir_id(id) { Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), .. diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 3c62614ce4766..34bb0a0fe5bd5 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -308,9 +308,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { let upvar_decl = &self.mir.upvar_decls[field.index()]; let upvar_hir_id = upvar_decl.var_hir_id.assert_crate_local(); - let upvar_node_id = - self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id); - let upvar_span = self.infcx.tcx.hir().span(upvar_node_id); + let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id); diag.span_label(upvar_span, "captured outer variable"); break; } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index bff8015511242..d034b181963b4 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -10,7 +10,7 @@ use rustc::ty::subst::{Substs, UnpackedKind}; use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt}; use rustc::util::ppaux::RegionHighlightMode; use rustc_errors::DiagnosticBuilder; -use syntax::ast::{Name, DUMMY_NODE_ID}; +use syntax::ast::Name; use syntax::symbol::keywords; use syntax_pos::Span; use syntax_pos::symbol::InternedString; @@ -215,14 +215,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { }, ty::BoundRegion::BrEnv => { - let mir_node_id = tcx.hir() - .as_local_node_id(mir_def_id) + let mir_hir_id = tcx.hir() + .as_local_hir_id(mir_def_id) .expect("non-local mir"); let def_ty = self.universal_regions.defining_ty; if let DefiningTy::Closure(def_id, substs) = def_ty { let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) = - tcx.hir().expect_expr(mir_node_id).node + tcx.hir().expect_expr(mir_hir_id).node { span } else { @@ -293,7 +293,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { name: &InternedString, ) -> Span { let scope = error_region.free_region_binding_scope(tcx); - let node = tcx.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); + let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); let span = tcx.sess.source_map().def_span(tcx.hir().span(node)); if let Some(param) = tcx.hir() @@ -352,8 +352,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { argument_index: usize, counter: &mut usize, ) -> Option { - let mir_node_id = infcx.tcx.hir().as_local_node_id(mir_def_id)?; - let fn_decl = infcx.tcx.hir().fn_decl(mir_node_id)?; + let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?; + let fn_decl = infcx.tcx.hir().fn_decl(mir_hir_id)?; let argument_hir_ty: &hir::Ty = &fn_decl.inputs[argument_index]; match argument_hir_ty.node { // This indicates a variable with no type annotation, like diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index c2f2e99c0a55b..1eafc222bc02c 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -71,11 +71,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { upvar_index: usize, ) -> (Symbol, Span) { let upvar_hir_id = mir.upvar_decls[upvar_index].var_hir_id.assert_crate_local(); - let upvar_node_id = tcx.hir().hir_to_node_id(upvar_hir_id); - debug!("get_upvar_name_and_span_for_region: upvar_node_id={:?}", upvar_node_id); + debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); - let upvar_name = tcx.hir().name(upvar_node_id); - let upvar_span = tcx.hir().span(upvar_node_id); + let upvar_name = tcx.hir().name(upvar_hir_id); + let upvar_span = tcx.hir().span(upvar_hir_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index c63d45ce1d272..d025ba7fd9ed4 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -23,7 +23,6 @@ use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_errors::DiagnosticBuilder; use std::iter; -use syntax::ast; use super::ToRegionVid; @@ -200,12 +199,10 @@ impl<'tcx> UniversalRegions<'tcx> { param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).unwrap(); - let mir_hir_id = tcx.hir().node_to_hir_id(mir_node_id); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).unwrap(); UniversalRegionsBuilder { infcx, mir_def_id, - mir_node_id, mir_hir_id, param_env, }.build() @@ -370,7 +367,6 @@ struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> { infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>, mir_def_id: DefId, mir_hir_id: HirId, - mir_node_id: ast::NodeId, param_env: ty::ParamEnv<'tcx>, } @@ -475,13 +471,13 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { let tcx = self.infcx.tcx; let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); - match tcx.hir().body_owner_kind(self.mir_node_id) { + match tcx.hir().body_owner_kind(self.mir_hir_id) { BodyOwnerKind::Fn => { let defining_ty = if self.mir_def_id == closure_base_def_id { tcx.type_of(closure_base_def_id) } else { let tables = tcx.typeck_tables_of(self.mir_def_id); - tables.node_id_to_type(self.mir_hir_id) + tables.hir_id_to_type(self.mir_hir_id) }; debug!("defining_ty (pre-replacement): {:?}", defining_ty); @@ -770,9 +766,9 @@ fn for_each_late_bound_region_defined_on<'tcx>( owner: fn_def_id.index, local_id: *late_bound, }; - let region_node_id = tcx.hir().hir_to_node_id(hir_id); - let name = tcx.hir().name(region_node_id).as_interned_str(); - let region_def_id = tcx.hir().local_def_id(region_node_id); + + let name = tcx.hir().name(hir_id).as_interned_str(); + let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: fn_def_id, bound_region: ty::BoundRegion::BrNamed(region_def_id, name), diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index f3d89a7a02515..78c22cf936d89 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -206,14 +206,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { debug!("update_source_scope_for({:?}, {:?})", span, safety_mode); let new_unsafety = match safety_mode { BlockSafety::Safe => None, - BlockSafety::ExplicitUnsafe(node_id) => { + BlockSafety::ExplicitUnsafe(hir_id) => { assert_eq!(self.push_unsafe_count, 0); match self.unpushed_unsafe { Safety::Safe => {} _ => return } - self.unpushed_unsafe = Safety::ExplicitUnsafe(node_id); - Some(Safety::ExplicitUnsafe(node_id)) + self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id); + Some(Safety::ExplicitUnsafe(hir_id)) } BlockSafety::PushUnsafe => { self.push_unsafe_count += 1; diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index d52ce9a67d29a..982fddeb30b9d 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -8,12 +8,13 @@ use build::ForGuard::{self, OutsideGuard, RefWithinGuard, ValWithinGuard}; use build::{BlockAnd, BlockAndExtension, Builder}; use build::{GuardFrame, GuardFrameLocal, LocalsForNode}; use hair::*; +use rustc::hir; use rustc::mir::*; use rustc::ty::{self, Ty}; use rustc::ty::layout::VariantIdx; use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::fx::FxHashMap; -use syntax::ast::{Name, NodeId}; +use syntax::ast::Name; use syntax_pos::Span; // helper functions, broken out by category: @@ -462,7 +463,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { pub fn storage_live_binding( &mut self, block: BasicBlock, - var: NodeId, + var: hir::HirId, span: Span, for_guard: ForGuard, ) -> Place<'tcx> { @@ -477,17 +478,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ); let place = Place::Local(local_id); let var_ty = self.local_decls[local_id].ty; - let hir_id = self.hir.tcx().hir().node_to_hir_id(var); - let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id); + let region_scope = self.hir.region_scope_tree.var_scope(var.local_id); self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage); place } - pub fn schedule_drop_for_binding(&mut self, var: NodeId, span: Span, for_guard: ForGuard) { + pub fn schedule_drop_for_binding(&mut self, var: hir::HirId, span: Span, for_guard: ForGuard) { let local_id = self.var_local_id(var, for_guard); let var_ty = self.local_decls[local_id].ty; - let hir_id = self.hir.tcx().hir().node_to_hir_id(var); - let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id); + let region_scope = self.hir.region_scope_tree.var_scope(var.local_id); self.schedule_drop( span, region_scope, @@ -508,7 +507,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { Mutability, Name, BindingMode, - NodeId, + hir::HirId, Span, Ty<'tcx>, UserTypeProjections<'tcx>, @@ -637,7 +636,7 @@ struct Binding<'tcx> { span: Span, source: Place<'tcx>, name: Name, - var_id: NodeId, + var_id: hir::HirId, var_ty: Ty<'tcx>, mutability: Mutability, binding_mode: BindingMode, @@ -1493,7 +1492,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { name: Name, mode: BindingMode, num_patterns: usize, - var_id: NodeId, + var_id: hir::HirId, var_ty: Ty<'tcx>, user_ty: UserTypeProjections<'tcx>, has_guard: ArmHasGuard, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 2bf2824d835cc..634f26f7979d6 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -10,14 +10,13 @@ use rustc::mir::*; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::subst::Substs; -use rustc::util::nodemap::NodeMap; +use rustc::util::nodemap::HirIdMap; use rustc_target::spec::PanicStrategy; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use shim; use std::mem; use std::u32; use rustc_target::spec::abi::Abi; -use syntax::ast; use syntax::attr::{self, UnwindAttr}; use syntax::symbol::keywords; use syntax_pos::Span; @@ -28,10 +27,10 @@ use super::lints; /// Construct the MIR for a given def-id. pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'tcx> { - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); // Figure out what primary body this item has. - let (body_id, return_ty_span) = match tcx.hir().get(id) { + let (body_id, return_ty_span) = match tcx.hir().get_by_hir_id(id) { Node::Variant(variant) => return create_constructor_shim(tcx, id, &variant.node.data), Node::StructCtor(ctor) => @@ -64,8 +63,8 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t ) => { (*body_id, ty.span) } - Node::AnonConst(hir::AnonConst { body, id, .. }) => { - (*body, tcx.hir().span(*id)) + Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => { + (*body, tcx.hir().span(*hir_id)) } _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), @@ -78,9 +77,9 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t } else if let hir::BodyOwnerKind::Fn = cx.body_owner_kind { // fetch the fully liberated fn signature (that is, all bound // types/lifetimes replaced) - let fn_hir_id = tcx.hir().node_to_hir_id(id); + let fn_hir_id = id; let fn_sig = cx.tables().liberated_fn_sigs()[fn_hir_id].clone(); - let fn_def_id = tcx.hir().local_def_id(id); + let fn_def_id = tcx.hir().local_def_id_from_hir_id(fn_hir_id); let ty = tcx.type_of(fn_def_id); let mut abi = fn_sig.abi; @@ -92,7 +91,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t Some(ArgInfo(liberated_closure_env_ty(tcx, id, body_id), None, None, None)) } ty::Generator(..) => { - let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id); + let gen_ty = tcx.body_tables(body_id).hir_id_to_type(fn_hir_id); Some(ArgInfo(gen_ty, None, None, None)) } _ => None, @@ -114,7 +113,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span(tcx.hir().hir_to_node_id(ty_hir_id)); + let ty_span = tcx.hir().span(ty_hir_id); opt_ty_info = Some(ty_span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { @@ -141,7 +140,8 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t ty::Generator(gen_def_id, gen_substs, ..) => gen_substs.sig(gen_def_id, tcx), _ => - span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty), + span_bug!(tcx.hir().span(id), + "generator w/o generator type: {:?}", ty), }; (Some(gen_sig.yield_ty), gen_sig.return_ty) } else { @@ -224,14 +224,14 @@ impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> { } fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - ctor_id: ast::NodeId, + ctor_id: hir::HirId, v: &'tcx hir::VariantData) -> Mir<'tcx> { let span = tcx.hir().span(ctor_id); - if let hir::VariantData::Tuple(ref fields, ctor_id) = *v { + if let hir::VariantData::Tuple(ref fields, hir_id) = *v { tcx.infer_ctxt().enter(|infcx| { - let mut mir = shim::build_adt_ctor(&infcx, ctor_id, fields, span); + let mut mir = shim::build_adt_ctor(&infcx, hir_id, fields, span); // Convert the Mir to global types. let tcx = infcx.tcx.global_tcx(); @@ -245,7 +245,7 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; mir_util::dump_mir(tcx, None, "mir_map", &0, - MirSource::item(tcx.hir().local_def_id(ctor_id)), + MirSource::item(tcx.hir().local_def_id_from_hir_id(hir_id)), &mir, |_, _| Ok(()) ); mir @@ -259,11 +259,10 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // BuildMir -- walks a crate, looking for fn items and methods to build MIR from fn liberated_closure_env_ty<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, - closure_expr_id: ast::NodeId, + closure_expr_hir_id: hir::HirId, body_id: hir::BodyId) -> Ty<'tcx> { - let closure_expr_hir_id = tcx.hir().node_to_hir_id(closure_expr_id); - let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_hir_id); + let closure_ty = tcx.body_tables(body_id).hir_id_to_type(closure_expr_hir_id); let (closure_def_id, closure_substs) = match closure_ty.sty { ty::Closure(closure_def_id, closure_substs) => (closure_def_id, closure_substs), @@ -377,7 +376,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// Maps node ids of variable bindings to the `Local`s created for them. /// (A match binding can have two locals; the 2nd is for the arm's guard.) - var_indices: NodeMap, + var_indices: HirIdMap, local_decls: IndexVec>, canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, upvar_decls: Vec, @@ -393,11 +392,11 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { } impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { - fn is_bound_var_in_guard(&self, id: ast::NodeId) -> bool { + fn is_bound_var_in_guard(&self, id: hir::HirId) -> bool { self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id)) } - fn var_local_id(&self, id: ast::NodeId, for_guard: ForGuard) -> Local { + fn var_local_id(&self, id: hir::HirId, for_guard: ForGuard) -> Local { self.var_indices[&id].local_id(for_guard) } } @@ -482,11 +481,11 @@ enum LocalsForNode { #[derive(Debug)] struct GuardFrameLocal { - id: ast::NodeId, + id: hir::HirId, } impl GuardFrameLocal { - fn new(id: ast::NodeId, _binding_mode: BindingMode) -> Self { + fn new(id: hir::HirId, _binding_mode: BindingMode) -> Self { GuardFrameLocal { id: id, } @@ -626,7 +625,7 @@ struct ArgInfo<'gcx>(Ty<'gcx>, Option); fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, - fn_id: ast::NodeId, + fn_id: hir::HirId, arguments: A, safety: Safety, abi: Abi, @@ -644,7 +643,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, let span = tcx_hir.span(fn_id); let hir_tables = hir.tables(); - let fn_def_id = tcx_hir.local_def_id(fn_id); + let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id); // Gather the upvars of a closure, if any. // In analyze_closure() in upvar.rs we gathered a list of upvars used by a @@ -658,7 +657,6 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, .flatten() .map(|upvar_id| { let var_hir_id = upvar_id.var_path.hir_id; - let var_node_id = tcx_hir.hir_to_node_id(var_hir_id); let capture = hir_tables.upvar_capture(*upvar_id); let by_ref = match capture { ty::UpvarCapture::ByValue => false, @@ -670,7 +668,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, by_ref, mutability: Mutability::Not, }; - if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) { + if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { decl.debug_name = ident.name; if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) { @@ -738,7 +736,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, // RustCall pseudo-ABI untuples the last argument. spread_arg = Some(Local::new(arguments.len())); } - let closure_expr_id = tcx_hir.local_def_id(fn_id); + let closure_expr_id = tcx_hir.local_def_id_from_hir_id(fn_id); info!("fn_id {:?} has attrs {:?}", closure_expr_id, tcx.get_attrs(closure_expr_id)); diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index b44c2cc9c166a..1ec04a1e75cfd 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -308,15 +308,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block); let source_scope = self.source_scope; let tcx = self.hir.tcx(); - if let LintLevel::Explicit(node_id) = lint_level { + if let LintLevel::Explicit(current_hir_id) = lint_level { let same_lint_scopes = tcx.dep_graph.with_ignore(|| { let sets = tcx.lint_levels(LOCAL_CRATE); let parent_hir_id = - tcx.hir().definitions().node_to_hir_id( - self.source_scope_local_data[source_scope].lint_root - ); - let current_hir_id = - tcx.hir().definitions().node_to_hir_id(node_id); + self.source_scope_local_data[source_scope].lint_root; sets.lint_level_set(parent_hir_id) == sets.lint_level_set(current_hir_id) }); diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index f5f4048167938..4bfd1fb2b5ce3 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -678,7 +678,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( let cid = key.value; let def_id = cid.instance.def.def_id(); - if let Some(id) = tcx.hir().as_local_node_id(def_id) { + if let Some(id) = tcx.hir().as_local_hir_id(def_id) { let tables = tcx.typeck_tables_of(def_id); // Do match-check before building MIR @@ -726,11 +726,11 @@ pub fn const_eval_raw_provider<'a, 'tcx>( // because any code that existed before validation could not have failed validation // thus preventing such a hard error from being a backwards compatibility hazard Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); err.report_as_lint( tcx.at(tcx.def_span(def_id)), "any use of this value will cause an error", - node_id, + hir_id, ) }, // promoting runtime code is only allowed to error if it references broken constants @@ -746,7 +746,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( err.report_as_lint( tcx.at(span), "reaching this expression at runtime will panic or abort", - tcx.hir().as_local_node_id(def_id).unwrap(), + tcx.hir().as_local_hir_id(def_id).unwrap(), ) } // anything else (array lengths, enum initializers, constant patterns) are reported diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs index 34752baa020e2..1949a7b51b594 100644 --- a/src/librustc_mir/dataflow/graphviz.rs +++ b/src/librustc_mir/dataflow/graphviz.rs @@ -1,6 +1,6 @@ //! Hook into libgraphviz for rendering dataflow graphs for MIR. -use syntax::ast::NodeId; +use rustc::hir::HirId; use rustc::mir::{BasicBlock, Mir}; use dot; @@ -16,7 +16,7 @@ use super::DebugFormatted; pub trait MirWithFlowState<'tcx> { type BD: BitDenotation<'tcx>; - fn node_id(&self) -> NodeId; + fn hir_id(&self) -> HirId; fn mir(&self) -> &Mir<'tcx>; fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>; } @@ -25,7 +25,7 @@ impl<'a, 'tcx, BD> MirWithFlowState<'tcx> for DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { type BD = BD; - fn node_id(&self) -> NodeId { self.node_id } + fn hir_id(&self) -> HirId { self.hir_id } fn mir(&self) -> &Mir<'tcx> { self.flow_state.mir() } fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { &self.flow_state.flow_state } } @@ -49,8 +49,8 @@ pub(crate) fn print_borrowck_graph_to<'a, 'tcx, BD, P>( let g = Graph { mbcx, phantom: PhantomData, render_idx }; let mut v = Vec::new(); dot::render(&g, &mut v)?; - debug!("print_borrowck_graph_to path: {} node_id: {}", - path.display(), mbcx.node_id); + debug!("print_borrowck_graph_to path: {} hir_id: {:?}", + path.display(), mbcx.hir_id); fs::write(path, v) } @@ -71,8 +71,8 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P> type Node = Node; type Edge = Edge; fn graph_id(&self) -> dot::Id { - dot::Id::new(format!("graph_for_node_{}", - self.mbcx.node_id())) + dot::Id::new(format!("graph_for_hir_{:?}", + self.mbcx.hir_id())) .unwrap() } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index f09db970b7353..56baa1e2f8385 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -4,6 +4,7 @@ use rustc_data_structures::bit_set::{BitSet, BitSetOperator, HybridBitSet}; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::work_queue::WorkQueue; +use rustc::hir; use rustc::ty::{self, TyCtxt}; use rustc::mir::{self, Mir, BasicBlock, BasicBlockData, Location, Statement, Terminator}; use rustc::mir::traversal; @@ -38,7 +39,7 @@ pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD> where BD: BitDenotation<'tcx> { - node_id: ast::NodeId, + hir_id: hir::HirId, flow_state: DataflowAnalysis<'a, 'tcx, BD>, print_preflow_to: Option, print_postflow_to: Option, @@ -116,7 +117,7 @@ pub struct MoveDataParamEnv<'gcx, 'tcx> { pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>, mir: &'a Mir<'tcx>, - node_id: ast::NodeId, + hir_id: hir::HirId, attributes: &[ast::Attribute], dead_unwinds: &BitSet, bd: BD, @@ -126,14 +127,14 @@ pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>, P: Fn(&BD, BD::Idx) -> DebugFormatted { let flow_state = DataflowAnalysis::new(mir, dead_unwinds, bd); - flow_state.run(tcx, node_id, attributes, p) + flow_state.run(tcx, hir_id, attributes, p) } impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { pub(crate) fn run

(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - node_id: ast::NodeId, + hir_id: hir::HirId, attributes: &[ast::Attribute], p: P) -> DataflowResults<'tcx, BD> where P: Fn(&BD, BD::Idx) -> DebugFormatted @@ -158,7 +159,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitD name_found(tcx.sess, attributes, "borrowck_graphviz_postflow"); let mut mbcx = DataflowBuilder { - node_id, + hir_id, print_preflow_to, print_postflow_to, flow_state: self, }; diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index ea8b2826732b4..242e5f473e3bd 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -30,7 +30,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe, hir::BlockCheckMode::UnsafeBlock(..) => - BlockSafety::ExplicitUnsafe(self.id), + BlockSafety::ExplicitUnsafe(self.hir_id), hir::BlockCheckMode::PushUnsafeBlock(..) => BlockSafety::PushUnsafe, hir::BlockCheckMode::PopUnsafeBlock(..) => @@ -46,12 +46,12 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, -> Vec> { let mut result = vec![]; for (index, stmt) in stmts.iter().enumerate() { - let hir_id = cx.tcx.hir().node_to_hir_id(stmt.node.id()); + let hir_id = stmt.node.hir_id(); let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); - let stmt_span = StatementSpan(cx.tcx.hir().span(stmt.node.id())); + let stmt_span = StatementSpan(cx.tcx.hir().span(stmt.node.hir_id())); match stmt.node { - hir::StmtKind::Expr(ref expr, _) | - hir::StmtKind::Semi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, ..) | + hir::StmtKind::Semi(ref expr, ..) => { result.push(StmtRef::Mirror(Box::new(Stmt { kind: StmtKind::Expr { scope: region::Scope { @@ -64,7 +64,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, span: stmt_span, }))) } - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { match decl.node { hir::DeclKind::Item(..) => { // ignore for purposes of the MIR @@ -103,7 +103,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, }, pattern, initializer: local.init.to_ref(), - lint_level: cx.lint_level_of(local.id), + lint_level: cx.lint_level_of(local.hir_id), }, opt_destruction_scope: opt_dxn_ext, span: stmt_span, @@ -119,7 +119,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, pub fn to_expr_ref<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, block: &'tcx hir::Block) -> ExprRef<'tcx> { - let block_ty = cx.tables().node_id_to_type(block.hir_id); + let block_ty = cx.tables().hir_id_to_type(block.hir_id); let temp_lifetime = cx.region_scope_tree.temporary_scope(block.hir_id.local_id); let expr = Expr { ty: block_ty, diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index eb536fbcf69bb..f81ab986c70ae 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -24,7 +24,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { data: region::ScopeData::Node }; - debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span); + debug!("Expr::make_mirror(): id={:?}, span={:?}", self.hir_id, self.span); let mut expr = make_mirror_unadjusted(cx, self); @@ -44,7 +44,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { kind: ExprKind::Scope { region_scope: expr_scope, value: expr.to_ref(), - lint_level: cx.lint_level_of(self.id), + lint_level: cx.lint_level_of(self.hir_id), }, }; @@ -304,7 +304,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } } else { ExprKind::Call { - ty: cx.tables().node_id_to_type(fun.hir_id), + ty: cx.tables().hir_id_to_type(fun.hir_id), fun: fun.to_ref(), args: args.to_ref(), from_hir_call: true, @@ -529,7 +529,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty); } }; - let upvars = cx.tcx.with_freevars(expr.id, |freevars| { + let upvars = cx.tcx.with_freevars(expr.hir_id, |freevars| { freevars.iter() .zip(substs.upvar_tys(def_id, cx.tcx)) .map(|(fv, ty)| capture_freevar(cx, expr, fv, ty)) @@ -558,7 +558,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // Now comes the rote stuff: hir::ExprKind::Repeat(ref v, ref count) => { - let def_id = cx.tcx.hir().local_def_id(count.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(count.hir_id); let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id); let instance = ty::Instance::resolve( cx.tcx.global_tcx(), @@ -637,7 +637,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::ExprKind::Field(ref source, ..) => { ExprKind::Field { lhs: source.to_ref(), - name: Field::new(cx.tcx.field_index(expr.id, cx.tables)), + name: Field::new(cx.tcx.field_index(expr.hir_id, cx.tables)), } } hir::ExprKind::Cast(ref source, ref cast_ty) => { @@ -677,7 +677,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let def = cx.tables().qpath_def(qpath, source.hir_id); cx .tables() - .node_id_to_type(source.hir_id) + .hir_id_to_type(source.hir_id) .ty_adt_def() .and_then(|adt_def| { match def { @@ -919,7 +919,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, debug!("convert_path_expr: user_ty={:?}", user_ty); ExprKind::Literal { literal: cx.tcx.intern_lazy_const(ty::LazyConst::Evaluated(ty::Const::zero_sized( - cx.tables().node_id_to_type(expr.hir_id), + cx.tables().hir_id_to_type(expr.hir_id), ))), user_ty, } @@ -940,7 +940,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let user_provided_types = cx.tables.user_provided_types(); let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty); debug!("convert_path_expr: user_provided_type={:?}", user_provided_type); - match cx.tables().node_id_to_type(expr.hir_id).sty { + match cx.tables().hir_id_to_type(expr.hir_id).sty { // A unit struct/variant which is used as a value. // We return a completely different ExprKind here to account for this special case. ty::Adt(adt_def, substs) => { @@ -979,17 +979,15 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, var_id, index, closure_expr_id); - let var_hir_id = cx.tcx.hir().node_to_hir_id(var_id); - let var_ty = cx.tables().node_id_to_type(var_hir_id); + let var_ty = cx.tables().hir_id_to_type(var_id); // FIXME free regions in closures are not right - let closure_ty = cx.tables() - .node_id_to_type(cx.tcx.hir().node_to_hir_id(closure_expr_id)); + let closure_ty = cx.tables().hir_id_to_type(closure_expr_id); // FIXME we're just hard-coding the idea that the // signature will be &self or &mut self and hence will // have a bound region with number 0 - let closure_def_id = cx.tcx.hir().local_def_id(closure_expr_id); + let closure_def_id = cx.tcx.hir().local_def_id_from_hir_id(closure_expr_id); let region = ty::ReFree(ty::FreeRegion { scope: closure_def_id, bound_region: ty::BoundRegion::BrAnon(0), @@ -1066,7 +1064,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // ...but the upvar might be an `&T` or `&mut T` capture, at which // point we need an implicit deref let upvar_id = ty::UpvarId { - var_path: ty::UpvarPath {hir_id: var_hir_id}, + var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id: LocalDefId::from_def_id(closure_def_id), }; match cx.tables().upvar_capture(upvar_id) { @@ -1181,14 +1179,14 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, freevar: &hir::Freevar, freevar_ty: Ty<'tcx>) -> ExprRef<'tcx> { - let var_hir_id = cx.tcx.hir().node_to_hir_id(freevar.var_id()); + let var_hir_id = freevar.var_id(); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, - closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.id).to_local(), + closure_expr_id: cx.tcx.hir().local_def_id_from_hir_id(closure_expr.hir_id).to_local(), }; let upvar_capture = cx.tables().upvar_capture(upvar_id); let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); - let var_ty = cx.tables().node_id_to_type(var_hir_id); + let var_ty = cx.tables().hir_id_to_type(var_hir_id); let captured_var = Expr { temp_lifetime, ty: var_ty, @@ -1223,7 +1221,7 @@ fn field_refs<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, fields.iter() .map(|field| { FieldExprRef { - name: Field::new(cx.tcx.field_index(field.id, cx.tables)), + name: Field::new(cx.tcx.field_index(field.hir_id, cx.tables)), expr: field.expr.to_ref(), } }) diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 6113d88e09591..e2319ae69dbbf 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -28,7 +28,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - pub root_lint_level: ast::NodeId, + pub root_lint_level: hir::HirId, pub param_env: ty::ParamEnv<'gcx>, /// Identity `Substs` for use with const-evaluation. @@ -53,9 +53,9 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - src_id: ast::NodeId) -> Cx<'a, 'gcx, 'tcx> { + src_id: hir::HirId) -> Cx<'a, 'gcx, 'tcx> { let tcx = infcx.tcx; - let src_def_id = tcx.hir().local_def_id(src_id); + let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id); let body_owner_kind = tcx.hir().body_owner_kind(src_id); let constness = match body_owner_kind { @@ -154,7 +154,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) { + let p = match tcx.hir().get_by_hir_id(p.hir_id) { Node::Pat(p) | Node::Binding(p) => p, node => bug!("pattern became {:?}", node) }; @@ -198,14 +198,13 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { ty.needs_drop(self.tcx.global_tcx(), param_env) } - fn lint_level_of(&self, node_id: ast::NodeId) -> LintLevel { - let hir_id = self.tcx.hir().definitions().node_to_hir_id(node_id); + fn lint_level_of(&self, hir_id: hir::HirId) -> LintLevel { let has_lint_level = self.tcx.dep_graph.with_ignore(|| { self.tcx.lint_levels(LOCAL_CRATE).lint_level_set(hir_id).is_some() }); if has_lint_level { - LintLevel::Explicit(node_id) + LintLevel::Explicit(hir_id) } else { LintLevel::Inherited } @@ -238,7 +237,7 @@ impl UserAnnotatedTyHelpers<'gcx, 'tcx> for Cx<'_, 'gcx, 'tcx> { } } -fn lint_level_for_hir_id(tcx: TyCtxt, mut id: ast::NodeId) -> ast::NodeId { +fn lint_level_for_hir_id(tcx: TyCtxt, mut hir_id: hir::HirId) -> hir::HirId { // Right now we insert a `with_ignore` node in the dep graph here to // ignore the fact that `lint_levels` below depends on the entire crate. // For now this'll prevent false positives of recompiling too much when @@ -250,15 +249,14 @@ fn lint_level_for_hir_id(tcx: TyCtxt, mut id: ast::NodeId) -> ast::NodeId { tcx.dep_graph.with_ignore(|| { let sets = tcx.lint_levels(LOCAL_CRATE); loop { - let hir_id = tcx.hir().definitions().node_to_hir_id(id); if sets.lint_level_set(hir_id).is_some() { - return id + return hir_id } - let next = tcx.hir().get_parent_node(id); - if next == id { + let next = tcx.hir().get_parent_node(hir_id); + if next == hir_id { bug!("lint traversal reached the root of the crate"); } - id = next; + hir_id = next; } }) } diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index e902423cd30fc..51a65d57d35b4 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -12,7 +12,6 @@ use rustc::ty::subst::Substs; use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserTypeAnnotation}; use rustc::ty::layout::VariantIdx; use rustc::hir; -use syntax::ast; use syntax_pos::Span; use self::cx::Cx; @@ -28,7 +27,7 @@ mod util; #[derive(Copy, Clone, Debug)] pub enum LintLevel { Inherited, - Explicit(ast::NodeId) + Explicit(hir::HirId) } impl LintLevel { @@ -54,7 +53,7 @@ pub struct Block<'tcx> { #[derive(Copy, Clone, Debug)] pub enum BlockSafety { Safe, - ExplicitUnsafe(ast::NodeId), + ExplicitUnsafe(hir::HirId), PushUnsafe, PopUnsafe } @@ -227,7 +226,7 @@ pub enum ExprKind<'tcx> { index: ExprRef<'tcx>, }, VarRef { - id: ast::NodeId, + id: hir::HirId, }, /// first argument, used for self in a closure SelfRef, diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 10213beba2a6d..08ca1b0aa8c39 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -24,7 +24,6 @@ use rustc::hir::{self, Pat, PatKind}; use smallvec::smallvec; use std::slice; -use syntax::ast; use syntax::ptr::P; use syntax_pos::{Span, DUMMY_SP, MultiSpan}; @@ -51,7 +50,7 @@ pub(crate) fn check_match<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, ) -> Result<(), ErrorReported> { - let body_id = if let Some(id) = tcx.hir().as_local_node_id(def_id) { + let body_id = if let Some(id) = tcx.hir().as_local_hir_id(def_id) { tcx.hir().body_owned_by(id) } else { return Ok(()); @@ -183,7 +182,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } } - let module = self.tcx.hir().get_module_parent(scrut.id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut have_errors = false; @@ -214,8 +213,8 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { // Then, if the match has no arms, check whether the scrutinee // is uninhabited. - let pat_ty = self.tables.node_id_to_type(scrut.hir_id); - let module = self.tcx.hir().get_module_parent(scrut.id); + let pat_ty = self.tables.hir_id_to_type(scrut.hir_id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); if inlined_arms.is_empty() { let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns { self.tcx.is_ty_uninhabited_from(module, pat_ty) @@ -247,13 +246,13 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { .flat_map(|arm| &arm.0) .map(|pat| smallvec![pat.0]) .collect(); - let scrut_ty = self.tables.node_id_to_type(scrut.hir_id); + let scrut_ty = self.tables.hir_id_to_type(scrut.hir_id); check_exhaustive(cx, scrut_ty, scrut.span, &matrix); }) } fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) { - let module = self.tcx.hir().get_module_parent(pat.id); + let module = self.tcx.hir().get_module_parent(pat.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut patcx = PatternContext::new(self.tcx, self.param_env.and(self.identity_substs), @@ -360,7 +359,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, hir::MatchSource::IfLetDesugar { .. } => { cx.tcx.lint_node( lint::builtin::IRREFUTABLE_LET_PATTERNS, - hir_pat.id, + hir_pat.hir_id, pat.span, "irrefutable if-let pattern", ); @@ -373,14 +372,14 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, 0 => { cx.tcx.lint_node( lint::builtin::UNREACHABLE_PATTERNS, - hir_pat.id, pat.span, + hir_pat.hir_id, pat.span, "unreachable pattern"); }, // The arm with the wildcard pattern. 1 => { cx.tcx.lint_node( lint::builtin::IRREFUTABLE_LET_PATTERNS, - hir_pat.id, + hir_pat.hir_id, pat.span, "irrefutable while-let pattern", ); @@ -393,7 +392,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, hir::MatchSource::Normal => { let mut err = cx.tcx.struct_span_lint_node( lint::builtin::UNREACHABLE_PATTERNS, - hir_pat.id, + hir_pat.hir_id, pat.span, "unreachable pattern", ); @@ -519,7 +518,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor, if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) { match bm { ty::BindByValue(..) => { - let pat_ty = cx.tables.node_id_to_type(p.hir_id); + let pat_ty = cx.tables.hir_id_to_type(p.hir_id); if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) { check_move(p, sub.as_ref().map(|p| &**p), span_vec); } @@ -574,10 +573,10 @@ struct MutationChecker<'a, 'tcx: 'a> { impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { fn matched_pat(&mut self, _: &Pat, _: &cmt_, _: euv::MatchMode) {} - fn consume(&mut self, _: ast::NodeId, _: Span, _: &cmt_, _: ConsumeMode) {} + fn consume(&mut self, _: hir::HirId, _: Span, _: &cmt_, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: &cmt_, _: ConsumeMode) {} fn borrow(&mut self, - _: ast::NodeId, + _: hir::HirId, span: Span, _: &cmt_, _: ty::Region<'tcx>, @@ -599,8 +598,8 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { ty::ImmBorrow | ty::UniqueImmBorrow => {} } } - fn decl_without_init(&mut self, _: ast::NodeId, _: Span) {} - fn mutate(&mut self, _: ast::NodeId, span: Span, _: &cmt_, mode: MutateMode) { + fn decl_without_init(&mut self, _: hir::HirId, _: Span) {} + fn mutate(&mut self, _: hir::HirId, span: Span, _: &cmt_, mode: MutateMode) { match mode { MutateMode::JustWrite | MutateMode::WriteAndRead => { struct_span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard") diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 8991a90737c7e..e624ae2c48f4e 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -118,7 +118,7 @@ pub enum PatternKind<'tcx> { mutability: Mutability, name: ast::Name, mode: BindingMode, - var: ast::NodeId, + var: hir::HirId, ty: Ty<'tcx>, subpattern: Option>, }, @@ -392,7 +392,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat) -> Pattern<'tcx> { - let mut ty = self.tables.node_id_to_type(pat.hir_id); + let mut ty = self.tables.hir_id_to_type(pat.hir_id); let kind = match pat.node { PatKind::Wild => PatternKind::Wild, @@ -511,7 +511,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } PatKind::Binding(_, id, ident, ref sub) => { - let var_ty = self.tables.node_id_to_type(pat.hir_id); + let var_ty = self.tables.hir_id_to_type(pat.hir_id); if let ty::Error = var_ty.sty { // Avoid ICE return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; @@ -582,7 +582,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { fields.iter() .map(|field| { FieldPattern { - field: Field::new(self.tcx.field_index(field.node.id, + field: Field::new(self.tcx.field_index(field.node.hir_id, self.tables)), pattern: self.lower_pattern(&field.node.pat), } @@ -745,7 +745,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { id: hir::HirId, span: Span) -> Pattern<'tcx> { - let ty = self.tables.node_id_to_type(id); + let ty = self.tables.hir_id_to_type(id); let def = self.tables.qpath_def(qpath, id); let is_associated_const = match def { Def::AssociatedConst(_) => true, @@ -902,7 +902,6 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { debug!("const_to_pat: cv.ty={:?} span={:?}", cv.ty, span); let kind = match cv.ty.sty { ty::Float(_) => { - let id = self.tcx.hir().hir_to_node_id(id); self.tcx.lint_node( ::rustc::lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, id, @@ -1038,7 +1037,7 @@ macro_rules! CloneImpls { } CloneImpls!{ <'tcx> - Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>, + Span, Field, Mutability, ast::Name, hir::HirId, usize, ty::Const<'tcx>, Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef, &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx>, UserTypeProjection<'tcx>, PatternTypeProjection<'tcx> diff --git a/src/librustc_mir/hair/util.rs b/src/librustc_mir/hair/util.rs index f0f8263b64de5..aaf609fcffa3c 100644 --- a/src/librustc_mir/hair/util.rs +++ b/src/librustc_mir/hair/util.rs @@ -16,7 +16,7 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> { let user_provided_types = self.tables().user_provided_types(); let mut user_ty = *user_provided_types.get(hir_id)?; debug!("user_subts_applied_to_ty_of_hir_id: user_ty={:?}", user_ty); - match &self.tables().node_id_to_type(hir_id).sty { + match &self.tables().hir_id_to_type(hir_id).sty { ty::Adt(adt_def, ..) => { if let UserTypeAnnotation::TypeOf(ref mut did, _) = &mut user_ty.value { *did = adt_def.did; diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 8ded31d89daea..51abd55181713 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -129,10 +129,10 @@ fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>, // no break */ }`) shouldn't be linted unless it actually // recurs. if !reached_exit_without_self_call && !self_call_locations.is_empty() { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let sp = tcx.sess.source_map().def_span(tcx.hir().span(node_id)); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id)); let mut db = tcx.struct_span_lint_node(UNCONDITIONAL_RECURSION, - node_id, + hir_id, sp, "function cannot return without recursing"); db.span_label(sp, "cannot return without recursing"); diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index a6a8fe5ade56c..ed4baebd45605 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -321,8 +321,8 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut roots = Vec::new(); { - let entry_fn = tcx.sess.entry_fn.borrow().map(|(node_id, _, _)| { - tcx.hir().local_def_id(node_id) + let entry_fn = tcx.sess.entry_fn.borrow().map(|(hir_id, _, _)| { + tcx.hir().local_def_id_from_hir_id(hir_id) }); debug!("collect_roots: entry_fn = {:?}", entry_fn); @@ -452,8 +452,8 @@ fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if recursion_depth > *tcx.sess.recursion_limit.get() { let error = format!("reached the recursion limit while instantiating `{}`", instance); - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - tcx.sess.span_fatal(tcx.hir().span(node_id), &error); + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + tcx.sess.span_fatal(tcx.hir().span(hir_id), &error); } else { tcx.sess.fatal(&error); } @@ -484,8 +484,8 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let instance_name = instance.to_string(); let msg = format!("reached the type-length limit while instantiating `{:.64}...`", instance_name); - let mut diag = if let Some(node_id) = tcx.hir().as_local_node_id(instance.def_id()) { - tcx.sess.struct_span_fatal(tcx.hir().span(node_id), &msg) + let mut diag = if let Some(hir_id) = tcx.hir().as_local_hir_id(instance.def_id()) { + tcx.sess.struct_span_fatal(tcx.hir().span(hir_id), &msg) } else { tcx.sess.struct_fatal(&msg) }; @@ -954,7 +954,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { hir::ItemKind::Union(_, ref generics) => { if generics.params.is_empty() { if self.mode == MonoItemCollectionMode::Eager { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); debug!("RootCollector: ADT drop-glue for {}", def_id_to_string(self.tcx, def_id)); @@ -966,11 +966,11 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { hir::ItemKind::GlobalAsm(..) => { debug!("RootCollector: ItemKind::GlobalAsm({})", def_id_to_string(self.tcx, - self.tcx.hir().local_def_id(item.id))); - self.output.push(MonoItem::GlobalAsm(item.id)); + self.tcx.hir().local_def_id_from_hir_id(item.hir_id))); + self.output.push(MonoItem::GlobalAsm(item.hir_id)); } hir::ItemKind::Static(..) => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); debug!("RootCollector: ItemKind::Static({})", def_id_to_string(self.tcx, def_id)); self.output.push(MonoItem::Static(def_id)); @@ -980,7 +980,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { // actually used somewhere. Just declaring them is insufficient. // but even just declaring them must collect the items they refer to - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let instance = Instance::mono(self.tcx, def_id); let cid = GlobalId { @@ -994,7 +994,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { } } hir::ItemKind::Fn(..) => { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); self.push_if_root(def_id); } } @@ -1008,7 +1008,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { match ii.node { hir::ImplItemKind::Method(hir::MethodSig { .. }, _) => { - let def_id = self.tcx.hir().local_def_id(ii.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(ii.hir_id); self.push_if_root(def_id); } _ => { /* Nothing to do here */ } @@ -1101,7 +1101,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - let impl_def_id = tcx.hir().local_def_id(item.id); + let impl_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); debug!("create_mono_items_for_default_impls(item={})", def_id_to_string(tcx, impl_def_id)); diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 7014f539d5754..14ec22aa52af6 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -57,8 +57,8 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug { MonoItem::Static(def_id) => { tcx.symbol_name(Instance::mono(tcx, def_id)) } - MonoItem::GlobalAsm(node_id) => { - let def_id = tcx.hir().local_def_id(node_id); + MonoItem::GlobalAsm(hir_id) => { + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); ty::SymbolName { name: Symbol::intern(&format!("global_asm_{:?}", def_id)).as_interned_str() } @@ -76,7 +76,8 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug { match *self.as_mono_item() { MonoItem::Fn(ref instance) => { let entry_def_id = - tcx.sess.entry_fn.borrow().map(|(id, _, _)| tcx.hir().local_def_id(id)); + tcx.sess.entry_fn.borrow().map(|(id, _, _)| + tcx.hir().local_def_id_from_hir_id(id)); // If this function isn't inlined or otherwise has explicit // linkage, then we'll be creating a globally shared version. if self.explicit_linkage(tcx).is_some() || @@ -189,15 +190,15 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug { fn local_span(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option { match *self.as_mono_item() { MonoItem::Fn(Instance { def, .. }) => { - tcx.hir().as_local_node_id(def.def_id()) + tcx.hir().as_local_hir_id(def.def_id()) } MonoItem::Static(def_id) => { - tcx.hir().as_local_node_id(def_id) + tcx.hir().as_local_hir_id(def_id) } - MonoItem::GlobalAsm(node_id) => { - Some(node_id) + MonoItem::GlobalAsm(hir_id) => { + Some(hir_id) } - }.map(|node_id| tcx.hir().span(node_id)) + }.map(|hir_id| tcx.hir().span(hir_id)) } } diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index c3613fbf04c1b..8c0cf60daf2af 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -96,10 +96,9 @@ use std::collections::hash_map::Entry; use std::cmp; use std::sync::Arc; -use syntax::ast::NodeId; use syntax::symbol::InternedString; use rustc::dep_graph::{WorkProductId, WorkProduct, DepNode, DepConstructor}; -use rustc::hir::CodegenFnAttrFlags; +use rustc::hir::{self, CodegenFnAttrFlags}; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX}; use rustc::hir::map::DefPathData; use rustc::mir::mono::{Linkage, Visibility, CodegenUnitNameBuilder}; @@ -162,7 +161,7 @@ pub trait CodegenUnitExt<'tcx> { // The codegen tests rely on items being process in the same order as // they appear in the file, so for local items, we sort by node_id first #[derive(PartialEq, Eq, PartialOrd, Ord)] - pub struct ItemSortKey(Option, ty::SymbolName); + pub struct ItemSortKey(Option, ty::SymbolName); fn item_sort_key<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: MonoItem<'tcx>) -> ItemSortKey { @@ -174,7 +173,7 @@ pub trait CodegenUnitExt<'tcx> { // the codegen tests and can even make item order // unstable. InstanceDef::Item(def_id) => { - tcx.hir().as_local_node_id(def_id) + tcx.hir().as_local_hir_id(def_id) } InstanceDef::VtableShim(..) | InstanceDef::Intrinsic(..) | @@ -188,10 +187,10 @@ pub trait CodegenUnitExt<'tcx> { } } MonoItem::Static(def_id) => { - tcx.hir().as_local_node_id(def_id) + tcx.hir().as_local_hir_id(def_id) } - MonoItem::GlobalAsm(node_id) => { - Some(node_id) + MonoItem::GlobalAsm(hir_id) => { + Some(hir_id) } }, item.symbol_name(tcx)) } @@ -404,8 +403,8 @@ fn mono_item_visibility( Visibility::Hidden }; } - MonoItem::GlobalAsm(node_id) => { - let def_id = tcx.hir().local_def_id(*node_id); + MonoItem::GlobalAsm(hir_id) => { + let def_id = tcx.hir().local_def_id_from_hir_id(*hir_id); return if tcx.is_reachable_non_generic(def_id) { *can_be_internalized = false; default_visibility(tcx, def_id, false) @@ -789,7 +788,7 @@ fn characteristic_def_id_of_mono_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Some(def_id) } MonoItem::Static(def_id) => Some(def_id), - MonoItem::GlobalAsm(node_id) => Some(tcx.hir().local_def_id(node_id)), + MonoItem::GlobalAsm(hir_id) => Some(tcx.hir().local_def_id_from_hir_id(hir_id)), } } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 751815eab287b..87c0089f6ad60 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -10,7 +10,6 @@ use rustc::ty::query::Providers; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use rustc_target::spec::abi::Abi; -use syntax::ast; use syntax_pos::Span; use std::fmt; @@ -846,14 +845,14 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, - ctor_id: ast::NodeId, + ctor_id: hir::HirId, fields: &[hir::StructField], span: Span) -> Mir<'tcx> { let tcx = infcx.tcx; let gcx = tcx.global_tcx(); - let def_id = tcx.hir().local_def_id(ctor_id); + let def_id = tcx.hir().local_def_id_from_hir_id(ctor_id); let param_env = gcx.param_env(def_id); // Normalize the sig. diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index eb151b56bed65..d3443f981ff28 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -11,7 +11,6 @@ use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSA use rustc::mir::*; use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext}; -use syntax::ast; use syntax::symbol::Symbol; use std::ops::Bound; @@ -27,8 +26,8 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, /// mark an `unsafe` block as used, so we don't lint it - used_unsafe: FxHashSet, - inherited_blocks: Vec<(ast::NodeId, bool)>, + used_unsafe: FxHashSet, + inherited_blocks: Vec<(hir::HirId, bool)>, } impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { @@ -300,7 +299,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], - unsafe_blocks: &[(ast::NodeId, bool)]) { + unsafe_blocks: &[(hir::HirId, bool)]) { let safety = self.source_scope_local_data[self.source_info.scope].safety; let within_unsafe = match safety { // `unsafe` blocks are required in safe code @@ -326,10 +325,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { } // `unsafe` function bodies allow unsafe without additional unsafe blocks Safety::BuiltinUnsafe | Safety::FnUnsafe => true, - Safety::ExplicitUnsafe(node_id) => { + Safety::ExplicitUnsafe(hir_id) => { // mark unsafe block as used if there are any unsafe operations inside if !violations.is_empty() { - self.used_unsafe.insert(node_id); + self.used_unsafe.insert(hir_id); } // only some unsafety is allowed in const fn if self.min_const_fn { @@ -356,8 +355,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { true } }; - self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(node_id, is_used)| { - (node_id, is_used && !within_unsafe) + self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(hir_id, is_used)| { + (hir_id, is_used && !within_unsafe) })); } fn check_mut_borrowing_layout_constrained_field( @@ -418,8 +417,8 @@ pub(crate) fn provide(providers: &mut Providers) { } struct UnusedUnsafeVisitor<'a> { - used_unsafe: &'a FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>, + used_unsafe: &'a FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>, } impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { @@ -433,19 +432,19 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { hir::intravisit::walk_block(self, block); if let hir::UnsafeBlock(hir::UserProvided) = block.rules { - self.unsafe_blocks.push((block.id, self.used_unsafe.contains(&block.id))); + self.unsafe_blocks.push((block.hir_id, self.used_unsafe.contains(&block.hir_id))); } } } fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - used_unsafe: &FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>) + used_unsafe: &FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>) { let body_id = - tcx.hir().as_local_node_id(def_id).and_then(|node_id| { - tcx.hir().maybe_body_owned_by(node_id) + tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { + tcx.hir().maybe_body_owned_by(hir_id) }); let body_id = match body_id { @@ -497,8 +496,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) } fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { - let lint_node_id = match tcx.hir().as_local_node_id(def_id) { - Some(node_id) => node_id, + let lint_hir_id = match tcx.hir().as_local_hir_id(def_id) { + Some(hir_id) => hir_id, None => bug!("checking unsafety for non-local def id {:?}", def_id) }; @@ -512,15 +511,15 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D does not derive Copy (error E0133)".to_string() }; tcx.lint_node(SAFE_PACKED_BORROWS, - lint_node_id, + lint_hir_id, tcx.def_span(def_id), &message); } /// Return the NodeId for an enclosing scope that is also `unsafe` fn is_enclosed(tcx: TyCtxt, - used_unsafe: &FxHashSet, - id: ast::NodeId) -> Option<(String, ast::NodeId)> { + used_unsafe: &FxHashSet, + id: hir::HirId) -> Option<(String, hir::HirId)> { let parent_id = tcx.hir().get_parent_node(id); if parent_id != id { if used_unsafe.contains(&parent_id) { @@ -528,7 +527,7 @@ fn is_enclosed(tcx: TyCtxt, } else if let Some(Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, header, _, _), .. - })) = tcx.hir().find(parent_id) { + })) = tcx.hir().find_by_hir_id(parent_id) { match header.unsafety { hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)), hir::Unsafety::Normal => None, @@ -541,7 +540,7 @@ fn is_enclosed(tcx: TyCtxt, } } -fn report_unused_unsafe(tcx: TyCtxt, used_unsafe: &FxHashSet, id: ast::NodeId) { +fn report_unused_unsafe(tcx: TyCtxt, used_unsafe: &FxHashSet, id: hir::HirId) { let span = tcx.sess.source_map().def_span(tcx.hir().span(id)); let msg = "unnecessary `unsafe` block"; let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg); @@ -596,20 +595,20 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { .note(&details.as_str()[..]) .emit(); } - UnsafetyViolationKind::ExternStatic(lint_node_id) => { + UnsafetyViolationKind::ExternStatic(lint_hir_id) => { tcx.lint_node_note(SAFE_EXTERN_STATICS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), &details.as_str()[..]); } - UnsafetyViolationKind::BorrowPacked(lint_node_id) => { + UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { tcx.unsafe_derive_on_repr_packed(impl_def_id); } else { tcx.lint_node_note(SAFE_PACKED_BORROWS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 03d6d3868c9f0..ab54697dcfd1e 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -607,10 +607,10 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> { .unwrap() .source_info .span; - let node_id = self + let hir_id = self .tcx .hir() - .as_local_node_id(self.source.def_id) + .as_local_hir_id(self.source.def_id) .expect("some part of a failing const eval must be local"); use rustc::mir::interpret::EvalErrorKind::*; let msg = match msg { @@ -649,7 +649,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> { }; self.tcx.lint_node( ::rustc::lint::builtin::CONST_ERR, - node_id, + hir_id, span, &msg, ); diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 06e16de8b43bc..4e2f36e5129b3 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -5,13 +5,13 @@ use dataflow::{on_all_children_bits, on_all_drop_children_bits}; use dataflow::{drop_flag_effects_for_location, on_lookup_result_bits}; use dataflow::MoveDataParamEnv; use dataflow::{self, do_dataflow, DebugFormatted}; +use rustc::hir; use rustc::ty::{self, TyCtxt}; use rustc::ty::layout::VariantIdx; use rustc::mir::*; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::bit_set::BitSet; use std::fmt; -use syntax::ast; use syntax_pos::Span; use transform::{MirPass, MirSource}; use util::patch::MirPatch; @@ -28,7 +28,7 @@ impl MirPass for ElaborateDrops { { debug!("elaborate_drops({:?} @ {:?})", src, mir.span); - let id = tcx.hir().as_local_node_id(src.def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(src.def_id).unwrap(); let param_env = tcx.param_env(src.def_id).with_reveal_all(); let move_data = match MoveData::gather_moves(mir, tcx) { Ok(move_data) => move_data, @@ -80,7 +80,7 @@ impl MirPass for ElaborateDrops { fn find_dead_unwinds<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, - id: ast::NodeId, + id: hir::HirId, env: &MoveDataParamEnv<'tcx, 'tcx>) -> BitSet { diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index ec0c118634d0f..f67e1486c1ddf 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -339,13 +339,13 @@ fn locals_live_across_suspend_points( FxHashMap>, ) { let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len()); - let node_id = tcx.hir().as_local_node_id(source.def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(source.def_id).unwrap(); // Calculate when MIR locals have live storage. This gives us an upper bound of their // lifetimes. let storage_live_analysis = MaybeStorageLive::new(mir); let storage_live = - do_dataflow(tcx, mir, node_id, &[], &dead_unwinds, storage_live_analysis, + do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, storage_live_analysis, |bd, p| DebugFormatted::new(&bd.mir().local_decls[p])); // Find the MIR locals which do not use StorageLive/StorageDead statements. @@ -359,7 +359,7 @@ fn locals_live_across_suspend_points( let borrowed_locals = if !movable { let analysis = HaveBeenBorrowedLocals::new(mir); let result = - do_dataflow(tcx, mir, node_id, &[], &dead_unwinds, analysis, + do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, analysis, |bd, p| DebugFormatted::new(&bd.mir().local_decls[p])); Some((analysis, result)) } else { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 8b970c1408e37..402686ffc5878 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { let param_env = self.tcx.param_env(self.source.def_id); // Only do inlining into fn bodies. - let id = self.tcx.hir().as_local_node_id(self.source.def_id).unwrap(); + let id = self.tcx.hir().as_local_hir_id(self.source.def_id).unwrap(); let body_owner_kind = self.tcx.hir().body_owner_kind(id); if let (hir::BodyOwnerKind::Fn, None) = (body_owner_kind, self.source.promoted) { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 5a80a5fdab501..71899003fe38a 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -78,10 +78,10 @@ fn mir_keys<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, krate: CrateNum) v: &'tcx hir::VariantData, _: ast::Name, _: &'tcx hir::Generics, - _: ast::NodeId, + _: hir::HirId, _: Span) { - if let hir::VariantData::Tuple(_, node_id) = *v { - self.set.insert(self.tcx.hir().local_def_id(node_id)); + if let hir::VariantData::Tuple(_, hir_id) = *v { + self.set.insert(self.tcx.hir().local_def_id_from_hir_id(hir_id)); } intravisit::walk_struct_def(self, v) } @@ -209,8 +209,8 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea } fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(node_id) { + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(hir_id) { // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. let _ = tcx.mir_const_qualif(def_id); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 78cf7153500c9..ad749e179d466 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1149,7 +1149,7 @@ impl MirPass for QualifyAndPromoteConstants { } let def_id = src.def_id; - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let mut const_promoted_temps = None; let mode = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Fn => { diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 36a6279e50320..80d04c09967b9 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -2,6 +2,7 @@ use rustc_target::spec::abi::{Abi}; use syntax::ast; use syntax_pos::Span; +use rustc::hir; use rustc::ty::{self, TyCtxt}; use rustc::mir::{self, Mir, Location}; use rustc_data_structures::bit_set::BitSet; @@ -24,7 +25,7 @@ impl MirPass for SanityCheck { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &mut Mir<'tcx>) { let def_id = src.def_id; - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); if !tcx.has_attr(def_id, "rustc_mir") { debug!("skipping rustc_peek::SanityCheck on {}", tcx.item_path_str(def_id)); return; @@ -83,7 +84,7 @@ impl MirPass for SanityCheck { /// errors are not intended to be used for unit tests.) pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, - id: ast::NodeId, + id: hir::HirId, _attributes: &[ast::Attribute], results: &DataflowResults<'tcx, O>) where O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx> diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index fca208b340d2a..7b2ff166ed255 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -569,7 +569,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>( } fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut dyn Write) -> io::Result<()> { - let id = tcx.hir().as_local_node_id(src.def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(src.def_id).unwrap(); let body_owner_kind = tcx.hir().body_owner_kind(id); match (body_owner_kind, src.promoted) { (_, Some(i)) => write!(w, "{:?} in", i)?, diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 604b31e7167a9..c671b241af606 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -2,7 +2,7 @@ // pieces of AST and HIR. The resulting numbers are good approximations but not // completely accurate (some things might be counted twice, others missed). -use rustc::hir; +use rustc::hir::{self, HirId}; use rustc::hir::intravisit as hir_visit; use rustc::util::common::to_readable_str; use rustc::util::nodemap::{FxHashMap, FxHashSet}; @@ -12,7 +12,7 @@ use syntax_pos::Span; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum Id { - Node(NodeId), + Hir(HirId), Attr(AttrId), None, } @@ -119,32 +119,32 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_item(&mut self, i: &'v hir::Item) { - self.record("Item", Id::Node(i.id), i); + self.record("Item", Id::Hir(i.hir_id), i); hir_visit::walk_item(self, i) } - fn visit_mod(&mut self, m: &'v hir::Mod, _s: Span, n: NodeId) { + fn visit_mod(&mut self, m: &'v hir::Mod, _s: Span, h: hir::HirId) { self.record("Mod", Id::None, m); - hir_visit::walk_mod(self, m, n) + hir_visit::walk_mod(self, m, h) } fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem) { - self.record("ForeignItem", Id::Node(i.id), i); + self.record("ForeignItem", Id::Hir(i.hir_id), i); hir_visit::walk_foreign_item(self, i) } fn visit_local(&mut self, l: &'v hir::Local) { - self.record("Local", Id::Node(l.id), l); + self.record("Local", Id::Hir(l.hir_id), l); hir_visit::walk_local(self, l) } fn visit_block(&mut self, b: &'v hir::Block) { - self.record("Block", Id::Node(b.id), b); + self.record("Block", Id::Hir(b.hir_id), b); hir_visit::walk_block(self, b) } fn visit_stmt(&mut self, s: &'v hir::Stmt) { - self.record("Stmt", Id::Node(s.node.id()), s); + self.record("Stmt", Id::Hir(s.node.hir_id()), s); hir_visit::walk_stmt(self, s) } @@ -154,7 +154,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_pat(&mut self, p: &'v hir::Pat) { - self.record("Pat", Id::Node(p.id), p); + self.record("Pat", Id::Hir(p.hir_id), p); hir_visit::walk_pat(self, p) } @@ -164,12 +164,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_expr(&mut self, ex: &'v hir::Expr) { - self.record("Expr", Id::Node(ex.id), ex); + self.record("Expr", Id::Hir(ex.hir_id), ex); hir_visit::walk_expr(self, ex) } fn visit_ty(&mut self, t: &'v hir::Ty) { - self.record("Ty", Id::Node(t.id), t); + self.record("Ty", Id::Hir(t.hir_id), t); hir_visit::walk_ty(self, t) } @@ -178,7 +178,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { fd: &'v hir::FnDecl, b: hir::BodyId, s: Span, - id: NodeId) { + id: HirId) { self.record("FnDecl", Id::None, fd); hir_visit::walk_fn(self, fk, fd, b, s, id) } @@ -189,12 +189,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem) { - self.record("TraitItem", Id::Node(ti.id), ti); + self.record("TraitItem", Id::Hir(ti.hir_id), ti); hir_visit::walk_trait_item(self, ti) } fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { - self.record("ImplItem", Id::Node(ii.id), ii); + self.record("ImplItem", Id::Hir(ii.hir_id), ii); hir_visit::walk_impl_item(self, ii) } @@ -204,20 +204,20 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_struct_field(&mut self, s: &'v hir::StructField) { - self.record("StructField", Id::Node(s.id), s); + self.record("StructField", Id::Hir(s.hir_id), s); hir_visit::walk_struct_field(self, s) } fn visit_variant(&mut self, v: &'v hir::Variant, g: &'v hir::Generics, - item_id: NodeId) { + item_id: HirId) { self.record("Variant", Id::None, v); hir_visit::walk_variant(self, v, g, item_id) } fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { - self.record("Lifetime", Id::Node(lifetime.id), lifetime); + self.record("Lifetime", Id::Hir(lifetime.hir_id), lifetime); hir_visit::walk_lifetime(self, lifetime) } @@ -239,7 +239,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding) { - self.record("TypeBinding", Id::Node(type_binding.id), type_binding); + self.record("TypeBinding", Id::Hir(type_binding.hir_id), type_binding); hir_visit::walk_assoc_type_binding(self, type_binding) } @@ -248,7 +248,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) { - self.record("MacroDef", Id::Node(macro_def.id), macro_def); + self.record("MacroDef", Id::Hir(macro_def.hir_id), macro_def); hir_visit::walk_macro_def(self, macro_def) } } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 7d9165a82bc8f..2cf4254e3c723 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -123,7 +123,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { let loop_kind = if loop_id == ast::DUMMY_NODE_ID { None } else { - Some(match self.hir_map.expect_expr(loop_id).node { + let hir_id = self.hir_map.node_to_hir_id(loop_id); + Some(match self.hir_map.expect_expr(hir_id).node { hir::ExprKind::While(..) => LoopKind::WhileLoop, hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source), ref r => span_bug!(e.span, diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index f0b559f80a28c..bd744f1e07063 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -23,10 +23,9 @@ use rustc::middle::mem_categorization::Categorization; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::query::Providers; use rustc::ty::subst::Substs; -use rustc::util::nodemap::{ItemLocalSet, NodeSet}; +use rustc::util::nodemap::{ItemLocalSet, HirIdSet}; use rustc::hir; use rustc_data_structures::sync::Lrc; -use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; use self::Promotability::*; use std::ops::{BitAnd, BitAndAssign, BitOr}; @@ -53,11 +52,11 @@ fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, { assert!(def_id.is_local()); - let node_id = tcx.hir().as_local_node_id(def_id) + let hir_id = tcx.hir().as_local_hir_id(def_id) .expect("rvalue_promotable_map invoked with non-local def-id"); - let body_id = tcx.hir().body_owned_by(node_id); - let body_hir_id = tcx.hir().node_to_hir_id(body_id.node_id); - tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id) + let body_id = tcx.hir().body_owned_by(hir_id); + + tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id) } fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -81,9 +80,9 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; // `def_id` should be a `Body` owner - let node_id = tcx.hir().as_local_node_id(def_id) + let hir_id = tcx.hir().as_local_hir_id(def_id) .expect("rvalue_promotable_map invoked with non-local def-id"); - let body_id = tcx.hir().body_owned_by(node_id); + let body_id = tcx.hir().body_owned_by(hir_id); let _ = visitor.check_nested_body(body_id); Lrc::new(visitor.result) @@ -93,7 +92,7 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, in_fn: bool, in_static: bool, - mut_rvalue_borrows: NodeSet, + mut_rvalue_borrows: HirIdSet, param_env: ty::ParamEnv<'tcx>, identity_substs: &'tcx Substs<'tcx>, tables: &'a ty::TypeckTables<'tcx>, @@ -170,7 +169,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { fn remove_mut_rvalue_borrow(&mut self, pat: &hir::Pat) -> bool { let mut any_removed = false; pat.walk(|p| { - any_removed |= self.mut_rvalue_borrows.remove(&p.id); + any_removed |= self.mut_rvalue_borrows.remove(&p.hir_id); true }); any_removed @@ -180,7 +179,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability { let item_id = self.tcx.hir().body_owner(body_id); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); let outer_in_fn = self.in_fn; let outer_tables = self.tables; @@ -220,12 +219,12 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability { match stmt.node { - hir::StmtKind::Decl(ref decl, _node_id) => { + hir::StmtKind::Decl(ref decl, ..) => { match &decl.node { hir::DeclKind::Local(local) => { if self.remove_mut_rvalue_borrow(&local.pat) { if let Some(init) = &local.init { - self.mut_rvalue_borrows.insert(init.id); + self.mut_rvalue_borrows.insert(init.hir_id); } } @@ -238,8 +237,8 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { hir::DeclKind::Item(_) => Promotable } } - hir::StmtKind::Expr(ref box_expr, _node_id) | - hir::StmtKind::Semi(ref box_expr, _node_id) => { + hir::StmtKind::Expr(ref box_expr, ..) | + hir::StmtKind::Semi(ref box_expr, ..) => { let _ = self.check_expr(box_expr); NotPromotable } @@ -247,12 +246,12 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { } fn check_expr(&mut self, ex: &'tcx hir::Expr) -> Promotability { - let node_ty = self.tables.node_id_to_type(ex.hir_id); + let node_ty = self.tables.hir_id_to_type(ex.hir_id); let mut outer = check_expr_kind(self, ex, node_ty); outer &= check_adjustments(self, ex); // Handle borrows on (or inside the autorefs of) this expression. - if self.mut_rvalue_borrows.remove(&ex.id) { + if self.mut_rvalue_borrows.remove(&ex.hir_id) { outer = NotPromotable } @@ -309,7 +308,7 @@ fn check_expr_kind<'a, 'tcx>( if v.tables.is_method_call(e) { return NotPromotable; } - match v.tables.node_id_to_type(lhs.hir_id).sty { + match v.tables.hir_id_to_type(lhs.hir_id).sty { ty::RawPtr(_) | ty::FnPtr(..) => { assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne || op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt || @@ -322,7 +321,7 @@ fn check_expr_kind<'a, 'tcx>( } hir::ExprKind::Cast(ref from, _) => { let expr_promotability = v.check_expr(from); - debug!("Checking const cast(id={})", from.id); + debug!("Checking const cast(id={:?})", from.hir_id); match v.tables.cast_kinds().get(from.hir_id) { None => { v.tcx.sess.delay_span_bug(e.span, "no kind for cast"); @@ -462,7 +461,7 @@ fn check_expr_kind<'a, 'tcx>( let nested_body_promotable = v.check_nested_body(body_id); // Paths in constant contexts cannot refer to local variables, // as there are none, and thus closures can't have upvars there. - if v.tcx.with_freevars(e.id, |fv| !fv.is_empty()) { + if v.tcx.with_freevars(e.hir_id, |fv| !fv.is_empty()) { NotPromotable } else { nested_body_promotable @@ -522,7 +521,7 @@ fn check_expr_kind<'a, 'tcx>( mut_borrow = v.remove_mut_rvalue_borrow(pat); } if mut_borrow { - v.mut_rvalue_borrows.insert(expr.id); + v.mut_rvalue_borrows.insert(expr.hir_id); } let _ = v.check_expr(expr); @@ -623,13 +622,13 @@ fn check_adjustments<'a, 'tcx>( impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> { fn consume(&mut self, - _consume_id: ast::NodeId, + _consume_id: hir::HirId, _consume_span: Span, _cmt: &mc::cmt_, _mode: euv::ConsumeMode) {} fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, _borrow_span: Span, cmt: &mc::cmt_<'tcx>, _loan_region: ty::Region<'tcx>, @@ -680,9 +679,9 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> { } } - fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {} + fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) {} fn mutate(&mut self, - _assignment_id: ast::NodeId, + _assignment_id: hir::HirId, _assignment_span: Span, _assignee_cmt: &mc::cmt_, _mode: euv::MutateMode) { diff --git a/src/librustc_plugin/build.rs b/src/librustc_plugin/build.rs index 46c452668c3c8..bb44b9c6f93a6 100644 --- a/src/librustc_plugin/build.rs +++ b/src/librustc_plugin/build.rs @@ -1,6 +1,5 @@ //! Used by `rustc` when compiling a plugin crate. -use syntax::ast; use syntax::attr; use syntax_pos::Span; use rustc::hir::itemlikevisit::ItemLikeVisitor; @@ -10,7 +9,7 @@ use rustc::ty::TyCtxt; use rustc::ty::query::Providers; struct RegistrarFinder { - registrars: Vec<(ast::NodeId, Span)> , + registrars: Vec<(hir::HirId, Span)> , } impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { @@ -18,7 +17,7 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { if let hir::ItemKind::Fn(..) = item.node { if attr::contains_name(&item.attrs, "plugin_registrar") { - self.registrars.push((item.id, item.span)); + self.registrars.push((item.hir_id, item.span)); } } } @@ -47,8 +46,8 @@ fn plugin_registrar_fn<'tcx>( match finder.registrars.len() { 0 => None, 1 => { - let (node_id, _) = finder.registrars.pop().unwrap(); - Some(tcx.hir().local_def_id(node_id)) + let (hir_id, _) = finder.registrars.pop().unwrap(); + Some(tcx.hir().local_def_id_from_hir_id(hir_id)) }, _ => { let diagnostic = tcx.sess.diagnostic(); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 4890369e13f20..6a90ebb7bdcf1 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -24,10 +24,10 @@ use rustc::ty::{self, TyCtxt, Ty, TraitRef, TypeFoldable, GenericParamDefKind}; use rustc::ty::fold::TypeVisitor; use rustc::ty::query::Providers; use rustc::ty::subst::Substs; -use rustc::util::nodemap::NodeSet; +use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; -use syntax::ast::{self, CRATE_NODE_ID, Ident}; +use syntax::ast::Ident; use syntax::attr; use syntax::symbol::keywords; use syntax_pos::Span; @@ -223,16 +223,16 @@ impl<'a, 'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'a, 'tcx, V> fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> (ty::Visibility, Span, &'static str) { - match tcx.hir().as_local_node_id(def_id) { - Some(node_id) => { - let vis = match tcx.hir().get(node_id) { + match tcx.hir().as_local_hir_id(def_id) { + Some(hir_id) => { + let vis = match tcx.hir().get_by_hir_id(hir_id) { Node::Item(item) => &item.vis, Node::ForeignItem(foreign_item) => &foreign_item.vis, Node::TraitItem(..) | Node::Variant(..) => { - return def_id_visibility(tcx, tcx.hir().get_parent_did(node_id)); + return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id)); } Node::ImplItem(impl_item) => { - match tcx.hir().get(tcx.hir().get_parent(node_id)) { + match tcx.hir().get_by_hir_id(tcx.hir().get_parent(hir_id)) { Node::Item(item) => match &item.node { hir::ItemKind::Impl(.., None, _, _) => &impl_item.vis, hir::ItemKind::Impl(.., Some(trait_ref), _, _) @@ -243,16 +243,17 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) } } Node::StructCtor(vdata) => { - let struct_node_id = tcx.hir().get_parent(node_id); - let item = match tcx.hir().get(struct_node_id) { + let struct_hir_id = tcx.hir().get_parent(hir_id); + let item = match tcx.hir().get_by_hir_id(struct_hir_id) { Node::Item(item) => item, node => bug!("unexpected node kind: {:?}", node), }; + let (mut ctor_vis, mut span, mut descr) = - (ty::Visibility::from_hir(&item.vis, struct_node_id, tcx), + (ty::Visibility::from_hir(&item.vis, struct_hir_id, tcx), item.vis.span, item.vis.node.descr()); for field in vdata.fields() { - let field_vis = ty::Visibility::from_hir(&field.vis, node_id, tcx); + let field_vis = ty::Visibility::from_hir(&field.vis, hir_id, tcx); if ctor_vis.is_at_least(field_vis, tcx) { ctor_vis = field_vis; span = field.vis.span; @@ -263,7 +264,7 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // If the structure is marked as non_exhaustive then lower the // visibility to within the crate. if ctor_vis == ty::Visibility::Public { - let adt_def = tcx.adt_def(tcx.hir().get_parent_did(node_id)); + let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id)); if adt_def.non_enum_variant().is_field_list_non_exhaustive() { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); span = attr::find_by_name(&item.attrs, "non_exhaustive").unwrap().span; @@ -274,12 +275,12 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) return (ctor_vis, span, descr); } Node::Expr(expr) => { - return (ty::Visibility::Restricted(tcx.hir().get_module_parent(expr.id)), - expr.span, "private") + return (ty::Visibility::Restricted( + tcx.hir().get_module_parent(expr.hir_id)), expr.span, "private") } node => bug!("unexpected node kind: {:?}", node) }; - (ty::Visibility::from_hir(vis, node_id, tcx), vis.span, vis.node.descr()) + (ty::Visibility::from_hir(vis, hir_id, tcx), vis.span, vis.node.descr()) } None => { let vis = tcx.visibility(def_id); @@ -292,10 +293,10 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // Set the correct `TypeckTables` for the given `item_id` (or an empty table if // there is no `TypeckTables` for the item). fn item_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - node_id: ast::NodeId, + hir_id: hir::HirId, empty_tables: &'a ty::TypeckTables<'tcx>) -> &'a ty::TypeckTables<'tcx> { - let def_id = tcx.hir().local_def_id(node_id); + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); if tcx.has_typeck_tables(def_id) { tcx.typeck_tables_of(def_id) } else { empty_tables } } @@ -351,10 +352,10 @@ trait VisibilityLike: Sized { // Returns an over-approximation (`skip_assoc_tys` = true) of visibility due to // associated types for which we can't determine visibility precisely. - fn of_impl<'a, 'tcx>(node_id: ast::NodeId, tcx: TyCtxt<'a, 'tcx, 'tcx>, + fn of_impl<'a, 'tcx>(hir_id: hir::HirId, tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &'a AccessLevels) -> Self { let mut find = FindMin { tcx, access_levels, min: Self::MAX }; - let def_id = tcx.hir().local_def_id(node_id); + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); find.visit(tcx.type_of(def_id)); if let Some(trait_ref) = tcx.impl_trait_ref(def_id) { find.visit_trait(trait_ref); @@ -411,16 +412,18 @@ struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> { } impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { - fn get(&self, id: ast::NodeId) -> Option { - self.access_levels.map.get(&id).cloned() + fn get(&self, id: hir::HirId) -> Option { + let node_id = self.tcx.hir().hir_to_node_id(id); + self.access_levels.map.get(&node_id).cloned() } // Updates node level and returns the updated level. - fn update(&mut self, id: ast::NodeId, level: Option) -> Option { + fn update(&mut self, id: hir::HirId, level: Option) -> Option { let old_level = self.get(id); // Accessibility levels can only grow. if level > old_level { - self.access_levels.map.insert(id, level.unwrap()); + let node_id = self.tcx.hir().hir_to_node_id(id); + self.access_levels.map.insert(node_id, level.unwrap()); self.changed = true; level } else { @@ -428,11 +431,11 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { } } - fn reach(&mut self, item_id: ast::NodeId, access_level: Option) + fn reach(&mut self, item_id: hir::HirId, access_level: Option) -> ReachEverythingInTheInterfaceVisitor<'_, 'a, 'tcx> { ReachEverythingInTheInterfaceVisitor { access_level: cmp::min(access_level, Some(AccessLevel::Reachable)), - item_def_id: self.tcx.hir().local_def_id(item_id), + item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id), ev: self, } } @@ -448,7 +451,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { let inherited_item_level = match item.node { hir::ItemKind::Impl(..) => - Option::::of_impl(item.id, self.tcx, &self.access_levels), + Option::::of_impl(item.hir_id, self.tcx, &self.access_levels), // Foreign modules inherit level from parents. hir::ItemKind::ForeignMod(..) => self.prev_level, // Other `pub` items inherit levels from parents. @@ -463,44 +466,46 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { }; // Update level of the item itself. - let item_level = self.update(item.id, inherited_item_level); + let item_level = self.update(item.hir_id, inherited_item_level); // Update levels of nested things. match item.node { hir::ItemKind::Enum(ref def, _) => { for variant in &def.variants { - let variant_level = self.update(variant.node.data.id(), item_level); + let variant_level = self.update(variant.node.data.hir_id(), item_level); for field in variant.node.data.fields() { - self.update(field.id, variant_level); + self.update(field.hir_id, variant_level); } } } hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => { for impl_item_ref in impl_item_refs { if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() { - self.update(impl_item_ref.id.node_id, item_level); + let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id); + self.update(hir_id, item_level); } } } hir::ItemKind::Trait(.., ref trait_item_refs) => { for trait_item_ref in trait_item_refs { - self.update(trait_item_ref.id.node_id, item_level); + let hir_id = self.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id); + self.update(hir_id, item_level); } } hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { if !def.is_struct() { - self.update(def.id(), item_level); + self.update(def.hir_id(), item_level); } for field in def.fields() { if field.vis.node.is_pub() { - self.update(field.id, item_level); + self.update(field.hir_id, item_level); } } } hir::ItemKind::ForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { if foreign_item.vis.node.is_pub() { - self.update(foreign_item.id, item_level); + self.update(foreign_item.hir_id, item_level); } } } @@ -531,21 +536,22 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time // reachable if they are returned via `impl Trait`, even from private functions. let exist_level = cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); - self.reach(item.id, exist_level).generics().predicates().ty(); + self.reach(item.hir_id, exist_level).generics().predicates().ty(); } // Visit everything. hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates().ty(); + self.reach(item.hir_id, item_level).generics().predicates().ty(); } } hir::ItemKind::Trait(.., ref trait_item_refs) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates(); + self.reach(item.hir_id, item_level).generics().predicates(); for trait_item_ref in trait_item_refs { - let mut reach = self.reach(trait_item_ref.id.node_id, item_level); + let hir_id = self.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id); + let mut reach = self.reach(hir_id, item_level); reach.generics().predicates(); if trait_item_ref.kind == hir::AssociatedItemKind::Type && @@ -559,18 +565,19 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } hir::ItemKind::TraitAlias(..) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates(); + self.reach(item.hir_id, item_level).generics().predicates(); } } // Visit everything except for private impl items. hir::ItemKind::Impl(.., ref impl_item_refs) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates().ty().trait_ref(); + self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref(); for impl_item_ref in impl_item_refs { - let impl_item_level = self.get(impl_item_ref.id.node_id); + let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id); + let impl_item_level = self.get(hir_id); if impl_item_level.is_some() { - self.reach(impl_item_ref.id.node_id, impl_item_level) + self.reach(hir_id, impl_item_level) .generics().predicates().ty(); } } @@ -580,26 +587,26 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // Visit everything, but enum variants have their own levels. hir::ItemKind::Enum(ref def, _) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates(); + self.reach(item.hir_id, item_level).generics().predicates(); } for variant in &def.variants { - let variant_level = self.get(variant.node.data.id()); + let variant_level = self.get(variant.node.data.hir_id()); if variant_level.is_some() { for field in variant.node.data.fields() { - self.reach(field.id, variant_level).ty(); + self.reach(field.hir_id, variant_level).ty(); } // Corner case: if the variant is reachable, but its // enum is not, make the enum reachable as well. - self.update(item.id, variant_level); + self.update(item.hir_id, variant_level); } } } // Visit everything, but foreign items have their own levels. hir::ItemKind::ForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { - let foreign_item_level = self.get(foreign_item.id); + let foreign_item_level = self.get(foreign_item.hir_id); if foreign_item_level.is_some() { - self.reach(foreign_item.id, foreign_item_level) + self.reach(foreign_item.hir_id, foreign_item_level) .generics().predicates().ty(); } } @@ -608,11 +615,11 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { if item_level.is_some() { - self.reach(item.id, item_level).generics().predicates(); + self.reach(item.hir_id, item_level).generics().predicates(); for field in struct_def.fields() { - let field_level = self.get(field.id); + let field_level = self.get(field.hir_id); if field_level.is_some() { - self.reach(field.id, field_level).ty(); + self.reach(field.hir_id, field_level).ty(); } } } @@ -633,17 +640,17 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { self.prev_level = orig_level; } - fn visit_mod(&mut self, m: &'tcx hir::Mod, _sp: Span, id: ast::NodeId) { + fn visit_mod(&mut self, m: &'tcx hir::Mod, _sp: Span, id: hir::HirId) { // This code is here instead of in visit_item so that the // crate module gets processed as well. if self.prev_level.is_some() { - let def_id = self.tcx.hir().local_def_id(id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(id); if let Some(exports) = self.tcx.module_exports(def_id) { for export in exports.iter() { if export.vis == ty::Visibility::Public { if let Some(def_id) = export.def.opt_def_id() { - if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { - self.update(node_id, Some(AccessLevel::Exported)); + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { + self.update(hir_id, Some(AccessLevel::Exported)); } } } @@ -656,43 +663,44 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { if md.legacy { - self.update(md.id, Some(AccessLevel::Public)); + self.update(md.hir_id, Some(AccessLevel::Public)); return } let module_did = ty::DefIdTree::parent( self.tcx, - self.tcx.hir().local_def_id(md.id) + self.tcx.hir().local_def_id_from_hir_id(md.hir_id) ).unwrap(); - let mut module_id = self.tcx.hir().as_local_node_id(module_did).unwrap(); + let mut module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap(); let level = if md.vis.node.is_pub() { self.get(module_id) } else { None }; - let level = self.update(md.id, level); + let level = self.update(md.hir_id, level); if level.is_none() { return } loop { - let module = if module_id == ast::CRATE_NODE_ID { + let module = if module_id == hir::CRATE_HIR_ID { &self.tcx.hir().krate().module } else if let hir::ItemKind::Mod(ref module) = - self.tcx.hir().expect_item(module_id).node { + self.tcx.hir().expect_item_by_hir_id(module_id).node { module } else { unreachable!() }; for id in &module.item_ids { - self.update(id.id, level); + let hir_id = self.tcx.hir().node_to_hir_id(id.id); + self.update(hir_id, level); } - let def_id = self.tcx.hir().local_def_id(module_id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(module_id); if let Some(exports) = self.tcx.module_exports(def_id) { for export in exports.iter() { - if let Some(node_id) = self.tcx.hir().as_local_node_id(export.def.def_id()) { - self.update(node_id, level); + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(export.def.def_id()) { + self.update(hir_id, level); } } } - if module_id == ast::CRATE_NODE_ID { + if module_id == hir::CRATE_HIR_ID { break } module_id = self.tcx.hir().get_parent_node(module_id); @@ -736,8 +744,8 @@ impl<'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'_, 'a, 'tcx> { impl<'a, 'tcx> DefIdVisitor<'a, 'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'a, 'tcx> { fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.ev.tcx } fn visit_def_id(&mut self, def_id: DefId, _kind: &str, _descr: &dyn fmt::Display) -> bool { - if let Some(node_id) = self.ev.tcx.hir().as_local_node_id(def_id) { - self.ev.update(node_id, self.access_level); + if let Some(hir_id) = self.ev.tcx.hir().as_local_hir_id(def_id) { + self.ev.update(hir_id, self.access_level); } false } @@ -753,7 +761,7 @@ impl<'a, 'tcx> DefIdVisitor<'a, 'tcx> for ReachEverythingInTheInterfaceVisitor<' struct NamePrivacyVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, - current_item: ast::NodeId, + current_item: hir::HirId, empty_tables: &'a ty::TypeckTables<'tcx>, } @@ -790,9 +798,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - let orig_current_item = mem::replace(&mut self.current_item, item.id); + let orig_current_item = mem::replace(&mut self.current_item, item.hir_id); let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, item.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables)); intravisit::walk_item(self, item); self.current_item = orig_current_item; self.tables = orig_tables; @@ -800,14 +808,14 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, ti.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, ti.hir_id, self.empty_tables)); intravisit::walk_trait_item(self, ti); self.tables = orig_tables; } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, ii.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, ii.hir_id, self.empty_tables)); intravisit::walk_impl_item(self, ii); self.tables = orig_tables; } @@ -824,7 +832,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { // unmentioned fields, just check them all. for (vf_index, variant_field) in variant.fields.iter().enumerate() { let field = fields.iter().find(|f| { - self.tcx.field_index(f.id, self.tables) == vf_index + self.tcx.field_index(f.hir_id, self.tables) == vf_index }); let (use_ctxt, span) = match field { Some(field) => (field.ident.span, field.span), @@ -835,7 +843,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { } else { for field in fields { let use_ctxt = field.ident.span; - let index = self.tcx.field_index(field.id, self.tables); + let index = self.tcx.field_index(field.hir_id, self.tables); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); } } @@ -854,7 +862,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { let variant = adt.variant_of_def(def); for field in fields { let use_ctxt = field.node.ident.span; - let index = self.tcx.field_index(field.node.id, self.tables); + let index = self.tcx.field_index(field.node.hir_id, self.tables); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); } } @@ -888,7 +896,7 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> { // Take node-id of an expression or pattern and check its type for privacy. fn check_expr_pat_type(&mut self, id: hir::HirId, span: Span) -> bool { self.span = span; - if self.visit(self.tables.node_id_to_type(id)) || self.visit(self.tables.node_substs(id)) { + if self.visit(self.tables.hir_id_to_type(id)) || self.visit(self.tables.node_substs(id)) { return true; } if let Some(adjustments) = self.tables.adjustments().get(id) { @@ -930,7 +938,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { self.span = hir_ty.span; if self.in_body { // Types in bodies. - if self.visit(self.tables.node_id_to_type(hir_ty.hir_id)) { + if self.visit(self.tables.hir_id_to_type(hir_ty.hir_id)) { return; } } else { @@ -1056,11 +1064,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { // Check types in item interfaces. fn visit_item(&mut self, item: &'tcx hir::Item) { - let orig_current_item = - mem::replace(&mut self.current_item, self.tcx.hir().local_def_id(item.id)); + let orig_current_item = mem::replace( + &mut self.current_item, self.tcx.hir().local_def_id_from_hir_id(item.hir_id)); let orig_in_body = mem::replace(&mut self.in_body, false); let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, item.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables)); intravisit::walk_item(self, item); self.tables = orig_tables; self.in_body = orig_in_body; @@ -1069,14 +1077,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, ti.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, ti.hir_id, self.empty_tables)); intravisit::walk_trait_item(self, ti); self.tables = orig_tables; } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { let orig_tables = - mem::replace(&mut self.tables, item_tables(self.tcx, ii.id, self.empty_tables)); + mem::replace(&mut self.tables, item_tables(self.tcx, ii.hir_id, self.empty_tables)); intravisit::walk_impl_item(self, ii); self.tables = orig_tables; } @@ -1101,7 +1109,7 @@ struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx: 'a> { access_levels: &'a AccessLevels, in_variant: bool, // Set of errors produced by this obsolete visitor. - old_error_set: NodeSet, + old_error_set: HirIdSet, } struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> { @@ -1136,22 +1144,24 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } } - fn trait_is_public(&self, trait_id: ast::NodeId) -> bool { + fn trait_is_public(&self, trait_id: hir::HirId) -> bool { // FIXME: this would preferably be using `exported_items`, but all // traits are exported currently (see `EmbargoVisitor.exported_trait`). - self.access_levels.is_public(trait_id) + let node_id = self.tcx.hir().hir_to_node_id(trait_id); + self.access_levels.is_public(node_id) } fn check_generic_bound(&mut self, bound: &hir::GenericBound) { if let hir::GenericBound::Trait(ref trait_ref, _) = *bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { - self.old_error_set.insert(trait_ref.trait_ref.ref_id); + self.old_error_set.insert(trait_ref.trait_ref.hir_ref_id); } } } - fn item_is_public(&self, id: &ast::NodeId, vis: &hir::Visibility) -> bool { - self.access_levels.is_reachable(*id) || vis.node.is_pub() + fn item_is_public(&self, id: &hir::HirId, vis: &hir::Visibility) -> bool { + let node_id = self.tcx.hir().hir_to_node_id(*id); + self.access_levels.is_reachable(node_id) || vis.node.is_pub() } } @@ -1199,7 +1209,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { hir::ItemKind::ForeignMod(_) => {} hir::ItemKind::Trait(.., ref bounds, _) => { - if !self.trait_is_public(item.id) { + if !self.trait_is_public(item.hir_id) { return } @@ -1241,8 +1251,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { |tr| { let did = tr.path.def.def_id(); - if let Some(node_id) = self.tcx.hir().as_local_node_id(did) { - self.trait_is_public(node_id) + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) { + self.trait_is_public(hir_id) } else { true // external traits must be public } @@ -1264,7 +1274,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { match impl_item.node { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => { - self.access_levels.is_reachable(impl_item.id) + self.access_levels.is_reachable( + impl_item_ref.id.node_id) } hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => false, @@ -1289,7 +1300,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { match impl_item.node { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) - if self.item_is_public(&impl_item.id, &impl_item.vis) => + if self.item_is_public(&impl_item.hir_id, &impl_item.vis) => { intravisit::walk_impl_item(self, impl_item) } @@ -1330,7 +1341,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // methods will be visible as `Public::foo`. let mut found_pub_static = false; for impl_item_ref in impl_item_refs { - if self.item_is_public(&impl_item_ref.id.node_id, &impl_item_ref.vis) { + let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id); + if self.item_is_public(&hir_id, &impl_item_ref.vis) { let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); match impl_item_ref.kind { hir::AssociatedItemKind::Const => { @@ -1357,7 +1369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { hir::ItemKind::Ty(..) => return, // Not at all public, so we don't care. - _ if !self.item_is_public(&item.id, &item.vis) => { + _ if !self.item_is_public(&item.hir_id, &item.vis) => { return; } @@ -1393,7 +1405,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) { - if self.access_levels.is_reachable(item.id) { + let node_id = self.tcx.hir().hir_to_node_id(item.hir_id); + if self.access_levels.is_reachable(node_id) { intravisit::walk_foreign_item(self, item) } } @@ -1401,7 +1414,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_ty(&mut self, t: &'tcx hir::Ty) { if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = t.node { if self.path_is_private_type(path) { - self.old_error_set.insert(t.id); + self.old_error_set.insert(t.hir_id); } } intravisit::walk_ty(self, t) @@ -1410,8 +1423,9 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_variant(&mut self, v: &'tcx hir::Variant, g: &'tcx hir::Generics, - item_id: ast::NodeId) { - if self.access_levels.is_reachable(v.node.data.id()) { + item_id: hir::HirId) { + let node_id = self.tcx.hir().hir_to_node_id(v.node.data.hir_id()); + if self.access_levels.is_reachable(node_id) { self.in_variant = true; intravisit::walk_variant(self, v, g, item_id); self.in_variant = false; @@ -1482,8 +1496,8 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> { } fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool { - let node_id = match self.tcx.hir().as_local_node_id(def_id) { - Some(node_id) => node_id, + let hir_id = match self.tcx.hir().as_local_hir_id(def_id) { + Some(hir_id) => hir_id, None => return false, }; @@ -1501,7 +1515,7 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> { err.emit(); } else { let err_code = if kind == "trait" { "E0445" } else { "E0446" }; - self.tcx.lint_node(lint::builtin::PRIVATE_IN_PUBLIC, node_id, self.span, + self.tcx.lint_node(lint::builtin::PRIVATE_IN_PUBLIC, hir_id, self.span, &format!("{} (error {})", msg, err_code)); } } @@ -1519,11 +1533,11 @@ impl<'a, 'tcx> DefIdVisitor<'a, 'tcx> for SearchInterfaceForPrivateItemsVisitor< struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, has_pub_restricted: bool, - old_error_set: &'a NodeSet, + old_error_set: &'a HirIdSet, } impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { - fn check(&self, item_id: ast::NodeId, required_visibility: ty::Visibility) + fn check(&self, item_id: hir::HirId, required_visibility: ty::Visibility) -> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> { let mut has_old_errors = false; @@ -1550,7 +1564,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { SearchInterfaceForPrivateItemsVisitor { tcx: self.tcx, - item_def_id: self.tcx.hir().local_def_id(item_id), + item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id), span: self.tcx.hir().span(item_id), required_visibility, has_pub_restricted: self.has_pub_restricted, @@ -1567,7 +1581,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> fn visit_item(&mut self, item: &'tcx hir::Item) { let tcx = self.tcx; - let item_visibility = ty::Visibility::from_hir(&item.vis, item.id, tcx); + let item_visibility = ty::Visibility::from_hir(&item.vis, item.hir_id, tcx); match item.node { // Crates are always public. @@ -1581,18 +1595,19 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // Subitems of these items have inherited publicity. hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => { - self.check(item.id, item_visibility).generics().predicates().ty(); + self.check(item.hir_id, item_visibility).generics().predicates().ty(); } hir::ItemKind::Existential(..) => { // `ty()` for existential types is the underlying type, // it's not a part of interface, so we skip it. - self.check(item.id, item_visibility).generics().predicates(); + self.check(item.hir_id, item_visibility).generics().predicates(); } hir::ItemKind::Trait(.., ref trait_item_refs) => { - self.check(item.id, item_visibility).generics().predicates(); + self.check(item.hir_id, item_visibility).generics().predicates(); for trait_item_ref in trait_item_refs { - let mut check = self.check(trait_item_ref.id.node_id, item_visibility); + let hir_id = self.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id); + let mut check = self.check(hir_id, item_visibility); check.in_assoc_ty = trait_item_ref.kind == hir::AssociatedItemKind::Type; check.generics().predicates(); @@ -1605,32 +1620,32 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> } } hir::ItemKind::TraitAlias(..) => { - self.check(item.id, item_visibility).generics().predicates(); + self.check(item.hir_id, item_visibility).generics().predicates(); } hir::ItemKind::Enum(ref def, _) => { - self.check(item.id, item_visibility).generics().predicates(); + self.check(item.hir_id, item_visibility).generics().predicates(); for variant in &def.variants { for field in variant.node.data.fields() { - self.check(field.id, item_visibility).ty(); + self.check(field.hir_id, item_visibility).ty(); } } } // Subitems of foreign modules have their own publicity. hir::ItemKind::ForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { - let vis = ty::Visibility::from_hir(&foreign_item.vis, item.id, tcx); - self.check(foreign_item.id, vis).generics().predicates().ty(); + let vis = ty::Visibility::from_hir(&foreign_item.vis, item.hir_id, tcx); + self.check(foreign_item.hir_id, vis).generics().predicates().ty(); } } // Subitems of structs and unions have their own publicity. hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { - self.check(item.id, item_visibility).generics().predicates(); + self.check(item.hir_id, item_visibility).generics().predicates(); for field in struct_def.fields() { - let field_visibility = ty::Visibility::from_hir(&field.vis, item.id, tcx); - self.check(field.id, min(item_visibility, field_visibility, tcx)).ty(); + let field_visibility = ty::Visibility::from_hir(&field.vis, item.hir_id, tcx); + self.check(field.hir_id, min(item_visibility, field_visibility, tcx)).ty(); } } // An inherent impl is public when its type is public @@ -1638,16 +1653,17 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // A trait impl is public when both its type and its trait are public // Subitems of trait impls have inherited publicity. hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => { - let impl_vis = ty::Visibility::of_impl(item.id, tcx, &Default::default()); - self.check(item.id, impl_vis).generics().predicates(); + let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default()); + self.check(item.hir_id, impl_vis).generics().predicates(); for impl_item_ref in impl_item_refs { let impl_item = tcx.hir().impl_item(impl_item_ref.id); let impl_item_vis = if trait_ref.is_none() { - min(ty::Visibility::from_hir(&impl_item.vis, item.id, tcx), impl_vis, tcx) + min(ty::Visibility::from_hir(&impl_item.vis, item.hir_id, tcx), + impl_vis, tcx) } else { impl_vis }; - let mut check = self.check(impl_item.id, impl_item_vis); + let mut check = self.check(impl_item.hir_id, impl_item_vis); check.in_assoc_ty = impl_item_ref.kind == hir::AssociatedItemKind::Type; check.generics().predicates().ty(); } @@ -1679,7 +1695,7 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut visitor = NamePrivacyVisitor { tcx, tables: &empty_tables, - current_item: CRATE_NODE_ID, + current_item: hir::CRATE_HIR_ID, empty_tables: &empty_tables, }; intravisit::walk_crate(&mut visitor, krate); @@ -1712,7 +1728,7 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, break } } - visitor.update(ast::CRATE_NODE_ID, Some(AccessLevel::Public)); + visitor.update(hir::CRATE_HIR_ID, Some(AccessLevel::Public)); { let mut visitor = ObsoleteVisiblePrivateTypesVisitor { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b41193723069c..09d6a019574ba 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -40,7 +40,7 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId}; use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap}; use rustc::session::config::nightly_options; use rustc::ty; -use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap}; +use rustc::util::nodemap::{HirIdMap, NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap}; use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; @@ -804,17 +804,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { function_kind: FnKind<'tcx>, declaration: &'tcx FnDecl, _: Span, - node_id: NodeId) + node_id: ast::NodeId) { let (rib_kind, asyncness) = match function_kind { FnKind::ItemFn(_, ref header, ..) => (ItemRibKind, header.asyncness), FnKind::Method(_, ref sig, _, _) => (TraitOrImplItemRibKind, sig.header.asyncness), - FnKind::Closure(_) => + FnKind::Closure(_) => { // Async closures aren't resolved through `visit_fn`-- they're // processed separately - (ClosureRibKind(node_id), IsAsync::NotAsync), + let hir_id = self.definitions.node_to_hir_id(node_id); + (ClosureRibKind(hir_id), IsAsync::NotAsync) + }, }; // Create a value rib for the function. @@ -836,7 +838,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { // Resolve the function body, potentially inside the body of an async closure if let IsAsync::Async { closure_id, .. } = asyncness { - let rib_kind = ClosureRibKind(closure_id); + let closure_hir_id = self.definitions.node_to_hir_id(closure_id); + let rib_kind = ClosureRibKind(closure_hir_id); self.ribs[ValueNS].push(Rib::new(rib_kind)); self.label_ribs.push(Rib::new(rib_kind)); } @@ -927,7 +930,7 @@ enum RibKind<'a> { /// We passed through a closure scope at the given node ID. /// Translate upvars as appropriate. - ClosureRibKind(NodeId /* func id */), + ClosureRibKind(hir::HirId /* func id */), /// We passed through an impl or trait and are now in one of its /// methods or associated types. Allow references to ty params that impl or trait @@ -1523,7 +1526,7 @@ pub struct Resolver<'a> { def_map: DefMap, import_map: ImportMap, pub freevars: FreevarMap, - freevars_seen: NodeMap>, + freevars_seen: HirIdMap>, pub export_map: ExportMap, pub trait_map: TraitMap, @@ -2304,10 +2307,10 @@ impl<'a> Resolver<'a> { // generate a fake "implementation scope" containing all the // implementations thus found, for compatibility with old resolve pass. - pub fn with_scope(&mut self, id: NodeId, f: F) -> T + pub fn with_scope(&mut self, id: hir::HirId, f: F) -> T where F: FnOnce(&mut Resolver) -> T { - let id = self.definitions.local_def_id(id); + let id = self.definitions.local_def_id_from_hir_id(id); let module = self.module_map.get(&id).cloned(); // clones a reference if let Some(module) = module { // Move down in the graph. @@ -2488,7 +2491,8 @@ impl<'a> Resolver<'a> { } ItemKind::Mod(_) | ItemKind::ForeignMod(_) => { - self.with_scope(item.id, |this| { + let hir_id = self.definitions.node_to_hir_id(item.id); + self.with_scope(hir_id, |this| { visit::walk_item(this, item); }); } @@ -2959,7 +2963,8 @@ impl<'a> Resolver<'a> { // because that breaks the assumptions later // passes make about or-patterns.) let ident = ident.modern_and_legacy(); - let mut def = Def::Local(pat_id); + let pat_hir_id = self.definitions.node_to_hir_id(pat_id); + let mut def = Def::Local(pat_hir_id); match bindings.get(&ident).cloned() { Some(id) if id == outer_pat_id => { // `Variant(a, a)`, error @@ -4061,7 +4066,7 @@ impl<'a> Resolver<'a> { Def::Upvar(..) => { span_bug!(span, "unexpected {:?} in bindings", def) } - Def::Local(node_id) => { + Def::Local(hir_id) => { for rib in ribs { match rib.kind { NormalRibKind | ModuleRibKind(..) | MacroDefinition(..) | @@ -4074,22 +4079,22 @@ impl<'a> Resolver<'a> { let seen = self.freevars_seen .entry(function_id) .or_default(); - if let Some(&index) = seen.get(&node_id) { - def = Def::Upvar(node_id, index, function_id); + if let Some(&index) = seen.get(&hir_id) { + def = Def::Upvar(hir_id, index, function_id); continue; } let vec = self.freevars .entry(function_id) .or_default(); let depth = vec.len(); - def = Def::Upvar(node_id, depth, function_id); + def = Def::Upvar(hir_id, depth, function_id); if record_used { vec.push(Freevar { def: prev_def, span, }); - seen.insert(node_id, depth); + seen.insert(hir_id, depth); } } ItemRibKind | TraitOrImplItemRibKind => { @@ -4157,7 +4162,7 @@ impl<'a> Resolver<'a> { } // Fields are generally expected in the same contexts as locals. - if filter_fn(Def::Local(ast::DUMMY_NODE_ID)) { + if filter_fn(Def::Local(hir::DUMMY_HIR_ID)) { if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) { // Look for a field with the same name in the current self_type. if let Some(resolution) = self.def_map.get(&node_id) { @@ -4453,7 +4458,8 @@ impl<'a> Resolver<'a> { } // Resolve the body of async exprs inside the async closure to which they desugar ExprKind::Async(_, async_closure_id, ref block) => { - let rib_kind = ClosureRibKind(async_closure_id); + let ac_hir_id = self.definitions.node_to_hir_id(async_closure_id); + let rib_kind = ClosureRibKind(ac_hir_id); self.ribs[ValueNS].push(Rib::new(rib_kind)); self.label_ribs.push(Rib::new(rib_kind)); self.visit_block(&block); @@ -4467,7 +4473,8 @@ impl<'a> Resolver<'a> { _, IsAsync::Async { closure_id: inner_closure_id, .. }, _, ref fn_decl, ref body, _span, ) => { - let rib_kind = ClosureRibKind(expr.id); + let expr_hir_id = self.definitions.node_to_hir_id(expr.id); + let rib_kind = ClosureRibKind(expr_hir_id); self.ribs[ValueNS].push(Rib::new(rib_kind)); self.label_ribs.push(Rib::new(rib_kind)); // Resolve arguments: @@ -4481,7 +4488,8 @@ impl<'a> Resolver<'a> { // Now resolve the inner closure { - let rib_kind = ClosureRibKind(inner_closure_id); + let ic_hir_id = self.definitions.node_to_hir_id(inner_closure_id); + let rib_kind = ClosureRibKind(ic_hir_id); self.ribs[ValueNS].push(Rib::new(rib_kind)); self.label_ribs.push(Rib::new(rib_kind)); // No need to resolve arguments: the inner closure has none. diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 05156fb51f9da..6b50f0f5207e2 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -226,7 +226,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } fn lookup_def_id(&self, ref_id: NodeId) -> Option { - match self.save_ctxt.get_path_def(ref_id) { + let hir_id = self.tcx.hir().node_to_hir_id(ref_id); + match self.save_ctxt.get_path_def(hir_id) { HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Err => None, def => Some(def.def_id()), } @@ -240,7 +241,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { for (id, ident, ..) in collector.collected_idents { let hir_id = self.tcx.hir().node_to_hir_id(id); - let typ = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) { + let typ = match self.save_ctxt.tables.hir_id_to_type_opt(hir_id) { Some(s) => s.to_string(), None => continue, }; @@ -857,14 +858,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { PatKind::Struct(ref _path, ref fields, _) => { // FIXME do something with _path? let hir_id = self.tcx.hir().node_to_hir_id(p.id); - let adt = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) { + let adt = match self.save_ctxt.tables.hir_id_to_type_opt(hir_id) { Some(ty) => ty.ty_adt_def().unwrap(), None => { visit::walk_pat(self, p); return; } }; - let variant = adt.variant_of_def(self.save_ctxt.get_path_def(p.id)); + let variant = adt.variant_of_def(self.save_ctxt.get_path_def(hir_id)); for &Spanned { node: ref field, .. } in fields { if let Some(index) = self.tcx.find_field_index(field.ident, variant) { @@ -894,25 +895,25 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // process collected paths for (id, ident, immut) in collector.collected_idents { - match self.save_ctxt.get_path_def(id) { + let hir_id = self.tcx.hir().node_to_hir_id(id); + match self.save_ctxt.get_path_def(hir_id) { HirDef::Local(id) => { let mut value = if immut == ast::Mutability::Immutable { self.span.snippet(ident.span) } else { "".to_owned() }; - let hir_id = self.tcx.hir().node_to_hir_id(id); let typ = self.save_ctxt .tables - .node_id_to_type_opt(hir_id) + .hir_id_to_type_opt(hir_id) .map(|t| t.to_string()) .unwrap_or_default(); value.push_str(": "); value.push_str(&typ); if !self.span.filter_generated(ident.span) { - let qualname = format!("{}${}", ident.to_string(), id); - let id = ::id_from_node_id(id, &self.save_ctxt); + let qualname = format!("{}${:?}", ident.to_string(), id); + let id = ::id_from_def_id(self.tcx.hir().local_def_id_from_hir_id(id)); let span = self.span_from_span(ident.span); self.dumper.dump_def( @@ -973,7 +974,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { _ => String::new(), }; let hir_id = self.tcx.hir().node_to_hir_id(id); - let typ = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) { + let typ = match self.save_ctxt.tables.hir_id_to_type_opt(hir_id) { Some(typ) => { let typ = typ.to_string(); if !value.is_empty() { @@ -1499,7 +1500,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc self.process_macro_use(ex.span); match ex.node { ast::ExprKind::Struct(ref path, ref fields, ref base) => { - let hir_expr = self.save_ctxt.tcx.hir().expect_expr(ex.id); + let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id); + let hir_expr = self.save_ctxt.tcx.hir().expect_expr(hir_id); let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) { Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(), _ => { @@ -1507,7 +1509,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc return; } }; - let def = self.save_ctxt.get_path_def(hir_expr.id); + let def = self.save_ctxt.get_path_def(hir_expr.hir_id); self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) } ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args), diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 4d55004a055f0..5189b703c6d1b 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -413,7 +413,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { 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)); + qualname.push_str(&self.tcx.hir().node_to_pretty_string_by_hir_id( + ty.hir_id)); let trait_id = self.tcx.trait_id_of_impl(impl_id); let mut decl_id = None; @@ -522,7 +523,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { - let hir_node = self.tcx.hir().expect_expr(expr.id); + let hir_id = self.tcx.hir().node_to_hir_id(expr.id); + let hir_node = self.tcx.hir().expect_expr(hir_id); let ty = self.tables.expr_ty_adjusted_opt(&hir_node); if ty.is_none() || ty.unwrap().sty == ty::Error { return None; @@ -614,8 +616,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } } - pub fn get_path_def(&self, id: NodeId) -> HirDef { - match self.tcx.hir().get(id) { + pub fn get_path_def(&self, id: hir::HirId) -> HirDef { + match self.tcx.hir().get_by_hir_id(id) { Node::TraitRef(tr) => tr.path.def, Node::Item(&hir::Item { @@ -651,8 +653,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { node: hir::PatKind::TupleStruct(ref qpath, ..), .. }) => { - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.tables.qpath_def(qpath, hir_id) + self.tables.qpath_def(qpath, id) } Node::Binding(&hir::Pat { @@ -715,7 +716,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { return None; } - let def = self.get_path_def(id); + let hir_id = self.tcx.hir().node_to_hir_id(id); + let def = self.get_path_def(hir_id); let span = path_seg.ident.span; filter!(self.span_utils, span); let span = self.span_from_span(span); @@ -725,7 +727,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Some(Ref { kind: RefKind::Variable, span, - ref_id: id_from_node_id(id, self), + ref_id: id_from_def_id(self.tcx.hir().local_def_id_from_hir_id(id)), }) } HirDef::Static(..) | @@ -881,7 +883,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } fn lookup_ref_id(&self, ref_id: NodeId) -> Option { - match self.get_path_def(ref_id) { + let hir_id = self.tcx.hir().node_to_hir_id(ref_id); + match self.get_path_def(hir_id) { HirDef::PrimTy(_) | HirDef::SelfTy(..) | HirDef::Err => None, def => Some(def.def_id()), } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 7d4c0d0f9f56f..6ba604d9dd1e4 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -269,7 +269,8 @@ impl Sig for ast::Ty { }; let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?); - let def = scx.get_path_def(id.ok_or("Missing id for Path")?); + let hir_id = scx.tcx.hir().node_to_hir_id(id.ok_or("Missing id for Path")?); + let def = scx.get_path_def(hir_id); let id = id_from_def_id(def.def_id()); if path.segments.len() - qself.position == 1 { let start = offset + prefix.len(); @@ -572,7 +573,8 @@ impl Sig for ast::Item { impl Sig for ast::Path { fn make(&self, offset: usize, id: Option, scx: &SaveContext) -> Result { - let def = scx.get_path_def(id.ok_or("Missing id for Path")?); + let hir_id = scx.tcx.hir().node_to_hir_id(id.ok_or("Missing id for Path")?); + let def = scx.get_path_def(hir_id); let (name, start, end) = match def { Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => { diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index a3fb96990545e..a1a846c1e537c 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -1,6 +1,7 @@ //! Provider for the `implied_outlives_bounds` query. //! Do not call this query directory. See [`rustc::traits::query::implied_outlives_bounds`]. +use rustc::hir; use rustc::infer::InferCtxt; use rustc::infer::canonical::{self, Canonical}; use rustc::traits::{TraitEngine, TraitEngineExt}; @@ -11,7 +12,6 @@ use rustc::ty::outlives::Component; use rustc::ty::query::Providers; use rustc::ty::wf; use smallvec::{SmallVec, smallvec}; -use syntax::ast::DUMMY_NODE_ID; use syntax::source_map::DUMMY_SP; use rustc::traits::FulfillmentContext; @@ -65,7 +65,7 @@ fn compute_implied_outlives_bounds<'tcx>( // unresolved inference variables here anyway, but there might be // during typeck under some circumstances.) let obligations = - wf::obligations(infcx, param_env, DUMMY_NODE_ID, ty, DUMMY_SP).unwrap_or(vec![]); + wf::obligations(infcx, param_env, hir::DUMMY_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]); // N.B., all of these predicates *ought* to be easily proven // true. In fact, their correctness is (mostly) implied by diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 5502a1d186eee..d8b1122dceecc 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -611,8 +611,8 @@ struct ClauseDumper<'a, 'tcx: 'a> { } impl<'a, 'tcx> ClauseDumper<'a, 'tcx> { - fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) { - let def_id = self.tcx.hir().local_def_id(node_id); + fn process_attrs(&mut self, hir_id: hir::HirId, attrs: &[ast::Attribute]) { + let def_id = self.tcx.hir().local_def_id_from_hir_id(hir_id); for attr in attrs { let mut clauses = None; @@ -654,22 +654,22 @@ impl<'a, 'tcx> Visitor<'tcx> for ClauseDumper<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - self.process_attrs(item.id, &item.attrs); + self.process_attrs(item.hir_id, &item.attrs); intravisit::walk_item(self, item); } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - self.process_attrs(trait_item.id, &trait_item.attrs); + self.process_attrs(trait_item.hir_id, &trait_item.attrs); intravisit::walk_trait_item(self, trait_item); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - self.process_attrs(impl_item.id, &impl_item.attrs); + self.process_attrs(impl_item.hir_id, &impl_item.attrs); intravisit::walk_impl_item(self, impl_item); } fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { - self.process_attrs(s.id, &s.attrs); + self.process_attrs(s.hir_id, &s.attrs); intravisit::walk_struct_field(self, s); } } diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index b31e9c15d0367..c90d5a2c85000 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -1,3 +1,4 @@ +use rustc::hir; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution}; use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt}; @@ -5,7 +6,6 @@ use rustc::ty::query::Providers; use rustc::ty::{ParamEnvAnd, TyCtxt}; use rustc_data_structures::sync::Lrc; use std::sync::atomic::Ordering; -use syntax::ast::DUMMY_NODE_ID; use syntax_pos::DUMMY_SP; crate fn provide(p: &mut Providers) { @@ -34,7 +34,7 @@ fn normalize_projection_ty<'tcx>( value: goal, }| { let selcx = &mut SelectionContext::new(infcx); - let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID); + let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); let mut obligations = vec![]; let answer = traits::normalize_projection_type( selcx, diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 52fcb5b80f4ae..3056a06e53bcc 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -1,6 +1,7 @@ use rustc::infer::at::ToTrace; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::infer::InferCtxt; +use rustc::hir; use rustc::hir::def_id::DefId; use rustc::mir::ProjectionKind; use rustc::mir::tcx::PlaceTy; @@ -20,7 +21,6 @@ use rustc::ty::{ }; use rustc_data_structures::sync::Lrc; use std::fmt; -use syntax::ast; use syntax_pos::DUMMY_SP; crate fn provide(p: &mut Providers) { @@ -74,7 +74,7 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> { self.infcx .partially_normalize_associated_types_in( DUMMY_SP, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, self.param_env, &value, ) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8e5eaa18b9de0..18deb6a2e3012 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -110,10 +110,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { { let tcx = self.tcx(); let lifetime_name = |def_id| { - tcx.hir().name(tcx.hir().as_local_node_id(def_id).unwrap()).as_interned_str() + tcx.hir().name(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str() }; - let hir_id = tcx.hir().node_to_hir_id(lifetime.id); + let hir_id = lifetime.hir_id; let r = match tcx.named_region(hir_id) { Some(rl::Region::Static) => { tcx.types.re_static @@ -305,7 +305,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let mut multispan = MultiSpan::from_span(span); multispan.push_span_label(span_late, note.to_string()); tcx.lint_node(lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS, - args.args[0].id(), multispan, msg); + args.args[0].hir_id(), multispan, msg); return (false, None); } } @@ -736,7 +736,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { // specify type to assert that error was already reported in Err case: let predicate: Result<_, ErrorReported> = self.ast_type_binding_to_poly_projection_predicate( - trait_ref.ref_id, poly_trait_ref, binding, speculative, &mut dup_bindings); + trait_ref.hir_ref_id, poly_trait_ref, binding, speculative, &mut dup_bindings); // okay to ignore Err because of ErrorReported (see above) Some((predicate.ok()?, binding.span)) })); @@ -820,7 +820,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { fn ast_type_binding_to_poly_projection_predicate( &self, - ref_id: ast::NodeId, + ref_id: hir::HirId, trait_ref: ty::PolyTraitRef<'tcx>, binding: &ConvertedBinding<'tcx>, speculative: bool, @@ -1158,7 +1158,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { self.ast_region_to_region(lifetime, None) } else { self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| { - let hir_id = tcx.hir().node_to_hir_id(lifetime.id); + let hir_id = lifetime.hir_id; if tcx.named_region(hir_id).is_some() { self.ast_region_to_region(lifetime, None) } else { @@ -1213,8 +1213,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let suitable_bounds = traits::transitive_bounds(tcx, bounds) .filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name)); - let param_node_id = tcx.hir().as_local_node_id(ty_param_def_id).unwrap(); - let param_name = tcx.hir().ty_param_name(param_node_id); + let param_hir_id = tcx.hir().as_local_hir_id(ty_param_def_id).unwrap(); + let param_name = tcx.hir().ty_param_name(param_hir_id); self.one_bound_for_assoc_type(suitable_bounds, ¶m_name.as_str(), assoc_name, @@ -1284,7 +1284,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { // Will fail except for `T::A` and `Self::A`; i.e., if `ty`/`ty_path_def` are not a type // parameter or `Self`. pub fn associated_path_def_to_ty(&self, - ref_id: ast::NodeId, + ref_id: hir::HirId, span: Span, ty: Ty<'tcx>, ty_path_def: Def, @@ -1668,12 +1668,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let node_id = tcx.hir().as_local_node_id(did).unwrap(); - let item_id = tcx.hir().get_parent_node(node_id); - let item_def_id = tcx.hir().local_def_id(item_id); + let hir_id = tcx.hir().as_local_hir_id(did).unwrap(); + let item_id = tcx.hir().get_parent_node(hir_id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)]; - tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str()) + let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); + let index = generics.param_def_id_to_index[&def_id]; + tcx.mk_ty_param(index, tcx.hir().name(hir_id).as_interned_str()) } Def::SelfTy(_, Some(def_id)) => { // `Self` in impl (we know the concrete type). @@ -1720,7 +1721,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// internal notion of a type. pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> { debug!("ast_ty_to_ty(id={:?}, ast_ty={:?} ty_ty={:?})", - ast_ty.id, ast_ty, ast_ty.node); + ast_ty.hir_id, ast_ty, ast_ty.node); let tcx = self.tcx(); @@ -1773,10 +1774,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { } else { Def::Err }; - self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, def, segment).0 + self.associated_path_def_to_ty(ast_ty.hir_id, ast_ty.span, ty, def, segment).0 } hir::TyKind::Array(ref ty, ref length) => { - let length_def_id = tcx.hir().local_def_id(length.id); + let length_def_id = tcx.hir().local_def_id_from_hir_id(length.hir_id); let substs = Substs::identity_for_item(tcx, length_def_id); let length = ty::LazyConst::Unevaluated(length_def_id, substs); let length = tcx.intern_lazy_const(length); diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 1767af4870d3b..9dcec74fb20c9 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -63,7 +63,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } PatKind::Path(ref qpath) => { - let (def, _, _) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, _, _) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); match def { Def::Const(..) | Def::AssociatedConst(..) => false, _ => true, @@ -238,7 +238,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .pat_binding_modes_mut() .insert(pat.hir_id, bm); debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm); - let local_ty = self.local_ty(pat.span, pat.id).decl_ty; + let local_ty = self.local_ty(pat.span, pat.hir_id).decl_ty; match bm { ty::BindByReference(mutbl) => { // if the binding is like @@ -264,7 +264,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // if there are multiple arms, make sure they all agree on // what the type of the binding `x` ought to be - if var_id != pat.id { + if var_id != pat.hir_id { let vt = self.local_ty(pat.span, var_id).decl_ty; self.demand_eqtype_pat(pat.span, vt, local_ty, match_discrim_span); } @@ -629,7 +629,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); if self.diverges.get().always() { for arm in arms { - self.warn_if_unreachable(arm.body.id, arm.body.span, "arm"); + self.warn_if_unreachable(arm.body.hir_id, arm.body.span, "arm"); } } @@ -739,7 +739,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); ) -> Ty<'tcx> { // Resolve the path and check the definition for errors. - let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.id) { + let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.hir_id) + { variant_ty } else { for field in fields { @@ -757,7 +758,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); self.demand_eqtype_pat(pat.span, expected, pat_ty, match_discrim_span); // Type-check subpatterns. - if self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm) { + if self.check_struct_pat_fields(pat_ty, pat.hir_id, pat.span, variant, fields, etc, def_bm) + { pat_ty } else { self.tcx.types.err @@ -773,7 +775,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let tcx = self.tcx; // Resolve the path and check the definition for errors. - let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); match def { Def::Err => { self.set_tainted_by_errors(); @@ -795,7 +797,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } // Type-check the path. - let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id).0; + let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.hir_id).0; self.demand_suptype(pat.span, expected, pat_ty); pat_ty } @@ -826,7 +828,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); }; // Resolve the path and check the definition for errors. - let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); if def == Def::Err { self.set_tainted_by_errors(); on_error(); @@ -834,7 +836,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } // Type-check the path. - let (pat_ty, def) = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id); + let (pat_ty, def) = self.instantiate_value_path( + segments, opt_ty, def, pat.span, pat.hir_id); if !pat_ty.is_fn() { report_unexpected_def(def); return self.tcx.types.err; @@ -874,7 +877,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs); self.check_pat_walk(&subpat, field_ty, def_bm, match_arm_pat_span); - self.tcx.check_stability(variant.fields[i].did, Some(pat.id), subpat.span); + self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span); } } else { let subpats_ending = if subpats.len() == 1 { "" } else { "s" }; @@ -894,7 +897,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); fn check_struct_pat_fields(&self, adt_ty: Ty<'tcx>, - pat_id: ast::NodeId, + pat_id: hir::HirId, span: Span, variant: &'tcx ty::VariantDef, fields: &'gcx [Spanned], @@ -940,7 +943,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); vacant.insert(span); field_map.get(&ident) .map(|(i, f)| { - self.write_field_index(field.id, *i); + self.write_field_index(field.hir_id, *i); self.tcx.check_stability(f.did, Some(pat_id), span); self.field_ty(span, f, substs) }) diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 35ac4f3957eb4..f863cfe1887db 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -1,6 +1,7 @@ use super::{FnCtxt, PlaceOp, Needs}; use super::method::MethodCallee; +use rustc::hir; use rustc::infer::{InferCtxt, InferOk}; use rustc::session::DiagnosticMessageId; use rustc::traits::{self, TraitEngine}; @@ -9,7 +10,7 @@ use rustc::ty::{ToPredicate, TypeFoldable}; use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref}; use syntax_pos::Span; -use syntax::ast::{self, Ident}; +use syntax::ast::Ident; use std::iter; @@ -21,7 +22,7 @@ enum AutoderefKind { pub struct Autoderef<'a, 'gcx: 'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, steps: Vec<(Ty<'tcx>, AutoderefKind)>, cur_ty: Ty<'tcx>, @@ -87,7 +88,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'gcx, 'tcx> diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index c59c143f74b62..3243124af9ac1 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -250,7 +250,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let &ty::Adt(adt_def, ..) = t { if adt_def.is_enum() { if let hir::ExprKind::Call(ref expr, _) = call_expr.node { - unit_variant = Some(self.tcx.hir().node_to_pretty_string(expr.id)) + unit_variant = Some( + self.tcx.hir().node_to_pretty_string_by_hir_id(expr.hir_id)) } } } @@ -317,7 +318,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let def_span = match def { Def::Err => None, - Def::Local(id) | Def::Upvar(id, ..) => Some(self.tcx.hir().span(id)), + Def::Local(id) + | Def::Upvar(id, ..) => Some(self.tcx.hir().span(id)), _ => def .opt_def_id() .and_then(|did| self.tcx.hir().span_if_local(did)), diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 3f185ba194903..ddd8d05f49902 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -401,7 +401,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { }; let mut err = fcx.tcx.struct_span_lint_node( lint, - self.expr.id, + self.expr.hir_id, self.span, &format!("trivial {}cast: `{}` as `{}`", adjective, @@ -416,8 +416,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty); self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty); - debug!("check_cast({}, {:?} as {:?})", - self.expr.id, + debug!("check_cast({:?}, {:?} as {:?})", + self.expr.hir_id, self.expr_ty, self.cast_ty); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index df83c92fde5b4..4a4a13188b9a3 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -72,7 +72,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { opt_kind, expected_sig ); - let expr_def_id = self.tcx.hir().local_def_id(expr.id); + let expr_def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); let ClosureSignatures { bound_sig, @@ -86,7 +86,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.param_env, liberated_sig, decl, - expr.id, + expr.hir_id, body, gen, ).1; @@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!( "check_closure: expr.id={:?} closure_type={:?}", - expr.id, closure_type + expr.hir_id, closure_type ); // Tuple up the arguments and insert the resulting function type into @@ -641,7 +641,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .liberate_late_bound_regions(expr_def_id, &bound_sig); let liberated_sig = self.inh.normalize_associated_types_in( body.value.span, - body.value.id, + body.value.hir_id, self.param_env, &liberated_sig, ); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index a82a0d3ce5232..24cf5d1e38a52 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -712,9 +712,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { let b = self.shallow_resolve(b); - let node_id_a = self.tcx.hir().as_local_node_id(def_id_a).unwrap(); + let hir_id_a = self.tcx.hir().as_local_hir_id(def_id_a).unwrap(); match b.sty { - ty::FnPtr(_) if self.tcx.with_freevars(node_id_a, |v| v.is_empty()) => { + ty::FnPtr(_) if self.tcx.with_freevars(hir_id_a, |v| v.is_empty()) => { // We coerce the closure, which has fn type // `extern "rust-call" fn((arg0,arg1,...)) -> _` // to @@ -1177,7 +1177,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> Expressions::UpFront(coercion_sites) => { // if the user gave us an array to validate, check that we got // the next expression in the list, as expected - assert_eq!(coercion_sites[self.pushed].as_coercion_site().id, e.id); + assert_eq!(coercion_sites[self.pushed].as_coercion_site().hir_id, + e.hir_id); } } self.pushed += 1; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 8c193cc8ff1a3..cc1950a0cea90 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -83,11 +83,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // This node-id should be used for the `body_id` field on each // `ObligationCause` (and the `FnCtxt`). This is what // `regionck_item` expects. - let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap(); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap(); let cause = ObligationCause { span: impl_m_span, - body_id: impl_m_node_id, + body_id: impl_m_hir_id, code: ObligationCauseCode::CompareImplMethodObligation { item_name: impl_m.ident.name, impl_item_def_id: impl_m.def_id, @@ -205,7 +205,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Construct trait parameter environment and then shift it into the placeholder viewpoint. // The key step here is to update the caller_bounds's predicates to be // the new hybrid bounds we computed. - let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_node_id); + let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_hir_id); let param_env = ty::ParamEnv::new( tcx.intern_predicates(&hybrid_preds.predicates), Reveal::UserFacing, @@ -262,7 +262,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ); let impl_sig = inh.normalize_associated_types_in(impl_m_span, - impl_m_node_id, + impl_m_hir_id, param_env, &impl_sig); let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig)); @@ -275,7 +275,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_sig.subst(tcx, trait_to_skol_substs); let trait_sig = inh.normalize_associated_types_in(impl_m_span, - impl_m_node_id, + impl_m_hir_id, param_env, &trait_sig); let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig)); @@ -347,8 +347,8 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Finally, resolve all regions. This catches wily misuses of // lifetime parameters. - let fcx = FnCtxt::new(&inh, param_env, impl_m_node_id); - fcx.regionck_item(impl_m_node_id, impl_m_span, &[]); + let fcx = FnCtxt::new(&inh, param_env, impl_m_hir_id); + fcx.regionck_item(impl_m_hir_id, impl_m_span, &[]); Ok(()) }) @@ -415,8 +415,11 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a trait_sig: ty::FnSig<'tcx>) -> (Span, Option) { let tcx = infcx.tcx; - let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap(); - let (impl_m_output, impl_m_iter) = match tcx.hir().expect_impl_item(impl_m_node_id).node { + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap(); + let (impl_m_output, impl_m_iter) = match tcx.hir() + .expect_impl_item_by_hir_id(impl_m_hir_id) + .node + { ImplItemKind::Method(ref impl_m_sig, _) => { (&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter()) } @@ -425,8 +428,9 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a match *terr { TypeError::Mutability => { - if let Some(trait_m_node_id) = tcx.hir().as_local_node_id(trait_m.def_id) { - let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_node_id).node { + if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) { + let trait_m_iter = match tcx.hir().expect_trait_item_by_hir_id(trait_m_hir_id).node + { TraitItemKind::Method(ref trait_m_sig, _) => { trait_m_sig.decl.inputs.iter() } @@ -450,9 +454,9 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a } } TypeError::Sorts(ExpectedFound { .. }) => { - if let Some(trait_m_node_id) = tcx.hir().as_local_node_id(trait_m.def_id) { + if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) { let (trait_m_output, trait_m_iter) = - match tcx.hir().expect_trait_item(trait_m_node_id).node { + match tcx.hir().expect_trait_item_by_hir_id(trait_m_hir_id).node { TraitItemKind::Method(ref trait_m_sig, _) => { (&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter()) } @@ -587,8 +591,8 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let num_trait_m_type_params = trait_m_generics.own_counts().types; if num_impl_m_type_params != num_trait_m_type_params { - let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap(); - let impl_m_item = tcx.hir().expect_impl_item(impl_m_node_id); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap(); + let impl_m_item = tcx.hir().expect_impl_item_by_hir_id(impl_m_hir_id); let span = if impl_m_item.generics.params.is_empty() || impl_m_item.generics.span.is_dummy() // impl Trait in argument position (#55374) { @@ -637,9 +641,9 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let trait_number_args = trait_m_fty.inputs().skip_binder().len(); let impl_number_args = impl_m_fty.inputs().skip_binder().len(); if trait_number_args != impl_number_args { - let trait_m_node_id = tcx.hir().as_local_node_id(trait_m.def_id); - let trait_span = if let Some(trait_id) = trait_m_node_id { - match tcx.hir().expect_trait_item(trait_id).node { + let trait_m_hir_id = tcx.hir().as_local_hir_id(trait_m.def_id); + let trait_span = if let Some(trait_id) = trait_m_hir_id { + match tcx.hir().expect_trait_item_by_hir_id(trait_id).node { TraitItemKind::Method(ref trait_m_sig, _) => { let pos = if trait_number_args > 0 { trait_number_args - 1 @@ -663,8 +667,8 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } else { trait_item_span }; - let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap(); - let impl_span = match tcx.hir().expect_impl_item(impl_m_node_id).node { + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap(); + let impl_span = match tcx.hir().expect_impl_item_by_hir_id(impl_m_hir_id).node { ImplItemKind::Method(ref impl_m_sig, _) => { let pos = if impl_number_args > 0 { impl_number_args - 1 @@ -736,8 +740,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, in impl_m_type_params.zip(trait_m_type_params) { if impl_synthetic != trait_synthetic { - let impl_node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap(); - let impl_span = tcx.hir().span(impl_node_id); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); + let impl_span = tcx.hir().span(impl_hir_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!(tcx.sess, impl_span, @@ -840,7 +844,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match param.kind { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { .. } => { - if param.id == impl_node_id { + if param.hir_id == impl_hir_id { Some(¶m.bounds) } else { None @@ -902,23 +906,23 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Create a parameter environment that represents the implementation's // method. - let impl_c_node_id = tcx.hir().as_local_node_id(impl_c.def_id).unwrap(); + let impl_c_hir_id = tcx.hir().as_local_hir_id(impl_c.def_id).unwrap(); // Compute placeholder form of impl and trait const tys. let impl_ty = tcx.type_of(impl_c.def_id); let trait_ty = tcx.type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs); - let mut cause = ObligationCause::misc(impl_c_span, impl_c_node_id); + let mut cause = ObligationCause::misc(impl_c_span, impl_c_hir_id); // There is no "body" here, so just pass dummy id. let impl_ty = inh.normalize_associated_types_in(impl_c_span, - impl_c_node_id, + impl_c_hir_id, param_env, &impl_ty); debug!("compare_const_impl: impl_ty={:?}", impl_ty); let trait_ty = inh.normalize_associated_types_in(impl_c_span, - impl_c_node_id, + impl_c_hir_id, param_env, &trait_ty); @@ -934,7 +938,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_ty); // Locate the Span containing just the type of the offending impl - match tcx.hir().expect_impl_item(impl_c_node_id).node { + match tcx.hir().expect_impl_item_by_hir_id(impl_c_hir_id).node { ImplItemKind::Const(ref ty, _) => cause.span = ty.span, _ => bug!("{:?} is not a impl const", impl_c), } @@ -946,10 +950,10 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait", trait_c.ident); - let trait_c_node_id = tcx.hir().as_local_node_id(trait_c.def_id); - let trait_c_span = trait_c_node_id.map(|trait_c_node_id| { + let trait_c_hir_id = tcx.hir().as_local_hir_id(trait_c.def_id); + let trait_c_span = trait_c_hir_id.map(|trait_c_hir_id| { // Add a label to the Span containing just the type of the const - match tcx.hir().expect_trait_item(trait_c_node_id).node { + match tcx.hir().expect_trait_item_by_hir_id(trait_c_hir_id).node { TraitItemKind::Const(ref ty, _) => ty.span, _ => bug!("{:?} is not a trait const", trait_c), } @@ -973,7 +977,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return; } - let fcx = FnCtxt::new(&inh, param_env, impl_c_node_id); - fcx.regionck_item(impl_c_node_id, impl_c_span, &[]); + let fcx = FnCtxt::new(&inh, param_env, impl_c_hir_id); + fcx.regionck_item(impl_c_hir_id, impl_c_span, &[]); }); } diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index c0cedd77440d9..11277453230d4 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -2,7 +2,6 @@ use check::FnCtxt; use rustc::infer::InferOk; use rustc::traits::{ObligationCause, ObligationCauseCode}; -use syntax::ast; use syntax::util::parser::PREC_POSTFIX; use syntax_pos::Span; use rustc::hir; @@ -164,7 +163,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { probe::Mode::MethodCall, expected, checked_ty, - ast::DUMMY_NODE_ID); + hir::DUMMY_HIR_ID); methods.retain(|m| { self.has_no_input_arg(m) && self.tcx.get_attrs(m.def_id).iter() @@ -215,16 +214,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let hir::def::Def::Local(id) = path.def { let parent = self.tcx.hir().get_parent_node(id); 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); + })) = self.tcx.hir().find_by_hir_id(parent) { + let parent = self.tcx.hir().get_parent_node(id); if let (Some(Node::Expr(hir::Expr { node: hir::ExprKind::MethodCall(path, span, expr), .. - })), 1) = (self.tcx.hir().find(parent), decl.inputs.len()) { - let self_ty = self.tables.borrow().node_id_to_type(expr[0].hir_id); + })), 1) = (self.tcx.hir().find_by_hir_id(parent), decl.inputs.len()) { + let self_ty = self.tables.borrow().hir_id_to_type(expr[0].hir_id); let self_ty = format!("{:?}", self_ty); let name = path.ident.as_str(); let is_as_ref_able = ( @@ -460,8 +458,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>) -> bool { - let parent_id = self.tcx.hir().get_parent_node(expr.id); - if let Some(parent) = self.tcx.hir().find(parent_id) { + let parent_id = self.tcx.hir().get_parent_node(expr.hir_id); + if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) { // Shouldn't suggest `.into()` on `const`s. if let Node::Item(Item { node: ItemKind::Const(_, _), .. }) = parent { // FIXME(estebank): modify once we decide to suggest `as` casts diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 60b5db0d12cc4..41d35bd3417fb 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -1,5 +1,6 @@ use check::regionck::RegionCtxt; +use hir; use hir::def_id::DefId; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, InferOk, SuppressRegionErrors}; @@ -9,7 +10,6 @@ use rustc::ty::subst::{Subst, Substs, UnpackedKind}; use rustc::ty::{self, Ty, TyCtxt}; use util::common::ErrorReported; -use syntax::ast; use syntax_pos::Span; /// check_drop_impl confirms that the Drop implementation identified by @@ -70,7 +70,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>( drop_impl_ty: Ty<'tcx>, self_type_did: DefId, ) -> Result<(), ErrorReported> { - let drop_impl_node_id = tcx.hir().as_local_node_id(drop_impl_did).unwrap(); + let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did).unwrap(); // check that the impl type can be made to match the trait type. @@ -85,7 +85,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>( let fresh_impl_substs = infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did); let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs); - let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id); + let cause = &ObligationCause::misc(drop_impl_span, drop_impl_hir_id); match infcx .at(cause, impl_param_env) .eq(named_type, fresh_impl_self_ty) @@ -184,7 +184,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // absent. So we report an error that the Drop impl injected a // predicate that is not present on the struct definition. - let self_type_node_id = tcx.hir().as_local_node_id(self_type_did).unwrap(); + let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap(); let drop_impl_span = tcx.def_span(drop_impl_did); @@ -216,7 +216,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // repeated `contains` calls. if !assumptions_in_impl_context.contains(&predicate) { - let item_span = tcx.hir().span(self_type_node_id); + let item_span = tcx.hir().span(self_type_hir_id); struct_span_err!( tcx.sess, drop_impl_span, @@ -292,7 +292,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>( rcx: &mut RegionCtxt<'a, 'gcx, 'tcx>, ty: Ty<'tcx>, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, scope: region::Scope, ) -> Result<(), ErrorReported> { debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}", diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 143715dff813b..e90a62514db46 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -22,7 +22,7 @@ fn equate_intrinsic_type<'a, 'tcx>( inputs: Vec>, output: Ty<'tcx>, ) { - let def_id = tcx.hir().local_def_id(it.id); + let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); match it.node { hir::ForeignItemKind::Fn(..) => {} @@ -58,7 +58,7 @@ fn equate_intrinsic_type<'a, 'tcx>( safety, abi ))); - let cause = ObligationCause::new(it.span, it.id, ObligationCauseCode::IntrinsicType); + let cause = ObligationCause::new(it.span, it.hir_id, ObligationCauseCode::IntrinsicType); require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty); } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 02687df6a94fc..32817893372dc 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn method_exists(&self, method_name: ast::Ident, self_ty: Ty<'tcx>, - call_expr_id: ast::NodeId, + call_expr_id: hir::HirId, allow_private: bool) -> bool { let mode = probe::Mode::MethodCall; @@ -131,7 +131,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { msg: &str, method_name: ast::Ident, self_ty: Ty<'tcx>, - call_expr_id: ast::NodeId, + call_expr_id: hir::HirId, ) { let has_params = self .probe_for_name( @@ -202,7 +202,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .unwrap().insert(import_def_id); } - self.tcx.check_stability(pick.item.def_id, Some(call_expr.id), span); + self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span); let result = self.confirm_method( span, @@ -255,7 +255,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let mode = probe::Mode::MethodCall; let self_ty = self.resolve_type_vars_if_possible(&self_ty); self.probe_for_name(span, mode, method_name, IsSuggestion(false), - self_ty, call_expr.id, scope) + self_ty, call_expr.hir_id, scope) } /// `lookup_method_in_trait` is used for overloaded operators. @@ -399,7 +399,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span: Span, method_name: ast::Ident, self_ty: Ty<'tcx>, - expr_id: ast::NodeId + expr_id: hir::HirId ) -> Result> { debug!( "resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}", diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 9a828ce01775c..6190f47bfbf35 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -178,9 +178,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { mode: Mode, return_type: Ty<'tcx>, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId) + scope_expr_id: hir::HirId) -> Vec { - debug!("probe(self_ty={:?}, return_type={}, scope_expr_id={})", + debug!("probe(self_ty={:?}, return_type={}, scope_expr_id={:?})", self_ty, return_type, scope_expr_id); @@ -207,10 +207,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { item_name: ast::Ident, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId, + scope_expr_id: hir::HirId, scope: ProbeScope) -> PickResult<'tcx> { - debug!("probe(self_ty={:?}, item_name={}, scope_expr_id={})", + debug!("probe(self_ty={:?}, item_name={}, scope_expr_id={:?})", self_ty, item_name, scope_expr_id); @@ -232,7 +232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { return_type: Option>, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId, + scope_expr_id: hir::HirId, scope: ProbeScope, op: OP) -> Result> @@ -370,7 +370,7 @@ fn method_autoderef_steps<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| { let ParamEnvAnd { param_env, value: self_ty } = goal; - let mut autoderef = Autoderef::new(infcx, param_env, ast::DUMMY_NODE_ID, DUMMY_SP, self_ty) + let mut autoderef = Autoderef::new(infcx, param_env, hir::DUMMY_HIR_ID, DUMMY_SP, self_ty) .include_raw_pointers() .silence_errors(); let mut reached_raw_pointer = false; @@ -781,13 +781,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } fn assemble_extension_candidates_for_traits_in_scope(&mut self, - expr_id: ast::NodeId) + expr_hir_id: hir::HirId) -> Result<(), MethodError<'tcx>> { - if expr_id == ast::DUMMY_NODE_ID { + if expr_hir_id == hir::DUMMY_HIR_ID { return Ok(()) } let mut duplicates = FxHashSet::default(); - let expr_hir_id = self.tcx.hir().node_to_hir_id(expr_id); let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id); if let Some(applicable_traits) = opt_applicable_traits { for trait_candidate in applicable_traits.iter() { @@ -1371,7 +1370,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { steps, IsSuggestion(true)); pcx.allow_similar_names = true; pcx.assemble_inherent_candidates(); - pcx.assemble_extension_candidates_for_traits_in_scope(ast::DUMMY_NODE_ID)?; + pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)?; let method_names = pcx.candidate_method_names(); pcx.allow_similar_names = false; @@ -1381,7 +1380,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { pcx.reset(); pcx.method_name = Some(method_name); pcx.assemble_inherent_candidates(); - pcx.assemble_extension_candidates_for_traits_in_scope(ast::DUMMY_NODE_ID) + pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID) .ok().map_or(None, |_| { pcx.pick_core() .and_then(|pick| pick.ok()) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 23bcd88d6afb5..eb2aeeca1af5c 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -251,14 +251,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ExprKind::Path(ref qpath) => { // local binding if let &QPath::Resolved(_, ref path) = &qpath { - if let hir::def::Def::Local(node_id) = path.def { - let span = tcx.hir().span(node_id); + if let hir::def::Def::Local(hir_id) = path.def { + let span = tcx.hir().span(hir_id); let snippet = tcx.sess.source_map().span_to_snippet(span) .unwrap(); let filename = tcx.sess.source_map().span_to_filename(span); - let parent_node = self.tcx.hir().get( - self.tcx.hir().get_parent_node(node_id), + let parent_node = self.tcx.hir().get_by_hir_id( + self.tcx.hir().get_parent_node(hir_id), ); let msg = format!( "you must specify a type for this binding, like `{}`", @@ -344,7 +344,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let field_ty = field.ty(tcx, substs); - let scope = self.tcx.hir().get_module_parent(self.body_id); + let scope = self.tcx.hir().get_module_parent( + self.body_id); if field.vis.is_accessible_from(scope, self.tcx) { if self.is_fn_ty(&field_ty, span) { err.help(&format!("use `({0}.{1})(...)` if you \ @@ -493,9 +494,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { mut msg: String, candidates: Vec) { let module_did = self.tcx.hir().get_module_parent(self.body_id); - let module_id = self.tcx.hir().as_local_node_id(module_did).unwrap(); + let module_hid = self.tcx.hir().as_local_hir_id(module_did).unwrap(); let krate = self.tcx.hir().krate(); - let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); + let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_hid); if let Some(span) = span { let path_strings = candidates.iter().map(|did| { // Produce an additional newline to separate the new use statement @@ -728,7 +729,7 @@ fn compute_all_traits<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Vec impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> { fn visit_item(&mut self, i: &'v hir::Item) { if let hir::ItemKind::Trait(..) = i.node { - let def_id = self.map.local_def_id(i.id); + let def_id = self.map.local_def_id_from_hir_id(i.hir_id); self.traits.push(def_id); } } @@ -785,7 +786,7 @@ pub fn provide(providers: &mut ty::query::Providers) { } struct UsePlacementFinder<'a, 'tcx: 'a, 'gcx: 'tcx> { - target_module: ast::NodeId, + target_module: hir::HirId, span: Option, found_use: bool, tcx: TyCtxt<'a, 'gcx, 'tcx> @@ -795,7 +796,7 @@ impl<'a, 'tcx, 'gcx> UsePlacementFinder<'a, 'tcx, 'gcx> { fn check( tcx: TyCtxt<'a, 'gcx, 'tcx>, krate: &'tcx hir::Crate, - target_module: ast::NodeId, + target_module: hir::HirId, ) -> (Option, bool) { let mut finder = UsePlacementFinder { target_module, @@ -813,13 +814,13 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, ' &mut self, module: &'tcx hir::Mod, _: Span, - node_id: ast::NodeId, + hir_id: hir::HirId, ) { if self.span.is_some() { return; } - if node_id != self.target_module { - hir::intravisit::walk_mod(self, module, node_id); + if hir_id != self.target_module { + hir::intravisit::walk_mod(self, module, hir_id); return; } // Find a `use` statement. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1b07385d4d1f4..ab8cd64c1f551 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -137,7 +137,7 @@ use TypeAndSubsts; use lint; use util::captures::Captures; use util::common::{ErrorReported, indenter}; -use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap}; +use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap}; pub use self::Expectation::*; use self::autoderef::Autoderef; @@ -194,7 +194,7 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { tables: MaybeInProgressTables<'a, 'tcx>, - locals: RefCell>>, + locals: RefCell>>, fulfillment_cx: RefCell>>, @@ -388,14 +388,14 @@ impl Needs { #[derive(Copy, Clone)] pub struct UnsafetyState { - pub def: ast::NodeId, + pub def: hir::HirId, pub unsafety: hir::Unsafety, pub unsafe_push_count: u32, from_fn: bool } impl UnsafetyState { - pub fn function(unsafety: hir::Unsafety, def: ast::NodeId) -> UnsafetyState { + pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> UnsafetyState { UnsafetyState { def: def, unsafety: unsafety, unsafe_push_count: 0, from_fn: true } } @@ -410,11 +410,11 @@ impl UnsafetyState { unsafety => { let (unsafety, def, count) = match blk.rules { hir::PushUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_add(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap()), hir::PopUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_sub(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap()), hir::UnsafeBlock(..) => - (hir::Unsafety::Unsafe, blk.id, self.unsafe_push_count), + (hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count), hir::DefaultBlock => (unsafety, self.def, self.unsafe_push_count), }; @@ -497,20 +497,20 @@ pub struct BreakableCtxt<'gcx: 'tcx, 'tcx> { pub struct EnclosingBreakables<'gcx: 'tcx, 'tcx> { stack: Vec>, - by_id: NodeMap, + by_id: HirIdMap, } impl<'gcx, 'tcx> EnclosingBreakables<'gcx, 'tcx> { - fn find_breakable(&mut self, target_id: ast::NodeId) -> &mut BreakableCtxt<'gcx, 'tcx> { + fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'gcx, 'tcx> { let ix = *self.by_id.get(&target_id).unwrap_or_else(|| { - bug!("could not find enclosing breakable with id {}", target_id); + bug!("could not find enclosing breakable with id {:?}", target_id); }); &mut self.stack[ix] } } pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { - body_id: ast::NodeId, + body_id: hir::HirId, /// The parameter environment used for proving trait obligations /// in this function. This can change when we descend into @@ -619,7 +619,7 @@ impl<'a, 'gcx, 'tcx> InheritedBuilder<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self { let tcx = infcx.tcx; - let item_id = tcx.hir().as_local_node_id(def_id); + let item_id = tcx.hir().as_local_hir_id(def_id); let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(id)); let implicit_region_bound = body_id.map(|body_id| { let body = tcx.hir().body(body_id); @@ -672,7 +672,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { fn normalize_associated_types_in(&self, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T) -> T where T : TypeFoldable<'tcx> @@ -810,6 +810,47 @@ fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } +fn primary_body_of_by_hir_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: hir::HirId) + -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> +{ + match tcx.hir().get_by_hir_id(id) { + Node::Item(item) => { + match item.node { + hir::ItemKind::Const(_, body) | + hir::ItemKind::Static(_, _, body) => + Some((body, None)), + hir::ItemKind::Fn(ref decl, .., body) => + Some((body, Some(decl))), + _ => + None, + } + } + Node::TraitItem(item) => { + match item.node { + hir::TraitItemKind::Const(_, Some(body)) => + Some((body, None)), + hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => + Some((body, Some(&sig.decl))), + _ => + None, + } + } + Node::ImplItem(item) => { + match item.node { + hir::ImplItemKind::Const(_, body) => + Some((body, None)), + hir::ImplItemKind::Method(ref sig, body) => + Some((body, Some(&sig.decl))), + _ => + None, + } + } + Node::AnonConst(constant) => Some((constant.body, None)), + _ => None, + } +} + fn has_typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool { @@ -840,11 +881,11 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return tcx.typeck_tables_of(outer_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().local_def_id_to_hir_id(def_id.to_local()); let span = tcx.hir().span(id); // Figure out what primary body this item has. - let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| { + let (body_id, fn_decl) = primary_body_of_by_hir_id(tcx, id).unwrap_or_else(|| { span_bug!(span, "can't type-check body of {:?}", def_id); }); let body = tcx.hir().body(body_id); @@ -861,14 +902,14 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.liberate_late_bound_regions(def_id, &fn_sig); let fn_sig = inh.normalize_associated_types_in(body.value.span, - body_id.node_id, + id, param_env, &fn_sig); let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None).0; fcx } else { - let fcx = FnCtxt::new(&inh, param_env, body.value.id); + let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); let expected_type = tcx.type_of(def_id); let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type); fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized); @@ -926,7 +967,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Consistency check our TypeckTables instance can hold all ItemLocalIds // it will need to hold. assert_eq!(tables.local_id_root, - Some(DefId::local(tcx.hir().definitions().node_to_hir_id(id).owner))); + Some(DefId::local(id.owner))); tables } @@ -939,16 +980,16 @@ fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) { struct GatherLocalsVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, - parent_id: ast::NodeId, + parent_id: hir::HirId, } impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> { - fn assign(&mut self, span: Span, nid: ast::NodeId, ty_opt: Option>) -> Ty<'tcx> { + fn assign(&mut self, span: Span, hid: hir::HirId, ty_opt: Option>) -> Ty<'tcx> { match ty_opt { None => { // infer the variable's type let var_ty = self.fcx.next_ty_var(TypeVariableOrigin::TypeInference(span)); - self.fcx.locals.borrow_mut().insert(nid, LocalTy { + self.fcx.locals.borrow_mut().insert(hid, LocalTy { decl_ty: var_ty, revealed_ty: var_ty }); @@ -956,7 +997,7 @@ impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> { } Some(typ) => { // take type that the user specified - self.fcx.locals.borrow_mut().insert(nid, typ); + self.fcx.locals.borrow_mut().insert(hid, typ); typ.revealed_ty } } @@ -994,29 +1035,29 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> { }, None => None, }; - self.assign(local.span, local.id, local_ty); + self.assign(local.span, local.hir_id, local_ty); debug!("Local variable {:?} is assigned type {}", local.pat, self.fcx.ty_to_string( - self.fcx.locals.borrow().get(&local.id).unwrap().clone().decl_ty)); + self.fcx.locals.borrow().get(&local.hir_id).unwrap().clone().decl_ty)); intravisit::walk_local(self, local); } // Add pattern bindings. fn visit_pat(&mut self, p: &'gcx hir::Pat) { if let PatKind::Binding(_, _, ident, _) = p.node { - let var_ty = self.assign(p.span, p.id, None); + let var_ty = self.assign(p.span, p.hir_id, None); if !self.fcx.tcx.features().unsized_locals { self.fcx.require_type_is_sized(var_ty, p.span, - traits::VariableType(p.id)); + traits::VariableType(p.hir_id)); } debug!("Pattern binding {} is assigned to {} with type {:?}", ident, self.fcx.ty_to_string( - self.fcx.locals.borrow().get(&p.id).unwrap().clone().decl_ty), + self.fcx.locals.borrow().get(&p.hir_id).unwrap().clone().decl_ty), var_ty); } intravisit::walk_pat(self, p); @@ -1024,7 +1065,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> { // Don't descend into the bodies of nested closures fn visit_fn(&mut self, _: intravisit::FnKind<'gcx>, _: &'gcx hir::FnDecl, - _: hir::BodyId, _: Span, _: ast::NodeId) { } + _: hir::BodyId, _: Span, _: hir::HirId) { } } /// When `check_fn` is invoked on a generator (i.e., a body that @@ -1051,18 +1092,18 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, fn_sig: ty::FnSig<'tcx>, decl: &'gcx hir::FnDecl, - fn_id: ast::NodeId, + fn_id: hir::HirId, body: &'gcx hir::Body, can_be_generator: Option) -> (FnCtxt<'a, 'gcx, 'tcx>, Option>) { let mut fn_sig = fn_sig.clone(); - debug!("check_fn(sig={:?}, fn_id={}, param_env={:?})", fn_sig, fn_id, param_env); + debug!("check_fn(sig={:?}, fn_id={:?}, param_env={:?})", fn_sig, fn_id, param_env); // Create the function context. This is either derived from scratch or, // in the case of closures, based on the outer context. - let mut fcx = FnCtxt::new(inherited, param_env, body.value.id); + let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id); *fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id); let declared_ret_ty = fn_sig.output(); @@ -1085,9 +1126,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.yield_ty = Some(yield_ty); } - let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id(fn_id)); - let outer_node_id = fcx.tcx.hir().as_local_node_id(outer_def_id).unwrap(); - GatherLocalsVisitor { fcx: &fcx, parent_id: outer_node_id, }.visit_body(body); + GatherLocalsVisitor { fcx: &fcx, parent_id: fn_id, }.visit_body(body); // Add formal parameters. for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) { @@ -1110,8 +1149,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.write_ty(arg.hir_id, arg_ty); } - let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); - inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig); + inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); fcx.check_return_expr(&body.value); @@ -1182,7 +1220,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !` if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { - if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) { + if panic_impl_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { // at this point we don't care if there are duplicate handlers or if the handler has // the wrong signature as this value we'll be used when writing metadata and that @@ -1218,7 +1256,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1240,7 +1278,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !` if let Some(alloc_error_handler_did) = fcx.tcx.lang_items().oom() { - if alloc_error_handler_did == fcx.tcx.hir().local_def_id(fn_id) { + if alloc_error_handler_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(alloc_layout_did) = fcx.tcx.lang_items().alloc_layout() { if declared_ret_ty.sty != ty::Never { fcx.tcx.sess.span_err( @@ -1266,7 +1304,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1291,9 +1329,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: ast::NodeId, + id: hir::HirId, span: Span) { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); @@ -1307,9 +1345,9 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: ast::NodeId, + id: hir::HirId, span: Span) { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); @@ -1340,28 +1378,28 @@ fn check_opaque<'a, 'tcx>( pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item) { debug!( - "check_item_type(it.id={}, it.name={})", - it.id, - tcx.item_path_str(tcx.hir().local_def_id(it.id)) + "check_item_type(it.hir_id={:?}, it.name={})", + it.hir_id, + tcx.item_path_str(tcx.hir().local_def_id_from_hir_id(it.hir_id)) ); let _indenter = indenter(); match it.node { // Consts can play a role in type-checking, so they are included here. hir::ItemKind::Static(..) => { - let def_id = tcx.hir().local_def_id(it.id); + let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); tcx.typeck_tables_of(def_id); maybe_check_static_with_link_section(tcx, def_id, it.span); } hir::ItemKind::Const(..) => { - tcx.typeck_tables_of(tcx.hir().local_def_id(it.id)); + tcx.typeck_tables_of(tcx.hir().local_def_id_from_hir_id(it.hir_id)); } hir::ItemKind::Enum(ref enum_definition, _) => { - check_enum(tcx, it.span, &enum_definition.variants, it.id); + check_enum(tcx, it.span, &enum_definition.variants, it.hir_id); } hir::ItemKind::Fn(..) => {} // entirely within check_item_body hir::ItemKind::Impl(.., ref impl_item_refs) => { - debug!("ItemKind::Impl {} with id {}", it.ident, it.id); - let impl_def_id = tcx.hir().local_def_id(it.id); + debug!("ItemKind::Impl {} with id {:?}", it.ident, it.hir_id); + let impl_def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) { check_impl_items_against_trait( tcx, @@ -1375,17 +1413,17 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite } } hir::ItemKind::Trait(..) => { - let def_id = tcx.hir().local_def_id(it.id); + let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); check_on_unimplemented(tcx, def_id, it); } hir::ItemKind::Struct(..) => { - check_struct(tcx, it.id, it.span); + check_struct(tcx, it.hir_id, it.span); } hir::ItemKind::Union(..) => { - check_union(tcx, it.id, it.span); + check_union(tcx, it.hir_id, it.span); } hir::ItemKind::Existential(..) => { - let def_id = tcx.hir().local_def_id(it.id); + let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); let pty_ty = tcx.type_of(def_id); let generics = tcx.generics_of(def_id); @@ -1394,7 +1432,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite check_opaque(tcx, def_id, substs, it.span); } hir::ItemKind::Ty(..) => { - let def_id = tcx.hir().local_def_id(it.id); + let def_id = tcx.hir().local_def_id_from_hir_id(it.hir_id); let pty_ty = tcx.type_of(def_id); let generics = tcx.generics_of(def_id); check_bounds_are_used(tcx, &generics, pty_ty); @@ -1412,7 +1450,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite } } else { for item in &m.items { - let generics = tcx.generics_of(tcx.hir().local_def_id(item.id)); + let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(item.hir_id)); if generics.params.len() - generics.own_counts().lifetimes != 0 { let mut err = struct_span_err!( tcx.sess, @@ -1481,7 +1519,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt, id: DefId, span: Span) { fn check_on_unimplemented<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_def_id: DefId, item: &hir::Item) { - let item_def_id = tcx.hir().local_def_id(item.id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); // an error would be reported if this fails. let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id); } @@ -1559,7 +1597,8 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Check existing impl methods to see if they are both present in trait // and compatible with trait signature for impl_item in impl_items() { - let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.id)); + let ty_impl_item = tcx.associated_item( + tcx.hir().local_def_id_from_hir_id(impl_item.hir_id)); let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id) .find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) && tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id)) @@ -1846,8 +1885,8 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, vs: &'tcx [hir::Variant], - id: ast::NodeId) { - let def_id = tcx.hir().local_def_id(id); + id: hir::HirId) { + let def_id = tcx.hir().local_def_id_from_hir_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated @@ -1875,7 +1914,7 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for v in vs { if let Some(ref e) = v.node.disr_expr { - tcx.typeck_tables_of(tcx.hir().local_def_id(e.id)); + tcx.typeck_tables_of(tcx.hir().local_def_id_from_hir_id(e.hir_id)); } } @@ -1884,14 +1923,14 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Check for duplicate discriminant values if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) { let variant_did = def.variants[VariantIdx::new(i)].did; - let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap(); - let variant_i = tcx.hir().expect_variant(variant_i_node_id); + let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap(); + let variant_i = tcx.hir().expect_variant(variant_i_hir_id); let i_span = match variant_i.node.disr_expr { - Some(ref expr) => tcx.hir().span(expr.id), - None => tcx.hir().span(variant_i_node_id) + Some(ref expr) => tcx.hir().span(expr.hir_id), + None => tcx.hir().span(variant_i_hir_id) }; let span = match v.node.disr_expr { - Some(ref expr) => tcx.hir().span(expr.id), + Some(ref expr) => tcx.hir().span(expr.hir_id), None => v.span }; struct_span_err!(tcx.sess, span, E0081, @@ -1923,9 +1962,9 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { -> Lrc> { let tcx = self.tcx; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item_id = tcx.hir().ty_param_owner(node_id); - let item_def_id = tcx.hir().local_def_id(item_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item_id = tcx.hir().ty_param_owner(hir_id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; Lrc::new(ty::GenericPredicates { @@ -2023,7 +2062,7 @@ enum TupleArgumentsFlag { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId) + body_id: hir::HirId) -> FnCtxt<'a, 'gcx, 'tcx> { FnCtxt { body_id, @@ -2033,7 +2072,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ret_coercion_span: RefCell::new(None), yield_ty: None, ps: RefCell::new(UnsafetyState::function(hir::Unsafety::Normal, - ast::CRATE_NODE_ID)), + hir::CRATE_HIR_ID)), diverges: Cell::new(Diverges::Maybe), has_errors: Cell::new(false), enclosing_breakables: RefCell::new(EnclosingBreakables { @@ -2054,7 +2093,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Produce warning on the given node, if the current point in the /// function is unreachable, and there hasn't been another warning. - fn warn_if_unreachable(&self, id: ast::NodeId, span: Span, kind: &str) { + fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) { if self.diverges.get() == Diverges::Always { self.diverges.set(Diverges::WarnedAlways); @@ -2129,10 +2168,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { format!("{:?}", self_ptr) } - pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> LocalTy<'tcx> { - self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| + pub fn local_ty(&self, span: Span, hid: hir::HirId) -> LocalTy<'tcx> { + self.locals.borrow().get(&hid).cloned().unwrap_or_else(|| span_bug!(span, "no type for local variable {}", - self.tcx.hir().node_to_string(nid)) + self.tcx.hir().hir_to_string(hid)) ) } @@ -2148,8 +2187,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - pub fn write_field_index(&self, node_id: ast::NodeId, index: usize) { - let hir_id = self.tcx.hir().node_to_hir_id(node_id); + pub fn write_field_index(&self, hir_id: hir::HirId, index: usize) { self.tables.borrow_mut().field_indices_mut().insert(hir_id, index); } @@ -2342,10 +2380,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// `InferCtxt::instantiate_opaque_types` for more details. fn instantiate_opaque_types_from_value>( &self, - parent_id: ast::NodeId, + parent_id: hir::HirId, value: &T, ) -> T { - let parent_def_id = self.tcx.hir().local_def_id(parent_id); + let parent_def_id = self.tcx.hir().local_def_id_from_hir_id(parent_id); debug!("instantiate_opaque_types_from_value(parent_def_id={:?}, value={:?})", parent_def_id, value); @@ -2453,9 +2491,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Some(&t) => t, None if self.is_tainted_by_errors() => self.tcx.types.err, None => { - let node_id = self.tcx.hir().hir_to_node_id(id); - bug!("no type for node {}: {} in fcx {}", - node_id, self.tcx.hir().node_to_string(node_id), + bug!("no type for node {:?}: {} in fcx {}", + id, self.tcx.hir().hir_to_string(id), self.tag()); } } @@ -3005,7 +3042,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Closure arguments themselves can't be diverging, but // a previous argument can, e.g., `foo(panic!(), || {})`. if !check_closures { - self.warn_if_unreachable(arg.id, arg.span, "expression"); + self.warn_if_unreachable(arg.hir_id, arg.span, "expression"); } let is_closure = match arg.node { @@ -3335,7 +3372,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ret_coercion.borrow_mut() .coerce(self, &self.cause(return_expr.span, - ObligationCauseCode::ReturnType(return_expr.id)), + ObligationCauseCode::ReturnType(return_expr.hir_id)), return_expr, return_expr_ty); } @@ -3506,13 +3543,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let field_ty = self.field_ty(expr.span, field, substs); // Save the index of all fields regardless of their visibility in case // of error recovery. - self.write_field_index(expr.id, index); + self.write_field_index(expr.hir_id, index); if field.vis.is_accessible_from(def_scope, self.tcx) { let adjustments = autoderef.adjust_steps(self, needs); self.apply_adjustments(base, adjustments); autoderef.finalize(self); - self.tcx.check_stability(field.did, Some(expr.id), expr.span); + self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span); return field_ty; } private_candidate = Some((base_def.did, field_ty)); @@ -3527,7 +3564,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.apply_adjustments(base, adjustments); autoderef.finalize(self); - self.write_field_index(expr.id, index); + self.write_field_index(expr.hir_id, index); return field_ty; } } @@ -3544,31 +3581,33 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { "field `{}` of struct `{}` is private", field, struct_path); // Also check if an accessible method exists, which is often what is meant. - if self.method_exists(field, expr_t, expr.id, false) && !self.expr_in_place(expr.id) { + if self.method_exists(field, expr_t, expr.hir_id, false) && + !self.expr_in_place(expr.hir_id) + { self.suggest_method_call( &mut err, &format!("a method `{}` also exists, call it with parentheses", field), field, expr_t, - expr.id, + expr.hir_id, ); } err.emit(); field_ty } else if field.name == keywords::Invalid.name() { self.tcx().types.err - } else if self.method_exists(field, expr_t, expr.id, true) { + } else if self.method_exists(field, expr_t, expr.hir_id, true) { let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0615, "attempted to take value of method `{}` on type `{}`", field, expr_t); - if !self.expr_in_place(expr.id) { + if !self.expr_in_place(expr.hir_id) { self.suggest_method_call( &mut err, "use parentheses to call the method", field, expr_t, - expr.id + expr.hir_id ); } else { err.help("methods are immutable and cannot be assigned to"); @@ -3608,7 +3647,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ) { let base = self.tcx.sess.source_map() .span_to_snippet(base.span) - .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id)); + .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string_by_hir_id( + base.hir_id)); let help = "instead of using tuple indexing, use array indexing"; let suggestion = format!("{}[{}]", base, field); let applicability = if len < user_index { @@ -3624,7 +3664,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty::RawPtr(..) => { let base = self.tcx.sess.source_map() .span_to_snippet(base.span) - .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id)); + .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string_by_hir_id( + base.hir_id)); let msg = format!("`{}` is a raw pointer; try dereferencing it", base); let suggestion = format!("(*{}).{}", base, field); err.span_suggestion_with_applicability( @@ -3749,7 +3790,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_expr_struct_fields(&self, adt_ty: Ty<'tcx>, expected: Expectation<'tcx>, - expr_id: ast::NodeId, + expr_id: hir::HirId, span: Span, variant: &'tcx ty::VariantDef, ast_fields: &'gcx [hir::Field], @@ -3782,7 +3823,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let ident = tcx.adjust_ident(field.ident, variant.did, self.body_id).0; let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) { seen_fields.insert(ident, field.span); - self.write_field_index(field.id, i); + self.write_field_index(field.hir_id, i); // We don't look at stability attributes on // struct-like enums (yet...), but it's definitely not @@ -3870,13 +3911,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn check_struct_path(&self, qpath: &QPath, - node_id: ast::NodeId) + hir_id: hir::HirId) -> Option<(&'tcx ty::VariantDef, Ty<'tcx>)> { let path_span = match *qpath { QPath::Resolved(_, ref path) => path.span, QPath::TypeRelative(ref qself, _) => qself.span }; - let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, node_id); + let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); let variant = match def { Def::Err => { self.set_tainted_by_errors(); @@ -3904,7 +3945,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some((variant, did, substs)) = variant { debug!("check_struct_path: did={:?} substs={:?}", did, substs); - let hir_id = self.tcx.hir().node_to_hir_id(node_id); self.write_user_type_annotation_from_substs(hir_id, did, substs, None); // Check bounds on type arguments used in the path. @@ -3933,7 +3973,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { // Find the relevant variant let (variant, adt_ty) = - if let Some(variant_ty) = self.check_struct_path(qpath, expr.id) { + if let Some(variant_ty) = self.check_struct_path(qpath, expr.hir_id) { variant_ty } else { self.check_struct_fields_on_error(fields, base_expr); @@ -3953,7 +3993,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { adt.variant_descr()); } - let error_happened = self.check_expr_struct_fields(adt_ty, expected, expr.id, path_span, + let error_happened = self.check_expr_struct_fields(adt_ty, expected, expr.hir_id, path_span, variant, fields, base_expr.is_none()); if let &Some(ref base_expr) = base_expr { // If check_expr_struct_fields hit an error, do not attempt to populate @@ -4002,7 +4042,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expr, expected); // Warn for expressions after diverging siblings. - self.warn_if_unreachable(expr.id, expr.span, "expression"); + self.warn_if_unreachable(expr.hir_id, expr.span, "expression"); // Hide the outer diverging and has_errors flags. let old_diverges = self.diverges.get(); @@ -4018,7 +4058,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ExprKind::Loop(..) | ExprKind::While(..) | ExprKind::If(..) | ExprKind::Match(..) => {} - _ => self.warn_if_unreachable(expr.id, expr.span, "expression") + _ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression") } // Any expression that produces a value of type `!` must have diverged @@ -4035,7 +4075,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.diverges.set(self.diverges.get() | old_diverges); self.has_errors.set(self.has_errors.get() | old_has_errors); - debug!("type of {} is...", self.tcx.hir().node_to_string(expr.id)); + debug!("type of {:?} is...", self.tcx.hir().hir_to_string(expr.hir_id)); debug!("... {:?}, expected is {:?}", ty, expected); ty @@ -4055,7 +4095,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ); let tcx = self.tcx; - let id = expr.id; + let id = expr.hir_id; match expr.node { ExprKind::Box(ref subexpr) => { let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| { @@ -4187,7 +4227,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } ExprKind::Path(ref qpath) => { - let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.id, expr.span); + let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.hir_id, + expr.span); let ty = match def { Def::Err => { self.set_tainted_by_errors(); @@ -4253,12 +4294,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ExprKind::Break(destination, ref expr_opt) => { if let Ok(target_id) = destination.target_id { let (e_ty, cause); + let target_hir_id = tcx.hir().node_to_hir_id(target_id); if let Some(ref e) = *expr_opt { // If this is a break with a value, we need to type-check // the expression. Get an expected type from the loop context. let opt_coerce_to = { let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - enclosing_breakables.find_breakable(target_id) + enclosing_breakables.find_breakable(target_hir_id) .coerce .as_ref() .map(|coerce| coerce.expected_ty()) @@ -4283,7 +4325,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // the `enclosing_loops` field and let's coerce the // type of `expr_opt` into what is expected. let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - let ctxt = enclosing_breakables.find_breakable(target_id); + let ctxt = enclosing_breakables.find_breakable(target_hir_id); if let Some(ref mut coerce) = ctxt.coerce { if let Some(ref e) = *expr_opt { coerce.coerce(self, &cause, e, e_ty); @@ -4353,7 +4395,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let mut coercion = self.ret_coercion.as_ref().unwrap().borrow_mut(); *self.ret_coercion_span.borrow_mut() = Some(expr.span); let cause = self.cause(expr.span, ObligationCauseCode::ReturnNoExpression); - if let Some((fn_decl, _)) = self.get_fn_decl(expr.id) { + if let Some((fn_decl, _)) = self.get_fn_decl(expr.hir_id) { coercion.coerce_forced_unit( self, &cause, @@ -4415,7 +4457,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, // Will get updated if/when we find a `break`. }; - let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(expr.hir_id, ctxt, || { self.check_expr_has_type_or_error(&cond, tcx.types.bool); let cond_diverging = self.diverges.get(); self.check_block_no_value(&body); @@ -4451,7 +4493,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, // Will get updated if/when we find a `break`. }; - let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(expr.hir_id, ctxt, || { self.check_block_no_value(&body); }); @@ -4542,7 +4584,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { tcx.mk_array(element_ty, args.len() as u64) } ExprKind::Repeat(ref element, ref count) => { - let count_def_id = tcx.hir().local_def_id(count.id); + let count_def_id = tcx.hir().local_def_id_from_hir_id(count.hir_id); let param_env = ty::ParamEnv::empty(); let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id); let instance = ty::Instance::resolve( @@ -4707,7 +4749,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn finish_resolving_struct_path(&self, qpath: &QPath, path_span: Span, - node_id: ast::NodeId) + hir_id: hir::HirId) -> (Def, Ty<'tcx>) { match *qpath { @@ -4724,11 +4766,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else { Def::Err }; - let (ty, def) = AstConv::associated_path_def_to_ty(self, node_id, path_span, + let (ty, def) = AstConv::associated_path_def_to_ty(self, hir_id, path_span, ty, def, segment); // Write back the new resolution. - let hir_id = self.tcx.hir().node_to_hir_id(node_id); self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, def); (def, ty) @@ -4740,11 +4781,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // The newly resolved definition is written into `type_dependent_defs`. pub fn resolve_ty_and_def_ufcs<'b>(&self, qpath: &'b QPath, - node_id: ast::NodeId, + hir_id: hir::HirId, span: Span) -> (Def, Option>, &'b [hir::PathSegment]) { - debug!("resolve_ty_and_def_ufcs: qpath={:?} node_id={:?} span={:?}", qpath, node_id, span); + debug!("resolve_ty_and_def_ufcs: qpath={:?} hir_id={:?} span={:?}", qpath, hir_id, span); let (ty, qself, item_segment) = match *qpath { QPath::Resolved(ref opt_qself, ref path) => { return (path.def, @@ -4755,14 +4796,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { (self.to_ty(qself), qself, segment) } }; - let hir_id = self.tcx.hir().node_to_hir_id(node_id); if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) { // Return directly on cache hit. This is useful to avoid doubly reporting // errors with default match binding modes. See #44614. return (*cached_def, Some(ty), slice::from_ref(&**item_segment)) } let item_name = item_segment.ident; - let def = match self.resolve_ufcs(span, item_name, ty, node_id) { + let def = match self.resolve_ufcs(span, item_name, ty, hir_id) { Ok(def) => def, Err(error) => { let def = match error { @@ -4796,7 +4836,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // See #44848. let ref_bindings = local.pat.contains_explicit_ref_binding(); - let local_ty = self.local_ty(init.span, local.id).revealed_ty; + let local_ty = self.local_ty(init.span, local.hir_id).revealed_ty; if let Some(m) = ref_bindings { // Somewhat subtle: if we have a `ref` binding in the pattern, // we want to avoid introducing coercions for the RHS. This is @@ -4815,7 +4855,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } pub fn check_decl_local(&self, local: &'gcx hir::Local) { - let t = self.local_ty(local.span, local.id).decl_ty; + let t = self.local_ty(local.span, local.hir_id).decl_ty; self.write_ty(local.hir_id, t); if let Some(ref init) = local.init { @@ -4840,7 +4880,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) { // Don't do all the complex logic below for `DeclItem`. match stmt.node { - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { if let hir::DeclKind::Item(_) = decl.node { return } @@ -4848,7 +4888,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {} } - self.warn_if_unreachable(stmt.node.id(), stmt.span, "statement"); + self.warn_if_unreachable(stmt.node.hir_id(), stmt.span, "statement"); // Hide the outer diverging and `has_errors` flags. let old_diverges = self.diverges.get(); @@ -4857,7 +4897,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.has_errors.set(false); match stmt.node { - hir::StmtKind::Decl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, ..) => { match decl.node { hir::DeclKind::Local(ref l) => { self.check_decl_local(&l); @@ -4866,11 +4906,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::DeclKind::Item(_) => () } } - hir::StmtKind::Expr(ref expr, _) => { + hir::StmtKind::Expr(ref expr, ..) => { // Check with expected type of `()`. self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit()); } - hir::StmtKind::Semi(ref expr, _) => { + hir::StmtKind::Semi(ref expr, ..) => { self.check_expr(&expr); } } @@ -4934,7 +4974,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, }; - let (ctxt, ()) = self.with_breakable_ctxt(blk.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(blk.hir_id, ctxt, || { for s in &blk.stmts { self.check_stmt(s); } @@ -4944,12 +4984,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected)); let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - let ctxt = enclosing_breakables.find_breakable(blk.id); + let ctxt = enclosing_breakables.find_breakable(blk.hir_id); let coerce = ctxt.coerce.as_mut().unwrap(); if let Some(tail_expr_ty) = tail_expr_ty { let tail_expr = tail_expr.unwrap(); let cause = self.cause(tail_expr.span, - ObligationCauseCode::BlockTailExpression(blk.id)); + ObligationCauseCode::BlockTailExpression(blk.hir_id)); coerce.coerce(self, &cause, tail_expr, @@ -4973,9 +5013,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // that highlight errors inline. let mut sp = blk.span; let mut fn_span = None; - if let Some((decl, ident)) = self.get_parent_fn_decl(blk.id) { + if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) { let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk.id) { + if let Some(block_sp) = self.parent_item_span(blk.hir_id) { // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the // output would otherwise be incorrect and even misleading. Make sure // the span we're aiming at correspond to a `fn` body. @@ -5015,8 +5055,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty } - fn parent_item_span(&self, id: ast::NodeId) -> Option { - let node = self.tcx.hir().get(self.tcx.hir().get_parent(id)); + fn parent_item_span(&self, id: hir::HirId) -> Option { + let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent(id)); match node { Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, _, _, body_id), .. @@ -5035,8 +5075,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Given a function block's `NodeId`, return its `FnDecl` if it exists, or `None` otherwise. - fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> { - let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id)); + fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, ast::Ident)> { + let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent(blk_id)); self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) } @@ -5067,11 +5107,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Given a `NodeId`, return the `FnDecl` of the method it is enclosed by and whether a /// suggestion can be made, `None` otherwise. - pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, bool)> { + pub fn get_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, bool)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| { - let parent = self.tcx.hir().get(blk_id); + let parent = self.tcx.hir().get_by_hir_id(blk_id); self.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) }) } @@ -5088,7 +5128,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, cause_span: Span, - blk_id: ast::NodeId, + blk_id: hir::HirId, ) { self.suggest_missing_semicolon(err, expression, expected, cause_span); if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) { @@ -5273,7 +5313,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None => return None, }; let last_expr = match last_stmt.node { - hir::StmtKind::Semi(ref e, _) => e, + hir::StmtKind::Semi(ref e, ..) => e, _ => return None, }; let last_expr_ty = self.node_ty(last_expr.hir_id); @@ -5291,14 +5331,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self_ty: Option>, def: Def, span: Span, - node_id: ast::NodeId) + hir_id: hir::HirId) -> (Ty<'tcx>, Def) { debug!( - "instantiate_value_path(segments={:?}, self_ty={:?}, def={:?}, node_id={})", + "instantiate_value_path(segments={:?}, self_ty={:?}, def={:?}, hir_id={:?})", segments, self_ty, def, - node_id, + hir_id, ); let tcx = self.tcx; @@ -5365,10 +5405,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } match def { - Def::Local(nid) | Def::Upvar(nid, ..) => { - let ty = self.local_ty(span, nid).decl_ty; + Def::Local(hid) | Def::Upvar(hid, ..) => { + let ty = self.local_ty(span, hid).decl_ty; let ty = self.normalize_associated_types_in(span, &ty); - self.write_ty(tcx.hir().node_to_hir_id(node_id), ty); + self.write_ty(hir_id, ty); return (ty, def); } _ => {} @@ -5520,7 +5560,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { assert!(!ty.has_escaping_bound_vars()); // First, store the "user substs" for later. - let hir_id = tcx.hir().node_to_hir_id(node_id); self.write_user_type_annotation_from_substs(hir_id, def_id, substs, user_self_ty); // Add all the obligations that are required, substituting and @@ -5554,10 +5593,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - self.check_rustc_args_require_const(def_id, node_id, span); + self.check_rustc_args_require_const(def_id, hir_id, span); debug!("instantiate_value_path: type of {:?} is {:?}", - node_id, + hir_id, ty_substituted); self.write_substs(hir_id, substs); @@ -5566,7 +5605,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_rustc_args_require_const(&self, def_id: DefId, - node_id: ast::NodeId, + hir_id: hir::HirId, span: Span) { // We're only interested in functions tagged with // #[rustc_args_required_const], so ignore anything that's not. @@ -5576,9 +5615,11 @@ 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. - if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(node_id)) { + if let Node::Expr(expr) = self.tcx.hir().get_by_hir_id( + self.tcx.hir().get_parent_node(hir_id)) + { if let ExprKind::Call(ref callee, ..) = expr.node { - if callee.id == node_id { + if callee.hir_id == hir_id { return } } @@ -5606,7 +5647,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - fn with_breakable_ctxt R, R>(&self, id: ast::NodeId, + fn with_breakable_ctxt R, R>(&self, id: hir::HirId, ctxt: BreakableCtxt<'gcx, 'tcx>, f: F) -> (BreakableCtxt<'gcx, 'tcx>, R) { let index; @@ -5643,22 +5684,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Returns whether an expression is contained inside the LHS of an assignment expression. - fn expr_in_place(&self, mut expr_id: ast::NodeId) -> bool { + fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool { let mut contained_in_place = false; while let hir::Node::Expr(parent_expr) = - self.tcx.hir().get(self.tcx.hir().get_parent_node(expr_id)) + self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_node(expr_id)) { match &parent_expr.node { hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => { - if lhs.id == expr_id { + if lhs.hir_id == expr_id { contained_in_place = true; break; } } _ => (), } - expr_id = parent_expr.id; + expr_id = parent_expr.hir_id; } contained_in_place @@ -5695,7 +5736,7 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }); for (&used, param) in types_used.iter().zip(types) { if !used { - let id = tcx.hir().as_local_node_id(param.def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(param.def_id).unwrap(); let span = tcx.hir().span(id); struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) .span_label(span, "unused type parameter") diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 7c871601af308..11f047340d873 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -51,8 +51,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { let tcx = self.tcx; - debug!("check_binop(expr.id={}, expr={:?}, op={:?}, lhs_expr={:?}, rhs_expr={:?})", - expr.id, + debug!("check_binop(expr.hir_id={:?}, expr={:?}, op={:?}, lhs_expr={:?}, rhs_expr={:?})", + expr.hir_id, expr, op, lhs_expr, @@ -150,8 +150,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { is_assign: IsAssign) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { - debug!("check_overloaded_binop(expr.id={}, op={:?}, is_assign={:?})", - expr.id, + debug!("check_overloaded_binop(expr.hir_id={:?}, op={:?}, is_assign={:?})", + expr.hir_id, op, is_assign); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b90c18eb41cb5..74ea35002cf08 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -90,7 +90,6 @@ use rustc_data_structures::sync::Lrc; use std::mem; use std::ops::Deref; use std::rc::Rc; -use syntax::ast; use syntax_pos::Span; // a variation on try that just returns unit @@ -112,7 +111,7 @@ macro_rules! ignore_err { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn regionck_expr(&self, body: &'gcx hir::Body) { let subject = self.tcx.hir().body_owner_def_id(body.id()); - let id = body.value.id; + let id = body.value.hir_id; let mut rcx = RegionCtxt::new( self, RepeatingScope(id), @@ -138,9 +137,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Region checking during the WF phase for items. `wf_tys` are the /// types from which we should derive implied bounds, if any. - pub fn regionck_item(&self, item_id: ast::NodeId, span: Span, wf_tys: &[Ty<'tcx>]) { + pub fn regionck_item(&self, item_id: hir::HirId, span: Span, wf_tys: &[Ty<'tcx>]) { debug!("regionck_item(item.id={:?}, wf_tys={:?})", item_id, wf_tys); - let subject = self.tcx.hir().local_def_id(item_id); + let subject = self.tcx.hir().local_def_id_from_hir_id(item_id); let mut rcx = RegionCtxt::new( self, RepeatingScope(item_id), @@ -163,14 +162,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// rest of type check and because sometimes we need type /// inference to have completed before we can determine which /// constraints to add. - pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) { - debug!("regionck_fn(id={})", fn_id); + pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'gcx hir::Body) { + debug!("regionck_fn(id={:?})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); - let node_id = body.value.id; + let hir_id = body.value.hir_id; let mut rcx = RegionCtxt::new( self, - RepeatingScope(node_id), - node_id, + RepeatingScope(hir_id), + hir_id, Subject(subject), self.param_env, ); @@ -201,13 +200,13 @@ pub struct RegionCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { outlives_environment: OutlivesEnvironment<'tcx>, // id of innermost fn body id - body_id: ast::NodeId, + body_id: hir::HirId, // call_site scope of innermost fn call_site_scope: Option, // id of innermost fn or loop - repeating_scope: ast::NodeId, + repeating_scope: hir::HirId, // id of AST node being analyzed (the subject of the analysis). subject_def_id: DefId, @@ -220,14 +219,14 @@ impl<'a, 'gcx, 'tcx> Deref for RegionCtxt<'a, 'gcx, 'tcx> { } } -pub struct RepeatingScope(ast::NodeId); +pub struct RepeatingScope(hir::HirId); pub struct Subject(DefId); impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { pub fn new( fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, RepeatingScope(initial_repeating_scope): RepeatingScope, - initial_body_id: ast::NodeId, + initial_body_id: hir::HirId, Subject(subject): Subject, param_env: ty::ParamEnv<'tcx>, ) -> RegionCtxt<'a, 'gcx, 'tcx> { @@ -244,7 +243,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } } - fn set_repeating_scope(&mut self, scope: ast::NodeId) -> ast::NodeId { + fn set_repeating_scope(&mut self, scope: hir::HirId) -> hir::HirId { mem::replace(&mut self.repeating_scope, scope) } @@ -301,15 +300,15 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// `intravisit::Visitor` impl below.) fn visit_fn_body( &mut self, - id: ast::NodeId, // the id of the fn itself + id: hir::HirId, // the id of the fn itself body: &'gcx hir::Body, span: Span, ) { // When we enter a function, we can derive - debug!("visit_fn_body(id={})", id); + debug!("visit_fn_body(id={:?})", id); let body_id = body.id(); - self.body_id = body_id.node_id; + self.body_id = body_id.hir_id; let call_site = region::Scope { id: body.value.hir_id.local_id, @@ -318,11 +317,11 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.call_site_scope = Some(call_site); let fn_sig = { - let fn_hir_id = self.tcx.hir().node_to_hir_id(id); + let fn_hir_id = id; match self.tables.borrow().liberated_fn_sigs().get(fn_hir_id) { Some(f) => f.clone(), None => { - bug!("No fn-sig entry for id={}", id); + bug!("No fn-sig entry for id={:?}", id); } } }; @@ -342,11 +341,11 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.outlives_environment.add_implied_bounds( self.fcx, &fn_sig_tys[..], - body_id.node_id, + body_id.hir_id, span, ); self.outlives_environment - .save_implied_bounds(body_id.node_id); + .save_implied_bounds(body_id.hir_id); self.link_fn_args( region::Scope { id: body.value.hir_id.local_id, @@ -355,7 +354,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { &body.arguments, ); self.visit_body(body); - self.visit_region_obligations(body_id.node_id); + self.visit_region_obligations(body_id.hir_id); let call_site_scope = self.call_site_scope.unwrap(); debug!( @@ -365,7 +364,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { ); let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope)); - let body_hir_id = self.tcx.hir().node_to_hir_id(body_id.node_id); + let body_hir_id = body_id.hir_id; self.type_of_node_must_outlive(infer::CallReturn(span), body_hir_id, call_site_region); self.constrain_opaque_types( @@ -374,8 +373,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { ); } - fn visit_region_obligations(&mut self, node_id: ast::NodeId) { - debug!("visit_region_obligations: node_id={}", node_id); + fn visit_region_obligations(&mut self, hir_id: hir::HirId) { + debug!("visit_region_obligations: hir_id={:?}", hir_id); // region checking can introduce new pending obligations // which, when processed, might generate new region @@ -457,7 +456,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { _: &'gcx hir::FnDecl, body_id: hir::BodyId, span: Span, - id: ast::NodeId, + id: hir::HirId, ) { assert!( match fk { @@ -502,7 +501,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { fn visit_expr(&mut self, expr: &'gcx hir::Expr) { debug!( - "regionck::visit_expr(e={:?}, repeating_scope={})", + "regionck::visit_expr(e={:?}, repeating_scope={:?})", expr, self.repeating_scope ); @@ -555,7 +554,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { } debug!( - "regionck::visit_expr(e={:?}, repeating_scope={}) - visiting subexprs", + "regionck::visit_expr(e={:?}, repeating_scope={:?}) - visiting subexprs", expr, self.repeating_scope ); match expr.node { @@ -679,16 +678,16 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { } hir::ExprKind::Loop(ref body, _, _) => { - let repeating_scope = self.set_repeating_scope(body.id); + let repeating_scope = self.set_repeating_scope(body.hir_id); intravisit::walk_expr(self, expr); self.set_repeating_scope(repeating_scope); } hir::ExprKind::While(ref cond, ref body, _) => { - let repeating_scope = self.set_repeating_scope(cond.id); + let repeating_scope = self.set_repeating_scope(cond.hir_id); self.visit_expr(&cond); - self.set_repeating_scope(body.id); + self.set_repeating_scope(body.hir_id); self.visit_block(&body); self.set_repeating_scope(repeating_scope); @@ -697,8 +696,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { hir::ExprKind::Ret(Some(ref ret_expr)) => { let call_site_scope = self.call_site_scope; debug!( - "visit_expr ExprKind::Ret ret_expr.id {} call_site_scope: {:?}", - ret_expr.id, call_site_scope + "visit_expr ExprKind::Ret ret_expr.hir_id {:?} call_site_scope: {:?}", + ret_expr.hir_id, call_site_scope ); let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope.unwrap())); self.type_of_node_must_outlive( @@ -758,7 +757,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } fn check_expr_fn_block(&mut self, expr: &'gcx hir::Expr, body_id: hir::BodyId) { - let repeating_scope = self.set_repeating_scope(body_id.node_id); + let repeating_scope = self.set_repeating_scope(body_id.hir_id); intravisit::walk_expr(self, expr); self.set_repeating_scope(repeating_scope); } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index ffd7c2114e5ab..08a6f5b8d18e3 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> { let body = self.fcx.tcx.hir().body(body_id); self.visit_body(body); self.fcx - .analyze_closure(expr.id, expr.hir_id, expr.span, body, cc); + .analyze_closure(expr.hir_id, expr.span, body, cc); } intravisit::walk_expr(self, expr); @@ -77,7 +77,6 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn analyze_closure( &self, - closure_node_id: ast::NodeId, closure_hir_id: hir::HirId, span: Span, body: &hir::Body, @@ -89,7 +88,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!( "analyze_closure(id={:?}, body.id={:?})", - closure_node_id, + closure_hir_id, body.id() ); @@ -105,7 +104,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span_bug!( span, "type of closure expr {:?} is not a closure {:?}", - closure_node_id, + closure_hir_id, t ); } @@ -121,12 +120,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None }; - self.tcx.with_freevars(closure_node_id, |freevars| { + self.tcx.with_freevars(closure_hir_id, |freevars| { let mut freevar_list: Vec = Vec::with_capacity(freevars.len()); for freevar in freevars { let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { - hir_id: self.tcx.hir().node_to_hir_id(freevar.var_id()), + hir_id: freevar.var_id(), }, closure_expr_id: LocalDefId::from_def_id(closure_def_id), }; @@ -216,10 +215,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // inference algorithm will reject it). // Equate the type variables for the upvars with the actual types. - let final_upvar_tys = self.final_upvar_tys(closure_node_id); + let final_upvar_tys = self.final_upvar_tys(closure_hir_id); debug!( "analyze_closure: id={:?} substs={:?} final_upvar_tys={:?}", - closure_node_id, substs, final_upvar_tys + closure_hir_id, substs, final_upvar_tys ); for (upvar_ty, final_upvar_ty) in substs .upvar_tys(closure_def_id, self.tcx) @@ -237,21 +236,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } // Returns a list of `ClosureUpvar`s for each upvar. - fn final_upvar_tys(&self, closure_id: ast::NodeId) -> Vec> { + fn final_upvar_tys(&self, closure_id: hir::HirId) -> Vec> { // Presently an unboxed closure type cannot "escape" out of a // function, so we will only encounter ones that originated in the // local crate or were inlined into it along with some function. // This may change if abstract return types of some sort are // implemented. let tcx = self.tcx; - let closure_def_index = tcx.hir().local_def_id(closure_id); + let closure_def_index = tcx.hir().local_def_id_from_hir_id(closure_id); tcx.with_freevars(closure_id, |freevars| { freevars .iter() .map(|freevar| { - let var_node_id = freevar.var_id(); - let var_hir_id = tcx.hir().node_to_hir_id(var_node_id); + let var_hir_id = freevar.var_id(); let freevar_ty = self.node_ty(var_hir_id); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, @@ -261,7 +259,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!( "var_id={:?} freevar_ty={:?} capture={:?}", - var_node_id, freevar_ty, capture + var_hir_id, freevar_ty, capture ); match capture { @@ -582,7 +580,7 @@ impl<'a, 'gcx, 'tcx> InferBorrowKind<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { fn consume( &mut self, - _consume_id: ast::NodeId, + _consume_id: hir::HirId, _consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode, @@ -611,7 +609,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { fn borrow( &mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, _borrow_span: Span, cmt: &mc::cmt_<'tcx>, _loan_region: ty::Region<'tcx>, @@ -619,7 +617,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { _loan_cause: euv::LoanCause, ) { debug!( - "borrow(borrow_id={}, cmt={:?}, bk={:?})", + "borrow(borrow_id={:?}, cmt={:?}, bk={:?})", borrow_id, cmt, bk ); @@ -634,11 +632,11 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { } } - fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {} + fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) {} fn mutate( &mut self, - _assignment_id: ast::NodeId, + _assignment_id: hir::HirId, _assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, _mode: euv::MutateMode, @@ -650,6 +648,5 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { } fn var_name(tcx: TyCtxt, var_hir_id: hir::HirId) -> ast::Name { - let var_node_id = tcx.hir().hir_to_node_id(var_hir_id); - tcx.hir().name(var_node_id) + tcx.hir().name(var_hir_id) } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 53e44d53e6a9b..9c78444b60bbc 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -22,7 +22,7 @@ use rustc::hir; /// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>)`. struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>, - id: ast::NodeId, + id: hir::HirId, span: Span, param_env: ty::ParamEnv<'tcx>, } @@ -65,8 +65,8 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); let item = tcx.hir().expect_item(node_id); - debug!("check_item_well_formed(it.id={}, it.name={})", - item.id, + debug!("check_item_well_formed(it.hir_id={:?}, it.name={})", + item.hir_id, tcx.item_path_str(def_id)); match item.node { @@ -88,7 +88,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def // won't be allowed unless there's an *explicit* implementation of `Send` // for `T` hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => { - let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id)) + let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id)) .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) { tcx.sess.span_err(item.span, "impls of auto traits cannot be default"); @@ -108,14 +108,14 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def check_item_fn(tcx, item); } hir::ItemKind::Static(ref ty, ..) => { - check_item_type(tcx, item.id, ty.span, false); + check_item_type(tcx, item.hir_id, ty.span, false); } hir::ItemKind::Const(ref ty, ..) => { - check_item_type(tcx, item.id, ty.span, false); + check_item_type(tcx, item.hir_id, ty.span, false); } hir::ItemKind::ForeignMod(ref module) => for it in module.items.iter() { if let hir::ForeignItemKind::Static(ref ty, ..) = it.node { - check_item_type(tcx, it.id, ty.span, true); + check_item_type(tcx, it.hir_id, ty.span, true); } }, hir::ItemKind::Struct(ref struct_def, ref ast_generics) => { @@ -150,36 +150,36 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def } pub fn check_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let trait_item = tcx.hir().expect_trait_item(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let trait_item = tcx.hir().expect_trait_item_by_hir_id(hir_id); let method_sig = match trait_item.node { hir::TraitItemKind::Method(ref sig, _) => Some(sig), _ => None }; - check_associated_item(tcx, trait_item.id, trait_item.span, method_sig); + check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig); } pub fn check_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let impl_item = tcx.hir().expect_impl_item(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let impl_item = tcx.hir().expect_impl_item_by_hir_id(hir_id); let method_sig = match impl_item.node { hir::ImplItemKind::Method(ref sig, _) => Some(sig), _ => None }; - check_associated_item(tcx, impl_item.id, impl_item.span, method_sig); + check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig); } fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - item_id: ast::NodeId, + item_id: hir::HirId, span: Span, sig_if_method: Option<&hir::MethodSig>) { debug!("check_associated_item: {:?}", item_id); let code = ObligationCauseCode::MiscObligation; for_id(tcx, item_id, span).with_fcx(|fcx, tcx| { - let item = fcx.tcx.associated_item(fcx.tcx.hir().local_def_id(item_id)); + let item = fcx.tcx.associated_item(fcx.tcx.hir().local_def_id_from_hir_id(item_id)); let (mut implied_bounds, self_ty) = match item.container { ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()), @@ -220,12 +220,12 @@ fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn for_item<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, item: &hir::Item) -> CheckWfFcxBuilder<'a, 'gcx, 'tcx> { - for_id(tcx, item.id, item.span) + for_id(tcx, item.hir_id, item.span) } -fn for_id<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: ast::NodeId, span: Span) +fn for_id<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'a, 'gcx, 'tcx> { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); CheckWfFcxBuilder { inherited: Inherited::build(tcx, def_id), id, @@ -241,7 +241,7 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>, { for_item(tcx, item).with_fcx(|fcx, fcx_tcx| { let variants = lookup_fields(fcx); - let def_id = fcx.tcx.hir().local_def_id(item.id); + let def_id = fcx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let packed = fcx.tcx.adt_def(def_id).repr.packed(); for variant in &variants { @@ -302,9 +302,9 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn check_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) { - debug!("check_trait: {:?}", item.id); + debug!("check_trait: {:?}", item.hir_id); - let trait_def_id = tcx.hir().local_def_id(item.id); + let trait_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); let trait_def = tcx.trait_def(trait_def_id); if trait_def.is_marker { @@ -326,7 +326,7 @@ fn check_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) { fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) { for_item(tcx, item).with_fcx(|fcx, tcx| { - let def_id = fcx.tcx.hir().local_def_id(item.id); + let def_id = fcx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let sig = fcx.tcx.fn_sig(def_id); let sig = fcx.normalize_associated_types_in(item.span, &sig); let mut implied_bounds = vec![]; @@ -338,14 +338,14 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) { fn check_item_type<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - item_id: ast::NodeId, + item_id: hir::HirId, ty_span: Span, allow_foreign_ty: bool, ) { debug!("check_item_type: {:?}", item_id); for_id(tcx, item_id, ty_span).with_fcx(|fcx, gcx| { - let ty = gcx.type_of(gcx.hir().local_def_id(item_id)); + let ty = gcx.type_of(tcx.hir().local_def_id_from_hir_id(item_id)); let item_ty = fcx.normalize_associated_types_in(ty_span, &ty); let mut forbid_unsized = true; @@ -376,7 +376,7 @@ fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, debug!("check_impl: {:?}", item); for_item(tcx, item).with_fcx(|fcx, tcx| { - let item_def_id = fcx.tcx.hir().local_def_id(item.id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); match *ast_trait_ref { Some(ref ast_trait_ref) => { @@ -610,8 +610,8 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>( let generics = tcx.generics_of(def_id); // only check named existential types if generics.parent.is_none() { - let opaque_node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - if may_define_existential_type(tcx, fn_def_id, opaque_node_id) { + let opaque_hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + if may_define_existential_type(tcx, fn_def_id, opaque_hir_id) { trace!("check_existential_types may define. Generics: {:#?}", generics); let mut seen: FxHashMap<_, Vec<_>> = FxHashMap::default(); for (subst, param) in substs.iter().zip(&generics.params) { @@ -887,7 +887,7 @@ fn check_variances_for_type_defn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item, hir_generics: &hir::Generics) { - let item_def_id = tcx.hir().local_def_id(item.id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); let ty = tcx.type_of(item_def_id); if tcx.has_error_field(ty) { return; @@ -968,13 +968,13 @@ fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) { fn check_false_global_bounds<'a, 'gcx, 'tcx>( fcx: &FnCtxt<'a, 'gcx, 'tcx>, span: Span, - id: ast::NodeId) + id: hir::HirId) { use rustc::ty::TypeFoldable; let empty_env = ty::ParamEnv::empty(); - let def_id = fcx.tcx.hir().local_def_id(id); + let def_id = fcx.tcx.hir().local_def_id_from_hir_id(id); let predicates = fcx.tcx.predicates_of(def_id).predicates .iter() .map(|(p, _)| *p) @@ -1022,21 +1022,21 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &hir::Item) { debug!("visit_item: {:?}", i); - let def_id = self.tcx.hir().local_def_id(i.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(i.hir_id); ty::query::queries::check_item_well_formed::ensure(self.tcx, def_id); intravisit::walk_item(self, i); } fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) { debug!("visit_trait_item: {:?}", trait_item); - let def_id = self.tcx.hir().local_def_id(trait_item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(trait_item.hir_id); ty::query::queries::check_trait_item_well_formed::ensure(self.tcx, def_id); intravisit::walk_trait_item(self, trait_item) } fn visit_impl_item(&mut self, impl_item: &'v hir::ImplItem) { debug!("visit_impl_item: {:?}", impl_item); - let def_id = self.tcx.hir().local_def_id(impl_item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); ty::query::queries::check_impl_item_well_formed::ensure(self.tcx, def_id); intravisit::walk_impl_item(self, impl_item) } @@ -1057,7 +1057,8 @@ struct AdtField<'tcx> { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> { let fields = struct_def.fields().iter().map(|field| { - let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.id)); + let field_ty = self.tcx.type_of( + self.tcx.hir().local_def_id_from_hir_id(field.hir_id)); let field_ty = self.normalize_associated_types_in(field.span, &field_ty); AdtField { ty: field_ty, span: field.span } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index c61159eb49481..920cc63b38e98 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -15,7 +15,6 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::util::nodemap::DefIdSet; use rustc_data_structures::sync::Lrc; use std::mem; -use syntax::ast; use syntax_pos::Span; /////////////////////////////////////////////////////////////////////////// @@ -33,7 +32,7 @@ use syntax_pos::Span; impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body) -> &'gcx ty::TypeckTables<'gcx> { let item_id = self.tcx.hir().body_owner(body.id()); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); // This attribute causes us to dump some writeback information // in the form of errors, which is used for unit tests. @@ -100,7 +99,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { body: &'gcx hir::Body, rustc_dump_user_substs: bool, ) -> WritebackCx<'cx, 'gcx, 'tcx> { - let owner = fcx.tcx.hir().definitions().node_to_hir_id(body.id().node_id); + let owner = body.id().hir_id; WritebackCx { fcx, @@ -243,11 +242,11 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> { } hir::ExprKind::Struct(_, ref fields, _) => { for field in fields { - self.visit_field_id(field.id); + self.visit_field_id(field.hir_id); } } hir::ExprKind::Field(..) => { - self.visit_field_id(e.id); + self.visit_field_id(e.hir_id); } _ => {} } @@ -273,7 +272,7 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> { } hir::PatKind::Struct(_, ref fields, _) => { for field in fields { - self.visit_field_id(field.node.id); + self.visit_field_id(field.node.hir_id); } } _ => {} @@ -287,7 +286,7 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> { fn visit_local(&mut self, l: &'gcx hir::Local) { intravisit::walk_local(self, l); - let var_ty = self.fcx.local_ty(l.span, l.id).decl_ty; + let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty; let var_ty = self.resolve(&var_ty, &l.span); self.write_ty_to_tables(l.hir_id, var_ty); } @@ -407,8 +406,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { if let ty::UserTypeAnnotation::TypeOf(_, user_substs) = c_ty.value { if self.rustc_dump_user_substs { // This is a unit-testing mechanism. - let node_id = self.tcx().hir().hir_to_node_id(hir_id); - let span = self.tcx().hir().span(node_id); + let span = self.tcx().hir().span(hir_id); // We need to buffer the errors in order to guarantee a consistent // order when emitting them. let err = self.tcx().sess.struct_span_err( @@ -451,8 +449,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { - let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap(); - let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id); + let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap(); + let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id); let generics = self.tcx().generics_of(def_id); @@ -583,8 +581,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { } } - fn visit_field_id(&mut self, node_id: ast::NodeId) { - let hir_id = self.tcx().hir().node_to_hir_id(node_id); + fn visit_field_id(&mut self, hir_id: hir::HirId) { if let Some(index) = self.fcx .tables .borrow_mut() @@ -731,7 +728,7 @@ impl Locatable for Span { } } -impl Locatable for ast::NodeId { +impl Locatable for hir::HirId { fn to_span(&self, tcx: &TyCtxt) -> Span { tcx.hir().span(*self) } @@ -739,15 +736,8 @@ impl Locatable for ast::NodeId { impl Locatable for DefIndex { fn to_span(&self, tcx: &TyCtxt) -> Span { - let node_id = tcx.hir().def_index_to_node_id(*self); - tcx.hir().span(node_id) - } -} - -impl Locatable for hir::HirId { - fn to_span(&self, tcx: &TyCtxt) -> Span { - let node_id = tcx.hir().hir_to_node_id(*self); - tcx.hir().span(node_id) + let hir_id = tcx.hir().def_index_to_hir_id(*self); + tcx.hir().span(hir_id) } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index bf767726ef715..6ddd16054f1d4 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -34,7 +34,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> { return; } if let hir::ItemKind::Use(ref path, _) = item.node { - self.check_import(item.id, path.span); + self.check_import(item.hir_id, path.span); } } @@ -51,13 +51,13 @@ struct CheckVisitor<'a, 'tcx: 'a> { } impl<'a, 'tcx> CheckVisitor<'a, 'tcx> { - fn check_import(&self, id: ast::NodeId, span: Span) { - let def_id = self.tcx.hir().local_def_id(id); + fn check_import(&self, id: hir::HirId, span: Span) { + let def_id = self.tcx.hir().local_def_id_from_hir_id(id); if !self.tcx.maybe_unused_trait_import(def_id) { return; } - let import_def_id = self.tcx.hir().local_def_id(id); + let import_def_id = self.tcx.hir().local_def_id_from_hir_id(id); if self.used_trait_imports.contains(&import_def_id) { return; } @@ -121,8 +121,8 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) { }); for extern_crate in &crates_to_lint { - let id = tcx.hir().as_local_node_id(extern_crate.def_id).unwrap(); - let item = tcx.hir().expect_item(id); + let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap(); + let item = tcx.hir().expect_item_by_hir_id(id); // If the crate is fully unused, we suggest removing it altogether. // We do this in any edition. @@ -213,7 +213,7 @@ struct ExternCrateToLint { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { if let hir::ItemKind::ExternCrate(orig_name) = item.node { - let extern_crate_def_id = self.tcx.hir().local_def_id(item.id); + let extern_crate_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); self.crates_to_lint.push( ExternCrateToLint { def_id: extern_crate_def_id, diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index bd2373d1659c9..e2402daf3b41b 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -76,7 +76,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId) { debug!("visit_implementation_of_copy: impl_did={:?}", impl_did); - let impl_node_id = if let Some(n) = tcx.hir().as_local_node_id(impl_did) { + let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) { n } else { debug!("visit_implementation_of_copy(): impl not in this crate"); @@ -87,7 +87,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span(impl_node_id); + let span = tcx.hir().span(impl_hir_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); @@ -97,7 +97,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: match param_env.can_type_implement_copy(tcx, self_type) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item(impl_node_id); + let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node { tr.path.span } else { @@ -114,7 +114,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: err.emit() } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item(impl_node_id); + let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., ref ty, _) = item.node { ty.span } else { @@ -162,8 +162,8 @@ fn visit_implementation_of_dispatch_from_dyn<'a, 'tcx>( if impl_did.is_local() { let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap(); - let impl_node_id = tcx.hir().as_local_node_id(impl_did).unwrap(); - let span = tcx.hir().span(impl_node_id); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap(); + let span = tcx.hir().span(impl_hir_id); let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -185,7 +185,7 @@ fn visit_implementation_of_dispatch_from_dyn<'a, 'tcx>( }; tcx.infer_ctxt().enter(|infcx| { - let cause = ObligationCause::misc(span, impl_node_id); + let cause = ObligationCause::misc(span, impl_hir_id); use ty::TyKind::*; match (&source.sty, &target.sty) { @@ -332,7 +332,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, }); // this provider should only get invoked for local def-ids - let impl_node_id = gcx.hir().as_local_node_id(impl_did).unwrap_or_else(|| { + let impl_hir_id = gcx.hir().as_local_hir_id(impl_did).unwrap_or_else(|| { bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did) }); @@ -344,7 +344,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, source, target); - let span = gcx.hir().span(impl_node_id); + let span = gcx.hir().span(impl_hir_id); let param_env = gcx.param_env(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -355,7 +355,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, target); gcx.infer_ctxt().enter(|infcx| { - let cause = ObligationCause::misc(span, impl_node_id); + let cause = ObligationCause::misc(span, impl_hir_id); let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>, mt_b: ty::TypeAndMut<'gcx>, mk_ptr: &dyn Fn(Ty<'gcx>) -> Ty<'gcx>| { @@ -481,11 +481,11 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, being coerced, none found"); return err_info; } else if diff_fields.len() > 1 { - let item = gcx.hir().expect_item(impl_node_id); + let item = gcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node { t.path.span } else { - gcx.hir().span(impl_node_id) + gcx.hir().span(impl_hir_id) }; let mut err = struct_span_err!(gcx.sess, @@ -527,7 +527,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, let mut fulfill_cx = TraitEngine::new(infcx.tcx); // Register an obligation for `A: Trait`. - let cause = traits::ObligationCause::misc(span, impl_node_id); + let cause = traits::ObligationCause::misc(span, impl_hir_id); let predicate = gcx.predicate_for_trait_def(param_env, cause, trait_def_id, diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 93cc86423ace3..d167c7fcafbe4 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -85,7 +85,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for InherentCollect<'a, 'tcx> { _ => return }; - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let self_ty = self.tcx.type_of(def_id); let lang_items = self.tcx.lang_items(); match self_ty.sty { @@ -288,7 +288,7 @@ impl<'a, 'tcx> InherentCollect<'a, 'tcx> { // Add the implementation to the mapping from implementation to base // type def ID, if there is a base type for this implementation and // the implementation does not have any associated traits. - let impl_def_id = self.tcx.hir().local_def_id(item.id); + let impl_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); let mut rc_vec = self.impls_map.inherent_impls .entry(def_id) .or_default(); diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 52dee29294cb7..833c1fa77365a 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -36,11 +36,11 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> { for &item2 in &impl_items2[..] { if (name, namespace) == name_and_namespace(item2) { - let node_id = self.tcx.hir().as_local_node_id(impl1); - let mut err = if used_to_be_allowed && node_id.is_some() { + let hir_id = self.tcx.hir().as_local_hir_id(impl1); + let mut err = if used_to_be_allowed && hir_id.is_some() { self.tcx.struct_span_lint_node( lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS, - node_id.unwrap(), + hir_id.unwrap(), self.tcx.span_of_impl(item1).unwrap(), &format!("duplicate definitions with name `{}` (E0592)", name) ) @@ -120,7 +120,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for InherentOverlapChecker<'a, 'tcx> { hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) | hir::ItemKind::Union(..) => { - let type_def_id = self.tcx.hir().local_def_id(item.id); + let type_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); self.check_for_overlapping_inherent_impls(type_def_id); } _ => {} diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 2df137c3f5094..33a7ef799fe12 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -22,11 +22,11 @@ impl<'cx, 'tcx, 'v> ItemLikeVisitor<'v> for OrphanChecker<'cx, 'tcx> { /// to prevent inundating the user with a bunch of similar error /// reports. fn visit_item(&mut self, item: &hir::Item) { - let def_id = self.tcx.hir().local_def_id(item.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); // "Trait" impl if let hir::ItemKind::Impl(.., Some(_), _, _) = item.node { debug!("coherence2::orphan check: trait impl {}", - self.tcx.hir().node_to_string(item.id)); + self.tcx.hir().hir_to_string(item.hir_id)); let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_def_id = trait_ref.def_id; let cm = self.tcx.sess.source_map(); diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 81ef4de3d80e5..8a00654b2d866 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -21,7 +21,7 @@ impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> { unsafety: hir::Unsafety, polarity: hir::ImplPolarity) { - if let Some(trait_ref) = self.tcx.impl_trait_ref(self.tcx.hir().local_def_id(item.id)) { + if let Some(trait_ref) = self.tcx.impl_trait_ref(self.tcx.hir().local_def_id_from_hir_id(item.hir_id)) { let trait_def = self.tcx.trait_def(trait_ref.def_id); let unsafe_attr = impl_generics.and_then(|generics| { generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle") diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 3a546f84469e6..da5908d0d1767 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -118,7 +118,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - convert_item(self.tcx, item.id); + convert_item(self.tcx, item.hir_id); intravisit::walk_item(self, item); } @@ -129,7 +129,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { hir::GenericParamKind::Type { default: Some(_), .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); self.tcx.type_of(def_id); } hir::GenericParamKind::Type { .. } => {} @@ -140,7 +140,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr) { if let hir::ExprKind::Closure(..) = expr.node { - let def_id = self.tcx.hir().local_def_id(expr.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); self.tcx.generics_of(def_id); self.tcx.type_of(def_id); } @@ -148,12 +148,12 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - convert_trait_item(self.tcx, trait_item.id); + convert_trait_item(self.tcx, trait_item.hir_id); intravisit::walk_trait_item(self, trait_item); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - convert_impl_item(self.tcx, impl_item.id); + convert_impl_item(self.tcx, impl_item.hir_id); intravisit::walk_impl_item(self, impl_item); } } @@ -251,9 +251,9 @@ fn type_param_predicates<'a, 'tcx>( // written inline like `` or in a where clause like // `where T : Foo`. - let param_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let param_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let param_owner = tcx.hir().ty_param_owner(param_id); - let param_owner_def_id = tcx.hir().local_def_id(param_owner); + let param_owner_def_id = tcx.hir().local_def_id_from_hir_id(param_owner); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&def_id]; let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id).as_interned_str()); @@ -276,8 +276,8 @@ 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) { + let item_hir_id = tcx.hir().as_local_hir_id(item_def_id).unwrap(); + let ast_generics = match tcx.hir().get_by_hir_id(item_hir_id) { Node::TraitItem(item) => &item.generics, Node::ImplItem(item) => &item.generics, @@ -297,7 +297,7 @@ fn type_param_predicates<'a, 'tcx>( | ItemKind::Union(_, ref generics) => generics, ItemKind::Trait(_, _, ref generics, ..) => { // Implied `Self: Trait` and supertrait bounds. - if param_id == item_node_id { + if param_id == item_hir_id { let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id); Lrc::make_mut(&mut result) .predicates @@ -333,7 +333,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { fn type_parameter_bounds_in_generics( &self, ast_generics: &hir::Generics, - param_id: ast::NodeId, + param_id: hir::HirId, ty: Ty<'tcx>, only_self_bounds: OnlySelfBounds, ) -> Vec<(ty::Predicate<'tcx>, Span)> { @@ -341,7 +341,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { .params .iter() .filter_map(|param| match param.kind { - GenericParamKind::Type { .. } if param.id == param_id => Some(¶m.bounds), + GenericParamKind::Type { .. } if param.hir_id == param_id => Some(¶m.bounds), _ => None, }) .flat_map(|bounds| bounds.iter()) @@ -378,12 +378,12 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { fn is_param<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, ast_ty: &hir::Ty, - param_id: ast::NodeId, + param_id: hir::HirId, ) -> bool { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node { match path.def { Def::SelfTy(Some(def_id), None) | Def::TyParam(def_id) => { - def_id == tcx.hir().local_def_id(param_id) + def_id == tcx.hir().local_def_id_from_hir_id(param_id) } _ => false, } @@ -392,10 +392,10 @@ fn is_param<'a, 'tcx>( } } -fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { - let it = tcx.hir().expect_item(item_id); - debug!("convert: item {} with id {}", it.ident, it.id); - let def_id = tcx.hir().local_def_id(item_id); +fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: hir::HirId) { + let it = tcx.hir().expect_item_by_hir_id(item_id); + debug!("convert: item {} with id {:?}", it.ident, it.hir_id); + let def_id = tcx.hir().local_def_id_from_hir_id(item_id); match it.node { // These don't define types. hir::ItemKind::ExternCrate(_) @@ -404,7 +404,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { | hir::ItemKind::GlobalAsm(_) => {} hir::ItemKind::ForeignMod(ref foreign_mod) => { for item in &foreign_mod.items { - let def_id = tcx.hir().local_def_id(item.id); + let def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -442,14 +442,14 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { tcx.predicates_of(def_id); for f in struct_def.fields() { - let def_id = tcx.hir().local_def_id(f.id); + let def_id = tcx.hir().local_def_id_from_hir_id(f.hir_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); } if !struct_def.is_struct() { - convert_variant_ctor(tcx, struct_def.id()); + convert_variant_ctor(tcx, struct_def.hir_id()); } } @@ -474,9 +474,9 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { } } -fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: ast::NodeId) { - let trait_item = tcx.hir().expect_trait_item(trait_item_id); - let def_id = tcx.hir().local_def_id(trait_item.id); +fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: hir::HirId) { + let trait_item = tcx.hir().expect_trait_item_by_hir_id(trait_item_id); + let def_id = tcx.hir().local_def_id_from_hir_id(trait_item.hir_id); tcx.generics_of(def_id); match trait_item.node { @@ -495,18 +495,18 @@ fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: ast: tcx.predicates_of(def_id); } -fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: ast::NodeId) { - let def_id = tcx.hir().local_def_id(impl_item_id); +fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: hir::HirId) { + let def_id = tcx.hir().local_def_id_from_hir_id(impl_item_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); - if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).node { + if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item_by_hir_id(impl_item_id).node { tcx.fn_sig(def_id); } } -fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: ast::NodeId) { - let def_id = tcx.hir().local_def_id(ctor_id); +fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: hir::HirId) { + let def_id = tcx.hir().local_def_id_from_hir_id(ctor_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -527,7 +527,7 @@ fn convert_enum_variant_types<'a, 'tcx>( let wrapped_discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx)); prev_discr = Some( if let Some(ref e) = variant.node.disr_expr { - let expr_did = tcx.hir().local_def_id(e.id); + let expr_did = tcx.hir().local_def_id_from_hir_id(e.hir_id); def.eval_explicit_discr(tcx, expr_did) } else if let Some(discr) = repr_type.disr_incr(tcx, prev_discr) { Some(discr) @@ -550,7 +550,7 @@ fn convert_enum_variant_types<'a, 'tcx>( ); for f in variant.node.data.fields() { - let def_id = tcx.hir().local_def_id(f.id); + let def_id = tcx.hir().local_def_id_from_hir_id(f.hir_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -558,7 +558,7 @@ fn convert_enum_variant_types<'a, 'tcx>( // Convert the ctor, if any. This also registers the variant as // an item. - convert_variant_ctor(tcx, variant.node.data.id()); + convert_variant_ctor(tcx, variant.node.data.hir_id()); } } @@ -572,12 +572,12 @@ fn convert_variant<'a, 'tcx>( attribute_def_id: DefId ) -> ty::VariantDef { let mut seen_fields: FxHashMap = Default::default(); - let node_id = tcx.hir().as_local_node_id(did).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(did).unwrap(); let fields = def .fields() .iter() .map(|f| { - let fid = tcx.hir().local_def_id(f.id); + let fid = tcx.hir().local_def_id_from_hir_id(f.hir_id); let dup_span = seen_fields.get(&f.ident.modern()).cloned(); if let Some(prev_span) = dup_span { struct_span_err!( @@ -596,7 +596,7 @@ fn convert_variant<'a, 'tcx>( ty::FieldDef { did: fid, ident: f.ident, - vis: ty::Visibility::from_hir(&f.vis, node_id, tcx), + vis: ty::Visibility::from_hir(&f.vis, hir_id, tcx), } }) .collect(); @@ -629,10 +629,10 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad def.variants .iter() .map(|v| { - let did = tcx.hir().local_def_id(v.node.data.id()); + let did = tcx.hir().local_def_id_from_hir_id(v.node.data.hir_id()); let discr = if let Some(ref e) = v.node.disr_expr { distance_from_explicit = 0; - ty::VariantDiscr::Explicit(tcx.hir().local_def_id(e.id)) + ty::VariantDiscr::Explicit(tcx.hir().local_def_id_from_hir_id(e.hir_id)) } else { ty::VariantDiscr::Relative(distance_from_explicit) }; @@ -647,7 +647,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad ItemKind::Struct(ref def, _) => { // Use separate constructor id for unit/tuple structs and reuse did for braced structs. let ctor_id = if !def.is_struct() { - Some(tcx.hir().local_def_id(def.id())) + Some(tcx.hir().local_def_id_from_hir_id(def.hir_id())) } else { None }; @@ -717,7 +717,7 @@ fn super_predicates_of<'a, 'tcx>( // as one of its "superpredicates". let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id); let superbounds2 = icx.type_parameter_bounds_in_generics( - generics, item.id, self_param_ty, OnlySelfBounds(!is_trait_alias)); + generics, item.hir_id, self_param_ty, OnlySelfBounds(!is_trait_alias)); // Combine the two lists to form the complete set of superbounds: let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect(); @@ -815,8 +815,7 @@ fn has_late_bound_regions<'a, 'tcx>( return; } - let hir_id = self.tcx.hir().node_to_hir_id(lt.id); - match self.tcx.named_region(hir_id) { + match self.tcx.named_region(lt.hir_id) { Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {} Some(rl::Region::LateBound(debruijn, _, _)) | Some(rl::Region::LateBoundAnon(debruijn, _)) if debruijn < self.outer_index => {} @@ -842,8 +841,7 @@ fn has_late_bound_regions<'a, 'tcx>( }; for param in &generics.params { if let GenericParamKind::Lifetime { .. } = param.kind { - let hir_id = tcx.hir().node_to_hir_id(param.id); - if tcx.is_late_bound(hir_id) { + if tcx.is_late_bound(param.hir_id) { return Some(param.span); } } @@ -884,14 +882,14 @@ 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::*; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let node = tcx.hir().get(node_id); + let node = tcx.hir().get_by_hir_id(hir_id); let parent_def_id = match node { 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)) + let parent_id = tcx.hir().get_parent(hir_id); + Some(tcx.hir().local_def_id_from_hir_id(parent_id)) } Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(..), @@ -934,12 +932,12 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty // // Something of a hack: use the node id for the trait, also as // the node id for the Self type parameter. - let param_id = item.id; + let param_id = item.hir_id; opt_self = Some(ty::GenericParamDef { index: 0, name: keywords::SelfUpper.name().as_interned_str(), - def_id: tcx.hir().local_def_id(param_id), + def_id: tcx.hir().local_def_id_from_hir_id(param_id), pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { has_default: false, @@ -985,13 +983,12 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty .map(|(i, param)| ty::GenericParamDef { name: param.name.ident().as_interned_str(), index: own_start + i as u32, - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Lifetime, }), ); - let hir_id = tcx.hir().node_to_hir_id(node_id); let object_lifetime_defaults = tcx.object_lifetime_defaults(hir_id); // Now create the real type parameters. @@ -1018,7 +1015,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty if !tcx.features().default_type_parameter_fallback { tcx.lint_node( lint::builtin::INVALID_TYPE_PARAM_DEFAULT, - param.id, + param.hir_id, param.span, &format!( "defaults for type parameters are only allowed in \ @@ -1031,7 +1028,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty let ty_param = ty::GenericParamDef { index: type_start + i as u32, name: param.name.ident().as_interned_str(), - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Type { has_default: default.is_some(), @@ -1079,7 +1076,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty }), ); - tcx.with_freevars(node_id, |fv| { + tcx.with_freevars(hir_id, |fv| { params.extend(fv.iter().zip((dummy_args.len() as u32)..).map(|(_, i)| { ty::GenericParamDef { index: type_start + i, @@ -1123,11 +1120,11 @@ 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::*; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let icx = ItemCtxt::new(tcx, def_id); - match tcx.hir().get(node_id) { + match tcx.hir().get_by_hir_id(hir_id) { Node::TraitItem(item) => match item.node { TraitItemKind::Method(..) => { let substs = Substs::identity_for_item(tcx, def_id); @@ -1147,7 +1144,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), ImplItemKind::Existential(_) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did(node_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1157,7 +1154,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { } ImplItemKind::Type(ref ty) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did(node_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1240,7 +1237,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }) => match *def { VariantData::Unit(..) | VariantData::Struct(..) => { - tcx.type_of(tcx.hir().get_parent_did(node_id)) + tcx.type_of(tcx.hir().get_parent_did(hir_id)) } VariantData::Tuple(..) => { let substs = Substs::identity_for_item(tcx, def_id); @@ -1255,8 +1252,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }) => { if gen.is_some() { - let hir_id = tcx.hir().node_to_hir_id(node_id); - return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id); + return tcx.typeck_tables_of(def_id).hir_id_to_type(hir_id); } let substs = ty::ClosureSubsts { @@ -1266,7 +1262,9 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { tcx.mk_closure(def_id, substs) } - Node::AnonConst(_) => match tcx.hir().get(tcx.hir().get_parent_node(node_id)) { + Node::AnonConst(_) => match tcx.hir().get_by_hir_id( + tcx.hir().get_parent_node(hir_id)) + { Node::Ty(&hir::Ty { node: hir::TyKind::Array(_, ref constant), .. @@ -1278,7 +1276,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { | Node::Expr(&hir::Expr { node: ExprKind::Repeat(_, ref constant), .. - }) if constant.id == node_id => + }) if constant.hir_id == hir_id => { tcx.types.usize } @@ -1290,9 +1288,9 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }, .. - }) if e.id == node_id => + }) if e.hir_id == hir_id => { - tcx.adt_def(tcx.hir().get_parent_did(node_id)) + tcx.adt_def(tcx.hir().get_parent_did(hir_id)) .repr .discr_type() .to_ty(tcx) @@ -1368,7 +1366,7 @@ fn find_existential_constraints<'a, 'tcx>( intravisit::NestedVisitorMap::All(&self.tcx.hir()) } fn visit_item(&mut self, it: &'tcx Item) { - let def_id = self.tcx.hir().local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(it.hir_id); // the existential type itself or its children are not within its reveal scope if def_id != self.def_id { self.check(def_id); @@ -1376,7 +1374,7 @@ fn find_existential_constraints<'a, 'tcx>( } } fn visit_impl_item(&mut self, it: &'tcx ImplItem) { - let def_id = self.tcx.hir().local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(it.hir_id); // the existential type itself or its children are not within its reveal scope if def_id != self.def_id { self.check(def_id); @@ -1384,7 +1382,7 @@ fn find_existential_constraints<'a, 'tcx>( } } fn visit_trait_item(&mut self, it: &'tcx TraitItem) { - let def_id = self.tcx.hir().local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(it.hir_id); self.check(def_id); intravisit::walk_trait_item(self, it); } @@ -1395,16 +1393,16 @@ fn find_existential_constraints<'a, 'tcx>( tcx, found: None, }; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let parent = tcx.hir().get_parent(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let parent = tcx.hir().get_parent(hir_id); trace!("parent_id: {:?}", parent); - if parent == ast::CRATE_NODE_ID { + if parent == hir::CRATE_HIR_ID { intravisit::walk_crate(&mut locator, tcx.hir().krate()); } else { - trace!("parent: {:?}", tcx.hir().get(parent)); - match tcx.hir().get(parent) { + trace!("parent: {:?}", tcx.hir().get_by_hir_id(parent)); + match tcx.hir().get_by_hir_id(parent) { 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), @@ -1429,11 +1427,11 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig use rustc::hir::*; use rustc::hir::Node::*; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let icx = ItemCtxt::new(tcx, def_id); - match tcx.hir().get(node_id) { + match tcx.hir().get_by_hir_id(hir_id) { TraitItem(hir::TraitItem { node: TraitItemKind::Method(sig, _), .. @@ -1452,7 +1450,7 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig node: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => { - let abi = tcx.hir().get_foreign_abi(node_id); + let abi = tcx.hir().get_foreign_abi(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi) } @@ -1465,10 +1463,10 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig }, .. }) => { - let ty = tcx.type_of(tcx.hir().get_parent_did(node_id)); + let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id)); let inputs = fields .iter() - .map(|f| tcx.type_of(tcx.hir().local_def_id(f.id))); + .map(|f| tcx.type_of(tcx.hir().local_def_id_from_hir_id(f.hir_id))); ty::Binder::bind(tcx.mk_fn_sig( inputs, ty, @@ -1597,8 +1595,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>( .iter() .filter(move |param| match param.kind { GenericParamKind::Lifetime { .. } => { - let hir_id = tcx.hir().node_to_hir_id(param.id); - !tcx.is_late_bound(hir_id) + !tcx.is_late_bound(param.hir_id) } _ => false, }) @@ -1827,7 +1824,7 @@ fn explicit_predicates_of<'a, 'tcx>( let mut index = parent_count + has_own_self as u32; for param in early_bound_lifetimes_from_generics(tcx, ast_generics) { let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), index, name: param.name.ident().as_interned_str(), })); @@ -1946,8 +1943,8 @@ fn explicit_predicates_of<'a, 'tcx>( _ => return vec![].into_iter() }; - let assoc_ty = - tcx.mk_projection(tcx.hir().local_def_id(trait_item.id), self_trait_ref.substs); + let def_id = tcx.hir().local_def_id_from_hir_id(trait_item.hir_id); + let assoc_ty = tcx.mk_projection(def_id, self_trait_ref.substs); let bounds = compute_bounds( &ItemCtxt::new(tcx, def_id), @@ -2109,7 +2106,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( &format!( "use of SIMD type `{}` in FFI is highly experimental and \ may result in invalid code", - tcx.hir().node_to_pretty_string(ast_ty.id) + tcx.hir().node_to_pretty_string_by_hir_id(ast_ty.hir_id) ), ) .help("add #![feature(simd_ffi)] to the crate attributes to enable") diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index d5e15b28fb04b..aeb3e2a28930a 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -62,7 +62,7 @@ struct ImplWfCheck<'a, 'tcx: 'a> { impl<'a, 'tcx> ItemLikeVisitor<'tcx> for ImplWfCheck<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { if let hir::ItemKind::Impl(.., ref impl_item_refs) = item.node { - let impl_def_id = self.tcx.hir().local_def_id(item.id); + let impl_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_item_refs); diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 8bd484aa0d352..cc458fcd0d5ef 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -119,7 +119,6 @@ use rustc::util; use rustc::util::profiling::ProfileCategory; use session::{CompileIncomplete, config}; use syntax_pos::Span; -use syntax::ast; use util::common::time; use std::iter; @@ -185,13 +184,13 @@ fn require_same_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - main_id: ast::NodeId, + main_id: hir::HirId, main_span: Span) { - let main_def_id = tcx.hir().local_def_id(main_id); + let main_def_id = tcx.hir().local_def_id_from_hir_id(main_id); let main_t = tcx.type_of(main_def_id); match main_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find(main_id) { + if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(main_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { @@ -251,13 +250,13 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - start_id: ast::NodeId, + start_id: hir::HirId, start_span: Span) { - let start_def_id = tcx.hir().local_def_id(start_id); + let start_def_id = tcx.hir().local_def_id_from_hir_id(start_id); let start_t = tcx.type_of(start_def_id); match start_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find(start_id) { + if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(start_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { @@ -378,8 +377,8 @@ pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> // In case there are any projections etc, find the "environment" // def-id that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. - let env_node_id = tcx.hir().get_parent(hir_ty.id); - let env_def_id = tcx.hir().local_def_id(env_node_id); + let env_hir_id = tcx.hir().get_parent(hir_ty.hir_id); + let env_def_id = tcx.hir().local_def_id_from_hir_id(env_hir_id); let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id); astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty) @@ -390,8 +389,8 @@ pub fn hir_trait_to_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_trait: // In case there are any projections etc, find the "environment" // def-id that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. - let env_node_id = tcx.hir().get_parent(hir_trait.ref_id); - let env_def_id = tcx.hir().local_def_id(env_node_id); + let env_hir_id = tcx.hir().get_parent(hir_trait.hir_ref_id); + let env_def_id = tcx.hir().local_def_id_from_hir_id(env_hir_id); let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id); let mut projections = Vec::new(); let (principal, _) = astconv::AstConv::instantiate_poly_trait_ref_inner( diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index e388a3e0d0c2f..6f119f7b6cb97 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -53,16 +53,11 @@ pub struct InferVisitor<'cx, 'tcx: 'cx> { impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { - let item_did = self.tcx.hir().local_def_id(item.id); + let item_did = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); debug!("InferVisitor::visit_item(item={:?})", item_did); - let node_id = self - .tcx - .hir() - .as_local_node_id(item_did) - .expect("expected local def-id"); - let item = match self.tcx.hir().get(node_id) { + let item = match self.tcx.hir().get_by_hir_id(item.hir_id) { Node::Item(item) => item, _ => bug!(), }; diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index cbeb7f7b69194..e10c836120718 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -14,7 +14,7 @@ struct OutlivesTest<'a, 'tcx: 'a> { impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { - let item_def_id = self.tcx.hir().local_def_id(item.id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); // For unit testing: check for a special "rustc_outlives" // attribute and report an error with various results if found. diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 868c1132e44c5..e0fd2f360ee8e 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -6,7 +6,6 @@ use hir::def_id::DefId; use rustc::ty::subst::{Substs, UnpackedKind}; use rustc::ty::{self, Ty, TyCtxt}; -use syntax::ast; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; @@ -72,31 +71,31 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { match item.node { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { - self.visit_node_helper(item.id); + self.visit_node_helper(item.hir_id); if let hir::VariantData::Tuple(..) = *struct_def { - self.visit_node_helper(struct_def.id()); + self.visit_node_helper(struct_def.hir_id()); } } hir::ItemKind::Enum(ref enum_def, _) => { - self.visit_node_helper(item.id); + self.visit_node_helper(item.hir_id); for variant in &enum_def.variants { if let hir::VariantData::Tuple(..) = variant.node.data { - self.visit_node_helper(variant.node.data.id()); + self.visit_node_helper(variant.node.data.hir_id()); } } } hir::ItemKind::Fn(..) => { - self.visit_node_helper(item.id); + self.visit_node_helper(item.hir_id); } hir::ItemKind::ForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { if let hir::ForeignItemKind::Fn(..) = foreign_item.node { - self.visit_node_helper(foreign_item.id); + self.visit_node_helper(foreign_item.hir_id); } } } @@ -107,21 +106,20 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) { if let hir::TraitItemKind::Method(..) = trait_item.node { - self.visit_node_helper(trait_item.id); + self.visit_node_helper(trait_item.hir_id); } } fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { if let hir::ImplItemKind::Method(..) = impl_item.node { - self.visit_node_helper(impl_item.id); + self.visit_node_helper(impl_item.hir_id); } } } impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { - fn visit_node_helper(&mut self, id: ast::NodeId) { - let tcx = self.terms_cx.tcx; - let def_id = tcx.hir().local_def_id(id); + fn visit_node_helper(&mut self, id: hir::HirId) { + let def_id = self.tcx().hir().local_def_id_from_hir_id(id); self.build_constraints_for_item(def_id); } @@ -138,7 +136,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { return; } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let inferred_start = self.terms_cx.inferred_starts[&id]; let current_item = &CurrentItem { inferred_start }; match tcx.type_of(def_id).sty { @@ -356,7 +354,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { return; } - let (local, remote) = if let Some(id) = self.tcx().hir().as_local_node_id(def_id) { + let (local, remote) = if let Some(id) = self.tcx().hir().as_local_hir_id(def_id) { (Some(self.terms_cx.inferred_starts[&id]), None) } else { (None, Some(self.tcx().variances_of(def_id))) diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index afb6a68482013..17dee5afa61b1 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -46,12 +46,12 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId) -> Lrc> { - let id = tcx.hir().as_local_node_id(item_def_id).expect("expected local def-id"); + let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") }; - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::Item(item) => match item.node { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index 550c1b1d68bd3..337d039b7dff0 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -83,12 +83,12 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { let solutions = &self.solutions; self.terms_cx.inferred_starts.iter().map(|(&id, &InferredIndex(start))| { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); let generics = tcx.generics_of(def_id); let mut variances = solutions[start..start+generics.count()].to_vec(); - debug!("id={} variances={:?}", id, variances); + debug!("id={:?} variances={:?}", id, variances); // Functions can have unused type parameters: make those invariant. if let ty::FnDef(..) = tcx.type_of(def_id).sty { diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index d53e2d2ad7883..ed1ff06668e01 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -12,10 +12,9 @@ use arena::TypedArena; use rustc::ty::{self, TyCtxt}; use std::fmt; -use syntax::ast; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; -use util::nodemap::NodeMap; +use util::nodemap::HirIdMap; use self::VarianceTerm::*; @@ -55,11 +54,11 @@ pub struct TermsContext<'a, 'tcx: 'a> { // For marker types, UnsafeCell, and other lang items where // variance is hardcoded, records the item-id and the hardcoded // variance. - pub lang_items: Vec<(ast::NodeId, Vec)>, + pub lang_items: Vec<(hir::HirId, Vec)>, // Maps from the node id of an item to the first inferred index // used for its type & region parameters. - pub inferred_starts: NodeMap, + pub inferred_starts: HirIdMap, // Maps from an InferredIndex to the term for that variable. pub inferred_terms: Vec>, @@ -86,7 +85,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx> terms_cx } -fn lang_items(tcx: TyCtxt) -> Vec<(ast::NodeId, Vec)> { +fn lang_items(tcx: TyCtxt) -> Vec<(hir::HirId, Vec)> { let lang_items = tcx.lang_items(); let all = vec![ (lang_items.phantom_data(), vec![ty::Covariant]), @@ -96,14 +95,14 @@ fn lang_items(tcx: TyCtxt) -> Vec<(ast::NodeId, Vec)> { all.into_iter() // iterating over (Option, Variance) .filter(|&(ref d,_)| d.is_some()) .map(|(d, v)| (d.unwrap(), v)) // (DefId, Variance) - .filter_map(|(d, v)| tcx.hir().as_local_node_id(d).map(|n| (n, v))) // (NodeId, Variance) + .filter_map(|(d, v)| tcx.hir().as_local_hir_id(d).map(|n| (n, v))) // (HirId, Variance) .collect() } impl<'a, 'tcx> TermsContext<'a, 'tcx> { - fn add_inferreds_for_item(&mut self, id: ast::NodeId) { + fn add_inferreds_for_item(&mut self, id: hir::HirId) { let tcx = self.tcx; - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); let count = tcx.generics_of(def_id).count(); if count == 0 { @@ -129,36 +128,36 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { debug!("add_inferreds for item {}", - self.tcx.hir().node_to_string(item.id)); + self.tcx.hir().hir_to_string(item.hir_id)); match item.node { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { - self.add_inferreds_for_item(item.id); + self.add_inferreds_for_item(item.hir_id); if let hir::VariantData::Tuple(..) = *struct_def { - self.add_inferreds_for_item(struct_def.id()); + self.add_inferreds_for_item(struct_def.hir_id()); } } hir::ItemKind::Enum(ref enum_def, _) => { - self.add_inferreds_for_item(item.id); + self.add_inferreds_for_item(item.hir_id); for variant in &enum_def.variants { if let hir::VariantData::Tuple(..) = variant.node.data { - self.add_inferreds_for_item(variant.node.data.id()); + self.add_inferreds_for_item(variant.node.data.hir_id()); } } } hir::ItemKind::Fn(..) => { - self.add_inferreds_for_item(item.id); + self.add_inferreds_for_item(item.hir_id); } hir::ItemKind::ForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { if let hir::ForeignItemKind::Fn(..) = foreign_item.node { - self.add_inferreds_for_item(foreign_item.id); + self.add_inferreds_for_item(foreign_item.hir_id); } } } @@ -169,13 +168,13 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) { if let hir::TraitItemKind::Method(..) = trait_item.node { - self.add_inferreds_for_item(trait_item.id); + self.add_inferreds_for_item(trait_item.hir_id); } } fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { if let hir::ImplItemKind::Method(..) = impl_item.node { - self.add_inferreds_for_item(impl_item.id); + self.add_inferreds_for_item(impl_item.hir_id); } } } diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index 0f566e6ded973..d04b1b276a2cc 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -12,7 +12,7 @@ struct VarianceTest<'a, 'tcx: 'a> { impl<'a, 'tcx> ItemLikeVisitor<'tcx> for VarianceTest<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { - let item_def_id = self.tcx.hir().local_def_id(item.id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); // For unit testing: check for a special "rustc_variance" // attribute and report an error with various results if found. diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 27ca205720d6a..8b8e58ef100b1 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -115,7 +115,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { if result.is_auto() { let trait_ = hir::TraitRef { path: get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait), - ref_id: ast::DUMMY_NODE_ID, hir_ref_id: hir::DUMMY_HIR_ID, }; diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index ab8656fa47c9b..1a6bb32ebffe0 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -123,7 +123,6 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { path: get_path_for_type(infcx.tcx, trait_def_id, hir::def::Def::Trait), - ref_id: ast::DUMMY_NODE_ID, hir_ref_id: hir::DUMMY_HIR_ID, }; let provided_trait_methods = diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6eea95b61c990..4a8495269d7dd 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -626,7 +626,7 @@ impl Clean for doctree::Module { visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), inner: ModuleItem(Module { is_crate: self.is_crate, items, @@ -1209,9 +1209,8 @@ impl Lifetime { impl Clean for hir::Lifetime { fn clean(&self, cx: &DocContext) -> Lifetime { - if self.id != ast::DUMMY_NODE_ID { - let hir_id = cx.tcx.hir().node_to_hir_id(self.id); - let def = cx.tcx.named_region(hir_id); + if self.hir_id != hir::DUMMY_HIR_ID { + let def = cx.tcx.named_region(self.hir_id); match def { Some(rl::Region::EarlyBound(_, node_id, _)) | Some(rl::Region::LateBound(_, node_id, _)) | @@ -1468,7 +1467,7 @@ impl Clean for hir::GenericParam { } hir::GenericParamKind::Type { ref default, synthetic, .. } => { (self.name.ident().name.clean(cx), GenericParamDefKind::Type { - did: cx.tcx.hir().local_def_id(self.id), + did: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), bounds: self.bounds.clean(cx), default: default.clean(cx), synthetic: synthetic, @@ -1672,7 +1671,7 @@ impl Clean for doctree::Function { (self.generics.clean(cx), (&self.decl, self.body).clean(cx)) }); - let did = cx.tcx.hir().local_def_id(self.id); + let did = cx.tcx.hir().local_def_id_from_hir_id(self.id); let constness = if cx.tcx.is_min_const_fn(did) { hir::Constness::Const } else { @@ -1858,7 +1857,7 @@ impl Clean for doctree::Trait { name: Some(self.name.clean(cx)), attrs: attrs, source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -1886,7 +1885,7 @@ impl Clean for hir::IsAuto { impl Clean for hir::TraitRef { fn clean(&self, cx: &DocContext) -> Type { - resolve_type(cx, self.path.clean(cx), self.ref_id) + resolve_type(cx, self.path.clean(cx), self.hir_ref_id) } } @@ -1927,10 +1926,10 @@ impl Clean for hir::TraitItem { name: Some(self.ident.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.span.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), visibility: None, - stability: get_stability(cx, cx.tcx.hir().local_def_id(self.id)), - deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id(self.id)), + stability: get_stability(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), + deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), inner, } } @@ -1959,10 +1958,10 @@ impl Clean for hir::ImplItem { name: Some(self.ident.name.clean(cx)), source: self.span.clean(cx), attrs: self.attrs.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), visibility: self.vis.clean(cx), - stability: get_stability(cx, cx.tcx.hir().local_def_id(self.id)), - deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id(self.id)), + stability: get_stability(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), + deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), inner, } } @@ -2412,7 +2411,7 @@ impl Clean for hir::Ty { } TyKind::Slice(ref ty) => Slice(box ty.clean(cx)), TyKind::Array(ref ty, ref length) => { - let def_id = cx.tcx.hir().local_def_id(length.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(length.hir_id); let param_env = cx.tcx.param_env(def_id); let substs = Substs::identity_for_item(cx.tcx, def_id); let cid = GlobalId { @@ -2480,15 +2479,15 @@ impl Clean for hir::Ty { if let Some(lt) = lifetime.cloned() { if !lt.is_elided() { let lt_def_id = - cx.tcx.hir().local_def_id(param.id); + cx.tcx.hir().local_def_id_from_hir_id(param.hir_id); lt_substs.insert(lt_def_id, lt.clean(cx)); } } indices.lifetimes += 1; } hir::GenericParamKind::Type { ref default, .. } => { - let ty_param_def = - Def::TyParam(cx.tcx.hir().local_def_id(param.id)); + let ty_param_def = Def::TyParam( + cx.tcx.hir().local_def_id_from_hir_id(param.hir_id)); let mut j = 0; let type_ = generic_args.args.iter().find_map(|arg| { match arg { @@ -2515,7 +2514,7 @@ impl Clean for hir::Ty { }); return cx.enter_alias(ty_substs, lt_substs, || ty.clean(cx)); } - resolve_type(cx, path.clean(cx), self.id) + resolve_type(cx, path.clean(cx), self.hir_id) } TyKind::Path(hir::QPath::Resolved(Some(ref qself), ref p)) => { let mut segments: Vec<_> = p.segments.clone().into(); @@ -2528,7 +2527,7 @@ impl Clean for hir::Ty { Type::QPath { name: p.segments.last().expect("segments were empty").ident.name.clean(cx), self_type: box qself.clean(cx), - trait_: box resolve_type(cx, trait_path.clean(cx), self.id) + trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id) } } TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => { @@ -2545,7 +2544,7 @@ impl Clean for hir::Ty { Type::QPath { name: segment.ident.name.clean(cx), self_type: box qself.clean(cx), - trait_: box resolve_type(cx, trait_path.clean(cx), self.id) + trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id) } } TyKind::TraitObject(ref bounds, ref lifetime) => { @@ -2772,9 +2771,9 @@ impl Clean for hir::StructField { attrs: self.attrs.clean(cx), source: self.span.clean(cx), visibility: self.vis.clean(cx), - stability: get_stability(cx, cx.tcx.hir().local_def_id(self.id)), - deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id(self.id)), - def_id: cx.tcx.hir().local_def_id(self.id), + stability: get_stability(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), + deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), inner: StructFieldItem(self.ty.clean(cx)), } } @@ -2846,7 +2845,7 @@ impl Clean for doctree::Struct { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -2866,7 +2865,7 @@ impl Clean for doctree::Union { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -2913,7 +2912,7 @@ impl Clean for doctree::Enum { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -2940,7 +2939,7 @@ impl Clean for doctree::Variant { visibility: None, stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.def.id()), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.def.hir_id()), inner: VariantItem(Variant { kind: self.def.clean(cx), }), @@ -3226,7 +3225,7 @@ impl Clean for doctree::Typedef { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id.clone()), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -3250,7 +3249,7 @@ impl Clean for doctree::Existential { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id.clone()), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -3301,7 +3300,7 @@ impl Clean for doctree::Static { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -3326,7 +3325,7 @@ impl Clean for doctree::Constant { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -3426,7 +3425,7 @@ impl Clean> for doctree::Impl { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), @@ -3659,10 +3658,10 @@ impl Clean for hir::ForeignItem { name: Some(self.ident.clean(cx)), attrs: self.attrs.clean(cx), source: self.span.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), visibility: self.vis.clean(cx), - stability: get_stability(cx, cx.tcx.hir().local_def_id(self.id)), - deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id(self.id)), + stability: get_stability(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), + deprecation: get_deprecation(cx, cx.tcx.hir().local_def_id_from_hir_id(self.hir_id)), inner, } } @@ -3725,8 +3724,8 @@ fn name_from_pat(p: &hir::Pat) -> String { fn print_const(cx: &DocContext, n: ty::LazyConst) -> String { match n { ty::LazyConst::Unevaluated(def_id, _) => { - if let Some(node_id) = cx.tcx.hir().as_local_node_id(def_id) { - print_const_expr(cx, cx.tcx.hir().body_owned_by(node_id)) + if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(def_id) { + print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id)) } else { inline::print_inlined_const(cx, def_id) } @@ -3745,14 +3744,14 @@ fn print_const(cx: &DocContext, n: ty::LazyConst) -> String { } fn print_const_expr(cx: &DocContext, body: hir::BodyId) -> String { - cx.tcx.hir().node_to_pretty_string(body.node_id) + cx.tcx.hir().node_to_pretty_string_by_hir_id(body.hir_id) } /// Given a type Path, resolve it to a Type using the TyCtxt fn resolve_type(cx: &DocContext, path: Path, - id: ast::NodeId) -> Type { - if id == ast::DUMMY_NODE_ID { + id: hir::HirId) -> Type { + if id == hir::DUMMY_HIR_ID { debug!("resolve_type({:?})", path); } else { debug!("resolve_type({:?},{:?})", path, id); @@ -3871,7 +3870,7 @@ impl Clean for doctree::ProcMacro { visibility: Some(Public), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.id), inner: ProcMacroItem(ProcMacro { kind: self.kind, helpers: self.helpers.clean(cx), @@ -4071,6 +4070,7 @@ where F: Fn(DefId) -> Def { segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment { ident: ast::Ident::from_str(&s), id: None, + hir_id: None, def: None, args: None, infer_types: false, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 78dbf41bf21fd..2d792f70a4ea6 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -162,6 +162,14 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { } } + pub fn as_local_hir_id(&self, def_id: DefId) -> Option { + if self.all_fake_def_ids.borrow().contains(&def_id) { + None + } else { + self.tcx.hir().as_local_hir_id(def_id) + } + } + pub fn get_real_ty(&self, def_id: DefId, def_ctor: &F, @@ -177,6 +185,7 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { real_name.unwrap_or(last.ident), None, None, + None, self.generics_to_path_params(generics.clone()), false, )); @@ -188,7 +197,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { }; hir::Ty { - id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), span: DUMMY_SP, hir_id: hir::DUMMY_HIR_ID, @@ -208,7 +216,7 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { }; args.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: ast::DUMMY_NODE_ID, + hir_id: hir::DUMMY_HIR_ID, span: DUMMY_SP, name: hir::LifetimeName::Param(name), })); @@ -229,7 +237,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); hir::Ty { - id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved( None, P(hir::Path { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index cc27da70b16d7..b63f4a7b918b6 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -3,7 +3,7 @@ pub use self::StructType::*; use syntax::ast; -use syntax::ast::{Name, NodeId}; +use syntax::ast::Name; use syntax::attr; use syntax::ext::base::MacroKind; use syntax::ptr::P; @@ -25,7 +25,7 @@ pub struct Module { pub enums: Vec, pub fns: Vec, pub mods: Vec, - pub id: NodeId, + pub id: hir::HirId, pub typedefs: Vec, pub existentials: Vec, pub statics: Vec, @@ -45,7 +45,7 @@ impl Module { pub fn new(name: Option) -> Module { Module { name : name, - id: ast::CRATE_NODE_ID, + id: hir::CRATE_HIR_ID, vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited }, stab: None, depr: None, @@ -87,7 +87,7 @@ pub struct Struct { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub id: NodeId, + pub id: hir::HirId, pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, @@ -100,7 +100,7 @@ pub struct Union { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub id: NodeId, + pub id: hir::HirId, pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, @@ -116,7 +116,7 @@ pub struct Enum { pub variants: hir::HirVec, pub generics: hir::Generics, pub attrs: hir::HirVec, - pub id: NodeId, + pub id: hir::HirId, pub whence: Span, pub name: Name, } @@ -133,7 +133,7 @@ pub struct Variant { pub struct Function { pub decl: hir::FnDecl, pub attrs: hir::HirVec, - pub id: NodeId, + pub id: hir::HirId, pub name: Name, pub vis: hir::Visibility, pub stab: Option, @@ -148,7 +148,7 @@ pub struct Typedef { pub ty: P, pub gen: hir::Generics, pub name: Name, - pub id: ast::NodeId, + pub id: hir::HirId, pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, @@ -159,7 +159,7 @@ pub struct Typedef { pub struct Existential { pub exist_ty: hir::ExistTy, pub name: Name, - pub id: ast::NodeId, + pub id: hir::HirId, pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, @@ -177,7 +177,7 @@ pub struct Static { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub id: ast::NodeId, + pub id: hir::HirId, pub whence: Span, } @@ -189,7 +189,7 @@ pub struct Constant { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub id: ast::NodeId, + pub id: hir::HirId, pub whence: Span, } @@ -201,7 +201,7 @@ pub struct Trait { pub generics: hir::Generics, pub bounds: hir::HirVec, pub attrs: hir::HirVec, - pub id: ast::NodeId, + pub id: hir::HirId, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, @@ -222,7 +222,7 @@ pub struct Impl { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub id: ast::NodeId, + pub id: hir::HirId, } // For Macro we store the DefId instead of the NodeId, since we also create @@ -249,7 +249,7 @@ pub struct ExternCrate { pub struct Import { pub name: Name, - pub id: NodeId, + pub id: hir::HirId, pub vis: hir::Visibility, pub attrs: hir::HirVec, pub path: hir::Path, @@ -259,7 +259,7 @@ pub struct Import { pub struct ProcMacro { pub name: Name, - pub id: NodeId, + pub id: hir::HirId, pub kind: MacroKind, pub helpers: Vec, pub attrs: hir::HirVec, diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index fdc1c0616187a..f93a5982b775e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -3,7 +3,7 @@ use rustc::hir; use rustc::hir::def::Def; use rustc::ty; use syntax; -use syntax::ast::{self, Ident, NodeId}; +use syntax::ast::{self, Ident}; use syntax::feature_gate::UnstableFeatures; use syntax::symbol::Symbol; use syntax_pos::{self, DUMMY_SP}; @@ -45,7 +45,7 @@ enum PathKind { struct LinkCollector<'a, 'tcx: 'a, 'rcx: 'a> { cx: &'a DocContext<'a, 'tcx, 'rcx>, - mod_ids: Vec, + mod_ids: Vec, is_nightly_build: bool, } @@ -65,7 +65,7 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { path_str: &str, is_val: bool, current_item: &Option, - parent_id: Option) + parent_id: Option) -> Result<(Def, Option), ()> { let cx = self.cx; @@ -205,8 +205,8 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { fn fold_item(&mut self, mut item: Item) -> Option { - let item_node_id = if item.is_mod() { - if let Some(id) = self.cx.tcx.hir().as_local_node_id(item.def_id) { + let item_hir_id = if item.is_mod() { + if let Some(id) = self.cx.tcx.hir().as_local_hir_id(item.def_id) { Some(id) } else { debug!("attempting to fold on a non-local item: {:?}", item); @@ -217,11 +217,11 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { }; // FIXME: get the resolver to work with non-local resolve scopes. - let parent_node = self.cx.as_local_node_id(item.def_id).and_then(|node_id| { + let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| { // FIXME: this fails hard for impls in non-module scope, but is necessary for the // current `resolve()` implementation. - match self.cx.tcx.hir().get_module_parent_node(node_id) { - id if id != node_id => Some(id), + match self.cx.tcx.hir().get_module_parent_node(hir_id) { + id if id != hir_id => Some(id), _ => None, } }); @@ -233,14 +233,14 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { let current_item = match item.inner { ModuleItem(..) => { if item.attrs.inner_docs { - if item_node_id.unwrap() != NodeId::from_u32(0) { + if item_hir_id.unwrap() != hir::CRATE_HIR_ID { item.name.clone() } else { None } } else { match parent_node.or(self.mod_ids.last().cloned()) { - Some(parent) if parent != NodeId::from_u32(0) => { + Some(parent) if parent != hir::CRATE_HIR_ID => { // FIXME: can we pull the parent module's name from elsewhere? Some(self.cx.tcx.hir().name(parent).to_string()) } @@ -259,7 +259,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { }; if item.is_mod() && item.attrs.inner_docs { - self.mod_ids.push(item_node_id.unwrap()); + self.mod_ids.push(item_hir_id.unwrap()); } let cx = self.cx; @@ -406,7 +406,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> { } if item.is_mod() && !item.attrs.inner_docs { - self.mod_ids.push(item_node_id.unwrap()); + self.mod_ids.push(item_hir_id.unwrap()); } if item.is_mod() { @@ -523,7 +523,7 @@ fn resolution_failure( let mut diag = cx.tcx.struct_span_lint_node( lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, - NodeId::from_u32(0), + hir::CRATE_HIR_ID, sp, &msg, ); @@ -532,7 +532,7 @@ fn resolution_failure( } else { let mut diag = cx.tcx.struct_span_lint_node( lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, - NodeId::from_u32(0), + hir::CRATE_HIR_ID, sp, &msg, ); @@ -557,7 +557,7 @@ fn resolution_failure( } } else { cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, - NodeId::from_u32(0), + hir::CRATE_HIR_ID, sp, &msg) }; diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index e897b9a7de58e..b7f3c80568b19 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -1,13 +1,13 @@ //! Contains information about "passes", used to modify crate information during the documentation //! process. +use rustc::hir; use rustc::hir::def_id::DefId; use rustc::lint as lint; use rustc::middle::privacy::AccessLevels; use rustc::util::nodemap::DefIdSet; use std::mem; use std::fmt; -use syntax::ast::NodeId; use clean::{self, GetDefId, Item}; use core::{DocContext, DocAccessLevels}; @@ -380,7 +380,7 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>( if check_missing_code == true && tests.found_tests == 0 { let mut diag = cx.tcx.struct_span_lint_node( lint::builtin::MISSING_DOC_CODE_EXAMPLES, - NodeId::from_u32(0), + hir::CRATE_HIR_ID, span_of_attrs(&item.attrs), "Missing code example in this documentation"); diag.emit(); @@ -389,7 +389,7 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>( !cx.renderinfo.borrow().access_levels.is_doc_reachable(item.def_id) { let mut diag = cx.tcx.struct_span_lint_node( lint::builtin::PRIVATE_DOC_TESTS, - NodeId::from_u32(0), + hir::CRATE_HIR_ID, span_of_attrs(&item.attrs), "Documentation test in private item"); diag.emit(); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index af47c7d5e8bfa..6247855bfc23b 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -838,7 +838,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> { fn visit_item(&mut self, item: &'hir hir::Item) { let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.node { - self.map.node_to_pretty_string(ty.id) + self.map.node_to_pretty_string_by_hir_id(ty.hir_id) } else { item.ident.to_string() }; @@ -869,7 +869,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> { fn visit_variant(&mut self, v: &'hir hir::Variant, g: &'hir hir::Generics, - item_id: ast::NodeId) { + item_id: hir::HirId) { self.visit_testable(v.node.ident.to_string(), &v.node.attrs, |this| { intravisit::walk_variant(this, v, g, item_id); }); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 953ab7c2565bf..91e5abee2dc40 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -30,7 +30,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> { pub module: Module, pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, - view_item_stack: FxHashSet, + view_item_stack: FxHashSet, inlining: bool, /// Are the current module and all of its parents public? inside_public_path: bool, @@ -43,7 +43,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { ) -> RustdocVisitor<'a, 'tcx, 'rcx> { // If the root is re-exported, terminate all recursion. let mut stack = FxHashSet::default(); - stack.insert(ast::CRATE_NODE_ID); + stack.insert(hir::CRATE_HIR_ID); RustdocVisitor { module: Module::new(None), attrs: hir::HirVec::new(), @@ -65,14 +65,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - fn stability(&self, id: ast::NodeId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) - .and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned() + fn stability(&self, id: hir::HirId) -> Option { + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id); + self.cx.tcx.lookup_stability(def_id).cloned() } - fn deprecation(&self, id: ast::NodeId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) - .and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id)) + fn deprecation(&self, id: hir::HirId) -> Option { + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(id); + self.cx.tcx.lookup_deprecation(def_id) } pub fn visit(&mut self, krate: &hir::Crate) { @@ -82,7 +82,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { krate.attrs.clone(), Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public }, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, &krate.module, None); // Attach the crate's exported macros to the top-level module: @@ -100,12 +100,12 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { debug!("Visiting struct"); let struct_type = struct_type_from_def(&*sd); Struct { - id: item.id, + id: item.hir_id, struct_type, name, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), generics: generics.clone(), fields: sd.fields().iter().cloned().collect(), @@ -119,12 +119,12 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { debug!("Visiting union"); let struct_type = struct_type_from_def(&*sd); Union { - id: item.id, + id: item.hir_id, struct_type, name, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), generics: generics.clone(), fields: sd.fields().iter().cloned().collect(), @@ -141,17 +141,17 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { variants: def.variants.iter().map(|v| Variant { name: v.node.ident.name, attrs: v.node.attrs.clone(), - stab: self.stability(v.node.data.id()), - depr: self.deprecation(v.node.data.id()), + stab: self.stability(v.node.data.hir_id()), + depr: self.deprecation(v.node.data.hir_id()), def: v.node.data.clone(), whence: v.span, }).collect(), vis: it.vis.clone(), - stab: self.stability(it.id), - depr: self.deprecation(it.id), + stab: self.stability(it.hir_id), + depr: self.deprecation(it.hir_id), generics: params.clone(), attrs: it.attrs.clone(), - id: it.id, + id: it.hir_id, whence: it.span, } } @@ -201,21 +201,21 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.proc_macros.push(ProcMacro { name, - id: item.id, + id: item.hir_id, kind, helpers, attrs: item.attrs.clone(), whence: item.span, - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }); } None => { om.fns.push(Function { - id: item.id, + id: item.hir_id, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), decl: fd.clone(), name, @@ -229,7 +229,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec, - vis: hir::Visibility, id: ast::NodeId, + vis: hir::Visibility, id: hir::HirId, m: &hir::Mod, name: Option) -> Module { let mut om = Module::new(name); @@ -261,20 +261,20 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { /// /// Returns true if the target has been inlined. fn maybe_inline_local(&mut self, - id: ast::NodeId, + id: hir::HirId, def: Def, renamed: Option, glob: bool, om: &mut Module, please_inline: bool) -> bool { - fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool { - while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) { - node = id; - if cx.tcx.hir().attrs(node).lists("doc").has_word("hidden") { + fn inherits_doc_hidden(cx: &core::DocContext, mut hir: hir::HirId) -> bool { + while let Some(id) = cx.tcx.hir().get_enclosing_scope(hir) { + hir = id; + if cx.tcx.hir().attrs(hir).lists("doc").has_word("hidden") { return true; } - if node == ast::CRATE_NODE_ID { + if hir == hir::CRATE_HIR_ID { break; } } @@ -322,21 +322,21 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { return false } - let def_node_id = match tcx.hir().as_local_node_id(def_did) { + let def_hir_id = match tcx.hir().as_local_hir_id(def_did) { Some(n) => n, None => return false }; let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(def_did); - let is_hidden = inherits_doc_hidden(self.cx, def_node_id); + let is_hidden = inherits_doc_hidden(self.cx, def_hir_id); // Only inline if requested or if the item would otherwise be stripped. if (!please_inline && !is_private && !is_hidden) || is_no_inline { return false } - if !self.view_item_stack.insert(def_node_id) { return false } + if !self.view_item_stack.insert(def_hir_id) { return false } - let ret = match tcx.hir().get(def_node_id) { + let ret = match tcx.hir().get_by_hir_id(def_hir_id) { 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 { @@ -355,7 +355,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { 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), + abi: tcx.hir().get_foreign_abi(it.hir_id), items: vec![hir::ForeignItem { ident: renamed.unwrap_or(it.ident), .. it.clone() @@ -369,7 +369,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } _ => false, }; - self.view_item_stack.remove(&def_node_id); + self.view_item_stack.remove(&def_hir_id); ret } @@ -379,7 +379,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { let ident = renamed.unwrap_or(item.ident); if item.vis.node.is_pub() { - let def_id = self.cx.tcx.hir().local_def_id(item.id); + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); self.store_path(def_id); } @@ -399,7 +399,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { _ if self.inlining && !item.vis.node.is_pub() => {} hir::ItemKind::GlobalAsm(..) => {} hir::ItemKind::ExternCrate(orig_name) => { - let def_id = self.cx.tcx.hir().local_def_id(item.id); + let def_id = self.cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); om.extern_crates.push(ExternCrate { cnum: self.cx.tcx.extern_mod_stmt_cnum(def_id) .unwrap_or(LOCAL_CRATE), @@ -434,7 +434,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } }); let ident = if is_glob { None } else { Some(ident) }; - if self.maybe_inline_local(item.id, + if self.maybe_inline_local(item.hir_id, path.def, ident, is_glob, @@ -446,7 +446,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.imports.push(Import { name: ident.name, - id: item.id, + id: item.hir_id, vis: item.vis.clone(), attrs: item.attrs.clone(), path: (**path).clone(), @@ -458,7 +458,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(), item.vis.clone(), - item.id, + item.hir_id, m, Some(ident.name))); }, @@ -475,12 +475,12 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { ty: ty.clone(), gen: gen.clone(), name: ident.name, - id: item.id, + id: item.hir_id, attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.typedefs.push(t); }, @@ -488,12 +488,12 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { let t = Existential { exist_ty: exist_ty.clone(), name: ident.name, - id: item.id, + id: item.hir_id, attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.existentials.push(t); }, @@ -502,13 +502,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { type_: ty.clone(), mutability: mut_.clone(), expr: exp.clone(), - id: item.id, + id: item.hir_id, name: ident.name, attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.statics.push(s); }, @@ -516,13 +516,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { let s = Constant { type_: ty.clone(), expr: exp.clone(), - id: item.id, + id: item.hir_id, name: ident.name, attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.constants.push(s); }, @@ -537,12 +537,12 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { items, generics: gen.clone(), bounds: b.iter().cloned().collect(), - id: item.id, + id: item.hir_id, attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.traits.push(t); }, @@ -572,11 +572,11 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { for_: ty.clone(), items, attrs: item.attrs.clone(), - id: item.id, + id: item.hir_id, whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.impls.push(i); } @@ -596,13 +596,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); Macro { - def_id: self.cx.tcx.hir().local_def_id(def.id), + def_id: self.cx.tcx.hir().local_def_id_from_hir_id(def.hir_id), attrs: def.attrs.clone(), name: renamed.unwrap_or(def.name), whence: def.span, matchers, - stab: self.stability(def.id), - depr: self.deprecation(def.id), + stab: self.stability(def.hir_id), + depr: self.deprecation(def.hir_id), imported_from: None, } }