Skip to content

Commit 0800b6e

Browse files
authored
Rollup merge of rust-lang#61836 - ljedrz:i_still_hate_node_ids, r=ljedrz
Replace some uses of NodeId with HirId We are still using `NodeId` in some spots where we could use `HirId` instead; this PR targets some of these spots and removes some of the associated `hir::map` functions.
2 parents a2259aa + e1bf56d commit 0800b6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+270
-378
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG {
4242
let body_exit;
4343

4444
// Find the tables for this body.
45-
let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id()));
45+
let owner_def_id = tcx.hir().body_owner_def_id(body.id());
4646
let tables = tcx.typeck_tables_of(owner_def_id);
4747

4848
let mut cfg_builder = CFGBuilder {
@@ -357,7 +357,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
357357
args: I) -> CFGIndex {
358358
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
359359
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
360-
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
360+
let m = self.tcx.hir().get_module_parent(call_expr.hir_id);
361361
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
362362
self.add_unreachable_node()
363363
} else {

src/librustc/cfg/graphviz.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
2222
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
2323
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
2424
assert!(self.cfg.owner_def_id.is_local());
25-
let node_id = self.tcx.hir().hir_to_node_id(hir::HirId {
25+
let hir_id = hir::HirId {
2626
owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
2727
local_id
28-
});
29-
let s = self.tcx.hir().node_to_string(node_id);
28+
};
29+
let s = self.tcx.hir().node_to_string(hir_id);
3030

3131
// Replacing newlines with \\l causes each line to be left-aligned,
3232
// improving presentation of (long) pretty-printed expressions.

src/librustc/hir/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub trait Visitor<'v> : Sized {
171171
/// but cannot supply a `Map`; see `nested_visit_map` for advice.
172172
#[allow(unused_variables)]
173173
fn visit_nested_item(&mut self, id: ItemId) {
174-
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item_by_hir_id(id.id));
174+
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id));
175175
if let Some(item) = opt_item {
176176
self.visit_item(item);
177177
}

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
22
use crate::hir::{self, intravisit, HirId, ItemLocalId};
3-
use syntax::ast::NodeId;
43
use crate::hir::itemlikevisit::ItemLikeVisitor;
54
use rustc_data_structures::fx::FxHashSet;
65
use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter};
@@ -112,19 +111,9 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
112111

113112
trace!("missing hir id {:#?}", hir_id);
114113

115-
// We are already in ICE mode here, so doing a linear search
116-
// should be fine.
117-
let (node_id, _) = self.hir_map
118-
.definitions()
119-
.node_to_hir_id
120-
.iter()
121-
.enumerate()
122-
.find(|&(_, &entry)| hir_id == entry)
123-
.expect("no node_to_hir_id entry");
124-
let node_id = NodeId::from_usize(node_id);
125114
missing_items.push(format!("[local_id: {}, node:{}]",
126115
local_id,
127-
self.hir_map.node_to_string(node_id)));
116+
self.hir_map.node_to_string(hir_id)));
128117
}
129118
self.error(|| format!(
130119
"ItemLocalIds not assigned densely in {}. \
@@ -138,7 +127,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
138127
owner: owner_def_index,
139128
local_id,
140129
})
141-
.map(|h| format!("({:?} {})", h, self.hir_map.hir_to_string(h)))
130+
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
142131
.collect::<Vec<_>>()));
143132
}
144133
}
@@ -156,14 +145,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
156145

157146
if hir_id == hir::DUMMY_HIR_ID {
158147
self.error(|| format!("HirIdValidator: HirId {:?} is invalid",
159-
self.hir_map.hir_to_string(hir_id)));
148+
self.hir_map.node_to_string(hir_id)));
160149
return;
161150
}
162151

163152
if owner != hir_id.owner {
164153
self.error(|| format!(
165154
"HirIdValidator: The recorded owner of {} is {} instead of {}",
166-
self.hir_map.hir_to_string(hir_id),
155+
self.hir_map.node_to_string(hir_id),
167156
self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(),
168157
self.hir_map.def_path(DefId::local(owner)).to_string_no_crate()));
169158
}

0 commit comments

Comments
 (0)