AsLocalKey trait
This commit is contained in:
parent
7e6506764b
commit
dcaf956de0
@ -26,12 +26,6 @@ pub trait Key: Sized {
|
||||
// r-a issue: <https://github.com/rust-lang/rust-analyzer/issues/13693>
|
||||
type CacheSelector;
|
||||
|
||||
type LocalKey;
|
||||
|
||||
/// Given an instance of this key, what crate is it referring to?
|
||||
/// This is used to find the provider.
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey>;
|
||||
|
||||
/// In the event that a cycle occurs, if no explicit span has been
|
||||
/// given for a query with key `self`, what span should we use?
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
|
||||
@ -47,14 +41,16 @@ fn ty_adt_id(&self) -> Option<DefId> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsLocalKey: Key {
|
||||
type LocalKey;
|
||||
|
||||
/// Given an instance of this key, what crate is it referring to?
|
||||
/// This is used to find the provider.
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey>;
|
||||
}
|
||||
|
||||
impl Key for () {
|
||||
type CacheSelector = SingleCacheSelector;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -63,26 +59,23 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for ty::InstanceDef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
self.def_id().is_local().then(|| *self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for ty::Instance<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
impl<'tcx> AsLocalKey for ty::InstanceDef<'tcx> {
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.def_id().is_local().then(|| *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for ty::Instance<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
@ -91,12 +84,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.instance.default_span(tcx)
|
||||
@ -105,12 +92,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -119,12 +100,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -133,26 +108,23 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for CrateNum {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
type LocalKey = ();
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(*self == LOCAL_CRATE).then_some(())
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for OwnerId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
impl AsLocalKey for CrateNum {
|
||||
type LocalKey = ();
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(*self == LOCAL_CRATE).then_some(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for OwnerId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.to_def_id().default_span(tcx)
|
||||
@ -165,12 +137,6 @@ fn key_as_def_id(&self) -> Option<DefId> {
|
||||
|
||||
impl Key for LocalDefId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.to_def_id().default_span(tcx)
|
||||
@ -183,12 +149,6 @@ fn key_as_def_id(&self) -> Option<DefId> {
|
||||
|
||||
impl Key for DefId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = LocalDefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.as_local()
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(*self)
|
||||
@ -200,14 +160,17 @@ fn key_as_def_id(&self) -> Option<DefId> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for ty::WithOptConstParam<LocalDefId> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
impl AsLocalKey for DefId {
|
||||
type LocalKey = LocalDefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.as_local()
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for ty::WithOptConstParam<LocalDefId> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.did.default_span(tcx)
|
||||
@ -216,12 +179,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for SimplifiedType {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -230,12 +187,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (DefId, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = (LocalDefId, DefId);
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some((self.0.as_local()?, self.1))
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
@ -244,12 +195,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -258,12 +203,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (DefId, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = (LocalDefId, LocalDefId);
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some((self.0.as_local()?, self.1))
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
@ -272,12 +211,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (LocalDefId, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -286,12 +219,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (LocalDefId, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -300,11 +227,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (DefId, Option<Ident>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = (LocalDefId, Option<Ident>);
|
||||
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some((self.0.as_local()?, self.1))
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.0)
|
||||
@ -318,11 +240,6 @@ fn key_as_def_id(&self) -> Option<DefId> {
|
||||
|
||||
impl Key for (LocalDefId, LocalDefId, Ident) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
@ -331,40 +248,40 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (CrateNum, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = DefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(self.0 == LOCAL_CRATE).then_some(self.1)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (CrateNum, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = SimplifiedType;
|
||||
impl AsLocalKey for (CrateNum, DefId) {
|
||||
type LocalKey = DefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(self.0 == LOCAL_CRATE).then_some(self.1)
|
||||
(self.0 == LOCAL_CRATE).then(|| self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (CrateNum, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (DefId, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = (LocalDefId, SimplifiedType);
|
||||
impl AsLocalKey for (CrateNum, SimplifiedType) {
|
||||
type LocalKey = SimplifiedType;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some((self.0.as_local()?, self.1))
|
||||
(self.0 == LOCAL_CRATE).then(|| self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (DefId, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -373,12 +290,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for SubstsRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -387,12 +298,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = (LocalDefId, SubstsRef<'tcx>);
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
Some((self.0.as_local()?, self.1))
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -401,12 +306,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.0.def.is_local().then_some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
(self.0).def.did.default_span(tcx)
|
||||
@ -415,12 +314,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -429,12 +322,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.1.def_id().is_local().then_some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.1.def_id())
|
||||
@ -443,12 +330,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::Const<'tcx>, mir::Field) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -457,12 +338,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -471,12 +346,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.def_id().is_local().then_some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
@ -485,12 +354,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.def_id().is_local().then_some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
@ -499,12 +362,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.0.def_id().is_local().then_some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.0.def_id())
|
||||
@ -513,12 +370,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for GenericArg<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -527,12 +378,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -541,12 +386,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for ty::Const<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -555,12 +394,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for Ty<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -576,12 +409,6 @@ fn ty_adt_id(&self) -> Option<DefId> {
|
||||
|
||||
impl<'tcx> Key for TyAndLayout<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -590,12 +417,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -604,12 +425,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -618,12 +433,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -632,11 +441,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = ty::ParamEnvAnd<'tcx, T::LocalKey>;
|
||||
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.value.as_local_key().map(|value| ty::ParamEnvAnd { param_env: self.param_env, value })
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.value.default_span(tcx)
|
||||
@ -645,12 +449,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for Symbol {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -659,12 +457,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for Option<Symbol> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -675,12 +467,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
/// are not tied to any crate in particular.
|
||||
impl<'tcx, T: Clone> Key for Canonical<'tcx, T> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(self.clone())
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -689,12 +475,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for (Symbol, u32, u32) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -703,12 +483,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -717,12 +491,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -731,12 +499,6 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -745,12 +507,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
@ -759,12 +515,6 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
@ -773,12 +523,6 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
|
||||
impl Key for HirId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.hir().span(*self)
|
||||
@ -792,13 +536,8 @@ fn key_as_def_id(&self) -> Option<DefId> {
|
||||
|
||||
impl<'tcx> Key for (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
type LocalKey = Self;
|
||||
|
||||
// Just forward to `Ty<'tcx>`
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self> {
|
||||
Some(*self)
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
|
@ -8,7 +8,7 @@
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
|
||||
mod keys;
|
||||
pub use keys::Key;
|
||||
pub use keys::{AsLocalKey, Key};
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
// `Providers` struct for requesting a value of that type, and a method
|
||||
@ -796,7 +796,6 @@
|
||||
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
|
||||
desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
|
||||
cache_on_disk_if { true }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
/// Given an `impl_id`, return the trait it implements.
|
||||
|
@ -17,7 +17,7 @@
|
||||
};
|
||||
use crate::mir::interpret::{LitToConstError, LitToConstInput};
|
||||
use crate::mir::mono::CodegenUnit;
|
||||
use crate::query::Key;
|
||||
use crate::query::{AsLocalKey, Key};
|
||||
use crate::thir;
|
||||
use crate::traits::query::{
|
||||
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
|
||||
@ -233,7 +233,7 @@ pub mod query_keys {
|
||||
pub mod query_keys_local {
|
||||
use super::*;
|
||||
|
||||
$(pub type $name<'tcx> = <$($K)* as Key>::LocalKey;)*
|
||||
$(pub type $name<'tcx> = <$($K)* as AsLocalKey>::LocalKey;)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_values {
|
||||
@ -416,17 +416,14 @@ pub struct ExternProviders {
|
||||
|
||||
impl Default for Providers {
|
||||
fn default() -> Self {
|
||||
use crate::query::Key;
|
||||
|
||||
Providers {
|
||||
$($name: |_, key| bug!(
|
||||
"`tcx.{}({:?})` is not supported for {} crate;\n\
|
||||
"`tcx.{}({:?})` is not supported for this key;\n\
|
||||
hint: Queries can be either made to the local crate, or the external crate. \
|
||||
This error means you tried to use it for one that's not supported.\n\
|
||||
If that's not the case, {} was likely never assigned to a provider function.\n",
|
||||
stringify!($name),
|
||||
key,
|
||||
if key.as_local_key().is_some() { "local" } else { "external" },
|
||||
stringify!($name),
|
||||
),)*
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::{self, DepKindStruct};
|
||||
use rustc_middle::query::Key;
|
||||
use rustc_middle::query::AsLocalKey;
|
||||
use rustc_middle::ty::query::{
|
||||
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user