Skip to content

Commit ff14cac

Browse files
committed
Index Modules using their LocalDefId.
1 parent 7878fa7 commit ff14cac

File tree

10 files changed

+27
-38
lines changed

10 files changed

+27
-38
lines changed

Diff for: compiler/rustc_ast_lowering/src/item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> {
3535

3636
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
3737
fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
38-
let hir_id = self.lctx.lower_node_id(n);
38+
let def_id = self.lctx.lower_node_id(n).expect_owner();
3939

4040
self.lctx.modules.insert(
41-
hir_id,
41+
def_id,
4242
hir::ModuleItems {
4343
items: BTreeSet::new(),
4444
trait_items: BTreeSet::new(),
@@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
4848
);
4949

5050
let old = self.lctx.current_module;
51-
self.lctx.current_module = hir_id;
51+
self.lctx.current_module = def_id;
5252
visit::walk_mod(self, m);
5353
self.lctx.current_module = old;
5454
}

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
4848
use rustc_errors::struct_span_err;
4949
use rustc_hir as hir;
5050
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
51-
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
51+
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID};
5252
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
5353
use rustc_hir::intravisit;
5454
use rustc_hir::{ConstArg, GenericArg, ParamName};
@@ -110,7 +110,7 @@ struct LoweringContext<'a, 'hir: 'a> {
110110

111111
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
112112

113-
modules: BTreeMap<hir::HirId, hir::ModuleItems>,
113+
modules: BTreeMap<LocalDefId, hir::ModuleItems>,
114114

115115
generator_kind: Option<hir::GeneratorKind>,
116116

@@ -158,7 +158,7 @@ struct LoweringContext<'a, 'hir: 'a> {
158158
/// vector.
159159
in_scope_lifetimes: Vec<ParamName>,
160160

161-
current_module: hir::HirId,
161+
current_module: LocalDefId,
162162

163163
type_def_lifetime_params: DefIdMap<usize>,
164164

@@ -314,8 +314,8 @@ pub fn lower_crate<'a, 'hir>(
314314
is_in_dyn_type: false,
315315
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
316316
type_def_lifetime_params: Default::default(),
317-
current_module: hir::CRATE_HIR_ID,
318-
current_hir_id_owner: vec![(LocalDefId { local_def_index: CRATE_DEF_INDEX }, 0)],
317+
current_module: CRATE_DEF_ID,
318+
current_hir_id_owner: vec![(CRATE_DEF_ID, 0)],
319319
item_local_id_counters: Default::default(),
320320
node_id_to_hir_id: IndexVec::new(),
321321
generator_kind: None,

Diff for: compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub struct Crate<'hir> {
668668

669669
/// A list of modules written out in the order in which they
670670
/// appear in the crate. This includes the main crate module.
671-
pub modules: BTreeMap<HirId, ModuleItems>,
671+
pub modules: BTreeMap<LocalDefId, ModuleItems>,
672672
/// A list of proc macro HirIds, written out in the order in which
673673
/// they are declared in the static array generated by proc_macro_harness.
674674
pub proc_macros: Vec<HirId>,

Diff for: compiler/rustc_interface/src/passes.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
831831
},
832832
{
833833
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
834-
let local_def_id = tcx.hir().local_def_id(module);
835-
tcx.ensure().check_mod_loops(local_def_id);
836-
tcx.ensure().check_mod_attrs(local_def_id);
837-
tcx.ensure().check_mod_naked_functions(local_def_id);
838-
tcx.ensure().check_mod_unstable_api_usage(local_def_id);
839-
tcx.ensure().check_mod_const_bodies(local_def_id);
834+
tcx.ensure().check_mod_loops(module);
835+
tcx.ensure().check_mod_attrs(module);
836+
tcx.ensure().check_mod_naked_functions(module);
837+
tcx.ensure().check_mod_unstable_api_usage(module);
838+
tcx.ensure().check_mod_const_bodies(module);
840839
});
841840
}
842841
);
@@ -861,10 +860,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
861860
// "not all control paths return a value" is reported here.
862861
//
863862
// maybe move the check to a MIR pass?
864-
let local_def_id = tcx.hir().local_def_id(module);
865-
866-
tcx.ensure().check_mod_liveness(local_def_id);
867-
tcx.ensure().check_mod_intrinsics(local_def_id);
863+
tcx.ensure().check_mod_liveness(module);
864+
tcx.ensure().check_mod_intrinsics(module);
868865
});
869866
});
870867
}
@@ -926,7 +923,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
926923
{
927924
sess.time("privacy_checking_modules", || {
928925
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
929-
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
926+
tcx.ensure().check_mod_privacy(module);
930927
});
931928
});
932929
}

Diff for: compiler/rustc_lint/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
496496
tcx.sess.time("module_lints", || {
497497
// Run per-module lints
498498
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
499-
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
499+
tcx.ensure().lint_mod(module);
500500
});
501501
});
502502
},

Diff for: compiler/rustc_middle/src/hir/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ pub fn provide(providers: &mut Providers) {
7373
};
7474
providers.hir_crate = |tcx, _| tcx.untracked_crate;
7575
providers.index_hir = map::index_hir;
76-
providers.hir_module_items = |tcx, id| {
77-
let hir = tcx.hir();
78-
let module = hir.local_def_id_to_hir_id(id);
79-
&tcx.untracked_crate.modules[&module]
80-
};
76+
providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id];
8177
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
8278
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
8379
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);

Diff for: compiler/rustc_passes/src/hir_id_validator.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
1414
let errors = Lock::new(Vec::new());
1515
let hir_map = tcx.hir();
1616

17-
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
18-
let local_def_id = hir_map.local_def_id(*module_id);
19-
hir_map.visit_item_likes_in_module(
20-
local_def_id,
21-
&mut OuterVisitor { hir_map, errors: &errors },
22-
);
17+
par_iter(&hir_map.krate().modules).for_each(|(&module_id, _)| {
18+
hir_map
19+
.visit_item_likes_in_module(module_id, &mut OuterVisitor { hir_map, errors: &errors });
2320
});
2421

2522
let errors = errors.into_inner();

Diff for: compiler/rustc_typeck/src/impl_wf_check.rs

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

Diff for: compiler/rustc_typeck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
369369
tcx.sess.track_errors(|| {
370370
tcx.sess.time("type_collecting", || {
371371
for &module in tcx.hir().krate().modules.keys() {
372-
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
372+
tcx.ensure().collect_mod_item_types(module);
373373
}
374374
});
375375
})?;
@@ -401,7 +401,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
401401
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
402402
tcx.sess.time("item_types_checking", || {
403403
for &module in tcx.hir().krate().modules.keys() {
404-
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
404+
tcx.ensure().check_mod_item_types(module);
405405
}
406406
});
407407

Diff for: src/librustdoc/core.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ crate fn run_global_ctxt(
479479
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
480480
tcx.sess.time("item_types_checking", || {
481481
for &module in tcx.hir().krate().modules.keys() {
482-
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
482+
tcx.ensure().check_mod_item_types(module);
483483
}
484484
});
485485
tcx.sess.abort_if_errors();
@@ -488,8 +488,7 @@ crate fn run_global_ctxt(
488488
});
489489
tcx.sess.time("check_mod_attrs", || {
490490
for &module in tcx.hir().krate().modules.keys() {
491-
let local_def_id = tcx.hir().local_def_id(module);
492-
tcx.ensure().check_mod_attrs(local_def_id);
491+
tcx.ensure().check_mod_attrs(module);
493492
}
494493
});
495494

0 commit comments

Comments
 (0)