From 96a72961c9e52de46bb8f1833cd1074dcfbc0194 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 11 Feb 2019 16:06:35 +0100 Subject: [PATCH 1/3] Revert ljedrz:HirIdify_typeck This reverts commit 576df31bedd35a1c7336ce7259bbe93ab662edef, reversing changes made to 4424a2c31a5c84dc4d47083113af6e916ff938c0. --- src/librustc/hir/map/mod.rs | 8 ++------ src/librustc_metadata/encoder.rs | 2 +- src/librustc_typeck/astconv.rs | 13 ++++++------- src/librustc_typeck/check/compare_method.rs | 6 +++--- src/librustc_typeck/check/dropck.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 14 +++++++------- src/librustc_typeck/check/upvar.rs | 3 ++- src/librustc_typeck/check/wfcheck.rs | 10 +++++----- src/librustc_typeck/check/writeback.rs | 10 ++++++---- src/librustc_typeck/coherence/builtin.rs | 8 ++++---- src/librustc_typeck/collect.rs | 12 ++++++------ src/librustc_typeck/variance/mod.rs | 6 +++--- 12 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 2bf82180779d9..955f834e40398 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -934,9 +934,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData { - let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible - + pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData { match self.find(id) { Some(Node::Item(i)) => { match i.node { @@ -951,9 +949,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant(&self, id: HirId) -> &'hir Variant { - let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible - + pub fn expect_variant(&self, id: NodeId) -> &'hir Variant { match self.find(id) { Some(Node::Variant(variant)) => variant, _ => bug!("expected variant, found {}", self.node_to_string(id)), diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 4699f4cac165f..d68ab9750b970 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -674,7 +674,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let def_id = field.did; debug!("IsolatedEncoder::encode_field({:?})", def_id); - let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap(); + let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap(); let variant_data = tcx.hir().expect_variant_data(variant_id); Entry { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 733b03df85704..757385aeb3edc 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -111,7 +111,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { { let tcx = self.tcx(); let lifetime_name = |def_id| { - tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str() + tcx.hir().name(tcx.hir().as_local_node_id(def_id).unwrap()).as_interned_str() }; let r = match tcx.named_region(lifetime.hir_id) { @@ -1682,13 +1682,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let hir_id = tcx.hir().as_local_hir_id(did).unwrap(); - let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); - let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); + let node_id = tcx.hir().as_local_node_id(did).unwrap(); + let item_id = tcx.hir().get_parent_node(node_id); + let item_def_id = tcx.hir().local_def_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[ - &tcx.hir().local_def_id_from_hir_id(hir_id)]; - tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str()) + let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)]; + tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str()) } Def::SelfTy(_, Some(def_id)) => { // `Self` in impl (we know the concrete type). diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 0cc5071dbdd4f..0eb8d7d06b1f6 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -736,8 +736,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, in impl_m_type_params.zip(trait_m_type_params) { if impl_synthetic != trait_synthetic { - let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); - let impl_span = tcx.hir().span_by_hir_id(impl_hir_id); + let impl_node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap(); + let impl_span = tcx.hir().span(impl_node_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!(tcx.sess, impl_span, @@ -840,7 +840,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match param.kind { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { .. } => { - if param.hir_id == impl_hir_id { + if param.id == impl_node_id { Some(¶m.bounds) } else { None diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index e210909127b2a..60b5db0d12cc4 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -184,7 +184,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // absent. So we report an error that the Drop impl injected a // predicate that is not present on the struct definition. - let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap(); + let self_type_node_id = tcx.hir().as_local_node_id(self_type_did).unwrap(); let drop_impl_span = tcx.def_span(drop_impl_did); @@ -216,7 +216,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // repeated `contains` calls. if !assumptions_in_impl_context.contains(&predicate) { - let item_span = tcx.hir().span_by_hir_id(self_type_hir_id); + let item_span = tcx.hir().span(self_type_node_id); struct_span_err!( tcx.sess, drop_impl_span, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f82c07e4c4e0a..fb8f608812197 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1883,14 +1883,14 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Check for duplicate discriminant values if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) { let variant_did = def.variants[VariantIdx::new(i)].did; - let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap(); - let variant_i = tcx.hir().expect_variant(variant_i_hir_id); + let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap(); + let variant_i = tcx.hir().expect_variant(variant_i_node_id); let i_span = match variant_i.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), - None => tcx.hir().span_by_hir_id(variant_i_hir_id) + Some(ref expr) => tcx.hir().span(expr.id), + None => tcx.hir().span(variant_i_node_id) }; let span = match v.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), + Some(ref expr) => tcx.hir().span(expr.id), None => v.span }; struct_span_err!(tcx.sess, span, E0081, @@ -5703,8 +5703,8 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }); for (&used, param) in types_used.iter().zip(types) { if !used { - let id = tcx.hir().as_local_hir_id(param.def_id).unwrap(); - let span = tcx.hir().span_by_hir_id(id); + let id = tcx.hir().as_local_node_id(param.def_id).unwrap(); + let span = tcx.hir().span(id); struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) .span_label(span, "unused type parameter") .emit(); diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 15ae0166b93cb..ffd7c2114e5ab 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -650,5 +650,6 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { } fn var_name(tcx: TyCtxt, var_hir_id: hir::HirId) -> ast::Name { - tcx.hir().name_by_hir_id(var_hir_id) + let var_node_id = tcx.hir().hir_to_node_id(var_hir_id); + tcx.hir().name(var_node_id) } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 1206c8eb1eaa5..97881708b0a07 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -62,11 +62,11 @@ impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> { /// not included it frequently leads to confusing errors in fn bodies. So it's better to check /// the types first. pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let item = tcx.hir().expect_item(node_id); - debug!("check_item_well_formed(it.hir_id={:?}, it.name={})", - item.hir_id, + debug!("check_item_well_formed(it.id={}, it.name={})", + item.id, tcx.item_path_str(def_id)); match item.node { @@ -88,7 +88,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def // won't be allowed unless there's an *explicit* implementation of `Send` // for `T` hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => { - let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id)) + let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id)) .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) { tcx.sess.span_err(item.span, "impls of auto traits cannot be default"); diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 29f531201e4d8..238b087fe32f8 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -407,7 +407,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { if let ty::UserType::TypeOf(_, user_substs) = c_ty.value { if self.rustc_dump_user_substs { // This is a unit-testing mechanism. - let span = self.tcx().hir().span_by_hir_id(hir_id); + let node_id = self.tcx().hir().hir_to_node_id(hir_id); + let span = self.tcx().hir().span(node_id); // We need to buffer the errors in order to guarantee a consistent // order when emitting them. let err = self.tcx().sess.struct_span_err( @@ -738,14 +739,15 @@ impl Locatable for ast::NodeId { impl Locatable for DefIndex { fn to_span(&self, tcx: &TyCtxt) -> Span { - let hir_id = tcx.hir().def_index_to_hir_id(*self); - tcx.hir().span_by_hir_id(hir_id) + let node_id = tcx.hir().def_index_to_node_id(*self); + tcx.hir().span(node_id) } } impl Locatable for hir::HirId { fn to_span(&self, tcx: &TyCtxt) -> Span { - tcx.hir().span_by_hir_id(*self) + let node_id = tcx.hir().hir_to_node_id(*self); + tcx.hir().span(node_id) } } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 3ec08f221f576..bd2373d1659c9 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -76,7 +76,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId) { debug!("visit_implementation_of_copy: impl_did={:?}", impl_did); - let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) { + let impl_node_id = if let Some(n) = tcx.hir().as_local_node_id(impl_did) { n } else { debug!("visit_implementation_of_copy(): impl not in this crate"); @@ -87,7 +87,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span_by_hir_id(impl_hir_id); + let span = tcx.hir().span(impl_node_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); @@ -97,7 +97,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: match param_env.can_type_implement_copy(tcx, self_type) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_node_id); let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node { tr.path.span } else { @@ -114,7 +114,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: err.emit() } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_node_id); let span = if let ItemKind::Impl(.., ref ty, _) = item.node { ty.span } else { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f5e50678040f6..9dc74c5d63a4e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -737,8 +737,8 @@ fn super_predicates_of<'a, 'tcx>( } fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let item = tcx.hir().expect_item(node_id); let (is_auto, unsafety) = match item.node { hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety), @@ -1509,8 +1509,8 @@ fn impl_trait_ref<'a, 'tcx>( ) -> Option> { let icx = ItemCtxt::new(tcx, def_id); - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - match tcx.hir().expect_item_by_hir_id(hir_id).node { + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + match tcx.hir().expect_item(node_id).node { hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => { opt_trait_ref.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1522,8 +1522,8 @@ fn impl_trait_ref<'a, 'tcx>( } fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> hir::ImplPolarity { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - match tcx.hir().expect_item_by_hir_id(hir_id).node { + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + match tcx.hir().expect_item(node_id).node { hir::ItemKind::Impl(_, polarity, ..) => polarity, ref item => bug!("impl_polarity: {:?} not an impl", item), } diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index 347422780d516..afb6a68482013 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -46,12 +46,12 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId) -> Lrc> { - let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); + let id = tcx.hir().as_local_node_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. - span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item") + span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") }; - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::Item(item) => match item.node { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | From ce4af9581ed44ff7e116c6557830c4b2b550f75d Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 11 Feb 2019 16:07:34 +0100 Subject: [PATCH 2/3] Revert HirIdify_mir This reverts commit 4424a2c31a5c84dc4d47083113af6e916ff938c0, reversing changes made to 2d725287e3ac05e5f7aa1c8f9f41011bd593c73a. --- src/librustc_mir/borrow_check/error_reporting.rs | 4 ++-- src/librustc_mir/borrow_check/move_errors.rs | 5 +++-- .../nll/region_infer/error_reporting/region_name.rs | 6 +++--- .../nll/region_infer/error_reporting/var_name.rs | 7 ++++--- src/librustc_mir/borrow_check/nll/universal_regions.rs | 5 +++-- src/librustc_mir/build/mod.rs | 6 +++--- src/librustc_mir/hair/cx/block.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 8 ++++---- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 5a8d7545e6826..afb26963217ff 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -833,13 +833,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { format!("`{}` would have to be valid for `{}`...", name, region_name), ); - if let Some(fn_hir_id) = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id) { + if let Some(fn_node_id) = self.infcx.tcx.hir().as_local_node_id(self.mir_def_id) { err.span_label( drop_span, format!( "...but `{}` will be dropped here, when the function `{}` returns", name, - self.infcx.tcx.hir().name_by_hir_id(fn_hir_id), + self.infcx.tcx.hir().name(fn_node_id), ), ); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 2a5433d431786..f7d46925e17df 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -308,8 +308,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { let upvar_decl = &self.mir.upvar_decls[field.index()]; let upvar_hir_id = upvar_decl.var_hir_id.assert_crate_local(); - let upvar_span = self.infcx.tcx.hir().span_by_hir_id( - upvar_hir_id); + let upvar_node_id = + self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id); + let upvar_span = self.infcx.tcx.hir().span(upvar_node_id); diag.span_label(upvar_span, "captured outer variable"); break; } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index e2148140c56ce..2c4f359f65fa5 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -10,7 +10,7 @@ use rustc::ty::subst::{Substs, UnpackedKind}; use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt}; use rustc::util::ppaux::RegionHighlightMode; use rustc_errors::DiagnosticBuilder; -use syntax::ast::Name; +use syntax::ast::{Name, DUMMY_NODE_ID}; use syntax::symbol::keywords; use syntax_pos::Span; use syntax_pos::symbol::InternedString; @@ -293,9 +293,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { name: &InternedString, ) -> Span { let scope = error_region.free_region_binding_scope(tcx); - let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); + let node = tcx.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); - let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node)); + let span = tcx.sess.source_map().def_span(tcx.hir().span(node)); if let Some(param) = tcx.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index f6bbaf2db0383..bd7b8829c7b4f 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -71,10 +71,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { upvar_index: usize, ) -> (Symbol, Span) { let upvar_hir_id = mir.upvar_decls[upvar_index].var_hir_id.assert_crate_local(); - debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); + let upvar_node_id = tcx.hir().hir_to_node_id(upvar_hir_id); + debug!("get_upvar_name_and_span_for_region: upvar_node_id={:?}", upvar_node_id); - let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id); - let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id); + let upvar_name = tcx.hir().name(upvar_node_id); + let upvar_span = tcx.hir().span(upvar_node_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index ad4444e0df24c..0a214e60bdd78 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -771,8 +771,9 @@ fn for_each_late_bound_region_defined_on<'tcx>( owner: fn_def_id.index, local_id: *late_bound, }; - let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); - let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); + let region_node_id = tcx.hir().hir_to_node_id(hir_id); + let name = tcx.hir().name(region_node_id).as_interned_str(); + let region_def_id = tcx.hir().local_def_id(region_node_id); let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: fn_def_id, bound_region: ty::BoundRegion::BrNamed(region_def_id, name), diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index ed35fb2e532f5..a52b032aeb508 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -64,8 +64,8 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t ) => { (*body_id, ty.span) } - Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => { - (*body, tcx.hir().span_by_hir_id(*hir_id)) + Node::AnonConst(hir::AnonConst { body, id, .. }) => { + (*body, tcx.hir().span(*id)) } _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), @@ -114,7 +114,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); + let ty_span = tcx.hir().span(tcx.hir().hir_to_node_id(ty_hir_id)); opt_ty_info = Some(ty_span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index ed9f95fdecac6..c24cf956504da 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -48,7 +48,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, for (index, stmt) in stmts.iter().enumerate() { let hir_id = stmt.hir_id; let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); - let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id)); + let stmt_span = StatementSpan(cx.tcx.hir().span(stmt.id)); match stmt.node { hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index a76aa7454cbe4..7f3c24daf606d 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -450,8 +450,8 @@ fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if recursion_depth > *tcx.sess.recursion_limit.get() { let error = format!("reached the recursion limit while instantiating `{}`", instance); - if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error); + if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { + tcx.sess.span_fatal(tcx.hir().span(node_id), &error); } else { tcx.sess.fatal(&error); } @@ -482,8 +482,8 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let instance_name = instance.to_string(); let msg = format!("reached the type-length limit while instantiating `{:.64}...`", instance_name); - let mut diag = if let Some(hir_id) = tcx.hir().as_local_hir_id(instance.def_id()) { - tcx.sess.struct_span_fatal(tcx.hir().span_by_hir_id(hir_id), &msg) + let mut diag = if let Some(node_id) = tcx.hir().as_local_node_id(instance.def_id()) { + tcx.sess.struct_span_fatal(tcx.hir().span(node_id), &msg) } else { tcx.sess.struct_fatal(&msg) }; From 5fa4351ac454e7cfb111c5de3a05f05ceaef07f9 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 11 Feb 2019 16:08:50 +0100 Subject: [PATCH 3/3] Revert HirIdify_rustc This reverts commit c3d2490433aa675b850d54cac3beed0977074637, reversing changes made to 68650cacf23c60ee2f346b27bcefa7c6c31de1e4. --- src/librustc/infer/error_reporting/mod.rs | 18 ++++++++++-------- src/librustc/infer/error_reporting/note.rs | 6 ++++-- src/librustc/middle/reachable.rs | 4 ++-- src/librustc/middle/resolve_lifetime.rs | 8 ++++---- src/librustc/traits/error_reporting.rs | 3 +-- src/librustc/traits/util.rs | 6 +++--- src/librustc/ty/item_path.rs | 4 ++-- src/librustc/ty/mod.rs | 12 ++++++------ src/librustc/util/ppaux.rs | 2 +- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 1c23438a3b48a..8510533391287 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -56,6 +56,7 @@ use crate::hir::def_id::DefId; use crate::hir::Node; use crate::middle::region; use std::{cmp, fmt}; +use syntax::ast::DUMMY_NODE_ID; use syntax_pos::{Pos, Span}; use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::ty::error::TypeError; @@ -181,8 +182,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let cm = self.sess.source_map(); let scope = region.free_region_binding_scope(self); - let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); - let tag = match self.hir().find_by_hir_id(node) { + let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); + let tag = match self.hir().find(node) { Some(Node::Block(_)) | Some(Node::Expr(_)) => "body", Some(Node::Item(it)) => Self::item_scope_tag(&it), Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it), @@ -191,7 +192,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { }; let (prefix, span) = match *region { ty::ReEarlyBound(ref br) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&br.name)) @@ -204,7 +205,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { bound_region: ty::BoundRegion::BrNamed(_, ref name), .. }) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&name)) @@ -216,15 +217,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), - self.hir().span_by_hir_id(node), + self.hir().span(node), ), ty::BrFresh(_) => ( "an anonymous lifetime defined on".to_owned(), - self.hir().span_by_hir_id(node), + self.hir().span(node), ), _ => ( format!("the lifetime {} as defined on", fr.bound_region), - cm.def_span(self.hir().span_by_hir_id(node)), + cm.def_span(self.hir().span(node)), ), }, _ => bug!(), @@ -1450,7 +1451,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { format!(" for lifetime parameter `{}` in coherence check", name) } infer::UpvarRegion(ref upvar_id, _) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(var_node_id); format!(" for capture of `{}` by closure", var_name) } infer::NLL(..) => bug!("NLL variable found in lexical phase"), diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 6c481e8c0c114..efd7f3c55e900 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -31,7 +31,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "...so that reference does not outlive borrowed content"); } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(var_node_id); err.span_note(span, &format!("...so that closure can access `{}`", var_name)); } @@ -163,7 +164,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(var_node_id); let mut err = struct_span_err!(self.tcx.sess, span, E0313, diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 99d0c5e88d638..73ba47d411915 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -177,8 +177,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. - let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap(); - match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node { + let impl_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap(); + match self.tcx.hir().expect_item(impl_node_id).node { hir::ItemKind::Impl(..) => { let generics = self.tcx.generics_of(impl_did); generics.requires_monomorphization(self.tcx) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index f187928e0d900..f7cd241236498 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1248,12 +1248,12 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { } => { // FIXME (#24278): non-hygienic comparison if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) { - let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); + let node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(tcx.hir().span(node_id)), shadower_label(label.span), ); return; @@ -2593,12 +2593,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { ref lifetimes, s, .. } => { if let Some(&def) = lifetimes.get(¶m.name.modern()) { - let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); + let node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(self.tcx.hir().span(node_id)), shadower_lifetime(¶m), ); return; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index c17adaf1f9f98..79afc593a4676 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1035,8 +1035,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ).collect::>()) } Node::StructCtor(ref variant_data) => { - (self.tcx.sess.source_map().def_span( - self.tcx.hir().span_by_hir_id(variant_data.hir_id())), + (self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())), vec![ArgKind::empty(); variant_data.fields().len()]) } _ => panic!("non-FnLike node found: {:?}", node), diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 754cc94073b10..67c919ac91610 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -525,9 +525,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn impl_is_default(self, node_item_def_id: DefId) -> bool { - match self.hir().as_local_hir_id(node_item_def_id) { - Some(hir_id) => { - let item = self.hir().expect_item_by_hir_id(hir_id); + match self.hir().as_local_node_id(node_item_def_id) { + Some(node_id) => { + let item = self.hir().expect_item(node_id); if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node { defaultness.is_default() } else { diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 3f49c1b27ce5f..8214c8bacc704 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -462,8 +462,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // only occur very early in the compiler pipeline. let parent_def_id = self.parent_def_id(impl_def_id).unwrap(); self.push_item_path(buffer, parent_def_id, pushed_prelude_crate); - let hir_id = self.hir().as_local_hir_id(impl_def_id).unwrap(); - let item = self.hir().expect_item_by_hir_id(hir_id); + let node_id = self.hir().as_local_node_id(impl_def_id).unwrap(); + let item = self.hir().expect_item(node_id); let span_str = self.sess.source_map().span_to_string(item.span); buffer.push(&format!("", span_str)); } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1f08d930fbda5..60e3ac673a0a0 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2939,8 +2939,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Get the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'gcx> { - if let Some(id) = self.hir().as_local_hir_id(did) { - Attributes::Borrowed(self.hir().attrs_by_hir_id(id)) + if let Some(id) = self.hir().as_local_node_id(did) { + Attributes::Borrowed(self.hir().attrs(id)) } else { Attributes::Owned(self.item_attrs(did)) } @@ -2991,8 +2991,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// with the name of the crate containing the impl. pub fn span_of_impl(self, impl_did: DefId) -> Result { if impl_did.is_local() { - let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); - Ok(self.hir().span_by_hir_id(hir_id)) + let node_id = self.hir().as_local_node_id(impl_did).unwrap(); + Ok(self.hir().span(node_id)) } else { Err(self.crate_name(impl_did.krate)) } @@ -3110,8 +3110,8 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Lrc> { - let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(id); + let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let item = tcx.hir().expect_item(id); let vec: Vec<_> = match item.node { hir::ItemKind::Trait(.., ref trait_item_refs) => { trait_item_refs.iter() diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 4945bf8364877..a12ec3471a91c 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -802,7 +802,7 @@ impl fmt::Debug for ty::UpvarId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, - ty::tls::with(|tcx| tcx.hir().name_by_hir_id(self.var_path.hir_id)), + ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))), self.closure_expr_id) } }