diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 30a0477467d80..e96709f6d14e5 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -571,9 +571,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { match destination.target_id { Ok(loop_id) => { for b in &self.breakable_block_scopes { - if b.block_expr_id == self.tcx.hir().node_to_hir_id(loop_id).local_id { + if b.block_expr_id == loop_id.local_id { let scope = region::Scope { - id: self.tcx.hir().node_to_hir_id(loop_id).local_id, + id: loop_id.local_id, data: region::ScopeData::Node }; return (scope, match scope_cf_kind { @@ -583,9 +583,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } for l in &self.loop_scopes { - if l.loop_id == self.tcx.hir().node_to_hir_id(loop_id).local_id { + if l.loop_id == loop_id.local_id { let scope = region::Scope { - id: self.tcx.hir().node_to_hir_id(loop_id).local_id, + id: loop_id.local_id, data: region::ScopeData::Node }; return (scope, match scope_cf_kind { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 0aeac8cc440ec..977830315e23e 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -34,7 +34,6 @@ use syntax::ast::{Ident, Name, Attribute}; use syntax_pos::Span; use crate::hir::*; -use crate::hir::def::Def; use crate::hir::map::Map; use super::itemlikevisit::DeepVisitor; @@ -228,9 +227,6 @@ pub trait Visitor<'v> : Sized { fn visit_id(&mut self, _hir_id: HirId) { // Nothing to do. } - fn visit_def_mention(&mut self, _def: Def) { - // Nothing to do. - } fn visit_name(&mut self, _span: Span, _name: Name) { // Nothing to do. } @@ -494,13 +490,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ty(typ); visitor.visit_generics(type_parameters) } - ItemKind::Existential(ExistTy {ref generics, ref bounds, impl_trait_fn}) => { + ItemKind::Existential(ExistTy { ref generics, ref bounds, impl_trait_fn: _ }) => { 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 { - visitor.visit_def_mention(Def::Fn(impl_trait_fn)) - } } ItemKind::Enum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters); @@ -640,7 +633,6 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: Hir } pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { - visitor.visit_def_mention(path.def); for segment in &path.segments { visitor.visit_path_segment(path.span, segment); } @@ -697,8 +689,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { PatKind::Ref(ref subpattern, _) => { visitor.visit_pat(subpattern) } - PatKind::Binding(_, canonical_id, _hir_id, ident, ref optional_subpattern) => { - visitor.visit_def_mention(Def::Local(canonical_id)); + PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => { visitor.visit_ident(ident); walk_list!(visitor, visit_pat, optional_subpattern); } @@ -1064,18 +1055,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprKind::Break(ref destination, ref opt_expr) => { if let Some(ref label) = destination.label { visitor.visit_label(label); - if let Ok(node_id) = destination.target_id { - visitor.visit_def_mention(Def::Label(node_id)) - } } walk_list!(visitor, visit_expr, opt_expr); } ExprKind::Continue(ref destination) => { if let Some(ref label) = destination.label { visitor.visit_label(label); - if let Ok(node_id) = destination.target_id { - visitor.visit_def_mention(Def::Label(node_id)) - } } } ExprKind::Ret(ref optional_expression) => { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 52ad800e81c6a..949fdd2682b96 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1068,7 +1068,7 @@ impl<'a> LoweringContext<'a> { let target_id = match destination { Some((id, _)) => { if let Def::Label(loop_id) = self.expect_full_def(id) { - Ok(self.lower_node_id(loop_id).node_id) + Ok(self.lower_node_id(loop_id).hir_id) } else { Err(hir::LoopIdError::UnresolvedLabel) } @@ -1077,7 +1077,7 @@ impl<'a> LoweringContext<'a> { self.loop_scopes .last() .cloned() - .map(|id| Ok(self.lower_node_id(id).node_id)) + .map(|id| Ok(self.lower_node_id(id).hir_id)) .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)) .into() } @@ -1932,7 +1932,6 @@ impl<'a> LoweringContext<'a> { hir::PathSegment::new( segment.ident, - Some(id.node_id), Some(id.hir_id), Some(def), generic_args, @@ -3276,10 +3275,8 @@ impl<'a> LoweringContext<'a> { debug!("renumber_segment_ids(path = {:?})", path); let mut path = path.clone(); for seg in path.segments.iter_mut() { - if seg.id.is_some() { - let next_id = self.next_id(); - seg.id = Some(next_id.node_id); - seg.hir_id = Some(next_id.hir_id); + if seg.hir_id.is_some() { + seg.hir_id = Some(self.next_id().hir_id); } } path @@ -3682,11 +3679,10 @@ impl<'a> LoweringContext<'a> { Some(Def::Local(id)) => id, _ => p.id, }; - let hir_id = self.lower_node_id(canonical_id).hir_id; + hir::PatKind::Binding( self.lower_binding_mode(binding_mode), - canonical_id, - hir_id, + self.lower_node_id(canonical_id).hir_id, ident, sub.as_ref().map(|x| self.lower_pat(x)), ) @@ -4568,12 +4564,13 @@ impl<'a> LoweringContext<'a> { let thin_attrs = ThinVec::from(attrs); let catch_scope = self.catch_scopes.last().map(|x| *x); let ret_expr = if let Some(catch_node) = catch_scope { + let target_id = Ok(self.lower_node_id(catch_node).hir_id); P(self.expr( e.span, hir::ExprKind::Break( hir::Destination { label: None, - target_id: Ok(catch_node), + target_id, }, Some(from_err_expr), ), @@ -4988,7 +4985,7 @@ impl<'a> LoweringContext<'a> { ( P(hir::Pat { hir_id, - node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None), + node: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None), span, }), node_id @@ -5024,8 +5021,8 @@ impl<'a> LoweringContext<'a> { for seg in path.segments.iter_mut() { - if let Some(id) = seg.id { - seg.id = Some(self.lower_node_id(id).node_id); + if seg.hir_id.is_some() { + seg.hir_id = Some(self.next_id().hir_id); } } path diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 21a9ed5ebe03a..86b6805cc9b4c 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -501,10 +501,10 @@ impl<'hir> Map<'hir> { } /// Given a body owner's id, returns the `BodyId` associated with it. - pub fn body_owned_by(&self, id: NodeId) -> 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)); + pub fn body_owned_by(&self, id: HirId) -> BodyId { + self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| { + span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body", + self.hir_to_string(id)); }) } @@ -539,19 +539,19 @@ impl<'hir> Map<'hir> { self.body_owner_kind(node_id) } - 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)) + Node::GenericParam(_) => self.get_parent_node_by_hir_id(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)), } } @@ -618,11 +618,11 @@ impl<'hir> Map<'hir> { } for id in &module.trait_items { - visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id)); + visitor.visit_trait_item(self.expect_trait_item(id.hir_id)); } for id in &module.impl_items { - visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id)); + visitor.visit_impl_item(self.expect_impl_item(id.hir_id)); } } @@ -929,66 +929,52 @@ impl<'hir> Map<'hir> { // FIXME(@ljedrz): replace the NodeId variant pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { - let node_id = self.hir_to_node_id(id); - self.expect_item(node_id) + 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) { + pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem { + match self.find_by_hir_id(id) { Some(Node::ImplItem(item)) => item, - _ => bug!("expected impl item, found {}", self.node_to_string(id)) + _ => bug!("expected impl item, found {}", self.hir_to_string(id)) } } - // FIXME(@ljedrz): replace the NodeId variant - pub fn expect_impl_item_by_hir_id(&self, id: HirId) -> &'hir ImplItem { - let node_id = self.hir_to_node_id(id); - self.expect_impl_item(node_id) - } - - // FIXME(@ljedrz): replace the NodeId variant - pub fn expect_trait_item_by_hir_id(&self, id: HirId) -> &'hir TraitItem { - let node_id = self.hir_to_node_id(id); - self.expect_trait_item(node_id) - } - - pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem { - match self.find(id) { + pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem { + match self.find_by_hir_id(id) { Some(Node::TraitItem(item)) => item, - _ => bug!("expected trait item, found {}", self.node_to_string(id)) + _ => bug!("expected trait item, found {}", self.hir_to_string(id)) } } pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData { - let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible - - match self.find(id) { + 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: HirId) -> &'hir Variant { - let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible - - match self.find(id) { + 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)) } } @@ -1016,7 +1002,7 @@ impl<'hir> Map<'hir> { Node::Field(f) => f.ident.name, Node::Lifetime(lt) => lt.name.ident().name, Node::GenericParam(param) => param.name.ident().name, - Node::Binding(&Pat { node: PatKind::Binding(_, _, _, l, _), .. }) => l.name, + Node::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)) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 4b5670af13858..b9db4523ce1d1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -328,7 +328,6 @@ pub struct PathSegment { // therefore will not have 'jump to def' in IDEs, but otherwise will not be // 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, @@ -351,7 +350,6 @@ impl PathSegment { pub fn from_ident(ident: Ident) -> PathSegment { PathSegment { ident, - id: None, hir_id: None, def: None, infer_types: true, @@ -361,7 +359,6 @@ impl PathSegment { pub fn new( ident: Ident, - id: Option, hir_id: Option, def: Option, args: GenericArgs, @@ -369,7 +366,6 @@ impl PathSegment { ) -> Self { PathSegment { ident, - id, hir_id, def, infer_types, @@ -941,10 +937,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, HirId, 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 `..`. @@ -1623,7 +1619,7 @@ pub struct Destination { // These errors are caught and then reported during the diagnostics pass in // librustc_passes/loops.rs - pub target_id: Result, + pub target_id: Result, } #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index 312351ab850c2..18a3d6708db64 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -70,7 +70,7 @@ impl hir::Pat { where F: FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident), { self.walk(|p| { - if let PatKind::Binding(binding_mode, _, _, ident, _) = p.node { + if let PatKind::Binding(binding_mode, _, ident, _) = p.node { f(binding_mode, p.hir_id, p.span, ident); } true @@ -110,8 +110,8 @@ impl hir::Pat { pub fn simple_ident(&self) -> Option { match self.node { - PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, None) | - PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, None) => Some(ident), + PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) | + PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, None) => Some(ident), _ => None, } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 28e9403e9dba2..54a21f2ed5c2a 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1765,7 +1765,7 @@ impl<'a> State<'a> { // is that it doesn't matter match pat.node { PatKind::Wild => self.s.word("_")?, - PatKind::Binding(binding_mode, _, _, ident, ref sub) => { + PatKind::Binding(binding_mode, _, ident, ref sub) => { match binding_mode { hir::BindingAnnotation::Ref => { self.word_nbsp("ref")?; diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index d8d4157e20ec9..6fff16538044e 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -165,7 +165,6 @@ impl_stable_hash_for!(struct hir::Path { impl_stable_hash_for!(struct hir::PathSegment { ident -> (ident.name), - id, hir_id, def, infer_types, @@ -443,7 +442,7 @@ impl_stable_hash_for!(enum hir::RangeEnd { impl_stable_hash_for!(enum hir::PatKind { Wild, - Binding(binding_mode, var, hir_id, name, sub), + Binding(binding_mode, hir_id, name, sub), Struct(path, field_pats, dotdot), TupleStruct(path, field_pats, dotdot), Path(path), diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 1b7ecc7c3a67c..8bd2084316320 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -4,7 +4,6 @@ use crate::hir::Node; use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin}; use crate::infer::outlives::free_region_map::FreeRegionRelations; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; use crate::traits::{self, PredicateObligation}; use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind}; use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder}; @@ -686,13 +685,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_item(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 { @@ -706,7 +706,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(), }, @@ -714,13 +714,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 { @@ -839,20 +839,20 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { 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_item(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_item(hir_id); } // syntactically we are allowed to define the concrete type - node_id == mod_id + hir_id == mod_id } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 6e8b661b7b895..78a9e406c95e9 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -860,7 +860,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // Each match binding is effectively an assignment to the // binding being produced. - let def = Def::Local(canonical_id); + let def = Def::Local(mc.tcx.hir().hir_to_node_id(canonical_id)); if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) { delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init); } @@ -918,9 +918,8 @@ 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); - let closure_node_id = self.tcx().hir().hir_to_node_id(closure_expr.hir_id); - let closure_def_id = self.tcx().hir().local_def_id(closure_node_id); - self.tcx().with_freevars(closure_node_id, |freevars| { + let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id); + 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 upvar_id = ty::UpvarId { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 76933a6e3484b..2fafc57ce4b2d 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -102,7 +102,7 @@ use crate::hir::Node; use crate::ty::{self, TyCtxt}; use crate::ty::query::Providers; use crate::lint; -use crate::util::nodemap::{NodeMap, HirIdMap, HirIdSet}; +use crate::util::nodemap::{HirIdMap, HirIdSet}; use errors::Applicability; use std::collections::{BTreeMap, VecDeque}; @@ -407,7 +407,7 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P) { while let Some(pat) = pats.pop_front() { use crate::hir::PatKind::*; match pat.node { - Binding(_, _, _, _, ref inner_pat) => { + Binding(_, _, _, ref inner_pat) => { pats.extend(inner_pat.iter()); } Struct(_, ref fields, _) => { @@ -476,8 +476,7 @@ 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(); - let node_id = ir.tcx.hir().hir_to_node_id(expr.hir_id); - ir.tcx.with_freevars(node_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)); @@ -670,8 +669,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> { @@ -952,8 +951,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode) -> LiveNode { if blk.targeted_by_break { - let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id); - self.break_ln.insert(node_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| { @@ -1112,7 +1110,7 @@ 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(hir_id) => self.break_ln.get(&hir_id), Err(err) => span_bug!(expr.span, "loop scope error: {}", err), }.cloned(); @@ -1391,15 +1389,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { debug!("propagate_through_loop: using id for loop body {} {}", expr.hir_id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id)); - let node_id = self.ir.tcx.hir().hir_to_node_id(expr.hir_id); - self.break_ln.insert(node_id, succ); + self.break_ln.insert(expr.hir_id, succ); let cond_ln = match kind { LoopLoop => ln, WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln), }; - self.cont_ln.insert(node_id, cond_ln); + self.cont_ln.insert(expr.hir_id, cond_ln); let body_ln = self.propagate_through_block(body, cond_ln); diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 086b3a318e6b6..8ccf52b4efb28 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -51,8 +51,8 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) { return true } - if let Some(impl_node_id) = tcx.hir().as_local_node_id(impl_src) { - match tcx.hir().find(impl_node_id) { + if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) { + match tcx.hir().find_by_hir_id(impl_hir_id) { Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs), Some(..) | None => @@ -141,12 +141,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Returns true if the given def ID represents a local item that is // eligible for inlining and false otherwise. fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool { - let node_id = match self.tcx.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; } }; - match self.tcx.hir().find(node_id) { + match self.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(item)) => { match item.node { hir::ItemKind::Fn(..) => @@ -173,7 +173,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } else { let impl_did = self.tcx .hir() - .get_parent_did(node_id); + .get_parent_did_by_hir_id(hir_id); // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 3499138fb7915..062742bca7608 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -223,7 +223,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,8 +650,8 @@ 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 scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| { + let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); + let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| { tcx.hir().body(body_id).value.hir_id.local_id }).unwrap_or_else(|| { // The lifetime was defined on node that doesn't own a body, @@ -661,7 +661,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 +686,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 } } @@ -1328,8 +1328,8 @@ 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 scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) { + 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_by_hir_id(id) { let mut visitor = RegionResolutionVisitor { tcx, scope_tree: ScopeTree::default(), @@ -1348,10 +1348,10 @@ 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)); + visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id)); } _ => {} } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index d2bec1070f921..f862b690f8806 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1585,9 +1585,9 @@ 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().as_local_hir_id(def_id).unwrap(); + debug!("hir 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.hir_id, hir_lifetime.span, @@ -1626,8 +1626,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!("Not one use lifetime"); } 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().as_local_hir_id(def_id).unwrap(); + if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) { Node::Lifetime(hir_lifetime) => Some(( hir_lifetime.hir_id, hir_lifetime.span, diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 0462bb802312a..7a91059b6bf45 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2411,15 +2411,15 @@ 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_by_hir_id(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()); struct_fmt.field(&var_name.as_str(), place); @@ -2433,11 +2433,12 @@ 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_by_hir_id(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()); struct_fmt.field(&var_name.as_str(), place); diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 2296fe5763c94..c75f7d7d15946 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -1,5 +1,5 @@ use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; -use syntax::ast::NodeId; +use crate::hir::HirId; use syntax::symbol::{Symbol, InternedString}; use crate::ty::{Instance, TyCtxt}; use crate::util::nodemap::FxHashMap; @@ -14,7 +14,7 @@ use std::hash::Hash; pub enum MonoItem<'tcx> { Fn(Instance<'tcx>), Static(DefId), - GlobalAsm(NodeId), + GlobalAsm(HirId), } impl<'tcx> MonoItem<'tcx> { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 322e384e13e20..448b0f26d5616 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -761,7 +761,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap(); let closure_span = self.tcx.sess.source_map() .def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap()); - let node_id = self.tcx.hir().as_local_node_id(closure_def_id).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap(); let mut err = struct_span_err!( self.tcx.sess, closure_span, E0525, "expected a closure that implements the `{}` trait, \ @@ -780,8 +780,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // a particular trait. if let Some(tables) = self.in_progress_tables { let tables = tables.borrow(); - let closure_hir_id = self.tcx.hir().node_to_hir_id(node_id); - match (found_kind, tables.closure_kind_origins().get(closure_hir_id)) { + match (found_kind, tables.closure_kind_origins().get(hir_id)) { (ty::ClosureKind::FnOnce, Some((span, name))) => { err.span_label(*span, format!( "closure is `FnOnce` because it moves the \ diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index fff5dcf433ed9..e33d0a74ea013 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -67,10 +67,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { /// only checks whether the function has a `const` modifier fn is_const_fn_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool { - let node_id = tcx.hir().as_local_node_id(def_id) - .expect("Non-local call to local provider is_const_fn"); + let hir_id = tcx.hir().as_local_hir_id(def_id) + .expect("Non-local call to local provider is_const_fn"); - if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get(node_id)) { + if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) { fn_like.constness() == hir::Constness::Const } else { false diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f6e6067bb6fc8..2a3a9d1f5f43b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1619,10 +1619,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { _ => return None, // not a free region }; - let node_id = self.hir() - .as_local_node_id(suitable_region_binding_scope) + let hir_id = self.hir() + .as_local_hir_id(suitable_region_binding_scope) .unwrap(); - let is_impl_item = match self.hir().find(node_id) { + let is_impl_item = match self.hir().find_by_hir_id(hir_id) { Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false, Some(Node::ImplItem(..)) => { self.is_bound_region_in_impl_item(suitable_region_binding_scope) @@ -1642,8 +1642,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { scope_def_id: DefId, ) -> Option> { // HACK: `type_of_def_id()` will fail on these (#55796), so return None - let node_id = self.hir().as_local_node_id(scope_def_id).unwrap(); - match self.hir().get(node_id) { + let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap(); + match self.hir().get_by_hir_id(hir_id) { Node::Item(item) => { match item.node { ItemKind::Fn(..) => { /* type_of_def_id() will work */ } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a649e312b4345..356f9c32f03df 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -5,7 +5,7 @@ pub use self::IntVarValue::*; pub use self::fold::TypeFoldable; use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap}; -use crate::hir::Node; +use crate::hir::{HirId, Node}; use crate::hir::def::{Def, CtorKind, ExportMap}; use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::hir::map::DefPathData; @@ -2726,8 +2726,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn opt_associated_item(self, def_id: DefId) -> Option { - let is_associated_item = if let Some(node_id) = self.hir().as_local_node_id(def_id) { - match self.hir().get(node_id) { + let is_associated_item = if let Some(hir_id) = self.hir().as_local_hir_id(def_id) { + match self.hir().get_by_hir_id(hir_id) { Node::TraitItem(_) | Node::ImplItem(_) => true, _ => false, } @@ -3048,10 +3048,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: 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), @@ -3163,8 +3163,8 @@ fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option /// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition. pub fn is_impl_trait_defn(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option { - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - if let Node::Item(item) = tcx.hir().get(node_id) { + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + if let Node::Item(item) = tcx.hir().get_by_hir_id(hir_id) { if let hir::ItemKind::Existential(ref exist_ty) = item.node { return exist_ty.impl_trait_fn; } diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index feca0f7170ef3..49aa6b9e9568a 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -313,7 +313,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/util/ppaux.rs b/src/librustc/util/ppaux.rs index cdc0c3371ebcd..a1398c69ff0c5 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -1380,10 +1380,10 @@ 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_by_hir_id(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) { print!(f, cx, write("{}{}:", @@ -1416,14 +1416,14 @@ 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_by_hir_id(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) { print!(f, cx, write("{}{}:", diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index bd854e3aa3c81..d2d5c4fe85c90 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -188,8 +188,8 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); - let node_id = bccx.tcx.hir().as_local_node_id(def_id).unwrap(); - let movable_generator = !match bccx.tcx.hir().get(node_id) { + let hir_id = bccx.tcx.hir().as_local_hir_id(def_id).unwrap(); + let movable_generator = !match bccx.tcx.hir().get_by_hir_id(hir_id) { Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), .. diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 310a9a2ef8dad..a15d3d10adf0e 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -98,7 +98,7 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>, cmt: &'c mc::cmt_<'tcx>) { let source = get_pattern_source(bccx.tcx,move_pat); let pat_span_path_opt = match move_pat.node { - PatKind::Binding(_, _, _, ident, _) => { + PatKind::Binding(_, _, ident, _) => { Some(MovePlace { span: move_pat.span, name: ident.name, diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 6d0efb163b8f7..da065f9e05d9e 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -83,9 +83,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 @@ -681,8 +681,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { Origin::Ast); let need_note = match lp.ty.sty { ty::Closure(id, _) => { - let node_id = self.tcx.hir().as_local_node_id(id).unwrap(); - let hir_id = self.tcx.hir().node_to_hir_id(node_id); + let hir_id = self.tcx.hir().as_local_hir_id(id).unwrap(); if let Some((span, name)) = self.tables.closure_kind_origins().get(hir_id) { err.span_note(*span, &format!( "closure cannot be invoked more than once because \ @@ -1253,12 +1252,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } Some(ImmutabilityBlame::AdtFieldDeref(_, field)) => { - let node_id = match self.tcx.hir().as_local_node_id(field.did) { - Some(node_id) => node_id, + let hir_id = match self.tcx.hir().as_local_hir_id(field.did) { + Some(hir_id) => hir_id, None => return }; - if let Node::Field(ref field) = self.tcx.hir().get(node_id) { + if let Node::Field(ref field) = self.tcx.hir().get_by_hir_id(hir_id) { if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) { db.span_label(field.ty.span, msg); } diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 4c88d4f0e63ca..8c83e9ef538e5 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -213,10 +213,10 @@ impl CodegenCx<'ll, 'tcx> { debug!("get_static: sym={} instance={:?}", sym, instance); - let g = if let Some(id) = self.tcx.hir().as_local_node_id(def_id) { + let g = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) { let llty = self.layout_of(ty).llvm_type(self); - let (g, attrs) = match self.tcx.hir().get(id) { + let (g, attrs) = match self.tcx.hir().get_by_hir_id(id) { Node::Item(&hir::Item { ref attrs, span, node: hir::ItemKind::Static(..), .. }) => { diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index bfb6a9153809a..48159d7979923 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/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 76e74e9e2b464..5de5c297c30e5 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -242,7 +242,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) { @@ -256,8 +256,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_lint/builtin.rs b/src/librustc_lint/builtin.rs index 641adec82cdd9..aafae28b49ea5 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -198,7 +198,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { // (Issue #49588) continue; } - if let PatKind::Binding(_, _, _, ident, None) = fieldpat.node.pat.node { + 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.hir_id, cx.tables)) { let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, @@ -458,8 +458,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { // If the trait is private, add the impl items to private_traits so they don't get // reported for missing docs. let real_trait = trait_ref.path.def.def_id(); - if let Some(node_id) = cx.tcx.hir().as_local_node_id(real_trait) { - match cx.tcx.hir().find(node_id) { + if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) { + match cx.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(item)) => { if let hir::VisibilityKind::Inherited = item.vis.node { for impl_item_ref in impl_item_refs { diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 4c4032a36956d..fa18dd1eb8ddb 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -358,7 +358,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { } fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) { - if let &PatKind::Binding(_, _, _, ident, _) = &p.node { + if let &PatKind::Binding(_, _, ident, _) = &p.node { self.check_snake_case(cx, "variable", &ident); } } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 683056c9b33a0..ce0618d4599e7 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -783,8 +783,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(hir_id); let trait_item = tcx.associated_item(def_id); let container = match trait_item.defaultness { @@ -893,8 +893,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(hir_id); let impl_item = self.tcx.associated_item(def_id); let container = match impl_item.defaultness { @@ -982,7 +982,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let body = self.tcx.hir().body(body_id); self.lazy_seq(body.arguments.iter().map(|arg| { match arg.pat.node { - PatKind::Binding(_, _, _, ident, _) => ident.name, + PatKind::Binding(_, _, ident, _) => ident.name, _ => keywords::Invalid.name(), } })) @@ -1364,8 +1364,7 @@ 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 hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); let kind = match tables.node_type(hir_id).sty { ty::Generator(def_id, ..) => { let layout = self.tcx.generator_layout(def_id); @@ -1407,7 +1406,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; diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index dc1979b6380b1..fe07cc0698a0a 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -191,8 +191,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let needs_note = match ty.sty { ty::Closure(id, _) => { let tables = self.infcx.tcx.typeck_tables_of(id); - let node_id = self.infcx.tcx.hir().as_local_node_id(id).unwrap(); - let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(id).unwrap(); tables.closure_kind_origins().get(hir_id).is_none() } @@ -1525,8 +1524,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { debug!("add_moved_or_invoked_closure_note: closure={:?}", closure); if let ty::TyKind::Closure(did, _) = self.mir.local_decls[closure].ty.sty { - let node_id = self.infcx.tcx.hir().as_local_node_id(did).unwrap(); - let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(did).unwrap(); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did) .closure_kind_origins() @@ -1549,8 +1547,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Check if we are just moving a closure after it has been invoked. if let Some(target) = target { if let ty::TyKind::Closure(did, _) = self.mir.local_decls[target].ty.sty { - let node_id = self.infcx.tcx.hir().as_local_node_id(did).unwrap(); - let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(did).unwrap(); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did) .closure_kind_origins() @@ -1790,10 +1787,10 @@ 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() } @@ -2105,8 +2102,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_by_hir_id(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: @@ -2560,14 +2557,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_by_hir_id(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 715ee856a7a62..d5dfdf0add528 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 @@ -163,7 +163,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), )); - let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure(); + let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure(); let borrow_set = Rc::new(BorrowSet::build( tcx, mir, locals_are_invalidated_at_exit, &mdpe.move_data)); @@ -216,7 +216,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/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index f68ed4422bca0..65703adfdff70 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -314,7 +314,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { if let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, _, - _, upvar_ident, _, ) = pat.node @@ -635,8 +634,8 @@ fn annotate_struct_field( if let ty::TyKind::Adt(def, _) = ty.sty { let field = def.all_fields().nth(field.index())?; // Use the HIR types to construct the diagnostic message. - let node_id = tcx.hir().as_local_node_id(field.did)?; - let node = tcx.hir().find(node_id)?; + let hir_id = tcx.hir().as_local_hir_id(field.did)?; + let node = tcx.hir().find_by_hir_id(hir_id)?; // Now we're dealing with the actual struct that we're going to suggest a change to, // we can expect a field that is an immutable reference to a type. if let hir::Node::Field(field) = node { diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 8f1301b743e9d..d3731e7c1274e 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -10,12 +10,13 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode}; use crate::hair::{self, *}; +use rustc::hir::HirId; use rustc::mir::*; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc::ty::layout::VariantIdx; use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use syntax::ast::{Name, NodeId}; +use syntax::ast::Name; use syntax_pos::Span; // helper functions, broken out by category: @@ -530,7 +531,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { pub fn storage_live_binding( &mut self, block: BasicBlock, - var: NodeId, + var: HirId, span: Span, for_guard: ForGuard, ) -> Place<'tcx> { @@ -545,17 +546,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ); let place = Place::Base(PlaceBase::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: 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, @@ -576,7 +575,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { Mutability, Name, BindingMode, - NodeId, + HirId, Span, Ty<'tcx>, UserTypeProjections<'tcx>, @@ -703,7 +702,7 @@ struct Binding<'tcx> { span: Span, source: Place<'tcx>, name: Name, - var_id: NodeId, + var_id: HirId, var_ty: Ty<'tcx>, mutability: Mutability, binding_mode: BindingMode, @@ -1694,7 +1693,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability: Mutability, name: Name, mode: BindingMode, - var_id: NodeId, + var_id: 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 61ead366a87c5..c855940cada67 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -13,13 +13,12 @@ use rustc::mir::*; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::subst::SubstsRef; -use rustc::util::nodemap::NodeMap; +use rustc::util::nodemap::HirIdMap; use rustc_target::spec::PanicStrategy; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; 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 `DefId`. 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) => @@ -68,19 +67,18 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t (*body, tcx.hir().span_by_hir_id(*hir_id)) } - _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), + _ => span_bug!(tcx.hir().span_by_hir_id(id), "can't build MIR for {:?}", def_id), }; tcx.infer_ctxt().enter(|infcx| { - let fn_hir_id = tcx.hir().node_to_hir_id(id); - let cx = Cx::new(&infcx, fn_hir_id); + let cx = Cx::new(&infcx, id); let mut mir = if cx.tables().tainted_by_errors { build::construct_error(cx, body_id) } else if cx.body_owner_kind.is_fn_or_closure() { // fetch the fully liberated fn signature (that is, all bound // types/lifetimes replaced) - let fn_sig = cx.tables().liberated_fn_sigs()[fn_hir_id].clone(); - let fn_def_id = tcx.hir().local_def_id(id); + let fn_sig = cx.tables().liberated_fn_sigs()[id].clone(); + let fn_def_id = tcx.hir().local_def_id_from_hir_id(id); let ty = tcx.type_of(fn_def_id); let mut abi = fn_sig.abi; @@ -92,7 +90,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_type(fn_hir_id); + let gen_ty = tcx.body_tables(body_id).node_type(id); Some(ArgInfo(gen_ty, None, None, None)) } _ => None, @@ -141,7 +139,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_by_hir_id(id), + "generator w/o generator type: {:?}", ty), }; (Some(gen_sig.yield_ty), gen_sig.return_ty) } else { @@ -224,11 +223,11 @@ 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); + let span = tcx.hir().span_by_hir_id(ctor_id); if let hir::VariantData::Tuple(ref fields, ctor_id) = *v { tcx.infer_ctxt().enter(|infcx| { let mut mir = shim::build_adt_ctor(&infcx, ctor_id, fields, span); @@ -259,11 +258,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_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_type(closure_expr_hir_id); + let closure_ty = tcx.body_tables(body_id).node_type(closure_expr_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 +375,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// Maps `NodeId`s 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 +391,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) } } @@ -472,11 +470,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, } @@ -606,7 +604,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, @@ -621,10 +619,10 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, let tcx = hir.tcx(); let tcx_hir = tcx.hir(); - let span = tcx_hir.span(fn_id); + let span = tcx_hir.span_by_hir_id(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 @@ -651,7 +649,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, mutability: Mutability::Not, }; if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) { - if let hir::PatKind::Binding(_, _, _, ident, _) = pat.node { + 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) { if bm == ty::BindByValue(hir::MutMutable) { @@ -718,9 +716,8 @@ 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); - info!("fn_id {:?} has attrs {:?}", closure_expr_id, - tcx.get_attrs(closure_expr_id)); + info!("fn_id {:?} has attrs {:?}", fn_def_id, + tcx.get_attrs(fn_def_id)); let mut mir = builder.finish(yield_ty); mir.spread_arg = spread_arg; @@ -857,8 +854,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let mut name = None; if let Some(pat) = pattern { match pat.node { - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, _) - | hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, _) => { + hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _) + | hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, _) => { name = Some(ident.name); } _ => (), diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 35ca13891876c..3f5d82e5f091a 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -617,7 +617,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 @@ -625,7 +625,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( return Err(ErrorHandled::Reported) } - if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(id) { + if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(id) { tcx.mir_const_qualif(def_id); } diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs index c7f6983be6192..da9cc118f5521 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 std::fs; @@ -14,7 +14,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>; } @@ -23,7 +23,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 } } @@ -47,8 +47,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) } @@ -70,7 +70,7 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P> type Edge = Edge; fn graph_id(&self) -> dot::Id<'_> { dot::Id::new(format!("graph_for_node_{}", - self.mbcx.node_id())) + self.mbcx.hir_id())) .unwrap() } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index c24a776605cb8..03f8ac6743617 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::HirId; 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: 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: 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: 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/expr.rs b/src/librustc_mir/hair/cx/expr.rs index e70756ad2f251..6af45957acf09 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -530,8 +530,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 expr_node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id); - let upvars = cx.tcx.with_freevars(expr_node_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)) @@ -592,7 +591,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, match dest.target_id { Ok(target_id) => ExprKind::Break { label: region::Scope { - id: cx.tcx.hir().node_to_hir_id(target_id).local_id, + id: target_id.local_id, data: region::ScopeData::Node }, value: value.to_ref(), @@ -604,7 +603,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, match dest.target_id { Ok(loop_id) => ExprKind::Continue { label: region::Scope { - id: cx.tcx.hir().node_to_hir_id(loop_id).local_id, + id: loop_id.local_id, data: region::ScopeData::Node }, }, @@ -993,7 +992,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id); match def { - Def::Local(id) => ExprKind::VarRef { id }, + Def::Local(id) => ExprKind::VarRef { id: cx.tcx.hir().node_to_hir_id(id) }, Def::Upvar(var_id, index, closure_expr_id) => { debug!("convert_var(upvar({:?}, {:?}, {:?}))", diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 6707b01ccc11b..385249ec1c13b 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -12,7 +12,6 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserType}; use rustc::ty::layout::VariantIdx; use rustc::hir; -use syntax::ast; use syntax_pos::Span; use self::cx::Cx; @@ -230,7 +229,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 9af513a90905e..9768706b37eaa 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -38,7 +38,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(()); @@ -315,7 +315,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pat) { pat.walk(|p| { - if let PatKind::Binding(_, _, _, ident, None) = p.node { + if let PatKind::Binding(_, _, ident, None) = p.node { if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) { if bm != ty::BindByValue(hir::MutImmutable) { // Nothing to check. @@ -590,7 +590,7 @@ fn check_legality_of_move_bindings( for pat in pats { pat.walk(|p| { - if let PatKind::Binding(_, _, _, _, ref sub) = p.node { + if let PatKind::Binding(_, _, _, ref sub) = p.node { if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) { match bm { ty::BindByValue(..) => { diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index d5f2e7a7275e8..55547cd0bc64e 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -126,7 +126,7 @@ pub enum PatternKind<'tcx> { mutability: Mutability, name: ast::Name, mode: BindingMode, - var: ast::NodeId, + var: hir::HirId, ty: Ty<'tcx>, subpattern: Option>, }, @@ -559,7 +559,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } } - PatKind::Binding(_, id, _, ident, ref sub) => { + PatKind::Binding(_, id, ident, ref sub) => { let var_ty = self.tables.node_type(pat.hir_id); if let ty::Error = var_ty.sty { // Avoid ICE @@ -1090,7 +1090,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, SubstsRef<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>, UserTypeProjection<'tcx>, PatternTypeProjection<'tcx> diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index bfc977c28cd39..6d6a3f9147269 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -10,9 +10,9 @@ use rustc::ty::subst::InternalSubsts; pub fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, def_id: DefId) { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(node_id)) { + if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) { check_fn_for_unconditional_recursion(tcx, fn_like_node.kind(), mir, def_id); } } diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 4350bfcdc7a96..1e245faddf04c 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -976,8 +976,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { debug!("RootCollector: ItemKind::GlobalAsm({})", def_id_to_string(self.tcx, self.tcx.hir().local_def_id_from_hir_id(item.hir_id))); - let node_id = self.tcx.hir().hir_to_node_id(item.hir_id); - self.output.push(MonoItem::GlobalAsm(node_id)); + self.output.push(MonoItem::GlobalAsm(item.hir_id)); } hir::ItemKind::Static(..) => { let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id); diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index f0d19ec8bf2fa..211f9ad1735c3 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -58,8 +58,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() } @@ -190,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_by_hir_id(hir_id)) } } diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index f98bc476aafec..c0e2186d9f34c 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::{CodegenFnAttrFlags, HirId}; 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,19 +161,19 @@ 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 { ItemSortKey(match item { MonoItem::Fn(ref instance) => { match instance.def { - // We only want to take NodeIds of user-defined + // We only want to take HirIds of user-defined // instances into account. The others don't matter for // 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/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 047731e3fe6a7..b494592c89f43 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -533,8 +533,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) let param_env = tcx.param_env(def_id); - let id = tcx.hir().as_local_node_id(def_id).unwrap(); - let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let (const_context, min_const_fn) = match tcx.hir().body_owner_kind_by_hir_id(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => (tcx.is_const_fn(def_id), tcx.is_min_const_fn(def_id)), hir::BodyOwnerKind::Const | diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 9febe6af5b1fc..23d8138efccaf 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -37,10 +37,10 @@ impl MirPass for ConstProp { } use rustc::hir::map::blocks::FnLikeNode; - let node_id = tcx.hir().as_local_node_id(source.def_id()) - .expect("Non-local call to local provider is_const_fn"); + let hir_id = tcx.hir().as_local_hir_id(source.def_id()) + .expect("Non-local call to local provider is_const_fn"); - let is_fn_like = FnLikeNode::from_node(tcx.hir().get(node_id)).is_some(); + let is_fn_like = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)).is_some(); let is_assoc_const = match tcx.describe_def(source.def_id()) { Some(Def::AssociatedConst(_)) => true, _ => false, diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 74175d0149ff4..32c027d90a0ce 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -11,11 +11,11 @@ use crate::util::elaborate_drops::{DropFlagState, Unwind, elaborate_drop}; use crate::util::elaborate_drops::{DropElaborator, DropStyle, DropFlagMode}; use rustc::ty::{self, TyCtxt}; use rustc::ty::layout::VariantIdx; +use rustc::hir; 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; pub struct ElaborateDrops; @@ -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 6a71b58152822..1f59802f8c6c0 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -383,13 +383,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. @@ -403,7 +403,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 918375e426b7d..234483df13ada 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -72,8 +72,10 @@ 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(); - if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() { + let id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap(); + if self.tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure() + && self.source.promoted.is_none() + { for (bb, bb_data) in caller_mir.basic_blocks().iter_enumerated() { if let Some(callsite) = self.get_valid_function_call(bb, bb_data, diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 8f5fc6963771a..0cd2cecf39c03 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -214,8 +214,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_by_hir_id(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/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index a44ec526f9ddc..f078316b97ce8 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -3,6 +3,7 @@ use syntax::ast; use syntax_pos::Span; use rustc::ty::{self, TyCtxt}; +use rustc::hir; use rustc::mir::{self, Mir, Location}; use rustc_data_structures::bit_set::BitSet; use crate::transform::{MirPass, MirSource}; @@ -26,7 +27,7 @@ impl MirPass for SanityCheck { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource<'tcx>, 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; @@ -85,7 +86,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/graphviz.rs b/src/librustc_mir/util/graphviz.rs index 5d495fc04588b..61b1a5a850d28 100644 --- a/src/librustc_mir/util/graphviz.rs +++ b/src/librustc_mir/util/graphviz.rs @@ -27,7 +27,7 @@ pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>, w: &mut W) -> io::Result<()> where W: Write { - writeln!(w, "digraph Mir_{} {{", tcx.hir().as_local_node_id(def_id).unwrap())?; + writeln!(w, "digraph Mir_{} {{", tcx.hir().as_local_hir_id(def_id).unwrap())?; // Global graph properties writeln!(w, r#" graph [fontname="monospace"];"#)?; diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 9cda6cfdacbe3..d08fb40966c49 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -282,7 +282,7 @@ fn dump_matched_mir_node<'a, 'tcx>( ) { let mut file_path = PathBuf::new(); file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir)); - let item_id = tcx.hir().as_local_node_id(source.def_id()).unwrap(); + let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap(); let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name); file_path.push(&file_name); let _ = fs::File::create(&file_path).and_then(|mut file| { diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 533e043efa9d2..2272ac97cddaa 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -8,7 +8,6 @@ use rustc::hir::def_id::DefId; use rustc::hir::map::Map; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::{self, Node, Destination}; -use syntax::ast; use syntax::struct_span_err; use syntax_pos::Span; use errors::Applicability; @@ -105,25 +104,25 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { let loop_id = match label.target_id.into() { Ok(loop_id) => loop_id, - Err(hir::LoopIdError::OutsideLoopScope) => ast::DUMMY_NODE_ID, + Err(hir::LoopIdError::OutsideLoopScope) => hir::DUMMY_HIR_ID, Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => { self.emit_unlabled_cf_in_while_condition(e.span, "break"); - ast::DUMMY_NODE_ID + hir::DUMMY_HIR_ID }, - Err(hir::LoopIdError::UnresolvedLabel) => ast::DUMMY_NODE_ID, + Err(hir::LoopIdError::UnresolvedLabel) => hir::DUMMY_HIR_ID, }; - if loop_id != ast::DUMMY_NODE_ID { - if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() { + if loop_id != hir::DUMMY_HIR_ID { + if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() { return } } if opt_expr.is_some() { - let loop_kind = if loop_id == ast::DUMMY_NODE_ID { + let loop_kind = if loop_id == hir::DUMMY_HIR_ID { None } else { - Some(match self.hir_map.expect_expr(loop_id).node { + Some(match self.hir_map.expect_expr_by_hir_id(loop_id).node { hir::ExprKind::While(..) => LoopKind::WhileLoop, hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source), ref r => span_bug!(e.span, @@ -162,7 +161,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { match destination.target_id { Ok(loop_id) => { - if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() { + if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() { struct_span_err!(self.sess, e.span, E0696, "`continue` pointing to a labeled block") .span_label(e.span, diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index edd658254467f..af01e38cb5431 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -52,9 +52,9 @@ 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_id = tcx.hir().body_owned_by(hir_id); tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id) } @@ -79,9 +79,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) @@ -455,10 +455,9 @@ fn check_expr_kind<'a, 'tcx>( hir::ExprKind::Closure(_capture_clause, ref _box_fn_decl, body_id, _span, _option_generator_movability) => { let nested_body_promotable = v.check_nested_body(body_id); - let node_id = v.tcx.hir().hir_to_node_id(e.hir_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(node_id, |fv| !fv.is_empty()) { + if v.tcx.with_freevars(e.hir_id, |fv| !fv.is_empty()) { NotPromotable } else { nested_body_promotable diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index a9f05eb60db18..d07e89209e7f0 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1182,10 +1182,10 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // A path can only be private if: // it's in this crate... - if let Some(node_id) = self.tcx.hir().as_local_node_id(did) { + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) { // .. and it corresponds to a private type in the AST (this returns // `None` for type parameters). - match self.tcx.hir().find(node_id) { + match self.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(ref item)) => !item.vis.node.is_pub(), Some(_) | None => false, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index af3f54187b0c3..d80f3e5ce759c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -647,7 +647,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Node::Binding(&hir::Pat { node: hir::PatKind::Binding(_, canonical_id, ..), .. - }) => HirDef::Local(canonical_id), + }) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)), Node::Ty(ty) => if let hir::Ty { node: hir::TyKind::Path(ref qpath), diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index 962a145814c8b..c908c6993e19e 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -213,8 +213,8 @@ crate fn environment<'a, 'tcx>( // could bound lifetimes. .map(Clause::ForAll); - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let node = tcx.hir().get(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let node = tcx.hir().get_by_hir_id(hir_id); enum NodeKind { TraitImpl, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index be708c78a0dd1..89ec92a652160 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1223,8 +1223,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, diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index e27672842dbc1..1a3ade7f8baf6 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.demand_eqtype_pat(pat.span, expected, rhs_ty, match_discrim_span); common_type } - PatKind::Binding(ba, _, var_id, _, ref sub) => { + PatKind::Binding(ba, var_id, _, ref sub) => { let bm = if ba == hir::BindingAnnotation::Unannotated { def_bm } else { diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 64f61d5e5232e..6f3cd56c7bf5b 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 diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 32640d7d9a886..1e5f5d244e9c4 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -83,8 +83,7 @@ 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().node_to_hir_id(impl_m_node_id); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap(); let cause = ObligationCause { span: impl_m_span, @@ -416,8 +415,10 @@ 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(impl_m_hir_id) + .node { ImplItemKind::Method(ref impl_m_sig, _) => { (&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter()) } @@ -426,8 +427,10 @@ 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(trait_m_hir_id) + .node { TraitItemKind::Method(ref trait_m_sig, _) => { trait_m_sig.decl.inputs.iter() } @@ -451,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(trait_m_hir_id).node { TraitItemKind::Method(ref trait_m_sig, _) => { (&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter()) } @@ -596,8 +599,8 @@ fn compare_number_of_generics<'a, 'tcx>( if impl_count != trait_count { err_occurred = true; - let impl_node_id = tcx.hir().as_local_node_id(impl_.def_id).unwrap(); - let impl_item = tcx.hir().expect_impl_item(impl_node_id); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id).unwrap(); + let impl_item = tcx.hir().expect_impl_item(impl_hir_id); let span = if impl_item.generics.params.is_empty() || impl_item.generics.span.is_dummy() { // argument position impl Trait (#55374) impl_span @@ -661,8 +664,8 @@ 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 { + 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(trait_id).node { TraitItemKind::Method(ref trait_m_sig, _) => { let pos = if trait_number_args > 0 { @@ -687,8 +690,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(impl_m_hir_id).node { ImplItemKind::Method(ref impl_m_sig, _) => { let pos = if impl_number_args > 0 { impl_number_args - 1 @@ -927,8 +930,7 @@ 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().node_to_hir_id(impl_c_node_id); + 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); @@ -960,7 +962,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(impl_c_hir_id).node { ImplItemKind::Const(ref ty, _) => cause.span = ty.span, _ => bug!("{:?} is not a impl const", impl_c), } @@ -972,10 +974,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(trait_c_hir_id).node { TraitItemKind::Const(ref ty, _) => ty.span, _ => bug!("{:?} is not a trait const", trait_c), } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 301d7d3ac5623..2882ed47f12cc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -593,8 +593,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, def_id: DefId) -> InheritedBuilder<'a, 'gcx, 'tcx> { let hir_id_root = if def_id.is_local() { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let hir_id = tcx.hir().definitions().node_to_hir_id(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); DefId::local(hir_id.owner) } else { def_id @@ -619,8 +618,8 @@ 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 body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(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_by_hir_id(id)); let implicit_region_bound = body_id.map(|body_id| { let body = tcx.hir().body(body_id); tcx.mk_region(ty::ReScope(region::Scope { @@ -1005,7 +1004,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> { // Add pattern bindings. fn visit_pat(&mut self, p: &'gcx hir::Pat) { - if let PatKind::Binding(_, _, _, ident, _) = p.node { + if let PatKind::Binding(_, _, ident, _) = p.node { let var_ty = self.assign(p.span, p.hir_id, None); let node_id = self.fcx.tcx.hir().hir_to_node_id(p.hir_id); @@ -1920,9 +1919,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 { @@ -4263,7 +4262,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } ExprKind::Break(destination, ref expr_opt) => { if let Ok(target_id) = destination.target_id { - let target_id = tcx.hir().node_to_hir_id(target_id); let (e_ty, cause); if let Some(ref e) = *expr_opt { // If this is a break with a value, we need to type-check diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 89e8b2b840d1f..3e6e6576b63ba 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -120,9 +120,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None }; - let closure_node_id = self.tcx.hir().hir_to_node_id(closure_hir_id); - - 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 { @@ -217,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) @@ -238,14 +236,14 @@ 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 diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 16cf25f0d4916..c7bab8d170904 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -151,8 +151,8 @@ 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(hir_id); let method_sig = match trait_item.node { hir::TraitItemKind::Method(ref sig, _) => Some(sig), @@ -162,8 +162,8 @@ pub fn check_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { } 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(hir_id); let method_sig = match impl_item.node { hir::ImplItemKind::Method(ref sig, _) => Some(sig), @@ -625,8 +625,8 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>( let generics = tcx.generics_of(def_id); // only check named existential types defined in this crate if generics.parent.is_none() && def_id.is_local() { - 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) { diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 6079f12936b5c..cbb6d9b29f59f 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -94,8 +94,8 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) { // Note that if we carry through to the `extern_mod_stmt_cnum` query // below it'll cause a panic because `def_id` is actually bogus at this // point in time otherwise. - if let Some(id) = tcx.hir().as_local_node_id(def_id) { - if tcx.hir().find(id).is_none() { + if let Some(id) = tcx.hir().as_local_hir_id(def_id) { + if tcx.hir().find_by_hir_id(id).is_none() { return false; } } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 0996d1ff3b998..5d86bc5409532 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -50,8 +50,8 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: /* do nothing */ } else { // Destructors only work on nominal types. - if let Some(impl_node_id) = tcx.hir().as_local_node_id(impl_did) { - if let Some(Node::Item(item)) = tcx.hir().find(impl_node_id) { + if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_did) { + if let Some(Node::Item(item)) = tcx.hir().find_by_hir_id(impl_hir_id) { let span = match item.node { ItemKind::Impl(.., ref ty, _) => ty.span, _ => item.span, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index eb4bbe880693b..fb5b06470b957 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -255,9 +255,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()); @@ -280,8 +280,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, @@ -301,7 +301,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 @@ -322,10 +322,9 @@ fn type_param_predicates<'a, 'tcx>( }; let icx = ItemCtxt::new(tcx, item_def_id); - let param_hir_id = tcx.hir().node_to_hir_id(param_id); Lrc::make_mut(&mut result) .predicates - .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_hir_id, ty, + .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))); result } @@ -480,7 +479,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: hir::HirId) { } 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 trait_item = tcx.hir().expect_trait_item(trait_item_id); let def_id = tcx.hir().local_def_id_from_hir_id(trait_item.hir_id); tcx.generics_of(def_id); @@ -505,7 +504,7 @@ fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: hir::H 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_by_hir_id(impl_item_id).node { + if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).node { tcx.fn_sig(def_id); } } @@ -619,8 +618,8 @@ fn convert_variant<'a, 'tcx>( fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::AdtDef { use rustc::hir::*; - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item = match tcx.hir().get(node_id) { + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item = match tcx.hir().get_by_hir_id(hir_id) { Node::Item(item) => item, _ => bug!(), }; @@ -694,11 +693,11 @@ fn super_predicates_of<'a, 'tcx>( trait_def_id: DefId, ) -> Lrc> { debug!("super_predicates(trait_def_id={:?})", trait_def_id); - let trait_node_id = tcx.hir().as_local_node_id(trait_def_id).unwrap(); + let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id).unwrap(); - let item = match tcx.hir().get(trait_node_id) { + let item = match tcx.hir().get_by_hir_id(trait_hir_id) { Node::Item(item) => item, - _ => bug!("trait_node_id {} is not an item", trait_node_id), + _ => bug!("trait_node_id {} is not an item", trait_hir_id), }; let (generics, bounds) = match item.node { @@ -887,14 +886,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_item(hir_id); + Some(tcx.hir().local_def_id_from_hir_id(parent_id)) } Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(..), @@ -994,7 +993,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty }), ); - 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. @@ -1096,7 +1094,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, @@ -1569,16 +1567,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_item(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), @@ -1603,11 +1601,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, _), .. @@ -1626,7 +1624,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_by_hir_id(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi) } @@ -1639,7 +1637,7 @@ 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_by_hir_id(hir_id)); let inputs = fields .iter() .map(|f| tcx.type_of(tcx.hir().local_def_id_from_hir_id(f.hir_id))); @@ -1878,8 +1876,8 @@ fn explicit_predicates_of<'a, 'tcx>( } } - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let node = tcx.hir().get(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let node = tcx.hir().get_by_hir_id(hir_id); let mut is_trait = None; let mut is_default_impl_trait = None; diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 1ab414c1f015f..913990ee87897 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -26,10 +26,10 @@ fn inferred_outlives_of<'a, 'tcx>( ) -> Lrc>> { let id = tcx .hir() - .as_local_node_id(item_def_id) + .as_local_hir_id(item_def_id) .expect("expected local def-id"); - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::Item(item) => match item.node { hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => { let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE); diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index d07a4579ad5c3..0b656ed44cc63 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -3,7 +3,7 @@ use rustc::traits::auto_trait as auto; use rustc::ty::{self, TypeFoldable}; use std::fmt::Debug; -use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; +use self::def_ctor::{get_def_from_def_id, get_def_from_hir_id}; use super::*; @@ -25,9 +25,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { }) } - pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { - get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| { - let did = self.cx.tcx.hir().local_def_id(id); + pub fn get_with_hir_id(&self, id: hir::HirId, name: String) -> Vec { + get_def_from_hir_id(&self.cx, id, name, &|def_ctor, name| { + let did = self.cx.tcx.hir().local_def_id_from_hir_id(id); self.get_auto_trait_impls(did, &def_ctor, Some(name)) }) } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 5a13490eeccf2..86914f66c3d29 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -9,7 +9,7 @@ use crate::core::DocAccessLevels; use super::*; -use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; +use self::def_ctor::{get_def_from_def_id, get_def_from_hir_id}; pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> { pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, @@ -26,9 +26,9 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { }) } - pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { - get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| { - let did = self.cx.tcx.hir().local_def_id(id); + pub fn get_with_hir_id(&self, id: hir::HirId, name: String) -> Vec { + get_def_from_hir_id(&self.cx, id, name, &|def_ctor, name| { + let did = self.cx.tcx.hir().local_def_id_from_hir_id(id); self.get_blanket_impls(did, &def_ctor, Some(name)) }) } diff --git a/src/librustdoc/clean/def_ctor.rs b/src/librustdoc/clean/def_ctor.rs index fce86d590159b..17d53479a67ae 100644 --- a/src/librustdoc/clean/def_ctor.rs +++ b/src/librustdoc/clean/def_ctor.rs @@ -38,13 +38,13 @@ where F: Fn(& dyn Fn(DefId) -> Def) -> Vec { } } -pub fn get_def_from_node_id(cx: &DocContext<'_, '_, '_>, - id: ast::NodeId, - name: String, - callback: &F, +pub fn get_def_from_hir_id(cx: &DocContext<'_, '_, '_>, + id: hir::HirId, + name: String, + callback: &F, ) -> Vec where F: Fn(& dyn Fn(DefId) -> Def, String) -> Vec { - let item = &cx.tcx.hir().expect_item(id).node; + let item = &cx.tcx.hir().expect_item_by_hir_id(id).node; callback(&match *item { hir::ItemKind::Struct(_, _) => Def::Struct, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index cdffbdd540f8c..abaf87f7aef0f 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -422,8 +422,8 @@ fn build_module( } pub fn print_inlined_const(cx: &DocContext<'_, '_, '_>, did: DefId) -> String { - if let Some(node_id) = cx.tcx.hir().as_local_node_id(did) { - cx.tcx.hir().node_to_pretty_string(node_id) + if let Some(node_id) = cx.tcx.hir().as_local_hir_id(did) { + cx.tcx.hir().hir_to_pretty_string(node_id) } else { cx.tcx.rendered_const(did) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5d0d76507bd07..5a1b4d2f8ce77 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1847,7 +1847,7 @@ impl<'a, A: Copy> Clean for (&'a hir::FnDecl, A) impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { fn clean(&self, cx: &DocContext<'_, '_, '_>) -> FnDecl { let (did, sig) = *self; - let mut names = if cx.tcx.hir().as_local_node_id(did).is_some() { + let mut names = if cx.tcx.hir().as_local_hir_id(did).is_some() { vec![].into_iter() } else { cx.tcx.fn_arg_names(did).into_iter() @@ -3541,13 +3541,13 @@ pub struct Impl { pub blanket_impl: Option, } -pub fn get_auto_traits_with_node_id( +pub fn get_auto_traits_with_hir_id( cx: &DocContext<'_, '_, '_>, - id: ast::NodeId, + id: hir::HirId, name: String ) -> Vec { let finder = AutoTraitFinder::new(cx); - finder.get_with_node_id(id, name) + finder.get_with_hir_id(id, name) } pub fn get_auto_traits_with_def_id( @@ -3559,13 +3559,13 @@ pub fn get_auto_traits_with_def_id( finder.get_with_def_id(id) } -pub fn get_blanket_impls_with_node_id( +pub fn get_blanket_impls_with_hir_id( cx: &DocContext<'_, '_, '_>, - id: ast::NodeId, + id: hir::HirId, name: String ) -> Vec { let finder = BlanketImplFinder::new(cx); - finder.get_with_node_id(id, name) + finder.get_with_hir_id(id, name) } pub fn get_blanket_impls_with_def_id( @@ -3869,7 +3869,7 @@ fn name_from_pat(p: &hir::Pat) -> String { match p.node { PatKind::Wild => "_".to_string(), - PatKind::Binding(_, _, _, ident, _) => ident.to_string(), + PatKind::Binding(_, _, ident, _) => ident.to_string(), PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p), PatKind::Struct(ref name, ref fields, etc) => { format!("{} {{ {}{} }}", qpath_to_string(name), @@ -3902,8 +3902,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) } @@ -4250,7 +4250,6 @@ where F: Fn(DefId) -> Def { def: def_ctor(def_id), 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, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 07cfdde4a4e9d..8fe116bd9c873 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -3,7 +3,7 @@ use rustc_driver::{driver, abort_on_err}; use rustc::session::{self, config}; use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CrateNum, LOCAL_CRATE}; use rustc::hir::def::Def; -use rustc::hir::{self, HirVec}; +use rustc::hir::{self, HirId, HirVec}; use rustc::middle::cstore::CrateStore; use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, TyCtxt, AllArenas}; @@ -17,7 +17,7 @@ use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use rustc_target::spec::TargetTriple; -use syntax::ast::{self, Ident, NodeId}; +use syntax::ast::{self, Ident}; use syntax::source_map; use syntax::feature_gate::UnstableFeatures; use syntax::json::JsonEmitter; @@ -159,7 +159,7 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { /// Like the function of the same name on the HIR map, but skips calling it on fake DefIds. /// (This avoids a slice-index-out-of-bounds panic.) - pub fn as_local_node_id(&self, def_id: DefId) -> Option { + pub fn as_local_node_id(&self, def_id: DefId) -> Option { if self.all_fake_def_ids.borrow().contains(&def_id) { None } else { @@ -167,6 +167,15 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { } } + // FIXME(@ljedrz): remove the NodeId variant + 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, @@ -182,7 +191,6 @@ 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, )); diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 25c86b24c187b..c346714ab485a 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -4,7 +4,7 @@ use rustc::hir::def::Def; use rustc::hir::def_id::DefId; 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::DUMMY_SP; @@ -49,7 +49,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, } @@ -69,7 +69,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; @@ -220,8 +220,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); @@ -248,14 +248,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 != ast::CRATE_NODE_ID => { // FIXME: can we pull the parent module's name from elsewhere? Some(self.cx.tcx.hir().name(parent).to_string()) } @@ -274,7 +274,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(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap())); } let cx = self.cx; @@ -421,7 +421,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(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap())); } if item.is_mod() { diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 4c90540871d2e..044e48f990e42 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -155,11 +155,11 @@ impl<'a, 'tcx, 'rcx> SyntheticImplCollector<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx> DocFolder for SyntheticImplCollector<'a, 'tcx, 'rcx> { fn fold_item(&mut self, i: Item) -> Option { if i.is_struct() || i.is_enum() || i.is_union() { - if let (Some(node_id), Some(name)) = - (self.cx.tcx.hir().as_local_node_id(i.def_id), i.name.clone()) + if let (Some(hir_id), Some(name)) = + (self.cx.tcx.hir().as_local_hir_id(i.def_id), i.name.clone()) { - self.impls.extend(get_auto_traits_with_node_id(self.cx, node_id, name.clone())); - self.impls.extend(get_blanket_impls_with_node_id(self.cx, node_id, name)); + self.impls.extend(get_auto_traits_with_hir_id(self.cx, hir_id, name.clone())); + self.impls.extend(get_blanket_impls_with_hir_id(self.cx, hir_id, name)); } else { self.impls.extend(get_auto_traits_with_def_id(self.cx, i.def_id)); self.impls.extend(get_blanket_impls_with_def_id(self.cx, i.def_id)); diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index d6f3585a04f33..48fc6f61952b3 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -291,7 +291,7 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>( item: &Item, check_missing_code: bool, ) { - if cx.as_local_node_id(item.def_id).is_none() { + if cx.as_local_hir_id(item.def_id).is_none() { // If non-local, no need to check anything. return; } diff --git a/src/test/mir-opt/inline-closure-borrows-arg.rs b/src/test/mir-opt/inline-closure-borrows-arg.rs index 9f925e891c0de..d09ddce09c547 100644 --- a/src/test/mir-opt/inline-closure-borrows-arg.rs +++ b/src/test/mir-opt/inline-closure-borrows-arg.rs @@ -20,7 +20,7 @@ fn foo(_t: T, q: &i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@NodeId(53)]; +// _3 = [closure@HirId { owner: DefIndex(0:4), local_id: 27 }]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/inline-closure.rs b/src/test/mir-opt/inline-closure.rs index 68c88da9c0294..436a8c20e2b49 100644 --- a/src/test/mir-opt/inline-closure.rs +++ b/src/test/mir-opt/inline-closure.rs @@ -16,7 +16,7 @@ fn foo(_t: T, q: i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@NodeId(39)]; +// _3 = [closure@HirId { owner: DefIndex(0:4), local_id: 11 }]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs index bb794409ae01f..cdf635567378e 100644 --- a/src/test/mir-opt/retag.rs +++ b/src/test/mir-opt/retag.rs @@ -98,7 +98,7 @@ fn main() { // } // END rustc.main.EraseRegions.after.mir // START rustc.main-{{closure}}.EraseRegions.after.mir -// fn main::{{closure}}(_1: &[closure@NodeId(124)], _2: &i32) -> &i32 { +// fn main::{{closure}}(_1: &[closure@HirId { owner: DefIndex(0:7), local_id: 70 }], _2: &i32) -> &i32 { // ... // bb0: { // Retag([fn entry] _1); diff --git a/src/tools/clippy b/src/tools/clippy index caccf8bd4c3d4..5d78250c75db3 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit caccf8bd4c3d490d6a4cf329a3411bbf68753642 +Subproject commit 5d78250c75db3b1923072cf1be3b03f7d0cef5e2