Use Key impl to select cache.
This commit is contained in:
@@ -8,12 +8,15 @@ use crate::ty::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::hir_id::{HirId, OwnerId};
|
||||
use rustc_query_system::query::{DefaultCacheSelector, VecCacheSelector};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
/// The `Key` trait controls what types can legally be used as the key
|
||||
/// for a query.
|
||||
pub trait Key {
|
||||
pub trait Key: Sized {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
/// Given an instance of this key, what crate is it referring to?
|
||||
/// This is used to find the provider.
|
||||
fn query_crate_is_local(&self) -> bool;
|
||||
@@ -100,6 +103,8 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
||||
}
|
||||
|
||||
impl Key for CrateNum {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
*self == LOCAL_CRATE
|
||||
@@ -110,6 +115,8 @@ impl Key for CrateNum {
|
||||
}
|
||||
|
||||
impl Key for OwnerId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
@@ -123,6 +130,8 @@ impl Key for OwnerId {
|
||||
}
|
||||
|
||||
impl Key for LocalDefId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user