1 //! Defines the set of legal keys that can be used in queries.
3 use rustc_hir
::def_id
::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}
;
4 use rustc_middle
::infer
::canonical
::Canonical
;
6 use rustc_middle
::ty
::fast_reject
::SimplifiedType
;
7 use rustc_middle
::ty
::subst
::{GenericArg, SubstsRef}
;
8 use rustc_middle
::ty
::{self, Ty, TyCtxt}
;
9 use rustc_span
::symbol
::{Ident, Symbol}
;
10 use rustc_span
::{Span, DUMMY_SP}
;
12 /// The `Key` trait controls what types can legally be used as the key
15 /// Given an instance of this key, what crate is it referring to?
16 /// This is used to find the provider.
17 fn query_crate(&self) -> CrateNum
;
19 /// In the event that a cycle occurs, if no explicit span has been
20 /// given for a query with key `self`, what span should we use?
21 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
;
24 impl<'tcx
> Key
for ty
::InstanceDef
<'tcx
> {
25 fn query_crate(&self) -> CrateNum
{
29 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
30 tcx
.def_span(self.def_id())
34 impl<'tcx
> Key
for ty
::Instance
<'tcx
> {
35 fn query_crate(&self) -> CrateNum
{
39 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
40 tcx
.def_span(self.def_id())
44 impl<'tcx
> Key
for mir
::interpret
::GlobalId
<'tcx
> {
45 fn query_crate(&self) -> CrateNum
{
46 self.instance
.query_crate()
49 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
50 self.instance
.default_span(tcx
)
54 impl<'tcx
> Key
for mir
::interpret
::LitToConstInput
<'tcx
> {
55 fn query_crate(&self) -> CrateNum
{
59 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
64 impl Key
for CrateNum
{
65 fn query_crate(&self) -> CrateNum
{
68 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
73 impl Key
for LocalDefId
{
74 fn query_crate(&self) -> CrateNum
{
75 self.to_def_id().query_crate()
77 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
78 self.to_def_id().default_span(tcx
)
83 fn query_crate(&self) -> CrateNum
{
86 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
91 impl Key
for ty
::WithOptConstParam
<LocalDefId
> {
92 fn query_crate(&self) -> CrateNum
{
93 self.did
.query_crate()
95 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
96 self.did
.default_span(tcx
)
100 impl Key
for (DefId
, DefId
) {
101 fn query_crate(&self) -> CrateNum
{
104 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
105 self.1.default_span(tcx
)
109 impl Key
for (ty
::Instance
<'tcx
>, LocalDefId
) {
110 fn query_crate(&self) -> CrateNum
{
113 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
114 self.0.default_span(tcx
)
118 impl Key
for (DefId
, LocalDefId
) {
119 fn query_crate(&self) -> CrateNum
{
122 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
123 self.1.default_span(tcx
)
127 impl Key
for (LocalDefId
, DefId
) {
128 fn query_crate(&self) -> CrateNum
{
131 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
132 self.0.default_span(tcx
)
136 impl Key
for (DefId
, Option
<Ident
>) {
137 fn query_crate(&self) -> CrateNum
{
140 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
145 impl Key
for (DefId
, LocalDefId
, Ident
) {
146 fn query_crate(&self) -> CrateNum
{
149 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
150 self.1.default_span(tcx
)
154 impl Key
for (CrateNum
, DefId
) {
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 fn query_crate(&self) -> CrateNum
{
167 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
168 self.0.default_span(tcx
)
172 impl<'tcx
> Key
for SubstsRef
<'tcx
> {
173 fn query_crate(&self) -> CrateNum
{
176 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
181 impl<'tcx
> Key
for (DefId
, SubstsRef
<'tcx
>) {
182 fn query_crate(&self) -> CrateNum
{
185 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
186 self.0.default_span(tcx
)
192 (ty
::WithOptConstParam
<DefId
>, SubstsRef
<'tcx
>),
193 (ty
::WithOptConstParam
<DefId
>, SubstsRef
<'tcx
>),
196 fn query_crate(&self) -> CrateNum
{
199 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
200 (self.0).0.did
.default_span(tcx
)
204 impl<'tcx
> Key
for (LocalDefId
, DefId
, SubstsRef
<'tcx
>) {
205 fn query_crate(&self) -> CrateNum
{
208 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
209 self.0.default_span(tcx
)
213 impl<'tcx
> Key
for (ty
::ParamEnv
<'tcx
>, ty
::PolyTraitRef
<'tcx
>) {
214 fn query_crate(&self) -> CrateNum
{
215 self.1.def_id().krate
217 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
218 tcx
.def_span(self.1.def_id())
222 impl<'tcx
> Key
for (&'tcx ty
::Const
<'tcx
>, mir
::Field
) {
223 fn query_crate(&self) -> CrateNum
{
226 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
231 impl<'tcx
> Key
for mir
::interpret
::ConstAlloc
<'tcx
> {
232 fn query_crate(&self) -> CrateNum
{
235 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
240 impl<'tcx
> Key
for ty
::PolyTraitRef
<'tcx
> {
241 fn query_crate(&self) -> CrateNum
{
244 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
245 tcx
.def_span(self.def_id())
249 impl<'tcx
> Key
for GenericArg
<'tcx
> {
250 fn query_crate(&self) -> CrateNum
{
253 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
258 impl<'tcx
> Key
for &'tcx ty
::Const
<'tcx
> {
259 fn query_crate(&self) -> CrateNum
{
262 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
267 impl<'tcx
> Key
for Ty
<'tcx
> {
268 fn query_crate(&self) -> CrateNum
{
271 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
276 impl<'tcx
> Key
for &'tcx ty
::List
<ty
::Predicate
<'tcx
>> {
277 fn query_crate(&self) -> CrateNum
{
280 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
285 impl<'tcx
> Key
for ty
::ParamEnv
<'tcx
> {
286 fn query_crate(&self) -> CrateNum
{
289 fn default_span(&self, _
: TyCtxt
<'_
>) -> Span
{
294 impl<'tcx
, T
: Key
> Key
for ty
::ParamEnvAnd
<'tcx
, T
> {
295 fn query_crate(&self) -> CrateNum
{
296 self.value
.query_crate()
298 fn default_span(&self, tcx
: TyCtxt
<'_
>) -> Span
{
299 self.value
.default_span(tcx
)
303 impl Key
for Symbol
{
304 fn query_crate(&self) -> CrateNum
{
307 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
312 /// Canonical query goals correspond to abstract trait operations that
313 /// are not tied to any crate in particular.
314 impl<'tcx
, T
> Key
for Canonical
<'tcx
, T
> {
315 fn query_crate(&self) -> CrateNum
{
319 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
324 impl Key
for (Symbol
, u32, u32) {
325 fn query_crate(&self) -> CrateNum
{
329 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{
334 impl<'tcx
> Key
for (DefId
, Ty
<'tcx
>, SubstsRef
<'tcx
>, ty
::ParamEnv
<'tcx
>) {
335 fn query_crate(&self) -> CrateNum
{
339 fn default_span(&self, _tcx
: TyCtxt
<'_
>) -> Span
{