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(),
);
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;
}
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};
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
- modules: BTreeMap<hir::HirId, hir::ModuleItems>,
+ modules: BTreeMap<LocalDefId, hir::ModuleItems>,
generator_kind: Option<hir::GeneratorKind>,
/// vector.
in_scope_lifetimes: Vec<ParamName>,
- current_module: hir::HirId,
+ current_module: LocalDefId,
type_def_lifetime_params: DefIdMap<usize>,
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,
/// 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>,
},
{
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);
});
}
);
// "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);
});
});
}
{
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);
});
});
}
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);
});
});
},
};
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);
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();
// 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);
}
}
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);
}
});
})?;
// 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);
}
});
// 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();
});
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);
}
});