1 //! Defines the set of legal keys that can be used in queries.
3 use crate::infer
::canonical
::Canonical
;
5 use crate::ty
::fast_reject
::SimplifiedType
;
6 use crate::ty
::subst
::{GenericArg, SubstsRef}
;
7 use crate::ty
::{self, Ty, TyCtxt}
;
8 use rustc_hir
::def_id
::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}
;
9 use rustc_query_system
::query
::DefaultCacheSelector
;
10 use rustc_span
::symbol
::Symbol
;
11 use rustc_span
::{Span, DUMMY_SP}
;
13 /// The `Key` trait controls what types can legally be used as the key
18 /// Given an instance of this key, what crate is it referring to?
19 /// This is used to find the provider.
20 fn query_crate(&self) -> CrateNum
;
22 /// In the event that a cycle occurs, if no explicit span has been
23 /// given for a query with key `self`, what span should we use?
24 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
;
27 impl<'tcx
> Key
for ty
::InstanceDef
<'tcx
> {
28 type CacheSelector
= DefaultCacheSelector
;
30 fn query_crate(&self) -> CrateNum
{
34 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
35 tcx
.def_span(self.def_id())
39 impl<'tcx
> Key
for ty
::Instance
<'tcx
> {
40 type CacheSelector
= DefaultCacheSelector
;
42 fn query_crate(&self) -> CrateNum
{
46 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
47 tcx
.def_span(self.def_id())
51 impl<'tcx
> Key
for mir
::interpret
::GlobalId
<'tcx
> {
52 type CacheSelector
= DefaultCacheSelector
;
54 fn query_crate(&self) -> CrateNum
{
55 self.instance
.query_crate()
58 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
59 self.instance
.default_span(tcx
)
63 impl<'tcx
> Key
for mir
::interpret
::LitToConstInput
<'tcx
> {
64 type CacheSelector
= DefaultCacheSelector
;
66 fn query_crate(&self) -> CrateNum
{
70 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
75 impl Key
for CrateNum
{
76 type CacheSelector
= DefaultCacheSelector
;
78 fn query_crate(&self) -> CrateNum
{
81 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
86 impl Key
for LocalDefId
{
87 type CacheSelector
= DefaultCacheSelector
;
89 fn query_crate(&self) -> CrateNum
{
90 self.to_def_id().query_crate()
92 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
93 self.to_def_id().default_span(tcx
)
98 type CacheSelector
= DefaultCacheSelector
;
100 fn query_crate(&self) -> CrateNum
{
103 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
108 impl Key
for ty
::WithOptConstParam
<LocalDefId
> {
109 type CacheSelector
= DefaultCacheSelector
;
111 fn query_crate(&self) -> CrateNum
{
112 self.did
.query_crate()
114 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
115 self.did
.default_span(tcx
)
119 impl Key
for (DefId
, DefId
) {
120 type CacheSelector
= DefaultCacheSelector
;
122 fn query_crate(&self) -> CrateNum
{
125 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
126 self.1.default_span(tcx
)
130 impl Key
for (DefId
, LocalDefId
) {
131 type CacheSelector
= DefaultCacheSelector
;
133 fn query_crate(&self) -> CrateNum
{
136 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
137 self.1.default_span(tcx
)
141 impl Key
for (LocalDefId
, DefId
) {
142 type CacheSelector
= DefaultCacheSelector
;
144 fn query_crate(&self) -> CrateNum
{
147 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
148 self.0.default_span(tcx
)
152 impl Key
for (CrateNum
, DefId
) {
153 type CacheSelector
= DefaultCacheSelector
;
155 fn query_crate(&self) -> CrateNum
{
158 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
159 self.1.default_span(tcx
)
163 impl Key
for (DefId
, SimplifiedType
) {
164 type CacheSelector
= DefaultCacheSelector
;
166 fn query_crate(&self) -> CrateNum
{
169 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
170 self.0.default_span(tcx
)
174 impl<'tcx
> Key
for SubstsRef
<'tcx
> {
175 type CacheSelector
= DefaultCacheSelector
;
177 fn query_crate(&self) -> CrateNum
{
180 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
185 impl<'tcx
> Key
for (DefId
, SubstsRef
<'tcx
>) {
186 type CacheSelector
= DefaultCacheSelector
;
188 fn query_crate(&self) -> CrateNum
{
191 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
192 self.0.default_span(tcx
)
196 impl<'tcx
> Key
for (LocalDefId
, DefId
, SubstsRef
<'tcx
>) {
197 type CacheSelector
= DefaultCacheSelector
;
199 fn query_crate(&self) -> CrateNum
{
202 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
203 self.0.default_span(tcx
)
207 impl<'tcx
> Key
for (ty
::ParamEnv
<'tcx
>, ty
::PolyTraitRef
<'tcx
>) {
208 type CacheSelector
= DefaultCacheSelector
;
210 fn query_crate(&self) -> CrateNum
{
211 self.1.def_id().krate
213 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
214 tcx
.def_span(self.1.def_id())
218 impl<'tcx
> Key
for (&'tcx ty
::Const
<'tcx
>, mir
::Field
) {
219 type CacheSelector
= DefaultCacheSelector
;
221 fn query_crate(&self) -> CrateNum
{
224 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
229 impl<'tcx
> Key
for ty
::PolyTraitRef
<'tcx
> {
230 type CacheSelector
= DefaultCacheSelector
;
232 fn query_crate(&self) -> CrateNum
{
235 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
236 tcx
.def_span(self.def_id())
240 impl<'tcx
> Key
for GenericArg
<'tcx
> {
241 type CacheSelector
= DefaultCacheSelector
;
243 fn query_crate(&self) -> CrateNum
{
246 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
251 impl<'tcx
> Key
for &'tcx ty
::Const
<'tcx
> {
252 type CacheSelector
= DefaultCacheSelector
;
254 fn query_crate(&self) -> CrateNum
{
257 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
262 impl<'tcx
> Key
for Ty
<'tcx
> {
263 type CacheSelector
= DefaultCacheSelector
;
265 fn query_crate(&self) -> CrateNum
{
268 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
273 impl<'tcx
> Key
for &'tcx ty
::List
<ty
::Predicate
<'tcx
>> {
274 type CacheSelector
= DefaultCacheSelector
;
276 fn query_crate(&self) -> CrateNum
{
279 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
284 impl<'tcx
> Key
for ty
::ParamEnv
<'tcx
> {
285 type CacheSelector
= DefaultCacheSelector
;
287 fn query_crate(&self) -> CrateNum
{
290 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
295 impl<'tcx
, T
: Key
> Key
for ty
::ParamEnvAnd
<'tcx
, T
> {
296 type CacheSelector
= DefaultCacheSelector
;
298 fn query_crate(&self) -> CrateNum
{
299 self.value
.query_crate()
301 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
302 self.value
.default_span(tcx
)
306 impl Key
for Symbol
{
307 type CacheSelector
= DefaultCacheSelector
;
309 fn query_crate(&self) -> CrateNum
{
312 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
317 /// Canonical query goals correspond to abstract trait operations that
318 /// are not tied to any crate in particular.
319 impl<'tcx
, T
> Key
for Canonical
<'tcx
, T
> {
320 type CacheSelector
= DefaultCacheSelector
;
322 fn query_crate(&self) -> CrateNum
{
326 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
331 impl Key
for (Symbol
, u32, u32) {
332 type CacheSelector
= DefaultCacheSelector
;
334 fn query_crate(&self) -> CrateNum
{
338 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
343 impl<'tcx
> Key
for (DefId
, Ty
<'tcx
>, SubstsRef
<'tcx
>, ty
::ParamEnv
<'tcx
>) {
344 type CacheSelector
= DefaultCacheSelector
;
346 fn query_crate(&self) -> CrateNum
{
350 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{