Index Modules using their LocalDefId.
This commit is contained in:
parent
7878fa70d6
commit
ff14cac621
10 changed files with 27 additions and 38 deletions
|
@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> {
|
|||
|
||||
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
|
||||
fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
|
||||
let hir_id = self.lctx.lower_node_id(n);
|
||||
let def_id = self.lctx.lower_node_id(n).expect_owner();
|
||||
|
||||
self.lctx.modules.insert(
|
||||
hir_id,
|
||||
def_id,
|
||||
hir::ModuleItems {
|
||||
items: BTreeSet::new(),
|
||||
trait_items: BTreeSet::new(),
|
||||
|
@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
|
|||
);
|
||||
|
||||
let old = self.lctx.current_module;
|
||||
self.lctx.current_module = hir_id;
|
||||
self.lctx.current_module = def_id;
|
||||
visit::walk_mod(self, m);
|
||||
self.lctx.current_module = old;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
|
|||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::{ConstArg, GenericArg, ParamName};
|
||||
|
@ -110,7 +110,7 @@ struct LoweringContext<'a, 'hir: 'a> {
|
|||
|
||||
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
|
||||
|
||||
modules: BTreeMap<hir::HirId, hir::ModuleItems>,
|
||||
modules: BTreeMap<LocalDefId, hir::ModuleItems>,
|
||||
|
||||
generator_kind: Option<hir::GeneratorKind>,
|
||||
|
||||
|
@ -158,7 +158,7 @@ struct LoweringContext<'a, 'hir: 'a> {
|
|||
/// vector.
|
||||
in_scope_lifetimes: Vec<ParamName>,
|
||||
|
||||
current_module: hir::HirId,
|
||||
current_module: LocalDefId,
|
||||
|
||||
type_def_lifetime_params: DefIdMap<usize>,
|
||||
|
||||
|
@ -314,8 +314,8 @@ pub fn lower_crate<'a, 'hir>(
|
|||
is_in_dyn_type: false,
|
||||
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
|
||||
type_def_lifetime_params: Default::default(),
|
||||
current_module: hir::CRATE_HIR_ID,
|
||||
current_hir_id_owner: vec![(LocalDefId { local_def_index: CRATE_DEF_INDEX }, 0)],
|
||||
current_module: CRATE_DEF_ID,
|
||||
current_hir_id_owner: vec![(CRATE_DEF_ID, 0)],
|
||||
item_local_id_counters: Default::default(),
|
||||
node_id_to_hir_id: IndexVec::new(),
|
||||
generator_kind: None,
|
||||
|
|
|
@ -668,7 +668,7 @@ pub struct Crate<'hir> {
|
|||
|
||||
/// A list of modules written out in the order in which they
|
||||
/// appear in the crate. This includes the main crate module.
|
||||
pub modules: BTreeMap<HirId, ModuleItems>,
|
||||
pub modules: BTreeMap<LocalDefId, ModuleItems>,
|
||||
/// A list of proc macro HirIds, written out in the order in which
|
||||
/// they are declared in the static array generated by proc_macro_harness.
|
||||
pub proc_macros: Vec<HirId>,
|
||||
|
|
|
@ -831,12 +831,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
|||
},
|
||||
{
|
||||
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
|
||||
let local_def_id = tcx.hir().local_def_id(module);
|
||||
tcx.ensure().check_mod_loops(local_def_id);
|
||||
tcx.ensure().check_mod_attrs(local_def_id);
|
||||
tcx.ensure().check_mod_naked_functions(local_def_id);
|
||||
tcx.ensure().check_mod_unstable_api_usage(local_def_id);
|
||||
tcx.ensure().check_mod_const_bodies(local_def_id);
|
||||
tcx.ensure().check_mod_loops(module);
|
||||
tcx.ensure().check_mod_attrs(module);
|
||||
tcx.ensure().check_mod_naked_functions(module);
|
||||
tcx.ensure().check_mod_unstable_api_usage(module);
|
||||
tcx.ensure().check_mod_const_bodies(module);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -861,10 +860,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
|||
// "not all control paths return a value" is reported here.
|
||||
//
|
||||
// maybe move the check to a MIR pass?
|
||||
let local_def_id = tcx.hir().local_def_id(module);
|
||||
|
||||
tcx.ensure().check_mod_liveness(local_def_id);
|
||||
tcx.ensure().check_mod_intrinsics(local_def_id);
|
||||
tcx.ensure().check_mod_liveness(module);
|
||||
tcx.ensure().check_mod_intrinsics(module);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -926,7 +923,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
|||
{
|
||||
sess.time("privacy_checking_modules", || {
|
||||
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
|
||||
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_privacy(module);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -496,7 +496,7 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
|
|||
tcx.sess.time("module_lints", || {
|
||||
// Run per-module lints
|
||||
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
|
||||
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().lint_mod(module);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
|
@ -73,11 +73,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
};
|
||||
providers.hir_crate = |tcx, _| tcx.untracked_crate;
|
||||
providers.index_hir = map::index_hir;
|
||||
providers.hir_module_items = |tcx, id| {
|
||||
let hir = tcx.hir();
|
||||
let module = hir.local_def_id_to_hir_id(id);
|
||||
&tcx.untracked_crate.modules[&module]
|
||||
};
|
||||
providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id];
|
||||
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
|
||||
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
|
||||
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
|
||||
|
|
|
@ -14,12 +14,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
let errors = Lock::new(Vec::new());
|
||||
let hir_map = tcx.hir();
|
||||
|
||||
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
|
||||
let local_def_id = hir_map.local_def_id(*module_id);
|
||||
hir_map.visit_item_likes_in_module(
|
||||
local_def_id,
|
||||
&mut OuterVisitor { hir_map, errors: &errors },
|
||||
);
|
||||
par_iter(&hir_map.krate().modules).for_each(|(&module_id, _)| {
|
||||
hir_map
|
||||
.visit_item_likes_in_module(module_id, &mut OuterVisitor { hir_map, errors: &errors });
|
||||
});
|
||||
|
||||
let errors = errors.into_inner();
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
|
|||
// but it's one that we must perform earlier than the rest of
|
||||
// WfCheck.
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_impl_wf(module);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
|
|||
tcx.sess.track_errors(|| {
|
||||
tcx.sess.time("type_collecting", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().collect_mod_item_types(module);
|
||||
}
|
||||
});
|
||||
})?;
|
||||
|
@ -401,7 +401,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
|
|||
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
|
||||
tcx.sess.time("item_types_checking", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_item_types(module);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -479,7 +479,7 @@ crate fn run_global_ctxt(
|
|||
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
|
||||
tcx.sess.time("item_types_checking", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_item_types(module);
|
||||
}
|
||||
});
|
||||
tcx.sess.abort_if_errors();
|
||||
|
@ -488,8 +488,7 @@ crate fn run_global_ctxt(
|
|||
});
|
||||
tcx.sess.time("check_mod_attrs", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
let local_def_id = tcx.hir().local_def_id(module);
|
||||
tcx.ensure().check_mod_attrs(local_def_id);
|
||||
tcx.ensure().check_mod_attrs(module);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue