Skip to content

Commit 9a6ca41

Browse files
committed
HirIdify hir::Crate.modules
1 parent 4784645 commit 9a6ca41

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
@@ -539,9 +539,7 @@ impl<'hir> Map<'hir> {
539539
// in the expect_* calls the loops below
540540
self.read(hir_id);
541541

542-
let node_id = self.hir_to_node_id[&hir_id];
543-
544-
let module = &self.forest.krate.modules[&node_id];
542+
let module = &self.forest.krate.modules[&hir_id];
545543

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

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ pub struct Crate {
767767

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

773773
impl Crate {

src/librustc/lint/context.rs

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

src/librustc_interface/passes.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
913913
});
914914
}, {
915915
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
916-
tcx.ensure().check_mod_loops(tcx.hir().local_def_id_from_node_id(module));
917-
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id_from_node_id(module));
918-
tcx.ensure().check_mod_unstable_api_usage(
919-
tcx.hir().local_def_id_from_node_id(module));
916+
let local_def_id = tcx.hir().local_def_id(module);
917+
tcx.ensure().check_mod_loops(local_def_id);
918+
tcx.ensure().check_mod_attrs(local_def_id);
919+
tcx.ensure().check_mod_unstable_api_usage(local_def_id);
920920
});
921921
});
922922
});
@@ -939,9 +939,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
939939
// "not all control paths return a value" is reported here.
940940
//
941941
// maybe move the check to a MIR pass?
942-
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id_from_node_id(module));
942+
let local_def_id = tcx.hir().local_def_id(module);
943943

944-
tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id_from_node_id(module));
944+
tcx.ensure().check_mod_liveness(local_def_id);
945+
tcx.ensure().check_mod_intrinsics(local_def_id);
945946
});
946947
});
947948
});
@@ -1001,7 +1002,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
10011002
}, {
10021003
time(sess, "privacy checking modules", || {
10031004
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
1004-
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id_from_node_id(module));
1005+
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
10051006
});
10061007
});
10071008
});

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
@@ -306,7 +306,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
306306
tcx.sess.track_errors(|| {
307307
time(tcx.sess, "type collecting", || {
308308
for &module in tcx.hir().krate().modules.keys() {
309-
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
309+
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
310310
}
311311
});
312312
})?;
@@ -341,7 +341,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
341341

342342
time(tcx.sess, "item-types checking", || {
343343
for &module in tcx.hir().krate().modules.keys() {
344-
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
344+
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
345345
}
346346
});
347347

0 commit comments

Comments
 (0)