Skip to content

Commit 384d918

Browse files
authored
Rollup merge of rust-lang#58151 - ljedrz:HirIdify_rustc, r=Zoxc
Partially HirId-ify rustc Another step towards rust-lang#57578.
2 parents 9f00747 + 8d6e5fc commit 384d918

File tree

9 files changed

+30
-33
lines changed

9 files changed

+30
-33
lines changed

src/librustc/infer/error_reporting/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use crate::hir::def_id::DefId;
5656
use crate::hir::Node;
5757
use crate::middle::region;
5858
use std::{cmp, fmt};
59-
use syntax::ast::DUMMY_NODE_ID;
6059
use syntax_pos::{Pos, Span};
6160
use crate::traits::{ObligationCause, ObligationCauseCode};
6261
use crate::ty::error::TypeError;
@@ -182,8 +181,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
182181
let cm = self.sess.source_map();
183182

184183
let scope = region.free_region_binding_scope(self);
185-
let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
186-
let tag = match self.hir().find(node) {
184+
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
185+
let tag = match self.hir().find_by_hir_id(node) {
187186
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
188187
Some(Node::Item(it)) => Self::item_scope_tag(&it),
189188
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
@@ -192,7 +191,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
192191
};
193192
let (prefix, span) = match *region {
194193
ty::ReEarlyBound(ref br) => {
195-
let mut sp = cm.def_span(self.hir().span(node));
194+
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
196195
if let Some(param) = self.hir()
197196
.get_generics(scope)
198197
.and_then(|generics| generics.get_named(&br.name))
@@ -205,7 +204,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
205204
bound_region: ty::BoundRegion::BrNamed(_, ref name),
206205
..
207206
}) => {
208-
let mut sp = cm.def_span(self.hir().span(node));
207+
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
209208
if let Some(param) = self.hir()
210209
.get_generics(scope)
211210
.and_then(|generics| generics.get_named(&name))
@@ -217,15 +216,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
217216
ty::ReFree(ref fr) => match fr.bound_region {
218217
ty::BrAnon(idx) => (
219218
format!("the anonymous lifetime #{} defined on", idx + 1),
220-
self.hir().span(node),
219+
self.hir().span_by_hir_id(node),
221220
),
222221
ty::BrFresh(_) => (
223222
"an anonymous lifetime defined on".to_owned(),
224-
self.hir().span(node),
223+
self.hir().span_by_hir_id(node),
225224
),
226225
_ => (
227226
format!("the lifetime {} as defined on", fr.bound_region),
228-
cm.def_span(self.hir().span(node)),
227+
cm.def_span(self.hir().span_by_hir_id(node)),
229228
),
230229
},
231230
_ => bug!(),
@@ -1451,8 +1450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14511450
format!(" for lifetime parameter `{}` in coherence check", name)
14521451
}
14531452
infer::UpvarRegion(ref upvar_id, _) => {
1454-
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
1455-
let var_name = self.tcx.hir().name(var_node_id);
1453+
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
14561454
format!(" for capture of `{}` by closure", var_name)
14571455
}
14581456
infer::NLL(..) => bug!("NLL variable found in lexical phase"),

src/librustc/infer/error_reporting/note.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
3131
"...so that reference does not outlive borrowed content");
3232
}
3333
infer::ReborrowUpvar(span, ref upvar_id) => {
34-
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
35-
let var_name = self.tcx.hir().name(var_node_id);
34+
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
3635
err.span_note(span,
3736
&format!("...so that closure can access `{}`", var_name));
3837
}
@@ -164,8 +163,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
164163
err
165164
}
166165
infer::ReborrowUpvar(span, ref upvar_id) => {
167-
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
168-
let var_name = self.tcx.hir().name(var_node_id);
166+
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
169167
let mut err = struct_span_err!(self.tcx.sess,
170168
span,
171169
E0313,

src/librustc/middle/reachable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
177177
// Check the impl. If the generics on the self
178178
// type of the impl require inlining, this method
179179
// does too.
180-
let impl_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap();
181-
match self.tcx.hir().expect_item(impl_node_id).node {
180+
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap();
181+
match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node {
182182
hir::ItemKind::Impl(..) => {
183183
let generics = self.tcx.generics_of(impl_did);
184184
generics.requires_monomorphization(self.tcx)

src/librustc/middle/resolve_lifetime.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,12 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
12481248
} => {
12491249
// FIXME (#24278): non-hygienic comparison
12501250
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
1251-
let node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap();
1251+
let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
12521252

12531253
signal_shadowing_problem(
12541254
tcx,
12551255
label.name,
1256-
original_lifetime(tcx.hir().span(node_id)),
1256+
original_lifetime(tcx.hir().span_by_hir_id(hir_id)),
12571257
shadower_label(label.span),
12581258
);
12591259
return;
@@ -2593,12 +2593,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25932593
ref lifetimes, s, ..
25942594
} => {
25952595
if let Some(&def) = lifetimes.get(&param.name.modern()) {
2596-
let node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap();
2596+
let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
25972597

25982598
signal_shadowing_problem(
25992599
self.tcx,
26002600
param.name.ident().name,
2601-
original_lifetime(self.tcx.hir().span(node_id)),
2601+
original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)),
26022602
shadower_lifetime(&param),
26032603
);
26042604
return;

src/librustc/traits/error_reporting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10351035
).collect::<Vec<_>>())
10361036
}
10371037
Node::StructCtor(ref variant_data) => {
1038-
(self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())),
1038+
(self.tcx.sess.source_map().def_span(
1039+
self.tcx.hir().span_by_hir_id(variant_data.hir_id())),
10391040
vec![ArgKind::empty(); variant_data.fields().len()])
10401041
}
10411042
_ => panic!("non-FnLike node found: {:?}", node),

