]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/query/mod.rs
abaa60dec4a9638e98869abca95f64f95ea9c486
[rust.git] / compiler / rustc_middle / src / query / mod.rs
1 use crate::dep_graph::SerializedDepNodeIndex;
2 use crate::mir::interpret::{GlobalId, LitToConstInput};
3 use crate::traits;
4 use crate::traits::query::{
5     CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
6     CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
7     CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
8 };
9 use crate::ty::query::queries;
10 use crate::ty::subst::{GenericArg, SubstsRef};
11 use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
12 use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
13 use rustc_query_system::query::QueryDescription;
14
15 use rustc_span::symbol::Symbol;
16 use std::borrow::Cow;
17
18 fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
19     if def_id.is_top_level_module() {
20         "top-level module".to_string()
21     } else {
22         format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
23     }
24 }
25
26 // Each of these queries corresponds to a function pointer field in the
27 // `Providers` struct for requesting a value of that type, and a method
28 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
29 // which memoizes and does dep-graph tracking, wrapping around the actual
30 // `Providers` that the driver creates (using several `rustc_*` crates).
31 //
32 // The result type of each query must implement `Clone`, and additionally
33 // `ty::query::values::Value`, which produces an appropriate placeholder
34 // (error) value if the query resulted in a query cycle.
35 // Queries marked with `fatal_cycle` do not need the latter implementation,
36 // as they will raise an fatal error on query cycles instead.
37 rustc_queries! {
38         query trigger_delay_span_bug(key: DefId) -> () {
39             desc { "trigger a delay span bug" }
40         }
41
42         /// Represents crate as a whole (as distinct from the top-level crate module).
43         /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
44         /// we will have to assume that any change means that you need to be recompiled.
45         /// This is because the `hir_crate` query gives you access to all other items.
46         /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
47         /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
48         query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> {
49             eval_always
50             no_hash
51             desc { "get the crate HIR" }
52         }
53
54         /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
55         /// Avoid calling this query directly.
56         query index_hir(_: CrateNum) -> &'tcx map::IndexedHir<'tcx> {
57             eval_always
58             no_hash
59             desc { "index HIR" }
60         }
61
62         /// The items in a module.
63         ///
64         /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
65         /// Avoid calling this query directly.
66         query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
67             eval_always
68             desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
69         }
70
71         /// Gives access to the HIR node for the HIR owner `key`.
72         ///
73         /// This can be conveniently accessed by methods on `tcx.hir()`.
74         /// Avoid calling this query directly.
75         query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
76             eval_always
77             desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
78         }
79
80         /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
81         ///
82         /// This can be conveniently accessed by methods on `tcx.hir()`.
83         /// Avoid calling this query directly.
84         query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
85             eval_always
86             desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
87         }
88
89         /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
90         /// const argument and returns `None` otherwise.
91         ///
92         /// ```ignore (incomplete)
93         /// let a = foo::<7>();
94         /// //            ^ Calling `opt_const_param_of` for this argument,
95         ///
96         /// fn foo<const N: usize>()
97         /// //           ^ returns this `DefId`.
98         ///
99         /// fn bar() {
100         /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
101         /// }
102         /// ```
103         // It looks like caching this query on disk actually slightly
104         // worsened performance in #74376.
105         //
106         // Once const generics are more prevalently used, we might want to
107         // consider only caching calls returning `Some`.
108         query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
109             desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
110         }
111
112         /// Records the type of every item.
113         query type_of(key: DefId) -> Ty<'tcx> {
114             desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
115             cache_on_disk_if { key.is_local() }
116         }
117
118         query analysis(key: CrateNum) -> Result<(), ErrorReported> {
119             eval_always
120             desc { "running analysis passes on this crate" }
121         }
122
123         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
124         /// associated generics.
125         query generics_of(key: DefId) -> ty::Generics {
126             desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
127             storage(ArenaCacheSelector<'tcx>)
128             cache_on_disk_if { key.is_local() }
129             load_cached(tcx, id) {
130                 let generics: Option<ty::Generics> = tcx.queries.on_disk_cache.as_ref()
131                                                         .and_then(|c| c.try_load_query_result(tcx, id));
132                 generics
133             }
134         }
135
136         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
137         /// predicates (where-clauses) that must be proven true in order
138         /// to reference it. This is almost always the "predicates query"
139         /// that you want.
140         ///
141         /// `predicates_of` builds on `predicates_defined_on` -- in fact,
142         /// it is almost always the same as that query, except for the
143         /// case of traits. For traits, `predicates_of` contains
144         /// an additional `Self: Trait<...>` predicate that users don't
145         /// actually write. This reflects the fact that to invoke the
146         /// trait (e.g., via `Default::default`) you must supply types
147         /// that actually implement the trait. (However, this extra
148         /// predicate gets in the way of some checks, which are intended
149         /// to operate over only the actual where-clauses written by the
150         /// user.)
151         query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
152             desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
153             cache_on_disk_if { key.is_local() }
154         }
155
156         /// Returns the list of bounds that can be used for
157         /// `SelectionCandidate::ProjectionCandidate(_)` and
158         /// `ProjectionTyCandidate::TraitDef`.
159         /// Specifically this is the bounds written on the trait's type
160         /// definition, or those after the `impl` keyword
161         ///
162         /// ```ignore (incomplete)
163         /// type X: Bound + 'lt
164         /// //      ^^^^^^^^^^^
165         /// impl Debug + Display
166         /// //   ^^^^^^^^^^^^^^^
167         /// ```
168         ///
169         /// `key` is the `DefId` of the associated type or opaque type.
170         ///
171         /// Bounds from the parent (e.g. with nested impl trait) are not included.
172         query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
173             desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
174         }
175
176         /// Elaborated version of the predicates from `explicit_item_bounds`.
177         ///
178         /// For example:
179         ///
180         /// ```
181         /// trait MyTrait {
182         ///     type MyAType: Eq + ?Sized;
183         /// }
184         /// ```
185         ///
186         /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
187         /// and `item_bounds` returns
188         /// ```text
189         /// [
190         ///     <Self as Trait>::MyAType: Eq,
191         ///     <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
192         /// ]
193         /// ```
194         ///
195         /// Bounds from the parent (e.g. with nested impl trait) are not included.
196         query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
197             desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
198         }
199
200         query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
201             desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
202         }
203
204         query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
205             desc { "looking up the native libraries of a linked crate" }
206         }
207
208         query lint_levels(_: CrateNum) -> LintLevelMap {
209             storage(ArenaCacheSelector<'tcx>)
210             eval_always
211             desc { "computing the lint levels for items in this crate" }
212         }
213
214         query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
215             eval_always
216             desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
217         }
218
219         /// Internal helper query. Use `tcx.expansion_that_defined` instead
220         query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
221             desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
222         }
223
224         query is_panic_runtime(_: CrateNum) -> bool {
225             fatal_cycle
226             desc { "checking if the crate is_panic_runtime" }
227         }
228
229         /// Set of all the `DefId`s in this crate that have MIR associated with
230         /// them. This includes all the body owners, but also things like struct
231         /// constructors.
232         query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
233             storage(ArenaCacheSelector<'tcx>)
234             desc { "getting a list of all mir_keys" }
235         }
236
237         /// Maps DefId's that have an associated `mir::Body` to the result
238         /// of the MIR const-checking pass. This is the set of qualifs in
239         /// the final value of a `const`.
240         query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
241             desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
242             cache_on_disk_if { key.is_local() }
243         }
244         query mir_const_qualif_const_arg(
245             key: (LocalDefId, DefId)
246         ) -> mir::ConstQualifs {
247             desc {
248                 |tcx| "const checking the const argument `{}`",
249                 tcx.def_path_str(key.0.to_def_id())
250             }
251         }
252
253         /// Fetch the MIR for a given `DefId` right after it's built - this includes
254         /// unreachable code.
255         query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
256             desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
257         }
258
259         /// Fetch the MIR for a given `DefId` up till the point where it is
260         /// ready for const qualification.
261         ///
262         /// See the README for the `mir` module for details.
263         query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
264             desc {
265                 |tcx| "processing MIR for {}`{}`",
266                 if key.const_param_did.is_some() { "the const argument " } else { "" },
267                 tcx.def_path_str(key.did.to_def_id()),
268             }
269             no_hash
270         }
271
272         /// Try to build an abstract representation of the given constant.
273         query mir_abstract_const(
274             key: DefId
275         ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
276             desc {
277                 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
278             }
279         }
280         /// Try to build an abstract representation of the given constant.
281         query mir_abstract_const_of_const_arg(
282             key: (LocalDefId, DefId)
283         ) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
284             desc {
285                 |tcx|
286                 "building an abstract representation for the const argument {}",
287                 tcx.def_path_str(key.0.to_def_id()),
288             }
289         }
290
291         query try_unify_abstract_consts(key: (
292             (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
293             (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
294         )) -> bool {
295             desc {
296                 |tcx| "trying to unify the generic constants {} and {}",
297                 tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
298             }
299         }
300
301         query mir_drops_elaborated_and_const_checked(
302             key: ty::WithOptConstParam<LocalDefId>
303         ) -> &'tcx Steal<mir::Body<'tcx>> {
304             no_hash
305             desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
306         }
307
308         query mir_for_ctfe(
309             key: DefId
310         ) -> &'tcx mir::Body<'tcx> {
311             desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
312             cache_on_disk_if { key.is_local() }
313         }
314
315         query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
316             desc {
317                 |tcx| "MIR for CTFE of the const argument `{}`",
318                 tcx.def_path_str(key.0.to_def_id())
319             }
320         }
321
322         query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
323             (
324                 &'tcx Steal<mir::Body<'tcx>>,
325                 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
326             ) {
327             no_hash
328             desc {
329                 |tcx| "processing {}`{}`",
330                 if key.const_param_did.is_some() { "the const argument " } else { "" },
331                 tcx.def_path_str(key.did.to_def_id()),
332             }
333         }
334
335         /// MIR after our optimization passes have run. This is MIR that is ready
336         /// for codegen. This is also the only query that can fetch non-local MIR, at present.
337         query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
338             desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
339             cache_on_disk_if { key.is_local() }
340         }
341
342         /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
343         /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
344         query coverageinfo(key: DefId) -> mir::CoverageInfo {
345             desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) }
346             storage(ArenaCacheSelector<'tcx>)
347             cache_on_disk_if { key.is_local() }
348         }
349
350         /// Returns the name of the file that contains the function body, if instrumented for coverage.
351         query covered_file_name(key: DefId) -> Option<Symbol> {
352             desc { |tcx| "retrieving the covered file name, if instrumented, for `{}`", tcx.def_path_str(key) }
353             storage(ArenaCacheSelector<'tcx>)
354             cache_on_disk_if { key.is_local() }
355         }
356
357         /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
358         /// function was optimized out before codegen, and before being added to the Coverage Map.
359         query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
360             desc { |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`", tcx.def_path_str(key) }
361             storage(ArenaCacheSelector<'tcx>)
362             cache_on_disk_if { key.is_local() }
363         }
364
365         /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
366         /// `DefId`. This function returns all promoteds in the specified body. The body references
367         /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
368         /// after inlining a body may refer to promoteds from other bodies. In that case you still
369         /// need to use the `DefId` of the original body.
370         query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
371             desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
372             cache_on_disk_if { key.is_local() }
373         }
374         query promoted_mir_of_const_arg(
375             key: (LocalDefId, DefId)
376         ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
377             desc {
378                 |tcx| "optimizing promoted MIR for the const argument `{}`",
379                 tcx.def_path_str(key.0.to_def_id()),
380             }
381         }
382
383         /// Erases regions from `ty` to yield a new type.
384         /// Normally you would just use `tcx.erase_regions(value)`,
385         /// however, which uses this query as a kind of cache.
386         query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
387             // This query is not expected to have input -- as a result, it
388             // is not a good candidates for "replay" because it is essentially a
389             // pure function of its input (and hence the expectation is that
390             // no caller would be green **apart** from just these
391             // queries). Making it anonymous avoids hashing the result, which
392             // may save a bit of time.
393             anon
394             desc { "erasing regions from `{:?}`", ty }
395         }
396
397         query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
398             storage(ArenaCacheSelector<'tcx>)
399             desc { "wasm import module map" }
400         }
401
402         /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
403         /// predicates (where-clauses) directly defined on it. This is
404         /// equal to the `explicit_predicates_of` predicates plus the
405         /// `inferred_outlives_of` predicates.
406         query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
407             desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
408         }
409
410         /// Returns everything that looks like a predicate written explicitly
411         /// by the user on a trait item.
412         ///
413         /// Traits are unusual, because predicates on associated types are
414         /// converted into bounds on that type for backwards compatibility:
415         ///
416         /// trait X where Self::U: Copy { type U; }
417         ///
418         /// becomes
419         ///
420         /// trait X { type U: Copy; }
421         ///
422         /// `explicit_predicates_of` and `explicit_item_bounds` will then take
423         /// the appropriate subsets of the predicates here.
424         query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
425             desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
426         }
427
428         /// Returns the predicates written explicitly by the user.
429         query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
430             desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
431         }
432
433         /// Returns the inferred outlives predicates (e.g., for `struct
434         /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
435         query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
436             desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
437         }
438
439         /// Maps from the `DefId` of a trait to the list of
440         /// super-predicates. This is a subset of the full list of
441         /// predicates. We store these in a separate map because we must
442         /// evaluate them even during type conversion, often before the
443         /// full predicates are available (note that supertraits have
444         /// additional acyclicity requirements).
445         query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
446             desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
447         }
448
449         /// To avoid cycles within the predicates of a single item we compute
450         /// per-type-parameter predicates for resolving `T::AssocTy`.
451         query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
452             desc { |tcx| "computing the bounds for type parameter `{}`", {
453                 let id = tcx.hir().local_def_id_to_hir_id(key.1);
454                 tcx.hir().ty_param_name(id)
455             }}
456         }
457
458         query trait_def(key: DefId) -> ty::TraitDef {
459             desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
460             storage(ArenaCacheSelector<'tcx>)
461         }
462         query adt_def(key: DefId) -> &'tcx ty::AdtDef {
463             desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
464         }
465         query adt_destructor(key: DefId) -> Option<ty::Destructor> {
466             desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
467         }
468
469         // The cycle error here should be reported as an error by `check_representable`.
470         // We consider the type as Sized in the meanwhile to avoid
471         // further errors (done in impl Value for AdtSizedConstraint).
472         // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
473         // in case we accidentally otherwise don't emit an error.
474         query adt_sized_constraint(
475             key: DefId
476         ) -> AdtSizedConstraint<'tcx> {
477             desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
478             cycle_delay_bug
479         }
480
481         query adt_dtorck_constraint(
482             key: DefId
483         ) -> Result<DtorckConstraint<'tcx>, NoSolution> {
484             desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
485         }
486
487         /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
488         /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
489         /// not have the feature gate active).
490         ///
491         /// **Do not call this function manually.** It is only meant to cache the base data for the
492         /// `is_const_fn` function.
493         query is_const_fn_raw(key: DefId) -> bool {
494             desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
495         }
496
497         /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
498         ///
499         /// This query caches the base data for the `is_const_impl` helper function, which also
500         /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
501         query is_const_impl_raw(key: DefId) -> bool {
502             desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
503         }
504
505         query asyncness(key: DefId) -> hir::IsAsync {
506             desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
507         }
508
509         /// Returns `true` if calls to the function may be promoted.
510         ///
511         /// This is either because the function is e.g., a tuple-struct or tuple-variant
512         /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
513         /// be removed in the future in favour of some form of check which figures out whether the
514         /// function does not inspect the bits of any of its arguments (so is essentially just a
515         /// constructor function).
516         query is_promotable_const_fn(key: DefId) -> bool {
517             desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
518         }
519
520         /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
521         query is_foreign_item(key: DefId) -> bool {
522             desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
523         }
524
525         /// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
526         query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
527             desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
528         }
529
530         /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
531         query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
532             desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
533         }
534
535         /// Gets a map with the variance of every item; use `item_variance` instead.
536         query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> {
537             storage(ArenaCacheSelector<'tcx>)
538             desc { "computing the variances for items in this crate" }
539         }
540
541         /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
542         query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
543             desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
544         }
545
546         /// Maps from thee `DefId` of a type to its (inferred) outlives.
547         query inferred_outlives_crate(_: CrateNum)
548             -> ty::CratePredicatesMap<'tcx> {
549             storage(ArenaCacheSelector<'tcx>)
550             desc { "computing the inferred outlives predicates for items in this crate" }
551         }
552     
553         /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
554         query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
555             desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
556         }
557
558         /// Maps from a trait item to the trait item "descriptor".
559         query associated_item(key: DefId) -> ty::AssocItem {
560             desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
561             storage(ArenaCacheSelector<'tcx>)
562         }
563
564         /// Collects the associated items defined on a trait or impl.
565         query associated_items(key: DefId) -> ty::AssociatedItems<'tcx> {
566             storage(ArenaCacheSelector<'tcx>)
567             desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
568         }
569
570         /// Given an `impl_id`, return the trait it implements.
571         /// Return `None` if this is an inherent impl.
572         query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
573             desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
574         }
575         query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
576             desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
577         }
578
579         query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
580             desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
581         }
582     
583         /// Maps a `DefId` of a type to a list of its inherent impls.
584         /// Contains implementations of methods that are inherent to a type.
585         /// Methods in these implementations don't need to be exported.
586         query inherent_impls(key: DefId) -> &'tcx [DefId] {
587             desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
588             eval_always
589         }
590     
591         /// The result of unsafety-checking this `LocalDefId`.
592         query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
593             desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
594             cache_on_disk_if { true }
595         }
596         query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
597             desc {
598                 |tcx| "unsafety-checking the const argument `{}`",
599                 tcx.def_path_str(key.0.to_def_id())
600             }
601         }
602
603         /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
604         ///
605         /// Unsafety checking is executed for each method separately, but we only want
606         /// to emit this error once per derive. As there are some impls with multiple
607         /// methods, we use a query for deduplication.
608         query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
609             desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
610         }
611
612         /// The signature of functions.
613         query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
614             desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
615         }
616     
617         query lint_mod(key: LocalDefId) -> () {
618             desc { |tcx| "linting {}", describe_as_module(key, tcx) }
619         }
620
621         /// Checks the attributes in the module.
622         query check_mod_attrs(key: LocalDefId) -> () {
623             desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
624         }
625
626         query check_mod_unstable_api_usage(key: LocalDefId) -> () {
627             desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
628         }
629
630         /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
631         query check_mod_const_bodies(key: LocalDefId) -> () {
632             desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
633         }
634
635         /// Checks the loops in the module.
636         query check_mod_loops(key: LocalDefId) -> () {
637             desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
638         }
639
640         query check_mod_naked_functions(key: LocalDefId) -> () {
641             desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
642         }
643
644         query check_mod_item_types(key: LocalDefId) -> () {
645             desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
646         }
647
648         query check_mod_privacy(key: LocalDefId) -> () {
649             desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
650         }
651
652         query check_mod_intrinsics(key: LocalDefId) -> () {
653             desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
654         }
655
656         query check_mod_liveness(key: LocalDefId) -> () {
657             desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
658         }
659
660         query check_mod_impl_wf(key: LocalDefId) -> () {
661             desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
662         }
663
664         query collect_mod_item_types(key: LocalDefId) -> () {
665             desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
666         }
667
668         /// Caches `CoerceUnsized` kinds for impls on custom types.
669         query coerce_unsized_info(key: DefId)
670             -> ty::adjustment::CoerceUnsizedInfo {
671                 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
672             }
673     
674         query typeck_item_bodies(_: CrateNum) -> () {
675             desc { "type-checking all item bodies" }
676         }
677
678         query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
679             desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
680             cache_on_disk_if { true }
681         }
682         query typeck_const_arg(
683             key: (LocalDefId, DefId)
684         ) -> &'tcx ty::TypeckResults<'tcx> {
685             desc {
686                 |tcx| "type-checking the const argument `{}`",
687                 tcx.def_path_str(key.0.to_def_id()),
688             }
689         }
690         query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
691             desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
692             cache_on_disk_if { true }
693             load_cached(tcx, id) {
694                 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
695                     .queries.on_disk_cache.as_ref()
696                     .and_then(|c| c.try_load_query_result(tcx, id));
697
698                 typeck_results.map(|x| &*tcx.arena.alloc(x))
699             }
700         }
701     
702         query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
703             desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
704             cache_on_disk_if { true }
705         }
706     
707         query has_typeck_results(def_id: DefId) -> bool {
708             desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
709         }
710
711         query coherent_trait(def_id: DefId) -> () {
712             desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
713         }
714     
715         /// Borrow-checks the function body. If this is a closure, returns
716         /// additional requirements that the closure's creator must verify.
717         query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
718             desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
719             cache_on_disk_if(tcx, opt_result) {
720                 tcx.is_closure(key.to_def_id())
721                     || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
722             }
723         }
724         query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
725             desc {
726                 |tcx| "borrow-checking the const argument`{}`",
727                 tcx.def_path_str(key.0.to_def_id())
728             }
729         }
730     
731         /// Gets a complete map from all types to their inherent impls.
732         /// Not meant to be used directly outside of coherence.
733         /// (Defined only for `LOCAL_CRATE`.)
734         query crate_inherent_impls(k: CrateNum)
735             -> CrateInherentImpls {
736             storage(ArenaCacheSelector<'tcx>)
737             eval_always
738             desc { "all inherent impls defined in crate `{:?}`", k }
739         }
740
741         /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
742         /// Not meant to be used directly outside of coherence.
743         /// (Defined only for `LOCAL_CRATE`.)
744         query crate_inherent_impls_overlap_check(_: CrateNum)
745             -> () {
746             eval_always
747             desc { "check for overlap between inherent impls defined in this crate" }
748         }
749     
750         /// Check whether the function has any recursion that could cause the inliner to trigger
751         /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
752         /// current function, just all intermediate functions.
753         query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
754             fatal_cycle
755             desc { |tcx|
756                 "computing if `{}` (transitively) calls `{}`",
757                 key.0,
758                 tcx.def_path_str(key.1.to_def_id()),
759             }
760         }
761
762         /// Obtain all the calls into other local functions
763         query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
764             fatal_cycle
765             desc { |tcx|
766                 "computing all local function calls in `{}`",
767                 tcx.def_path_str(key.def_id()),
768             }
769         }
770
771         /// Evaluates a constant and returns the computed allocation.
772         ///
773         /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
774         query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
775             -> EvalToAllocationRawResult<'tcx> {
776             desc { |tcx|
777                 "const-evaluating + checking `{}`",
778                 key.value.display(tcx)
779             }
780             cache_on_disk_if { true }
781         }
782
783         /// Evaluates const items or anonymous constants
784         /// (such as enum variant explicit discriminants or array lengths)
785         /// into a representation suitable for the type system and const generics.
786         ///
787         /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
788         /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
789         query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
790             -> EvalToConstValueResult<'tcx> {
791             desc { |tcx|
792                 "simplifying constant for the type system `{}`",
793                 key.value.display(tcx)
794             }
795             cache_on_disk_if { true }
796         }
797
798         /// Destructure a constant ADT or array into its variant index and its
799         /// field values.
800         query destructure_const(
801             key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
802         ) -> mir::DestructuredConst<'tcx> {
803             desc { "destructure constant" }
804         }
805
806         /// Dereference a constant reference or raw pointer and turn the result into a constant
807         /// again.
808         query deref_const(
809             key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
810         ) -> &'tcx ty::Const<'tcx> {
811             desc { "deref constant" }
812         }
813
814         query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
815             desc { "get a &core::panic::Location referring to a span" }
816         }
817
818         query lit_to_const(
819             key: LitToConstInput<'tcx>
820         ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
821             desc { "converting literal to const" }
822         }
823     
824         query check_match(key: DefId) {
825             desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
826             cache_on_disk_if { key.is_local() }
827         }
828
829         /// Performs part of the privacy check and computes "access levels".
830         query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
831             eval_always
832             desc { "privacy access levels" }
833         }
834         query check_private_in_public(_: CrateNum) -> () {
835             eval_always
836             desc { "checking for private elements in public interfaces" }
837         }
838     
839         query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
840             storage(ArenaCacheSelector<'tcx>)
841             desc { "reachability" }
842         }
843
844         /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
845         /// in the case of closures, this will be redirected to the enclosing function.
846         query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
847             desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
848         }
849
850         query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
851             storage(ArenaCacheSelector<'tcx>)
852             desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
853         }
854
855         /// The `symbol_name` query provides the symbol name for calling a
856         /// given instance from the local crate. In particular, it will also
857         /// look up the correct symbol name of instances from upstream crates.
858         query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
859             desc { "computing the symbol for `{}`", key }
860             cache_on_disk_if { true }
861         }
862
863         query opt_def_kind(def_id: DefId) -> Option<DefKind> {
864             desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
865         }
866
867         query def_span(def_id: DefId) -> Span {
868             desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
869             // FIXME(mw): DefSpans are not really inputs since they are derived from
870             // HIR. But at the moment HIR hashing still contains some hacks that allow
871             // to make type debuginfo to be source location independent. Declaring
872             // DefSpan an input makes sure that changes to these are always detected
873             // regardless of HIR hashing.
874             eval_always
875         }
876
877         query def_ident_span(def_id: DefId) -> Option<Span> {
878             desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
879         }
880
881         query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
882             desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
883         }
884
885         query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
886             desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
887         }
888
889         query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
890             desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
891         }
892
893         query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
894             desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
895         }
896     
897         query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
898             desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
899             storage(ArenaCacheSelector<'tcx>)
900             cache_on_disk_if { true }
901         }
902
903         query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
904             desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
905         }
906         /// Gets the rendered value of the specified constant or associated constant.
907         /// Used by rustdoc.
908         query rendered_const(def_id: DefId) -> String {
909             desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
910         }
911         query impl_parent(def_id: DefId) -> Option<DefId> {
912             desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
913         }
914
915         /// Given an `associated_item`, find the trait it belongs to.
916         /// Return `None` if the `DefId` is not an associated item.
917         query trait_of_item(associated_item: DefId) -> Option<DefId> {
918             desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
919         }
920
921         query is_ctfe_mir_available(key: DefId) -> bool {
922             desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
923         }
924         query is_mir_available(key: DefId) -> bool {
925             desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
926         }
927
928         query vtable_methods(key: ty::PolyTraitRef<'tcx>)
929                             -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
930             desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
931         }
932
933         query codegen_fulfill_obligation(
934             key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
935         ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
936             cache_on_disk_if { true }
937             desc { |tcx|
938                 "checking if `{}` fulfills its obligations",
939                 tcx.def_path_str(key.1.def_id())
940             }
941         }
942
943         /// Return all `impl` blocks in the current crate.
944         ///
945         /// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
946         /// Passing in any other crate will cause an ICE.
947         ///
948         /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
949         query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
950             desc { "local trait impls" }
951         }
952
953         /// Given a trait `trait_id`, return all known `impl` blocks.
954         query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
955             storage(ArenaCacheSelector<'tcx>)
956             desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
957         }
958
959         query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
960             storage(ArenaCacheSelector<'tcx>)
961             desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
962             cache_on_disk_if { true }
963         }
964         query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
965             desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
966         }
967
968         /// Gets the ParameterEnvironment for a given item; this environment
969         /// will be in "user-facing" mode, meaning that it is suitable for
970         /// type-checking etc, and it does not normalize specializable
971         /// associated types. This is almost always what you want,
972         /// unless you are doing MIR optimizations, in which case you
973         /// might want to use `reveal_all()` method to change modes.
974         query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
975             desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
976         }
977
978         /// Like `param_env`, but returns the `ParamEnv in `Reveal::All` mode.
979         /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
980         /// as this method is more efficient.
981         query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
982             desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
983         }
984
985         /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
986         /// `ty.is_copy()`, etc, since that will prune the environment where possible.
987         query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
988             desc { "computing whether `{}` is `Copy`", env.value }
989         }
990         /// Query backing `TyS::is_sized`.
991         query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
992             desc { "computing whether `{}` is `Sized`", env.value }
993         }
994         /// Query backing `TyS::is_freeze`.
995         query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
996             desc { "computing whether `{}` is freeze", env.value }
997         }
998         /// Query backing `TyS::needs_drop`.
999         query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1000             desc { "computing whether `{}` needs drop", env.value }
1001         }
1002
1003         /// Query backing `TyS::is_structural_eq_shallow`.
1004         ///
1005         /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1006         /// correctly.
1007         query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1008             desc {
1009                 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1010                 ty
1011             }
1012         }
1013
1014         /// A list of types where the ADT requires drop if and only if any of
1015         /// those types require drop. If the ADT is known to always need drop
1016         /// then `Err(AlwaysRequiresDrop)` is returned.
1017         query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1018             desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1019             cache_on_disk_if { true }
1020         }
1021
1022         query layout_raw(
1023             env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1024         ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> {
1025             desc { "computing layout of `{}`", env.value }
1026         }
1027
1028         query dylib_dependency_formats(_: CrateNum)
1029                                         -> &'tcx [(CrateNum, LinkagePreference)] {
1030             desc { "dylib dependency formats of crate" }
1031         }
1032
1033         query dependency_formats(_: CrateNum)
1034             -> Lrc<crate::middle::dependency_format::Dependencies>
1035         {
1036             desc { "get the linkage format of all dependencies" }
1037         }
1038
1039         query is_compiler_builtins(_: CrateNum) -> bool {
1040             fatal_cycle
1041             desc { "checking if the crate is_compiler_builtins" }
1042         }
1043         query has_global_allocator(_: CrateNum) -> bool {
1044             fatal_cycle
1045             desc { "checking if the crate has_global_allocator" }
1046         }
1047         query has_panic_handler(_: CrateNum) -> bool {
1048             fatal_cycle
1049             desc { "checking if the crate has_panic_handler" }
1050         }
1051         query is_profiler_runtime(_: CrateNum) -> bool {
1052             fatal_cycle
1053             desc { "query a crate is `#![profiler_runtime]`" }
1054         }
1055         query panic_strategy(_: CrateNum) -> PanicStrategy {
1056             fatal_cycle
1057             desc { "query a crate's configured panic strategy" }
1058         }
1059         query is_no_builtins(_: CrateNum) -> bool {
1060             fatal_cycle
1061             desc { "test whether a crate has `#![no_builtins]`" }
1062         }
1063         query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1064             fatal_cycle
1065             desc { "query a crate's symbol mangling version" }
1066         }
1067
1068         query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1069             eval_always
1070             desc { "getting crate's ExternCrateData" }
1071         }
1072
1073         query specializes(_: (DefId, DefId)) -> bool {
1074             desc { "computing whether impls specialize one another" }
1075         }
1076         query in_scope_traits_map(_: LocalDefId)
1077             -> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
1078             eval_always
1079             desc { "traits in scope at a block" }
1080         }
1081
1082         query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
1083             desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1084             eval_always
1085         }
1086
1087         query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1088             desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1089         }
1090
1091         query check_item_well_formed(key: LocalDefId) -> () {
1092             desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1093         }
1094         query check_trait_item_well_formed(key: LocalDefId) -> () {
1095             desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1096         }
1097         query check_impl_item_well_formed(key: LocalDefId) -> () {
1098             desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1099         }
1100
1101         // The `DefId`s of all non-generic functions and statics in the given crate
1102         // that can be reached from outside the crate.
1103         //
1104         // We expect this items to be available for being linked to.
1105         //
1106         // This query can also be called for `LOCAL_CRATE`. In this case it will
1107         // compute which items will be reachable to other crates, taking into account
1108         // the kind of crate that is currently compiled. Crates with only a
1109         // C interface have fewer reachable things.
1110         //
1111         // Does not include external symbols that don't have a corresponding DefId,
1112         // like the compiler-generated `main` function and so on.
1113         query reachable_non_generics(_: CrateNum)
1114             -> DefIdMap<SymbolExportLevel> {
1115             storage(ArenaCacheSelector<'tcx>)
1116             desc { "looking up the exported symbols of a crate" }
1117         }
1118         query is_reachable_non_generic(def_id: DefId) -> bool {
1119             desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1120         }
1121         query is_unreachable_local_definition(def_id: DefId) -> bool {
1122             desc { |tcx|
1123                 "checking whether `{}` is reachable from outside the crate",
1124                 tcx.def_path_str(def_id),
1125             }
1126         }
1127
1128         /// The entire set of monomorphizations the local crate can safely link
1129         /// to because they are exported from upstream crates. Do not depend on
1130         /// this directly, as its value changes anytime a monomorphization gets
1131         /// added or removed in any upstream crate. Instead use the narrower
1132         /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1133         /// better, `Instance::upstream_monomorphization()`.
1134         query upstream_monomorphizations(
1135             k: CrateNum
1136         ) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1137             storage(ArenaCacheSelector<'tcx>)
1138             desc { "collecting available upstream monomorphizations `{:?}`", k }
1139         }
1140
1141         /// Returns the set of upstream monomorphizations available for the
1142         /// generic function identified by the given `def_id`. The query makes
1143         /// sure to make a stable selection if the same monomorphization is
1144         /// available in multiple upstream crates.
1145         ///
1146         /// You likely want to call `Instance::upstream_monomorphization()`
1147         /// instead of invoking this query directly.
1148         query upstream_monomorphizations_for(def_id: DefId)
1149             -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1150                 desc { |tcx|
1151                     "collecting available upstream monomorphizations for `{}`",
1152                     tcx.def_path_str(def_id),
1153                 }
1154             }
1155
1156         /// Returns the upstream crate that exports drop-glue for the given
1157         /// type (`substs` is expected to be a single-item list containing the
1158         /// type one wants drop-glue for).
1159         ///
1160         /// This is a subset of `upstream_monomorphizations_for` in order to
1161         /// increase dep-tracking granularity. Otherwise adding or removing any
1162         /// type with drop-glue in any upstream crate would invalidate all
1163         /// functions calling drop-glue of an upstream type.
1164         ///
1165         /// You likely want to call `Instance::upstream_monomorphization()`
1166         /// instead of invoking this query directly.
1167         ///
1168         /// NOTE: This query could easily be extended to also support other
1169         ///       common functions that have are large set of monomorphizations
1170         ///       (like `Clone::clone` for example).
1171         query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1172             desc { "available upstream drop-glue for `{:?}`", substs }
1173         }
1174
1175         query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1176             desc { "looking up the foreign modules of a linked crate" }
1177         }
1178
1179         /// Identifies the entry-point (e.g., the `main` function) for a given
1180         /// crate, returning `None` if there is no entry point (such as for library crates).
1181         query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
1182             desc { "looking up the entry function of a crate" }
1183         }
1184         query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
1185             desc { "looking up the plugin registrar for a crate" }
1186         }
1187         query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
1188             desc { "looking up the derive registrar for a crate" }
1189         }
1190         query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
1191             eval_always
1192             desc { "looking up the disambiguator a crate" }
1193         }
1194         // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1195         // Changing the name should cause a compiler error, but in case that changes, be aware.
1196         query crate_hash(_: CrateNum) -> Svh {
1197             eval_always
1198             desc { "looking up the hash a crate" }
1199         }
1200         query crate_host_hash(_: CrateNum) -> Option<Svh> {
1201             eval_always
1202             desc { "looking up the hash of a host version of a crate" }
1203         }
1204         query original_crate_name(_: CrateNum) -> Symbol {
1205             eval_always
1206             desc { "looking up the original name a crate" }
1207         }
1208         query extra_filename(_: CrateNum) -> String {
1209             eval_always
1210             desc { "looking up the extra filename for a crate" }
1211         }
1212         query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1213             eval_always
1214             desc { "looking up the paths for extern crates" }
1215         }
1216
1217         /// Given a crate and a trait, look up all impls of that trait in the crate.
1218         /// Return `(impl_id, self_ty)`.
1219         query implementations_of_trait(_: (CrateNum, DefId))
1220             -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1221             desc { "looking up implementations of a trait in a crate" }
1222         }
1223
1224         /// Given a crate, look up all trait impls in that crate.
1225         /// Return `(impl_id, self_ty)`.
1226         query all_trait_implementations(_: CrateNum)
1227             -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1228             desc { "looking up all (?) trait implementations" }
1229         }
1230
1231         query is_dllimport_foreign_item(def_id: DefId) -> bool {
1232             desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1233         }
1234         query is_statically_included_foreign_item(def_id: DefId) -> bool {
1235             desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1236         }
1237         query native_library_kind(def_id: DefId)
1238             -> Option<NativeLibKind> {
1239             desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1240         }
1241
1242         query link_args(_: CrateNum) -> Lrc<Vec<String>> {
1243             eval_always
1244             desc { "looking up link arguments for a crate" }
1245         }
1246
1247         /// Lifetime resolution. See `middle::resolve_lifetimes`.
1248         query resolve_lifetimes(_: CrateNum) -> ResolveLifetimes {
1249             storage(ArenaCacheSelector<'tcx>)
1250             desc { "resolving lifetimes" }
1251         }
1252         query named_region_map(_: LocalDefId) ->
1253             Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1254             desc { "looking up a named region" }
1255         }
1256         query is_late_bound_map(_: LocalDefId) ->
1257             Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1258             desc { "testing if a region is late bound" }
1259         }
1260         query object_lifetime_defaults_map(_: LocalDefId)
1261             -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
1262             desc { "looking up lifetime defaults for a region" }
1263         }
1264
1265         query visibility(def_id: DefId) -> ty::Visibility {
1266             eval_always
1267             desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1268         }
1269
1270         /// Computes the set of modules from which this type is visibly uninhabited.
1271         /// To check whether a type is uninhabited at all (not just from a given module), you could
1272         /// check whether the forest is empty.
1273         query type_uninhabited_from(
1274             key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1275         ) -> ty::inhabitedness::DefIdForest {
1276             desc { "computing the inhabitedness of `{:?}`", key }
1277         }
1278
1279         query dep_kind(_: CrateNum) -> CrateDepKind {
1280             eval_always
1281             desc { "fetching what a dependency looks like" }
1282         }
1283         query crate_name(_: CrateNum) -> Symbol {
1284             eval_always
1285             desc { "fetching what a crate is named" }
1286         }
1287         query item_children(def_id: DefId) -> &'tcx [Export<hir::HirId>] {
1288             desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
1289         }
1290         query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1291             desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1292         }
1293
1294         query get_lib_features(_: CrateNum) -> LibFeatures {
1295             storage(ArenaCacheSelector<'tcx>)
1296             eval_always
1297             desc { "calculating the lib features map" }
1298         }
1299         query defined_lib_features(_: CrateNum)
1300             -> &'tcx [(Symbol, Option<Symbol>)] {
1301             desc { "calculating the lib features defined in a crate" }
1302         }
1303         /// Returns the lang items defined in another crate by loading it from metadata.
1304         // FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1305         // of that argument?
1306         query get_lang_items(_: CrateNum) -> LanguageItems {
1307             storage(ArenaCacheSelector<'tcx>)
1308             eval_always
1309             desc { "calculating the lang items map" }
1310         }
1311
1312         /// Returns all diagnostic items defined in all crates.
1313         query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1314             storage(ArenaCacheSelector<'tcx>)
1315             eval_always
1316             desc { "calculating the diagnostic items map" }
1317         }
1318
1319         /// Returns the lang items defined in another crate by loading it from metadata.
1320         query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1321             desc { "calculating the lang items defined in a crate" }
1322         }
1323
1324         /// Returns the diagnostic items defined in a crate.
1325         query diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1326             storage(ArenaCacheSelector<'tcx>)
1327             desc { "calculating the diagnostic items map in a crate" }
1328         }
1329
1330         query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1331             desc { "calculating the missing lang items in a crate" }
1332         }
1333         query visible_parent_map(_: CrateNum)
1334             -> DefIdMap<DefId> {
1335             storage(ArenaCacheSelector<'tcx>)
1336             desc { "calculating the visible parent map" }
1337         }
1338         query trimmed_def_paths(_: CrateNum)
1339             -> FxHashMap<DefId, Symbol> {
1340             storage(ArenaCacheSelector<'tcx>)
1341             desc { "calculating trimmed def paths" }
1342         }
1343         query missing_extern_crate_item(_: CrateNum) -> bool {
1344             eval_always
1345             desc { "seeing if we're missing an `extern crate` item for this crate" }
1346         }
1347         query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1348             eval_always
1349             desc { "looking at the source for a crate" }
1350         }
1351         query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
1352             eval_always
1353             desc { "generating a postorder list of CrateNums" }
1354         }
1355
1356         query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1357             desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1358             eval_always
1359         }
1360         query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1361             eval_always
1362             desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1363         }
1364         query maybe_unused_extern_crates(_: CrateNum)
1365             -> &'tcx [(LocalDefId, Span)] {
1366             eval_always
1367             desc { "looking up all possibly unused extern crates" }
1368         }
1369         query names_imported_by_glob_use(def_id: LocalDefId)
1370             -> &'tcx FxHashSet<Symbol> {
1371             eval_always
1372             desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1373         }
1374
1375         query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1376             storage(ArenaCacheSelector<'tcx>)
1377             eval_always
1378             desc { "calculating the stability index for the local crate" }
1379         }
1380         query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
1381             eval_always
1382             desc { "fetching all foreign CrateNum instances" }
1383         }
1384
1385         /// A vector of every trait accessible in the whole crate
1386         /// (i.e., including those from subcrates). This is used only for
1387         /// error reporting.
1388         query all_traits(_: CrateNum) -> &'tcx [DefId] {
1389             desc { "fetching all foreign and local traits" }
1390         }
1391
1392         /// The list of symbols exported from the given crate.
1393         ///
1394         /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1395         ///   correspond to a publicly visible symbol in `cnum` machine code.
1396         /// - The `exported_symbols` sets of different crates do not intersect.
1397         query exported_symbols(_: CrateNum)
1398             -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1399             desc { "exported_symbols" }
1400         }
1401
1402         query collect_and_partition_mono_items(_: CrateNum)
1403             -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1404             eval_always
1405             desc { "collect_and_partition_mono_items" }
1406         }
1407         query is_codegened_item(def_id: DefId) -> bool {
1408             desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1409         }
1410         query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1411             desc { "codegen_unit" }
1412         }
1413         query unused_generic_params(key: DefId) -> FiniteBitSet<u32> {
1414             cache_on_disk_if { key.is_local() }
1415             desc {
1416                 |tcx| "determining which generic parameters are unused by `{}`",
1417                     tcx.def_path_str(key)
1418             }
1419         }
1420         query backend_optimization_level(_: CrateNum) -> OptLevel {
1421             desc { "optimization level used by backend" }
1422         }
1423
1424         query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1425             eval_always
1426             desc { "output_filenames" }
1427         }
1428
1429         /// Do not call this query directly: invoke `normalize` instead.
1430         query normalize_projection_ty(
1431             goal: CanonicalProjectionGoal<'tcx>
1432         ) -> Result<
1433             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1434             NoSolution,
1435         > {
1436             desc { "normalizing `{:?}`", goal }
1437         }
1438
1439         /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1440         query normalize_generic_arg_after_erasing_regions(
1441             goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1442         ) -> GenericArg<'tcx> {
1443             desc { "normalizing `{}`", goal.value }
1444         }
1445
1446         query implied_outlives_bounds(
1447             goal: CanonicalTyGoal<'tcx>
1448         ) -> Result<
1449             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1450             NoSolution,
1451         > {
1452             desc { "computing implied outlives bounds for `{:?}`", goal }
1453         }
1454
1455         /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1456         query dropck_outlives(
1457             goal: CanonicalTyGoal<'tcx>
1458         ) -> Result<
1459             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1460             NoSolution,
1461         > {
1462             desc { "computing dropck types for `{:?}`", goal }
1463         }
1464
1465         /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1466         /// `infcx.predicate_must_hold()` instead.
1467         query evaluate_obligation(
1468             goal: CanonicalPredicateGoal<'tcx>
1469         ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1470             desc { "evaluating trait selection obligation `{}`", goal.value.value }
1471         }
1472
1473         query evaluate_goal(
1474             goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1475         ) -> Result<
1476             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1477             NoSolution
1478         > {
1479             desc { "evaluating trait selection obligation `{}`", goal.value }
1480         }
1481
1482         query type_implements_trait(
1483             key: (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>, )
1484         ) -> bool {
1485             desc { "evaluating `type_implements_trait` `{:?}`", key }
1486         }
1487
1488         /// Do not call this query directly: part of the `Eq` type-op
1489         query type_op_ascribe_user_type(
1490             goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1491         ) -> Result<
1492             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1493             NoSolution,
1494         > {
1495             desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1496         }
1497
1498         /// Do not call this query directly: part of the `Eq` type-op
1499         query type_op_eq(
1500             goal: CanonicalTypeOpEqGoal<'tcx>
1501         ) -> Result<
1502             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1503             NoSolution,
1504         > {
1505             desc { "evaluating `type_op_eq` `{:?}`", goal }
1506         }
1507
1508         /// Do not call this query directly: part of the `Subtype` type-op
1509         query type_op_subtype(
1510             goal: CanonicalTypeOpSubtypeGoal<'tcx>
1511         ) -> Result<
1512             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1513             NoSolution,
1514         > {
1515             desc { "evaluating `type_op_subtype` `{:?}`", goal }
1516         }
1517
1518         /// Do not call this query directly: part of the `ProvePredicate` type-op
1519         query type_op_prove_predicate(
1520             goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1521         ) -> Result<
1522             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1523             NoSolution,
1524         > {
1525             desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1526         }
1527
1528         /// Do not call this query directly: part of the `Normalize` type-op
1529         query type_op_normalize_ty(
1530             goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1531         ) -> Result<
1532             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1533             NoSolution,
1534         > {
1535             desc { "normalizing `{:?}`", goal }
1536         }
1537
1538         /// Do not call this query directly: part of the `Normalize` type-op
1539         query type_op_normalize_predicate(
1540             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1541         ) -> Result<
1542             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1543             NoSolution,
1544         > {
1545             desc { "normalizing `{:?}`", goal }
1546         }
1547
1548         /// Do not call this query directly: part of the `Normalize` type-op
1549         query type_op_normalize_poly_fn_sig(
1550             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1551         ) -> Result<
1552             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1553             NoSolution,
1554         > {
1555             desc { "normalizing `{:?}`", goal }
1556         }
1557
1558         /// Do not call this query directly: part of the `Normalize` type-op
1559         query type_op_normalize_fn_sig(
1560             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1561         ) -> Result<
1562             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1563             NoSolution,
1564         > {
1565             desc { "normalizing `{:?}`", goal }
1566         }
1567
1568         query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1569             desc { |tcx|
1570                 "impossible substituted predicates:`{}`",
1571                 tcx.def_path_str(key.0)
1572             }
1573         }
1574
1575         query method_autoderef_steps(
1576             goal: CanonicalTyGoal<'tcx>
1577         ) -> MethodAutoderefStepsResult<'tcx> {
1578             desc { "computing autoderef types for `{:?}`", goal }
1579         }
1580
1581         query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1582             storage(ArenaCacheSelector<'tcx>)
1583             eval_always
1584             desc { "looking up supported target features" }
1585         }
1586
1587         /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1588         query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1589             -> usize {
1590             desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1591         }
1592
1593         query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
1594             eval_always
1595             desc { "looking up enabled feature gates" }
1596         }
1597
1598         /// Attempt to resolve the given `DefId` to an `Instance`, for the
1599         /// given generics args (`SubstsRef`), returning one of:
1600         ///  * `Ok(Some(instance))` on success
1601         ///  * `Ok(None)` when the `SubstsRef` are still too generic,
1602         ///    and therefore don't allow finding the final `Instance`
1603         ///  * `Err(ErrorReported)` when the `Instance` resolution process
1604         ///    couldn't complete due to errors elsewhere - this is distinct
1605         ///    from `Ok(None)` to avoid misleading diagnostics when an error
1606         ///    has already been/will be emitted, for the original cause
1607         query resolve_instance(
1608             key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1609         ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1610             desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1611         }
1612
1613         query resolve_instance_of_const_arg(
1614             key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1615         ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1616             desc {
1617                 "resolving instance of the const argument `{}`",
1618                 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1619             }
1620         }
1621
1622         query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1623             desc { "normalizing opaque types in {:?}", key }
1624         }
1625 }