Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
This commit is contained in:
@@ -150,7 +150,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'_, 'hir> {
|
||||
|
||||
impl<'hir> Map<'hir> {
|
||||
pub fn krate(&self) -> &'hir Crate<'hir> {
|
||||
self.tcx.hir_crate(LOCAL_CRATE)
|
||||
self.tcx.hir_crate(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -489,7 +489,7 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
|
||||
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] {
|
||||
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
}
|
||||
|
||||
/// Gets the attributes on the crate. This is preferable to
|
||||
@@ -928,9 +928,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx IndexedHir<'tcx> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tcx> {
|
||||
let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map");
|
||||
|
||||
let hcx = tcx.create_stable_hashing_context();
|
||||
@@ -943,10 +941,12 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
|
||||
}
|
||||
|
||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||
assert_eq!(crate_num, LOCAL_CRATE);
|
||||
|
||||
let mut hcx = tcx.create_stable_hashing_context();
|
||||
|
||||
let mut hir_body_nodes: Vec<_> = tcx
|
||||
.index_hir(crate_num)
|
||||
.index_hir(())
|
||||
.map
|
||||
.iter_enumerated()
|
||||
.filter_map(|(def_id, hod)| {
|
||||
|
||||
@@ -13,7 +13,7 @@ use rustc_ast::Attribute;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::*;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_span::DUMMY_SP;
|
||||
@@ -123,14 +123,14 @@ pub fn provide(providers: &mut Providers) {
|
||||
let hir = tcx.hir();
|
||||
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
|
||||
};
|
||||
providers.hir_crate = |tcx, _| tcx.untracked_crate;
|
||||
providers.hir_crate = |tcx, ()| tcx.untracked_crate;
|
||||
providers.index_hir = map::index_hir;
|
||||
providers.crate_hash = map::crate_hash;
|
||||
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.hir_owner = |tcx, id| tcx.index_hir(()).map[id].signature;
|
||||
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(()).map[id].with_bodies.as_deref();
|
||||
providers.hir_owner_parent = |tcx, id| {
|
||||
let index = tcx.index_hir(LOCAL_CRATE);
|
||||
let index = tcx.index_hir(());
|
||||
index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID)
|
||||
};
|
||||
providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.untracked_crate.attrs, prefix: id };
|
||||
@@ -151,4 +151,5 @@ pub fn provide(providers: &mut Providers) {
|
||||
}
|
||||
};
|
||||
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
|
||||
providers.all_local_trait_impls = |tcx, ()| &tcx.hir_crate(()).trait_impls;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user