Skip to content

Commit a023e61

Browse files
authored
Rollup merge of #70480 - lcnr:appayupyup, r=eddyb
clarify hir_id <-> node_id method names resolves 2 FIXME. r? @eddyb
2 parents 5b68f9c + 37603f4 commit a023e61

File tree

9 files changed

+50
-46
lines changed

9 files changed

+50
-46
lines changed

Diff for: src/librustc/hir/map/collector.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
241241
// Make sure that the DepNode of some node coincides with the HirId
242242
// owner of that node.
243243
if cfg!(debug_assertions) {
244-
let node_id = self.definitions.hir_to_node_id(hir_id);
245-
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
244+
let node_id = self.definitions.hir_id_to_node_id(hir_id);
245+
assert_eq!(self.definitions.node_id_to_hir_id(node_id), hir_id);
246246

247247
if hir_id.owner != self.current_dep_node_owner {
248248
let node_str = match self.definitions.opt_local_def_id(node_id) {
@@ -342,7 +342,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
342342
debug!("visit_item: {:?}", i);
343343
debug_assert_eq!(
344344
i.hir_id.owner,
345-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
345+
self.definitions
346+
.opt_local_def_id(self.definitions.hir_id_to_node_id(i.hir_id))
347+
.unwrap()
346348
);
347349
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
348350
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
@@ -374,7 +376,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
374376
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
375377
debug_assert_eq!(
376378
ti.hir_id.owner,
377-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
379+
self.definitions
380+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ti.hir_id))
381+
.unwrap()
378382
);
379383
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
380384
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
@@ -388,7 +392,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
388392
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
389393
debug_assert_eq!(
390394
ii.hir_id.owner,
391-
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
395+
self.definitions
396+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ii.hir_id))
397+
.unwrap()
392398
);
393399
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
394400
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);

Diff for: src/librustc/hir/map/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'hir> Map<'hir> {
161161
#[inline]
162162
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
163163
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
164-
let hir_id = self.node_to_hir_id(node);
164+
let hir_id = self.node_id_to_hir_id(node);
165165
bug!(
166166
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
167167
node,
@@ -184,7 +184,7 @@ impl<'hir> Map<'hir> {
184184

185185
#[inline]
186186
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
187-
let node_id = self.hir_to_node_id(hir_id);
187+
let node_id = self.hir_id_to_node_id(hir_id);
188188
self.opt_local_def_id_from_node_id(node_id)
189189
}
190190

@@ -204,13 +204,13 @@ impl<'hir> Map<'hir> {
204204
}
205205

206206
#[inline]
207-
pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId {
208-
self.tcx.definitions.hir_to_node_id(hir_id)
207+
pub fn hir_id_to_node_id(&self, hir_id: HirId) -> NodeId {
208+
self.tcx.definitions.hir_id_to_node_id(hir_id)
209209
}
210210

211211
#[inline]
212-
pub fn node_to_hir_id(&self, node_id: NodeId) -> HirId {
213-
self.tcx.definitions.node_to_hir_id(node_id)
212+
pub fn node_id_to_hir_id(&self, node_id: NodeId) -> HirId {
213+
self.tcx.definitions.node_id_to_hir_id(node_id)
214214
}
215215

216216
#[inline]

Diff for: src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> StableHashingContext<'a> {
137137

138138
#[inline]
139139
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
140-
self.definitions.node_to_hir_id(node_id)
140+
self.definitions.node_id_to_hir_id(node_id)
141141
}
142142

143143
#[inline]

Diff for: src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,11 @@ impl<'tcx> TyCtxt<'tcx> {
11261126

11271127
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
11281128
for (k, v) in resolutions.trait_map {
1129-
let hir_id = definitions.node_to_hir_id(k);
1129+
let hir_id = definitions.node_id_to_hir_id(k);
11301130
let map = trait_map.entry(hir_id.owner).or_default();
11311131
let v = v
11321132
.into_iter()
1133-
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
1133+
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
11341134
.collect();
11351135
map.insert(hir_id.local_id, StableVec::new(v));
11361136
}
@@ -1154,7 +1154,7 @@ impl<'tcx> TyCtxt<'tcx> {
11541154
.map(|(k, v)| {
11551155
let exports: Vec<_> = v
11561156
.into_iter()
1157-
.map(|e| e.map_id(|id| definitions.node_to_hir_id(id)))
1157+
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
11581158
.collect();
11591159
(k, exports)
11601160
})

Diff for: src/librustc_hir/definitions.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,13 @@ impl Definitions {
353353
}
354354
}
355355

356-
// FIXME(eddyb) rename to `hir_id_to_node_id`.
357356
#[inline]
358-
pub fn hir_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
357+
pub fn hir_id_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
359358
self.hir_id_to_node_id[&hir_id]
360359
}
361360

362-
// FIXME(eddyb) rename to `node_id_to_hir_id`.
363361
#[inline]
364-
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
362+
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
365363
self.node_id_to_hir_id[node_id]
366364
}
367365

Diff for: src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
644644
}
645645

646646
let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect();
647-
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
647+
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_id_to_node_id(*hir_id));
648648
let used_unsafe: FxHashSet<_> =
649649
unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect();
650650
for &(block_id, is_used) in unsafe_blocks {

Diff for: src/librustc_save_analysis/dump_visitor.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
225225
collector.visit_pat(&arg.pat);
226226

227227
for (id, ident, ..) in collector.collected_idents {
228-
let hir_id = self.tcx.hir().node_to_hir_id(id);
228+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
229229
let typ = match self.save_ctxt.tables.node_type_opt(hir_id) {
230230
Some(s) => s.to_string(),
231231
None => continue,
@@ -268,7 +268,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
268268
) {
269269
debug!("process_method: {}:{}", id, ident);
270270

271-
let hir_id = self.tcx.hir().node_to_hir_id(id);
271+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
272272
self.nest_tables(id, |v| {
273273
if let Some(mut method_data) = v.save_ctxt.get_method_data(id, ident, span) {
274274
v.process_formals(&sig.decl.inputs, &method_data.qualname);
@@ -308,7 +308,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
308308
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
309309
let field_data = self.save_ctxt.get_field_data(field, parent_id);
310310
if let Some(field_data) = field_data {
311-
let hir_id = self.tcx.hir().node_to_hir_id(field.id);
311+
let hir_id = self.tcx.hir().node_id_to_hir_id(field.id);
312312
self.dumper.dump_def(&access_from!(self.save_ctxt, field, hir_id), field_data);
313313
}
314314
}
@@ -360,7 +360,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
360360
ty_params: &'l ast::Generics,
361361
body: Option<&'l ast::Block>,
362362
) {
363-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
363+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
364364
self.nest_tables(item.id, |v| {
365365
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
366366
down_cast_data!(fn_data, DefData, item.span);
@@ -402,7 +402,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
402402
typ: &'l ast::Ty,
403403
expr: Option<&'l ast::Expr>,
404404
) {
405-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
405+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
406406
self.nest_tables(item.id, |v| {
407407
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
408408
down_cast_data!(var_data, DefData, item.span);
@@ -429,7 +429,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
429429
if !self.span.filter_generated(ident.span) {
430430
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
431431
let span = self.span_from_span(ident.span);
432-
let hir_id = self.tcx.hir().node_to_hir_id(id);
432+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
433433

434434
self.dumper.dump_def(
435435
&access_from_vis!(self.save_ctxt, vis, hir_id),
@@ -503,7 +503,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
503503

504504
if !self.span.filter_generated(item.ident.span) {
505505
let span = self.span_from_span(item.ident.span);
506-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
506+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
507507
self.dumper.dump_def(
508508
&access_from!(self.save_ctxt, item, hir_id),
509509
Def {
@@ -546,7 +546,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
546546
};
547547
down_cast_data!(enum_data, DefData, item.span);
548548

549-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
549+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
550550
let access = access_from!(self.save_ctxt, item, hir_id);
551551

552552
for variant in &enum_definition.variants {
@@ -699,7 +699,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
699699
let id = id_from_node_id(item.id, &self.save_ctxt);
700700
let span = self.span_from_span(item.ident.span);
701701
let children = methods.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect();
702-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
702+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
703703
self.dumper.dump_def(
704704
&access_from!(self.save_ctxt, item, hir_id),
705705
Def {
@@ -759,7 +759,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
759759
fn process_mod(&mut self, item: &ast::Item) {
760760
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
761761
down_cast_data!(mod_data, DefData, item.span);
762-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
762+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
763763
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), mod_data);
764764
}
765765
}
@@ -864,7 +864,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
864864
match p.kind {
865865
PatKind::Struct(ref _path, ref fields, _) => {
866866
// FIXME do something with _path?
867-
let hir_id = self.tcx.hir().node_to_hir_id(p.id);
867+
let hir_id = self.tcx.hir().node_id_to_hir_id(p.id);
868868
let adt = match self.save_ctxt.tables.node_type_opt(hir_id) {
869869
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
870870
_ => {
@@ -903,7 +903,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
903903
for (id, ident, _) in collector.collected_idents {
904904
match self.save_ctxt.get_path_res(id) {
905905
Res::Local(hir_id) => {
906-
let id = self.tcx.hir().hir_to_node_id(hir_id);
906+
let id = self.tcx.hir().hir_id_to_node_id(hir_id);
907907
let typ = self
908908
.save_ctxt
909909
.tables
@@ -1126,7 +1126,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11261126

11271127
// The access is calculated using the current tree ID, but with the root tree's visibility
11281128
// (since nested trees don't have their own visibility).
1129-
let hir_id = self.tcx.hir().node_to_hir_id(id);
1129+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
11301130
let access = access_from!(self.save_ctxt, root_item, hir_id);
11311131

11321132
// The parent `DefId` of a given use tree is always the enclosing item.
@@ -1321,7 +1321,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
13211321
if !self.span.filter_generated(item.ident.span) {
13221322
let span = self.span_from_span(item.ident.span);
13231323
let id = id_from_node_id(item.id, &self.save_ctxt);
1324-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
1324+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
13251325

13261326
self.dumper.dump_def(
13271327
&access_from!(self.save_ctxt, item, hir_id),
@@ -1420,7 +1420,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14201420
self.process_macro_use(ex.span);
14211421
match ex.kind {
14221422
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
1423-
let expr_hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id);
1423+
let expr_hir_id = self.save_ctxt.tcx.hir().node_id_to_hir_id(ex.id);
14241424
let hir_expr = self.save_ctxt.tcx.hir().expect_expr(expr_hir_id);
14251425
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
14261426
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
@@ -1429,7 +1429,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14291429
return;
14301430
}
14311431
};
1432-
let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id);
1432+
let node_id = self.save_ctxt.tcx.hir().hir_id_to_node_id(hir_expr.hir_id);
14331433
let res = self.save_ctxt.get_path_res(node_id);
14341434
self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
14351435
}
@@ -1514,7 +1514,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
15141514
}
15151515

15161516
fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
1517-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
1517+
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
15181518
let access = access_from!(self.save_ctxt, item, hir_id);
15191519

15201520
match item.kind {

Diff for: src/librustc_save_analysis/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
412412
let trait_id = self.tcx.trait_id_of_impl(impl_id);
413413
let mut docs = String::new();
414414
let mut attrs = vec![];
415-
if let Some(Node::ImplItem(item)) = hir.find(hir.node_to_hir_id(id)) {
415+
if let Some(Node::ImplItem(item)) = hir.find(hir.node_id_to_hir_id(id)) {
416416
docs = self.docs_for_attrs(&item.attrs);
417417
attrs = item.attrs.to_vec();
418418
}
@@ -452,7 +452,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
452452
Some(def_id) => {
453453
let mut docs = String::new();
454454
let mut attrs = vec![];
455-
let hir_id = self.tcx.hir().node_to_hir_id(id);
455+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
456456

457457
if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) {
458458
docs = self.docs_for_attrs(&item.attrs);
@@ -511,15 +511,15 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
511511
}
512512

513513
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
514-
let expr_hir_id = self.tcx.hir().node_to_hir_id(expr.id);
514+
let expr_hir_id = self.tcx.hir().node_id_to_hir_id(expr.id);
515515
let hir_node = self.tcx.hir().expect_expr(expr_hir_id);
516516
let ty = self.tables.expr_ty_adjusted_opt(&hir_node);
517517
if ty.is_none() || ty.unwrap().kind == ty::Error {
518518
return None;
519519
}
520520
match expr.kind {
521521
ast::ExprKind::Field(ref sub_ex, ident) => {
522-
let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id);
522+
let sub_ex_hir_id = self.tcx.hir().node_id_to_hir_id(sub_ex.id);
523523
let hir_node = match self.tcx.hir().find(sub_ex_hir_id) {
524524
Some(Node::Expr(expr)) => expr,
525525
_ => {
@@ -573,7 +573,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
573573
}
574574
}
575575
ast::ExprKind::MethodCall(ref seg, ..) => {
576-
let expr_hir_id = self.tcx.hir().definitions().node_to_hir_id(expr.id);
576+
let expr_hir_id = self.tcx.hir().definitions().node_id_to_hir_id(expr.id);
577577
let method_id = match self.tables.type_dependent_def_id(expr_hir_id) {
578578
Some(id) => id,
579579
None => {
@@ -605,7 +605,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
605605
}
606606

607607
pub fn get_path_res(&self, id: NodeId) -> Res {
608-
let hir_id = self.tcx.hir().node_to_hir_id(id);
608+
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
609609
match self.tcx.hir().get(hir_id) {
610610
Node::TraitRef(tr) => tr.path.res,
611611

@@ -619,7 +619,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
619619
Some(res) if res != Res::Err => res,
620620
_ => {
621621
let parent_node = self.tcx.hir().get_parent_node(hir_id);
622-
self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node))
622+
self.get_path_res(self.tcx.hir().hir_id_to_node_id(parent_node))
623623
}
624624
},
625625

@@ -681,7 +681,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
681681
Res::Local(id) => Some(Ref {
682682
kind: RefKind::Variable,
683683
span,
684-
ref_id: id_from_node_id(self.tcx.hir().hir_to_node_id(id), self),
684+
ref_id: id_from_node_id(self.tcx.hir().hir_id_to_node_id(id), self),
685685
}),
686686
Res::Def(HirDefKind::Trait, def_id) if fn_type(path_seg) => {
687687
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id) })

Diff for: src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
135135

136136
// In case we're in a module, try to resolve the relative path.
137137
if let Some(module_id) = parent_id.or(self.mod_ids.last().cloned()) {
138-
let module_id = cx.tcx.hir().hir_to_node_id(module_id);
138+
let module_id = cx.tcx.hir().hir_id_to_node_id(module_id);
139139
let result = cx.enter_resolver(|resolver| {
140140
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
141141
});

0 commit comments

Comments
 (0)