src/librustc/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
525525
}
526526

527527
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
528-
match self.hir().as_local_node_id(node_item_def_id) {
529-
Some(node_id) => {
530-
let item = self.hir().expect_item(node_id);
528+
match self.hir().as_local_hir_id(node_item_def_id) {
529+
Some(hir_id) => {
530+
let item = self.hir().expect_item_by_hir_id(hir_id);
531531
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node {
532532
defaultness.is_default()
533533
} else {

src/librustc/ty/item_path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
462462
// only occur very early in the compiler pipeline.
463463
let parent_def_id = self.parent_def_id(impl_def_id).unwrap();
464464
self.push_item_path(buffer, parent_def_id, pushed_prelude_crate);
465-
let node_id = self.hir().as_local_node_id(impl_def_id).unwrap();
466-
let item = self.hir().expect_item(node_id);
465+
let hir_id = self.hir().as_local_hir_id(impl_def_id).unwrap();
466+
let item = self.hir().expect_item_by_hir_id(hir_id);
467467
let span_str = self.sess.source_map().span_to_string(item.span);
468468
buffer.push(&format!("<impl at {}>", span_str));
469469
}

src/librustc/ty/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2939,8 +2939,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29392939

29402940
/// Get the attributes of a definition.
29412941
pub fn get_attrs(self, did: DefId) -> Attributes<'gcx> {
2942-
if let Some(id) = self.hir().as_local_node_id(did) {
2943-
Attributes::Borrowed(self.hir().attrs(id))
2942+
if let Some(id) = self.hir().as_local_hir_id(did) {
2943+
Attributes::Borrowed(self.hir().attrs_by_hir_id(id))
29442944
} else {
29452945
Attributes::Owned(self.item_attrs(did))
29462946
}
@@ -2991,8 +2991,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29912991
/// with the name of the crate containing the impl.
29922992
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {
29932993
if impl_did.is_local() {
2994-
let node_id = self.hir().as_local_node_id(impl_did).unwrap();
2995-
Ok(self.hir().span(node_id))
2994+
let hir_id = self.hir().as_local_hir_id(impl_did).unwrap();
2995+
Ok(self.hir().span_by_hir_id(hir_id))
29962996
} else {
29972997
Err(self.crate_name(impl_did.krate))
29982998
}
@@ -3110,8 +3110,8 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31103110
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31113111
def_id: DefId)
31123112
-> Lrc<Vec<DefId>> {
3113-
let id = tcx.hir().as_local_node_id(def_id).unwrap();
3114-
let item = tcx.hir().expect_item(id);
3113+
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
3114+
let item = tcx.hir().expect_item_by_hir_id(id);
31153115
let vec: Vec<_> = match item.node {
31163116
hir::ItemKind::Trait(.., ref trait_item_refs) => {
31173117
trait_item_refs.iter()

src/librustc/util/ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ impl fmt::Debug for ty::UpvarId {
802802
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
803803
write!(f, "UpvarId({:?};`{}`;{:?})",
804804
self.var_path.hir_id,
805-
ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))),
805+
ty::tls::with(|tcx| tcx.hir().name_by_hir_id(self.var_path.hir_id)),
806806
self.closure_expr_id)
807807
}
808808
}

0 commit comments

Comments
 (0)