rustc: partially HirIdify
This commit is contained in:
parent
8bf7fda6b5
commit
8d6e5fc20f
9 changed files with 30 additions and 33 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<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))
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue