Skip to content

Commit

Permalink
rustc: partially HirIdify
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Feb 5, 2019
1 parent 8bf7fda commit 8d6e5fc
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 33 deletions.
18 changes: 8 additions & 10 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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!(),
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2593,12 +2593,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
ref lifetimes, s, ..
} => {
if let Some(&def) = lifetimes.get(&param.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(&param),
);
return;
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
).collect::<Vec<_>>())
}
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),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!("<impl at {}>", span_str));
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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<Span, Symbol> {
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))
}
Expand Down Expand Up @@ -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<Vec<DefId>> {
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()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 8d6e5fc

Please sign in to comment.