LocalCrate key
This commit is contained in:
parent
dcaf956de0
commit
d213114cb5
11 changed files with 33 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::hir::{ModuleItems, Owner};
|
||||
use crate::query::LocalCrate;
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
@ -1131,7 +1132,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, (): ()) -> Svh {
|
||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
|
||||
let krate = tcx.hir_crate(());
|
||||
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCa
|
|||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
/// Placeholder for `CrateNum`'s "local" counterpart
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct LocalCrate;
|
||||
|
||||
/// The `Key` trait controls what types can legally be used as the key
|
||||
/// for a query.
|
||||
pub trait Key: Sized {
|
||||
|
@ -115,11 +119,11 @@ impl Key for CrateNum {
|
|||
}
|
||||
|
||||
impl AsLocalKey for CrateNum {
|
||||
type LocalKey = ();
|
||||
type LocalKey = LocalCrate;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(*self == LOCAL_CRATE).then_some(())
|
||||
(*self == LOCAL_CRATE).then_some(LocalCrate)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::ty::{self, print::describe_as_module, TyCtxt};
|
|||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
|
||||
mod keys;
|
||||
pub use keys::{AsLocalKey, Key};
|
||||
pub use keys::{AsLocalKey, Key, LocalCrate};
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
// `Providers` struct for requesting a value of that type, and a method
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::mir::interpret::{self, Allocation, ConstAllocation};
|
|||
use crate::mir::{
|
||||
Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
||||
};
|
||||
use crate::query::LocalCrate;
|
||||
use crate::thir::Thir;
|
||||
use crate::traits;
|
||||
use crate::traits::solve;
|
||||
|
@ -2519,10 +2520,10 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
providers.extern_mod_stmt_cnum =
|
||||
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
||||
providers.is_panic_runtime =
|
||||
|tcx, ()| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
||||
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
||||
providers.is_compiler_builtins =
|
||||
|tcx, ()| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||
providers.has_panic_handler = |tcx, ()| {
|
||||
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||
// We want to check if the panic handler was defined in this crate
|
||||
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue