From 8d6e5fc20f1c69f453ea7a786a6e47b2da85ed28 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 4 Feb 2019 16:27:09 +0100 Subject: [PATCH] rustc: partially HirIdify --- 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, 30 insertions(+), 33 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 66e4cd49c807f..dda079e295ec5 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -56,7 +56,6 @@ use hir::def_id::DefId; use hir::Node; use middle::region; use std::{cmp, fmt}; -use syntax::ast::DUMMY_NODE_ID; use syntax_pos::{Pos, Span}; use traits::{ObligationCause, ObligationCauseCode}; use ty::error::TypeError; @@ -182,8 +181,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let cm = self.sess.source_map(); let scope = region.free_region_binding_scope(self); - let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); - let tag = match self.hir().find(node) { + let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); + let tag = match self.hir().find_by_hir_id(node) { Some(Node::Block(_)) | Some(Node::Expr(_)) => "body", Some(Node::Item(it)) => Self::item_scope_tag(&it), Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it), @@ -192,7 +191,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(node)); + let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&br.name)) @@ -205,7 +204,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(node)); + let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&name)) @@ -217,15 +216,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(node), + self.hir().span_by_hir_id(node), ), ty::BrFresh(_) => ( "an anonymous lifetime defined on".to_owned(), - self.hir().span(node), + self.hir().span_by_hir_id(node), ), _ => ( format!("the lifetime {} as defined on", fr.bound_region), - cm.def_span(self.hir().span(node)), + cm.def_span(self.hir().span_by_hir_id(node)), ), }, _ => bug!(), @@ -1451,8 +1450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { format!(" for lifetime parameter `{}` in coherence check", name) } infer::UpvarRegion(ref upvar_id, _) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) } infer::NLL(..) => bug!("NLL variable found in lexical phase"), diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index e45a4b17cdd9c..397081292b91f 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -31,8 +31,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "...so that reference does not outlive borrowed content"); } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); err.span_note(span, &format!("...so that closure can access `{}`", var_name)); } @@ -164,8 +163,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_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 10deca836fff3..96f07ef835141 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_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap(); - match self.tcx.hir().expect_item(impl_node_id).node { + 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 { 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 34db30a1706b9..c9d0ddc3fb4e4 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 node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span(node_id)), + original_lifetime(tcx.hir().span_by_hir_id(hir_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 node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span(node_id)), + original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)), shadower_lifetime(¶m), ); return; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index ea3ea59c7613f..c026ca6ec8f1e 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1035,7 +1035,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ).collect::>()) } Node::StructCtor(ref variant_data) => { - (self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())), + (self.tcx.sess.source_map().def_span( + self.tcx.hir().span_by_hir_id(variant_data.hir_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 5b7ba5386725e..8e8deeb7a6bde 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_node_id(node_item_def_id) { - Some(node_id) => { - let item = self.hir().expect_item(node_id); + 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); 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 adb7e1fb3e322..c7b81824113b8 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -461,8 +461,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 node_id = self.hir().as_local_node_id(impl_def_id).unwrap(); - let item = self.hir().expect_item(node_id); + 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 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 c9089428b2324..263724998d7d5 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_node_id(did) { - Attributes::Borrowed(self.hir().attrs(id)) + if let Some(id) = self.hir().as_local_hir_id(did) { + Attributes::Borrowed(self.hir().attrs_by_hir_id(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 node_id = self.hir().as_local_node_id(impl_did).unwrap(); - Ok(self.hir().span(node_id)) + let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); + Ok(self.hir().span_by_hir_id(hir_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_node_id(def_id).unwrap(); - let item = tcx.hir().expect_item(id); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item = tcx.hir().expect_item_by_hir_id(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 51e9192cd290d..5830a0bab2743 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -801,7 +801,7 @@ impl fmt::Debug for ty::UpvarId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, - ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))), + ty::tls::with(|tcx| tcx.hir().name_by_hir_id(self.var_path.hir_id)), self.closure_expr_id) } }