Skip to content

Commit c26f129

Browse files
authored
Rollup merge of rust-lang#62975 - ljedrz:kill_off_hir_to_node_id, r=Zoxc
Almost fully deprecate hir::map::Map.hir_to_node_id - HirIdify `doctree::Module.id` - HirIdify `hir::Crate.modules` - introduce a `HirId` to `DefIndex` map in `map::Definitions` The only last uses of `hir::map::Map.hir_to_node_id` in the compiler are: - for the purposes of `driver::pretty` (in `map::nodes_matching_suffix`), but I don't know if we can remove `NodeId`s in there (I think when I attempted it previously there was some issue due to `HirId` not being representable with an integer) - in `ty::query::on_disk_cache` (not sure about the purpose of this one) - in `mir::transform::check_unsafety` (only important for error message order) Any suggestions how to kill these off? r? @Zoxc
2 parents acf7b50 + 9a6ca41 commit c26f129

File tree

9 files changed

+22
-21
lines changed

9 files changed

+22
-21
lines changed

src/librustc/hir/lowering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct LoweringContext<'a> {
9797

9898
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
9999

100-
modules: BTreeMap<NodeId, hir::ModuleItems>,
100+
modules: BTreeMap<hir::HirId, hir::ModuleItems>,
101101

102102
generator_kind: Option<hir::GeneratorKind>,
103103

@@ -141,7 +141,7 @@ pub struct LoweringContext<'a> {
141141
/// vector.
142142
in_scope_lifetimes: Vec<ParamName>,
143143

144-
current_module: NodeId,
144+
current_module: hir::HirId,
145145

146146
type_def_lifetime_params: DefIdMap<usize>,
147147

@@ -262,7 +262,7 @@ pub fn lower_crate(
262262
is_in_dyn_type: false,
263263
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
264264
type_def_lifetime_params: Default::default(),
265-
current_module: CRATE_NODE_ID,
265+
current_module: hir::CRATE_HIR_ID,
266266
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
267267
item_local_id_counters: Default::default(),
268268
node_id_to_hir_id: IndexVec::new(),

src/librustc/hir/lowering/item.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ impl<'tcx, 'interner> ItemLowerer<'tcx, 'interner> {
4545

4646
impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
4747
fn visit_mod(&mut self, m: &'tcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
48-
self.lctx.modules.insert(n, hir::ModuleItems {
48+
let hir_id = self.lctx.lower_node_id(n);
49+
50+
self.lctx.modules.insert(hir_id, hir::ModuleItems {
4951
items: BTreeSet::new(),
5052
trait_items: BTreeSet::new(),
5153
impl_items: BTreeSet::new(),
5254
});
5355

5456
let old = self.lctx.current_module;
55-
self.lctx.current_module = n;
57+
self.lctx.current_module = hir_id;
5658
visit::walk_mod(self, m);
5759
self.lctx.current_module = old;
5860
}

src/librustc/hir/map/hir_id_validator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn check_crate(hir_map: &hir::map::Map<'_>) {
1010
let errors = Lock::new(Vec::new());
1111

1212
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
13-
let local_def_id = hir_map.local_def_id_from_node_id(*module_id);
13+
let local_def_id = hir_map.local_def_id(*module_id);
1414
hir_map.visit_item_likes_in_module(local_def_id, &mut OuterVisitor {
1515
hir_map,
1616
errors: &errors,

src/librustc/hir/map/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,7 @@ impl<'hir> Map<'hir> {
536536
// in the expect_* calls the loops below
537537
self.read(hir_id);
538538

539-
let node_id = self.hir_to_node_id[&hir_id];
540-
541-
let module = &self.forest.krate.modules[&node_id];
539+
let module = &self.forest.krate.modules[&hir_id];
542540

543541
for id in &module.items {
544542
visitor.visit_item(self.expect_item(*id));

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ pub struct Crate {
766766

767767
/// A list of modules written out in the order in which they
768768
/// appear in the crate. This includes the main crate module.
769-
pub modules: BTreeMap<NodeId, ModuleItems>,
769+
pub modules: BTreeMap<HirId, ModuleItems>,
770770
}
771771

772772
impl Crate {

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
15101510
time(tcx.sess, "module lints", || {
15111511
// Run per-module lints
15121512
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
1513-
tcx.ensure().lint_mod(tcx.hir().local_def_id_from_node_id(module));
1513+
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
15141514
});
15151515
});
15161516
});

src/librustc_interface/passes.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
905905
});
906906
}, {
907907
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
908-
tcx.ensure().check_mod_loops(tcx.hir().local_def_id_from_node_id(module));
909-
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id_from_node_id(module));
910-
tcx.ensure().check_mod_unstable_api_usage(
911-
tcx.hir().local_def_id_from_node_id(module));
908+
let local_def_id = tcx.hir().local_def_id(module);
909+
tcx.ensure().check_mod_loops(local_def_id);
910+
tcx.ensure().check_mod_attrs(local_def_id);
911+
tcx.ensure().check_mod_unstable_api_usage(local_def_id);
912912
});
913913
});
914914
});
@@ -931,9 +931,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
931931
// "not all control paths return a value" is reported here.
932932
//
933933
// maybe move the check to a MIR pass?
934-
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id_from_node_id(module));
934+
let local_def_id = tcx.hir().local_def_id(module);
935935

936-
tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id_from_node_id(module));
936+
tcx.ensure().check_mod_liveness(local_def_id);
937+
tcx.ensure().check_mod_intrinsics(local_def_id);
937938
});
938939
});
939940
});
@@ -993,7 +994,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
993994
}, {
994995
time(sess, "privacy checking modules", || {
995996
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
996-
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id_from_node_id(module));
997+
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
997998
});
998999
});
9991000
});

src/librustc_typeck/impl_wf_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
5454
// but it's one that we must perform earlier than the rest of
5555
// WfCheck.
5656
for &module in tcx.hir().krate().modules.keys() {
57-
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id_from_node_id(module));
57+
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
5858
}
5959
}
6060

src/librustc_typeck/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
303303
tcx.sess.track_errors(|| {
304304
time(tcx.sess, "type collecting", || {
305305
for &module in tcx.hir().krate().modules.keys() {
306-
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
306+
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
307307
}
308308
});
309309
})?;
@@ -338,7 +338,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
338338

339339
time(tcx.sess, "item-types checking", || {
340340
for &module in tcx.hir().krate().modules.keys() {
341-
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
341+
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
342342
}
343343
});
344344

0 commit comments

Comments
 (0)