rust/compiler/rustc_middle/src/query/keys.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

611 lines
14 KiB
Rust
Raw Normal View History

2017-09-18 09:40:13 +00:00
//! Defines the set of legal keys that can be used in queries.
2023-04-26 18:53:51 +00:00
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
2022-07-22 16:48:36 +00:00
use rustc_hir::hir_id::{HirId, OwnerId};
use rustc_query_system::dep_graph::DepNodeIndex;
use rustc_query_system::query::{DefIdCache, DefaultCache, SingleCache, VecCache};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{DUMMY_SP, Span};
2017-09-18 09:40:13 +00:00
use crate::infer::canonical::CanonicalQueryInput;
2024-10-31 03:10:37 +00:00
use crate::mir::mono::CollectionMode;
2022-10-31 22:54:09 +00:00
use crate::ty::fast_reject::SimplifiedType;
use crate::ty::layout::{TyAndLayout, ValidityRequirement};
use crate::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt};
use crate::{mir, traits};
2023-03-13 22:22:59 +00:00
/// Placeholder for `CrateNum`'s "local" counterpart
#[derive(Copy, Clone, Debug)]
pub struct LocalCrate;
2017-09-18 09:40:13 +00:00
/// The `Key` trait controls what types can legally be used as the key
/// for a query.
2022-10-31 23:16:24 +00:00
pub trait Key: Sized {
// N.B. Most of the keys down below have `type Cache<V> = DefaultCache<Self, V>;`,
// it would be reasonable to use associated type defaults, to remove the duplication...
//
// ...But r-a doesn't support them yet and using a default here causes r-a to not infer
// return types of queries which is very annoying. Thus, until r-a support associated
2023-04-10 20:02:52 +00:00
// type defaults, please restrain from using them here <3
//
// r-a issue: <https://github.com/rust-lang/rust-analyzer/issues/13693>
type Cache<V>;
2022-10-31 23:16:24 +00:00
2017-09-18 09:40:13 +00:00
/// 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?
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
/// If the key is a [`DefId`] or `DefId`--equivalent, return that `DefId`.
/// Otherwise, return `None`.
fn key_as_def_id(&self) -> Option<DefId> {
None
}
2022-08-15 19:11:11 +00:00
fn ty_def_id(&self) -> Option<DefId> {
2022-08-15 19:11:11 +00:00
None
}
2017-09-18 09:40:13 +00:00
}
2023-03-13 22:11:07 +00:00
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>;
}
2021-05-11 09:26:52 +00:00
impl Key for () {
type Cache<V> = SingleCache<V>;
2021-05-11 09:26:52 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2024-06-17 01:35:16 +00:00
impl<'tcx> Key for ty::InstanceKind<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2017-09-18 09:40:13 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
tcx.def_span(self.def_id())
}
}
2024-06-17 01:35:16 +00:00
impl<'tcx> AsLocalKey for ty::InstanceKind<'tcx> {
2023-03-13 18:54:05 +00:00
type LocalKey = Self;
2021-05-15 08:55:53 +00:00
#[inline(always)]
2023-03-13 22:11:07 +00:00
fn as_local_key(&self) -> Option<Self::LocalKey> {
2023-03-13 18:54:05 +00:00
self.def_id().is_local().then(|| *self)
2017-09-18 09:40:13 +00:00
}
2023-03-13 22:11:07 +00:00
}
impl<'tcx> Key for ty::Instance<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2017-09-18 09:40:13 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
tcx.def_span(self.def_id())
}
}
2018-01-02 23:22:09 +00:00
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2018-01-02 23:22:09 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2018-01-02 23:22:09 +00:00
self.instance.default_span(tcx)
}
}
impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2017-09-18 09:40:13 +00:00
impl Key for CrateNum {
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
2023-03-13 22:11:07 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl AsLocalKey for CrateNum {
2023-03-13 22:22:59 +00:00
type LocalKey = LocalCrate;
2022-10-31 23:16:24 +00:00
2021-05-15 08:55:53 +00:00
#[inline(always)]
2023-03-13 18:54:05 +00:00
fn as_local_key(&self) -> Option<Self::LocalKey> {
2023-03-13 22:22:59 +00:00
(*self == LOCAL_CRATE).then_some(LocalCrate)
2017-09-18 09:40:13 +00:00
}
}
impl Key for OwnerId {
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.to_def_id().default_span(tcx)
}
2023-03-13 18:54:05 +00:00
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.to_def_id())
}
}
impl Key for LocalDefId {
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.to_def_id().default_span(tcx)
2017-09-18 09:40:13 +00:00
}
2023-03-13 18:54:05 +00:00
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.to_def_id())
}
2017-09-18 09:40:13 +00:00
}
impl Key for DefId {
type Cache<V> = DefIdCache<V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
tcx.def_span(*self)
}
2023-03-13 18:54:05 +00:00
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
Some(*self)
}
2017-09-18 09:40:13 +00:00
}
2023-03-13 22:11:07 +00:00
impl AsLocalKey for DefId {
type LocalKey = LocalDefId;
2021-05-15 08:55:53 +00:00
#[inline(always)]
2023-03-13 22:11:07 +00:00
fn as_local_key(&self) -> Option<Self::LocalKey> {
self.as_local()
2020-07-03 14:39:02 +00:00
}
2023-03-13 22:11:07 +00:00
}
2023-04-26 18:53:51 +00:00
impl Key for LocalModDefId {
type Cache<V> = DefaultCache<Self, V>;
2023-04-26 18:53:51 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(*self)
}
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.to_def_id())
}
}
impl Key for ModDefId {
type Cache<V> = DefaultCache<Self, V>;
2023-04-26 18:53:51 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(*self)
}
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.to_def_id())
}
}
impl AsLocalKey for ModDefId {
type LocalKey = LocalModDefId;
#[inline(always)]
fn as_local_key(&self) -> Option<Self::LocalKey> {
self.as_local()
}
}
impl Key for SimplifiedType {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2017-09-18 09:40:13 +00:00
impl Key for (DefId, DefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.1.default_span(tcx)
}
}
impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2020-12-29 16:21:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.0.default_span(tcx)
}
}
impl Key for (DefId, LocalDefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
self.1.default_span(tcx)
}
}
2020-07-07 23:03:19 +00:00
impl Key for (LocalDefId, DefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2020-07-07 23:03:19 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.0.default_span(tcx)
}
}
2022-07-12 14:10:22 +00:00
impl Key for (LocalDefId, LocalDefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2022-07-12 14:10:22 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.0.default_span(tcx)
}
}
impl Key for (DefId, Ident) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.0)
}
2023-03-13 18:54:05 +00:00
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.0)
}
}
2023-03-13 19:06:41 +00:00
impl Key for (LocalDefId, LocalDefId, Ident) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.1.default_span(tcx)
}
}
2017-09-18 09:40:13 +00:00
impl Key for (CrateNum, DefId) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
self.1.default_span(tcx)
}
}
2023-03-13 22:11:07 +00:00
impl AsLocalKey for (CrateNum, DefId) {
type LocalKey = DefId;
#[inline(always)]
2023-03-13 18:54:05 +00:00
fn as_local_key(&self) -> Option<Self::LocalKey> {
2023-03-13 22:11:07 +00:00
(self.0 == LOCAL_CRATE).then(|| self.1)
}
2023-03-13 22:11:07 +00:00
}
impl Key for (CrateNum, SimplifiedType) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2023-03-13 22:11:07 +00:00
impl AsLocalKey for (CrateNum, SimplifiedType) {
type LocalKey = SimplifiedType;
2021-05-15 08:55:53 +00:00
#[inline(always)]
2023-03-13 18:54:05 +00:00
fn as_local_key(&self) -> Option<Self::LocalKey> {
2023-03-13 22:11:07 +00:00
(self.0 == LOCAL_CRATE).then(|| self.1)
2017-09-18 09:40:13 +00:00
}
2023-03-13 22:11:07 +00:00
}
impl Key for (DefId, SimplifiedType) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
self.0.default_span(tcx)
}
}
impl<'tcx> Key for GenericArgsRef<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for (DefId, GenericArgsRef<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
self.0.default_span(tcx)
}
}
2022-09-22 10:34:23 +00:00
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2022-05-08 13:53:19 +00:00
(self.0).def.default_span(tcx)
}
}
impl<'tcx> Key for (LocalDefId, DefId, GenericArgsRef<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2020-07-02 21:56:17 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2020-07-07 23:03:19 +00:00
self.0.default_span(tcx)
2020-07-02 21:56:17 +00:00
}
}
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::TraitRef<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.1.def_id)
}
}
impl<'tcx> Key for ty::ParamEnvAnd<'tcx, Ty<'tcx>> {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for ty::TraitRef<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.def_id)
}
}
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.def_id())
}
}
impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.def_id())
}
}
2021-07-31 14:46:23 +00:00
impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2021-07-31 14:46:23 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.0.def_id())
}
}
impl<'tcx> Key for GenericArg<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for ty::Const<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2017-09-18 09:40:13 +00:00
impl<'tcx> Key for Ty<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
2023-03-13 18:54:05 +00:00
fn ty_def_id(&self) -> Option<DefId> {
match *self.kind() {
2022-08-15 19:11:11 +00:00
ty::Adt(adt, _) => Some(adt.did()),
ty::Coroutine(def_id, ..) => Some(def_id),
2022-08-15 19:11:11 +00:00
_ => None,
}
}
}
impl<'tcx> Key for TyAndLayout<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
DUMMY_SP
}
}
2024-03-24 21:49:31 +00:00
impl<'tcx> Key for ty::Clauses<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for ty::ParamEnv<'tcx> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.value.default_span(tcx)
}
fn ty_def_id(&self) -> Option<DefId> {
self.value.ty_def_id()
}
}
impl Key for Symbol {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
2019-06-13 21:48:52 +00:00
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
2017-09-18 09:40:13 +00:00
DUMMY_SP
}
}
impl Key for Option<Symbol> {
type Cache<V> = DefaultCache<Self, V>;
2023-03-13 18:54:05 +00:00
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2018-06-11 14:33:37 +00:00
/// Canonical query goals correspond to abstract trait operations that
/// are not tied to any crate in particular.
impl<'tcx, T: Clone> Key for CanonicalQueryInput<'tcx, T> {
type Cache<V> = DefaultCache<Self, V>;
2019-06-13 21:48:52 +00:00
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl Key for (Symbol, u32, u32) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2020-05-14 15:07:46 +00:00
impl<'tcx> Key for (DefId, Ty<'tcx>, GenericArgsRef<'tcx>, ty::ParamEnv<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
2020-05-14 15:07:46 +00:00
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
Add initial implementation of HIR-based WF checking for diagnostics During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).
2021-04-04 20:55:39 +00:00
impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
type Cache<V> = DefaultCache<Self, V>;
Add initial implementation of HIR-based WF checking for diagnostics During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).
2021-04-04 20:55:39 +00:00
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2021-09-01 21:29:15 +00:00
impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
type Cache<V> = DefaultCache<Self, V>;
2021-09-01 21:29:15 +00:00
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
type Cache<V> = DefaultCache<Self, V>;
2021-09-01 21:29:15 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.0.default_span(tcx)
}
}
impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
2022-07-22 16:48:36 +00:00
impl Key for HirId {
type Cache<V> = DefaultCache<Self, V>;
2022-07-22 16:48:36 +00:00
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
2022-09-10 09:55:10 +00:00
tcx.hir().span(*self)
2022-07-22 16:48:36 +00:00
}
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
2022-09-10 09:55:10 +00:00
None
2022-07-22 16:48:36 +00:00
}
}
impl Key for (LocalDefId, HirId) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span(self.1)
}
#[inline(always)]
fn key_as_def_id(&self) -> Option<DefId> {
Some(self.0.into())
}
}
impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) {
type Cache<V> = DefaultCache<Self, V>;
// Just forward to `Ty<'tcx>`
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
fn ty_def_id(&self) -> Option<DefId> {
match self.1.value.kind() {
ty::Adt(adt, _) => Some(adt.did()),
_ => None,
}
}
}
2024-10-31 03:10:37 +00:00
impl<'tcx> Key for (ty::Instance<'tcx>, CollectionMode) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.0.default_span(tcx)
}
}