rustc_middle/query/
mod.rs

1//!
2//! # The rustc Query System: Query Definitions and Modifiers
3//!
4//! The core processes in rustc are shipped as queries. Each query is a demand-driven function from some key to a value.
5//! The execution result of the function is cached and directly read during the next request, thereby improving compilation efficiency.
6//! Some results are saved locally and directly read during the next compilation, which are core of incremental compilation.
7//!
8//! ## How to Read This Module
9//!
10//! Each `query` block in this file defines a single query, specifying its key and value types, along with various modifiers.
11//! These query definitions are processed by the [`rustc_macros`], which expands them into the necessary boilerplate code
12//! for the query system—including the [`Providers`] struct (a function table for all query implementations, where each field is
13//! a function pointer to the actual provider), caching, and dependency graph integration.
14//! **Note:** The `Providers` struct is not a Rust trait, but a struct generated by the `rustc_macros` to hold all provider functions.
15//! The `rustc_macros` also supports a set of **query modifiers** (see below) that control the behavior of each query.
16//!
17//! The actual provider functions are implemented in various modules and registered into the `Providers` struct
18//! during compiler initialization (see [`rustc_interface::passes::DEFAULT_QUERY_PROVIDERS`]).
19//!
20//! [`rustc_macros`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_macros/index.html
21//! [`rustc_interface::passes::DEFAULT_QUERY_PROVIDERS`]: ../../rustc_interface/passes/static.DEFAULT_QUERY_PROVIDERS.html
22//!
23//! ## Query Modifiers
24//!
25//! Query modifiers are special flags that alter the behavior of a query. They are parsed and processed by the `rustc_macros`
26//! The main modifiers are:
27//!
28//! - `desc { ... }`: Sets the human-readable description for diagnostics and profiling. Required for every query.
29//! - `arena_cache`: Use an arena for in-memory caching of the query result.
30//! - `cache_on_disk_if { ... }`: Cache the query result to disk if the provided block evaluates to true.
31//! - `fatal_cycle`: If a dependency cycle is detected, abort compilation with a fatal error.
32//! - `cycle_delay_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
33//! - `cycle_stash`: If a dependency cycle is detected, stash the error for later handling.
34//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
35//! - `anon`: Make the query anonymous in the dependency graph (no dep node is created).
36//! - `eval_always`: Always evaluate the query, ignoring its dependencies and cached results.
37//! - `depth_limit`: Impose a recursion depth limit on the query to prevent stack overflows.
38//! - `separate_provide_extern`: Use separate provider functions for local and external crates.
39//! - `feedable`: Allow the query result to be set from another query ("fed" externally).
40//! - `return_result_from_ensure_ok`: When called via `tcx.ensure_ok()`, return `Result<(), ErrorGuaranteed>` instead of `()`.
41//!   If the query needs to be executed and returns an error, the error is returned to the caller.
42//!   Only valid for queries returning `Result<_, ErrorGuaranteed>`.
43//!
44//! For the up-to-date list, see the `QueryModifiers` struct in
45//! [`rustc_macros/src/query.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_macros/src/query.rs)
46//! and for more details in incremental compilation, see the
47//! [Query modifiers in incremental compilation](https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation-in-detail.html#query-modifiers) section of the rustc-dev-guide.
48//!
49//! ## Query Expansion and Code Generation
50//!
51//! The [`rustc_macros::rustc_queries`] macro expands each query definition into:
52//! - A method on [`TyCtxt`] (and [`TyCtxtAt`]) for invoking the query.
53//! - Provider traits and structs for supplying the query's value.
54//! - Caching and dependency graph integration.
55//! - Support for incremental compilation, disk caching, and arena allocation as controlled by the modifiers.
56//!
57//! [`rustc_macros::rustc_queries`]: ../../rustc_macros/macro.rustc_queries.html
58//!
59//! The macro-based approach allows the query system to be highly flexible and maintainable, while minimizing boilerplate.
60//!
61//! For more details, see the [rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html).
62
63#![allow(unused_parens)]
64
65use std::ffi::OsStr;
66use std::mem;
67use std::path::PathBuf;
68use std::sync::Arc;
69
70use rustc_abi::Align;
71use rustc_arena::TypedArena;
72use rustc_ast::expand::allocator::AllocatorKind;
73use rustc_data_structures::fingerprint::Fingerprint;
74use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
75use rustc_data_structures::sorted_map::SortedMap;
76use rustc_data_structures::steal::Steal;
77use rustc_data_structures::svh::Svh;
78use rustc_data_structures::unord::{UnordMap, UnordSet};
79use rustc_errors::ErrorGuaranteed;
80use rustc_hir::attrs::StrippedCfgItem;
81use rustc_hir::def::{DefKind, DocLinkResMap};
82use rustc_hir::def_id::{
83    CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
84};
85use rustc_hir::lang_items::{LangItem, LanguageItems};
86use rustc_hir::{Crate, ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate};
87use rustc_index::IndexVec;
88use rustc_lint_defs::LintId;
89use rustc_macros::rustc_queries;
90use rustc_query_system::ich::StableHashingContext;
91use rustc_query_system::query::{
92    QueryCache, QueryMode, QueryStackDeferred, QueryState, try_get_cached,
93};
94use rustc_session::Limits;
95use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
96use rustc_session::cstore::{
97    CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
98};
99use rustc_session::lint::LintExpectationId;
100use rustc_span::def_id::LOCAL_CRATE;
101use rustc_span::source_map::Spanned;
102use rustc_span::{DUMMY_SP, Span, Symbol};
103use rustc_target::spec::{PanicStrategy, SanitizerSet};
104use {rustc_abi as abi, rustc_ast as ast, rustc_hir as hir};
105
106use crate::infer::canonical::{self, Canonical};
107use crate::lint::LintExpectation;
108use crate::metadata::ModChild;
109use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
110use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
111use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
112use crate::middle::lib_features::LibFeatures;
113use crate::middle::privacy::EffectiveVisibilities;
114use crate::middle::resolve_bound_vars::{ObjectLifetimeDefault, ResolveBoundVars, ResolvedArg};
115use crate::middle::stability::DeprecationEntry;
116use crate::mir::interpret::{
117    EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult,
118    EvalToValTreeResult, GlobalId, LitToConstInput,
119};
120use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions};
121use crate::query::erase::{Erase, erase, restore};
122use crate::query::plumbing::{
123    CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
124};
125use crate::traits::query::{
126    CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
127    CanonicalPredicateGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
128    CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, DropckConstraint,
129    DropckOutlivesResult, MethodAutoderefStepsResult, NoSolution, NormalizationResult,
130    OutlivesBound,
131};
132use crate::traits::{
133    CodegenObligationError, DynCompatibilityViolation, EvaluationResult, ImplSource,
134    ObligationCause, OverflowError, WellFormedLoc, solve, specialization_graph,
135};
136use crate::ty::fast_reject::SimplifiedType;
137use crate::ty::layout::ValidityRequirement;
138use crate::ty::print::PrintTraitRefExt;
139use crate::ty::util::AlwaysRequiresDrop;
140use crate::ty::{
141    self, CrateInherentImpls, GenericArg, GenericArgsRef, PseudoCanonicalInput, SizedTraitKind, Ty,
142    TyCtxt, TyCtxtFeed,
143};
144use crate::{dep_graph, mir, thir};
145
146mod arena_cached;
147pub mod erase;
148mod keys;
149pub use keys::{AsLocalKey, Key, LocalCrate};
150pub mod on_disk_cache;
151#[macro_use]
152pub mod plumbing;
153pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
154
155// Each of these queries corresponds to a function pointer field in the
156// `Providers` struct for requesting a value of that type, and a method
157// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
158// which memoizes and does dep-graph tracking, wrapping around the actual
159// `Providers` that the driver creates (using several `rustc_*` crates).
160//
161// The result type of each query must implement `Clone`, and additionally
162// `ty::query::values::Value`, which produces an appropriate placeholder
163// (error) value if the query resulted in a query cycle.
164// Queries marked with `fatal_cycle` do not need the latter implementation,
165// as they will raise an fatal error on query cycles instead.
166rustc_queries! {
167    /// This exists purely for testing the interactions between delayed bugs and incremental.
168    query trigger_delayed_bug(key: DefId) {
169        desc { "triggering a delayed bug for testing incremental" }
170    }
171
172    /// Collects the list of all tools registered using `#![register_tool]`.
173    query registered_tools(_: ()) -> &'tcx ty::RegisteredTools {
174        arena_cache
175        desc { "compute registered tools for crate" }
176    }
177
178    query early_lint_checks(_: ()) {
179        desc { "perform lints prior to AST lowering" }
180    }
181
182    /// Tracked access to environment variables.
183    ///
184    /// Useful for the implementation of `std::env!`, `proc-macro`s change
185    /// detection and other changes in the compiler's behaviour that is easier
186    /// to control with an environment variable than a flag.
187    ///
188    /// NOTE: This currently does not work with dependency info in the
189    /// analysis, codegen and linking passes, place extra code at the top of
190    /// `rustc_interface::passes::write_dep_info` to make that work.
191    query env_var_os(key: &'tcx OsStr) -> Option<&'tcx OsStr> {
192        // Environment variables are global state
193        eval_always
194        desc { "get the value of an environment variable" }
195    }
196
197    query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
198        desc { "getting the resolver outputs" }
199    }
200
201    query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
202        eval_always
203        no_hash
204        desc { "getting the resolver for lowering" }
205    }
206
207    /// Return the span for a definition.
208    ///
209    /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
210    /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
211    /// of rustc_middle::hir::source_map.
212    query source_span(key: LocalDefId) -> Span {
213        // Accesses untracked data
214        eval_always
215        desc { "getting the source span" }
216    }
217
218    /// Represents crate as a whole (as distinct from the top-level crate module).
219    ///
220    /// If you call `tcx.hir_crate(())` we will have to assume that any change
221    /// means that you need to be recompiled. This is because the `hir_crate`
222    /// query gives you access to all other items. To avoid this fate, do not
223    /// call `tcx.hir_crate(())`; instead, prefer wrappers like
224    /// [`TyCtxt::hir_visit_all_item_likes_in_crate`].
225    query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
226        arena_cache
227        eval_always
228        desc { "getting the crate HIR" }
229    }
230
231    /// All items in the crate.
232    query hir_crate_items(_: ()) -> &'tcx rustc_middle::hir::ModuleItems {
233        arena_cache
234        eval_always
235        desc { "getting HIR crate items" }
236    }
237
238    /// The items in a module.
239    ///
240    /// This can be conveniently accessed by `tcx.hir_visit_item_likes_in_module`.
241    /// Avoid calling this query directly.
242    query hir_module_items(key: LocalModDefId) -> &'tcx rustc_middle::hir::ModuleItems {
243        arena_cache
244        desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key) }
245        cache_on_disk_if { true }
246    }
247
248    /// Returns HIR ID for the given `LocalDefId`.
249    query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
250        desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key) }
251        feedable
252    }
253
254    /// Gives access to the HIR node's parent for the HIR owner `key`.
255    ///
256    /// This can be conveniently accessed by `tcx.hir_*` methods.
257    /// Avoid calling this query directly.
258    query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
259        desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key) }
260    }
261
262    /// Gives access to the HIR nodes and bodies inside `key` if it's a HIR owner.
263    ///
264    /// This can be conveniently accessed by `tcx.hir_*` methods.
265    /// Avoid calling this query directly.
266    query opt_hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
267        desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
268        feedable
269    }
270
271    /// Gives access to the HIR attributes inside the HIR owner `key`.
272    ///
273    /// This can be conveniently accessed by `tcx.hir_*` methods.
274    /// Avoid calling this query directly.
275    query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
276        desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
277        feedable
278    }
279
280    /// Gives access to lints emitted during ast lowering.
281    ///
282    /// This can be conveniently accessed by `tcx.hir_*` methods.
283    /// Avoid calling this query directly.
284    query opt_ast_lowering_delayed_lints(key: hir::OwnerId) -> Option<&'tcx hir::lints::DelayedLints> {
285        desc { |tcx| "getting AST lowering delayed lints in `{}`", tcx.def_path_str(key) }
286    }
287
288    /// Returns the *default* of the const pararameter given by `DefId`.
289    ///
290    /// E.g., given `struct Ty<const N: usize = 3>;` this returns `3` for `N`.
291    query const_param_default(param: DefId) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> {
292        desc { |tcx| "computing the default for const parameter `{}`", tcx.def_path_str(param)  }
293        cache_on_disk_if { param.is_local() }
294        separate_provide_extern
295    }
296
297    /// Returns the *type* of the definition given by `DefId`.
298    ///
299    /// For type aliases (whether eager or lazy) and associated types, this returns
300    /// the underlying aliased type (not the corresponding [alias type]).
301    ///
302    /// For opaque types, this returns and thus reveals the hidden type! If you
303    /// want to detect cycle errors use `type_of_opaque` instead.
304    ///
305    /// To clarify, for type definitions, this does *not* return the "type of a type"
306    /// (aka *kind* or *sort*) in the type-theoretical sense! It merely returns
307    /// the type primarily *associated with* it.
308    ///
309    /// # Panics
310    ///
311    /// This query will panic if the given definition doesn't (and can't
312    /// conceptually) have an (underlying) type.
313    ///
314    /// [alias type]: rustc_middle::ty::AliasTy
315    query type_of(key: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
316        desc { |tcx|
317            "{action} `{path}`",
318            action = match tcx.def_kind(key) {
319                DefKind::TyAlias => "expanding type alias",
320                DefKind::TraitAlias => "expanding trait alias",
321                _ => "computing type of",
322            },
323            path = tcx.def_path_str(key),
324        }
325        cache_on_disk_if { key.is_local() }
326        separate_provide_extern
327        feedable
328    }
329
330    /// Returns the *hidden type* of the opaque type given by `DefId` unless a cycle occurred.
331    ///
332    /// This is a specialized instance of [`Self::type_of`] that detects query cycles.
333    /// Unless `CyclePlaceholder` needs to be handled separately, call [`Self::type_of`] instead.
334    /// This is used to improve the error message in cases where revealing the hidden type
335    /// for auto-trait leakage cycles.
336    ///
337    /// # Panics
338    ///
339    /// This query will panic if the given definition is not an opaque type.
340    query type_of_opaque(key: DefId) -> Result<ty::EarlyBinder<'tcx, Ty<'tcx>>, CyclePlaceholder> {
341        desc { |tcx|
342            "computing type of opaque `{path}`",
343            path = tcx.def_path_str(key),
344        }
345        cycle_stash
346    }
347    query type_of_opaque_hir_typeck(key: LocalDefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
348        desc { |tcx|
349            "computing type of opaque `{path}` via HIR typeck",
350            path = tcx.def_path_str(key),
351        }
352    }
353
354    /// Returns whether the type alias given by `DefId` is lazy.
355    ///
356    /// I.e., if the type alias expands / ought to expand to a [free] [alias type]
357    /// instead of the underlying aliased type.
358    ///
359    /// Relevant for features `lazy_type_alias` and `type_alias_impl_trait`.
360    ///
361    /// # Panics
362    ///
363    /// This query *may* panic if the given definition is not a type alias.
364    ///
365    /// [free]: rustc_middle::ty::Free
366    /// [alias type]: rustc_middle::ty::AliasTy
367    query type_alias_is_lazy(key: DefId) -> bool {
368        desc { |tcx|
369            "computing whether the type alias `{path}` is lazy",
370            path = tcx.def_path_str(key),
371        }
372        separate_provide_extern
373    }
374
375    query collect_return_position_impl_trait_in_trait_tys(key: DefId)
376        -> Result<&'tcx DefIdMap<ty::EarlyBinder<'tcx, Ty<'tcx>>>, ErrorGuaranteed>
377    {
378        desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
379        cache_on_disk_if { key.is_local() }
380        separate_provide_extern
381    }
382
383    query opaque_ty_origin(key: DefId) -> hir::OpaqueTyOrigin<DefId>
384    {
385        desc { "determine where the opaque originates from" }
386        separate_provide_extern
387    }
388
389    query unsizing_params_for_adt(key: DefId) -> &'tcx rustc_index::bit_set::DenseBitSet<u32>
390    {
391        arena_cache
392        desc { |tcx|
393            "determining what parameters of `{}` can participate in unsizing",
394            tcx.def_path_str(key),
395        }
396    }
397
398    /// The root query triggering all analysis passes like typeck or borrowck.
399    query analysis(key: ()) {
400        eval_always
401        desc { "running analysis passes on this crate" }
402    }
403
404    /// This query checks the fulfillment of collected lint expectations.
405    /// All lint emitting queries have to be done before this is executed
406    /// to ensure that all expectations can be fulfilled.
407    ///
408    /// This is an extra query to enable other drivers (like rustdoc) to
409    /// only execute a small subset of the `analysis` query, while allowing
410    /// lints to be expected. In rustc, this query will be executed as part of
411    /// the `analysis` query and doesn't have to be called a second time.
412    ///
413    /// Tools can additionally pass in a tool filter. That will restrict the
414    /// expectations to only trigger for lints starting with the listed tool
415    /// name. This is useful for cases were not all linting code from rustc
416    /// was called. With the default `None` all registered lints will also
417    /// be checked for expectation fulfillment.
418    query check_expectations(key: Option<Symbol>) {
419        eval_always
420        desc { "checking lint expectations (RFC 2383)" }
421    }
422
423    /// Returns the *generics* of the definition given by `DefId`.
424    query generics_of(key: DefId) -> &'tcx ty::Generics {
425        desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
426        arena_cache
427        cache_on_disk_if { key.is_local() }
428        separate_provide_extern
429        feedable
430    }
431
432    /// Returns the (elaborated) *predicates* of the definition given by `DefId`
433    /// that must be proven true at usage sites (and which can be assumed at definition site).
434    ///
435    /// This is almost always *the* "predicates query" that you want.
436    ///
437    /// **Tip**: You can use `#[rustc_dump_predicates]` on an item to basically print
438    /// the result of this query for use in UI tests or for debugging purposes.
439    query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
440        desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
441        cache_on_disk_if { key.is_local() }
442    }
443
444    query opaque_types_defined_by(
445        key: LocalDefId
446    ) -> &'tcx ty::List<LocalDefId> {
447        desc {
448            |tcx| "computing the opaque types defined by `{}`",
449            tcx.def_path_str(key.to_def_id())
450        }
451    }
452
453    /// A list of all bodies inside of `key`, nested bodies are always stored
454    /// before their parent.
455    query nested_bodies_within(
456        key: LocalDefId
457    ) -> &'tcx ty::List<LocalDefId> {
458        desc {
459            |tcx| "computing the coroutines defined within `{}`",
460            tcx.def_path_str(key.to_def_id())
461        }
462    }
463
464    /// Returns the explicitly user-written *bounds* on the associated or opaque type given by `DefId`
465    /// that must be proven true at definition site (and which can be assumed at usage sites).
466    ///
467    /// For associated types, these must be satisfied for an implementation
468    /// to be well-formed, and for opaque types, these are required to be
469    /// satisfied by the hidden type of the opaque.
470    ///
471    /// Bounds from the parent (e.g. with nested `impl Trait`) are not included.
472    ///
473    /// Syntactially, these are the bounds written on associated types in trait
474    /// definitions, or those after the `impl` keyword for an opaque:
475    ///
476    /// ```ignore (illustrative)
477    /// trait Trait { type X: Bound + 'lt; }
478    /// //                    ^^^^^^^^^^^
479    /// fn function() -> impl Debug + Display { /*...*/ }
480    /// //                    ^^^^^^^^^^^^^^^
481    /// ```
482    query explicit_item_bounds(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
483        desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
484        cache_on_disk_if { key.is_local() }
485        separate_provide_extern
486        feedable
487    }
488
489    /// Returns the explicitly user-written *bounds* that share the `Self` type of the item.
490    ///
491    /// These are a subset of the [explicit item bounds] that may explicitly be used for things
492    /// like closure signature deduction.
493    ///
494    /// [explicit item bounds]: Self::explicit_item_bounds
495    query explicit_item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
496        desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
497        cache_on_disk_if { key.is_local() }
498        separate_provide_extern
499        feedable
500    }
501
502    /// Returns the (elaborated) *bounds* on the associated or opaque type given by `DefId`
503    /// that must be proven true at definition site (and which can be assumed at usage sites).
504    ///
505    /// Bounds from the parent (e.g. with nested `impl Trait`) are not included.
506    ///
507    /// **Tip**: You can use `#[rustc_dump_item_bounds]` on an item to basically print
508    /// the result of this query for use in UI tests or for debugging purposes.
509    ///
510    /// # Examples
511    ///
512    /// ```
513    /// trait Trait { type Assoc: Eq + ?Sized; }
514    /// ```
515    ///
516    /// While [`Self::explicit_item_bounds`] returns `[<Self as Trait>::Assoc: Eq]`
517    /// here, `item_bounds` returns:
518    ///
519    /// ```text
520    /// [
521    ///     <Self as Trait>::Assoc: Eq,
522    ///     <Self as Trait>::Assoc: PartialEq<<Self as Trait>::Assoc>
523    /// ]
524    /// ```
525    query item_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
526        desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
527    }
528
529    query item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
530        desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
531    }
532
533    query item_non_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
534        desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
535    }
536
537    query impl_super_outlives(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
538        desc { |tcx| "elaborating supertrait outlives for trait of `{}`", tcx.def_path_str(key) }
539    }
540
541    /// Look up all native libraries this crate depends on.
542    /// These are assembled from the following places:
543    /// - `extern` blocks (depending on their `link` attributes)
544    /// - the `libs` (`-l`) option
545    query native_libraries(_: CrateNum) -> &'tcx Vec<NativeLib> {
546        arena_cache
547        desc { "looking up the native libraries of a linked crate" }
548        separate_provide_extern
549    }
550
551    query shallow_lint_levels_on(key: hir::OwnerId) -> &'tcx rustc_middle::lint::ShallowLintLevelMap {
552        arena_cache
553        desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key) }
554    }
555
556    query lint_expectations(_: ()) -> &'tcx Vec<(LintExpectationId, LintExpectation)> {
557        arena_cache
558        desc { "computing `#[expect]`ed lints in this crate" }
559    }
560
561    query lints_that_dont_need_to_run(_: ()) -> &'tcx UnordSet<LintId> {
562        arena_cache
563        desc { "Computing all lints that are explicitly enabled or with a default level greater than Allow" }
564    }
565
566    query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
567        desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
568        separate_provide_extern
569    }
570
571    query is_panic_runtime(_: CrateNum) -> bool {
572        fatal_cycle
573        desc { "checking if the crate is_panic_runtime" }
574        separate_provide_extern
575    }
576
577    /// Checks whether a type is representable or infinitely sized
578    query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
579        desc { "checking if `{}` is representable", tcx.def_path_str(key) }
580        // infinitely sized types will cause a cycle
581        cycle_delay_bug
582        // we don't want recursive representability calls to be forced with
583        // incremental compilation because, if a cycle occurs, we need the
584        // entire cycle to be in memory for diagnostics
585        anon
586    }
587
588    /// An implementation detail for the `representability` query
589    query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
590        desc { "checking if `{}` is representable", key }
591        cycle_delay_bug
592        anon
593    }
594
595    /// Set of param indexes for type params that are in the type's representation
596    query params_in_repr(key: DefId) -> &'tcx rustc_index::bit_set::DenseBitSet<u32> {
597        desc { "finding type parameters in the representation" }
598        arena_cache
599        no_hash
600        separate_provide_extern
601    }
602
603    /// Fetch the THIR for a given body. The THIR body gets stolen by unsafety checking unless
604    /// `-Zno-steal-thir` is on.
605    query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
606        // Perf tests revealed that hashing THIR is inefficient (see #85729).
607        no_hash
608        desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key) }
609    }
610
611    /// Set of all the `DefId`s in this crate that have MIR associated with
612    /// them. This includes all the body owners, but also things like struct
613    /// constructors.
614    query mir_keys(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexSet<LocalDefId> {
615        arena_cache
616        desc { "getting a list of all mir_keys" }
617    }
618
619    /// Maps DefId's that have an associated `mir::Body` to the result
620    /// of the MIR const-checking pass. This is the set of qualifs in
621    /// the final value of a `const`.
622    query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
623        desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
624        cache_on_disk_if { key.is_local() }
625        separate_provide_extern
626    }
627
628    /// Build the MIR for a given `DefId` and prepare it for const qualification.
629    ///
630    /// See the [rustc dev guide] for more info.
631    ///
632    /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/construction.html
633    query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
634        desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key) }
635        feedable
636    }
637
638    /// Try to build an abstract representation of the given constant.
639    query thir_abstract_const(
640        key: DefId
641    ) -> Result<Option<ty::EarlyBinder<'tcx, ty::Const<'tcx>>>, ErrorGuaranteed> {
642        desc {
643            |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
644        }
645        separate_provide_extern
646    }
647
648    query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
649        no_hash
650        desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key) }
651    }
652
653    query mir_for_ctfe(
654        key: DefId
655    ) -> &'tcx mir::Body<'tcx> {
656        desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
657        cache_on_disk_if { key.is_local() }
658        separate_provide_extern
659    }
660
661    query mir_promoted(key: LocalDefId) -> (
662        &'tcx Steal<mir::Body<'tcx>>,
663        &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
664    ) {
665        no_hash
666        desc { |tcx| "promoting constants in MIR for `{}`", tcx.def_path_str(key) }
667    }
668
669    query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> {
670        desc {
671            |tcx| "finding symbols for captures of closure `{}`",
672            tcx.def_path_str(key)
673        }
674    }
675
676    /// Returns names of captured upvars for closures and coroutines.
677    ///
678    /// Here are some examples:
679    ///  - `name__field1__field2` when the upvar is captured by value.
680    ///  - `_ref__name__field` when the upvar is captured by reference.
681    ///
682    /// For coroutines this only contains upvars that are shared by all states.
683    query closure_saved_names_of_captured_variables(def_id: DefId) -> &'tcx IndexVec<abi::FieldIdx, Symbol> {
684        arena_cache
685        desc { |tcx| "computing debuginfo for closure `{}`", tcx.def_path_str(def_id) }
686        separate_provide_extern
687    }
688
689    query mir_coroutine_witnesses(key: DefId) -> Option<&'tcx mir::CoroutineLayout<'tcx>> {
690        arena_cache
691        desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
692        cache_on_disk_if { key.is_local() }
693        separate_provide_extern
694    }
695
696    query check_coroutine_obligations(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
697        desc { |tcx| "verify auto trait bounds for coroutine interior type `{}`", tcx.def_path_str(key) }
698        return_result_from_ensure_ok
699    }
700
701    /// Used in case `mir_borrowck` fails to prove an obligation. We generally assume that
702    /// all goals we prove in MIR type check hold as we've already checked them in HIR typeck.
703    ///
704    /// However, we replace each free region in the MIR body with a unique region inference
705    /// variable. As we may rely on structural identity when proving goals this may cause a
706    /// goal to no longer hold. We store obligations for which this may happen during HIR
707    /// typeck in the `TypeckResults`. We then uniquify and reprove them in case MIR typeck
708    /// encounters an unexpected error. We expect this to result in an error when used and
709    /// delay a bug if it does not.
710    query check_potentially_region_dependent_goals(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
711        desc {
712            |tcx| "reproving potentially region dependent HIR typeck goals for `{}",
713            tcx.def_path_str(key)
714        }
715    }
716
717    /// MIR after our optimization passes have run. This is MIR that is ready
718    /// for codegen. This is also the only query that can fetch non-local MIR, at present.
719    query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
720        desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
721        cache_on_disk_if { key.is_local() }
722        separate_provide_extern
723    }
724
725    /// Checks for the nearest `#[coverage(off)]` or `#[coverage(on)]` on
726    /// this def and any enclosing defs, up to the crate root.
727    ///
728    /// Returns `false` if `#[coverage(off)]` was found, or `true` if
729    /// either `#[coverage(on)]` or no coverage attribute was found.
730    query coverage_attr_on(key: LocalDefId) -> bool {
731        desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
732        feedable
733    }
734
735    /// Scans through a function's MIR after MIR optimizations, to prepare the
736    /// information needed by codegen when `-Cinstrument-coverage` is active.
737    ///
738    /// This includes the details of where to insert `llvm.instrprof.increment`
739    /// intrinsics, and the expression tables to be embedded in the function's
740    /// coverage metadata.
741    ///
742    /// FIXME(Zalathar): This query's purpose has drifted a bit and should
743    /// probably be renamed, but that can wait until after the potential
744    /// follow-ups to #136053 have settled down.
745    ///
746    /// Returns `None` for functions that were not instrumented.
747    query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> Option<&'tcx mir::coverage::CoverageIdsInfo> {
748        desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
749        arena_cache
750    }
751
752    /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
753    /// `DefId`. This function returns all promoteds in the specified body. The body references
754    /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
755    /// after inlining a body may refer to promoteds from other bodies. In that case you still
756    /// need to use the `DefId` of the original body.
757    query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
758        desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
759        cache_on_disk_if { key.is_local() }
760        separate_provide_extern
761    }
762
763    /// Erases regions from `ty` to yield a new type.
764    /// Normally you would just use `tcx.erase_and_anonymize_regions(value)`,
765    /// however, which uses this query as a kind of cache.
766    query erase_and_anonymize_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
767        // This query is not expected to have input -- as a result, it
768        // is not a good candidates for "replay" because it is essentially a
769        // pure function of its input (and hence the expectation is that
770        // no caller would be green **apart** from just these
771        // queries). Making it anonymous avoids hashing the result, which
772        // may save a bit of time.
773        anon
774        desc { "erasing regions from `{}`", ty }
775    }
776
777    query wasm_import_module_map(_: CrateNum) -> &'tcx DefIdMap<String> {
778        arena_cache
779        desc { "getting wasm import module map" }
780    }
781
782    /// Returns the explicitly user-written *predicates and bounds* of the trait given by `DefId`.
783    ///
784    /// Traits are unusual, because predicates on associated types are
785    /// converted into bounds on that type for backwards compatibility:
786    ///
787    /// ```
788    /// trait X where Self::U: Copy { type U; }
789    /// ```
790    ///
791    /// becomes
792    ///
793    /// ```
794    /// trait X { type U: Copy; }
795    /// ```
796    ///
797    /// [`Self::explicit_predicates_of`] and [`Self::explicit_item_bounds`] will
798    /// then take the appropriate subsets of the predicates here.
799    ///
800    /// # Panics
801    ///
802    /// This query will panic if the given definition is not a trait.
803    query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
804        desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key) }
805    }
806
807    /// Returns the explicitly user-written *predicates* of the definition given by `DefId`
808    /// that must be proven true at usage sites (and which can be assumed at definition site).
809    ///
810    /// You should probably use [`Self::predicates_of`] unless you're looking for
811    /// predicates with explicit spans for diagnostics purposes.
812    query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
813        desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
814        cache_on_disk_if { key.is_local() }
815        separate_provide_extern
816        feedable
817    }
818
819    /// Returns the *inferred outlives-predicates* of the item given by `DefId`.
820    ///
821    /// E.g., for `struct Foo<'a, T> { x: &'a T }`, this would return `[T: 'a]`.
822    ///
823    /// **Tip**: You can use `#[rustc_outlives]` on an item to basically print the
824    /// result of this query for use in UI tests or for debugging purposes.
825    query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
826        desc { |tcx| "computing inferred outlives-predicates of `{}`", tcx.def_path_str(key) }
827        cache_on_disk_if { key.is_local() }
828        separate_provide_extern
829        feedable
830    }
831
832    /// Returns the explicitly user-written *super-predicates* of the trait given by `DefId`.
833    ///
834    /// These predicates are unelaborated and consequently don't contain transitive super-predicates.
835    ///
836    /// This is a subset of the full list of predicates. We store these in a separate map
837    /// because we must evaluate them even during type conversion, often before the full
838    /// predicates are available (note that super-predicates must not be cyclic).
839    query explicit_super_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
840        desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
841        cache_on_disk_if { key.is_local() }
842        separate_provide_extern
843    }
844
845    /// The predicates of the trait that are implied during elaboration.
846    ///
847    /// This is a superset of the super-predicates of the trait, but a subset of the predicates
848    /// of the trait. For regular traits, this includes all super-predicates and their
849    /// associated type bounds. For trait aliases, currently, this includes all of the
850    /// predicates of the trait alias.
851    query explicit_implied_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
852        desc { |tcx| "computing the implied predicates of `{}`", tcx.def_path_str(key) }
853        cache_on_disk_if { key.is_local() }
854        separate_provide_extern
855    }
856
857    /// The Ident is the name of an associated type.The query returns only the subset
858    /// of supertraits that define the given associated type. This is used to avoid
859    /// cycles in resolving type-dependent associated item paths like `T::Item`.
860    query explicit_supertraits_containing_assoc_item(
861        key: (DefId, rustc_span::Ident)
862    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
863        desc { |tcx| "computing the super traits of `{}` with associated type name `{}`",
864            tcx.def_path_str(key.0),
865            key.1
866        }
867    }
868
869    /// Compute the conditions that need to hold for a conditionally-const item to be const.
870    /// That is, compute the set of `[const]` where clauses for a given item.
871    ///
872    /// This can be thought of as the `[const]` equivalent of `predicates_of`. These are the
873    /// predicates that need to be proven at usage sites, and can be assumed at definition.
874    ///
875    /// This query also computes the `[const]` where clauses for associated types, which are
876    /// not "const", but which have item bounds which may be `[const]`. These must hold for
877    /// the `[const]` item bound to hold.
878    query const_conditions(
879        key: DefId
880    ) -> ty::ConstConditions<'tcx> {
881        desc { |tcx| "computing the conditions for `{}` to be considered const",
882            tcx.def_path_str(key)
883        }
884        separate_provide_extern
885    }
886
887    /// Compute the const bounds that are implied for a conditionally-const item.
888    ///
889    /// This can be though of as the `[const]` equivalent of `explicit_item_bounds`. These
890    /// are the predicates that need to proven at definition sites, and can be assumed at
891    /// usage sites.
892    query explicit_implied_const_bounds(
893        key: DefId
894    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
895        desc { |tcx| "computing the implied `[const]` bounds for `{}`",
896            tcx.def_path_str(key)
897        }
898        separate_provide_extern
899    }
900
901    /// To avoid cycles within the predicates of a single item we compute
902    /// per-type-parameter predicates for resolving `T::AssocTy`.
903    query type_param_predicates(
904        key: (LocalDefId, LocalDefId, rustc_span::Ident)
905    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
906        desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir_ty_param_name(key.1) }
907    }
908
909    query trait_def(key: DefId) -> &'tcx ty::TraitDef {
910        desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
911        arena_cache
912        cache_on_disk_if { key.is_local() }
913        separate_provide_extern
914    }
915    query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
916        desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
917        cache_on_disk_if { key.is_local() }
918        separate_provide_extern
919    }
920    query adt_destructor(key: DefId) -> Option<ty::Destructor> {
921        desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
922        cache_on_disk_if { key.is_local() }
923        separate_provide_extern
924    }
925    query adt_async_destructor(key: DefId) -> Option<ty::AsyncDestructor> {
926        desc { |tcx| "computing `AsyncDrop` impl for `{}`", tcx.def_path_str(key) }
927        cache_on_disk_if { key.is_local() }
928        separate_provide_extern
929    }
930    query adt_sizedness_constraint(
931        key: (DefId, SizedTraitKind)
932    ) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
933        desc { |tcx| "computing the sizedness constraint for `{}`", tcx.def_path_str(key.0) }
934    }
935
936    query adt_dtorck_constraint(
937        key: DefId
938    ) -> &'tcx DropckConstraint<'tcx> {
939        desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
940    }
941
942    /// Returns the constness of the function-like[^1] definition given by `DefId`.
943    ///
944    /// Tuple struct/variant constructors are *always* const, foreign functions are
945    /// *never* const. The rest is const iff marked with keyword `const` (or rather
946    /// its parent in the case of associated functions).
947    ///
948    /// <div class="warning">
949    ///
950    /// **Do not call this query** directly. It is only meant to cache the base data for the
951    /// higher-level functions. Consider using `is_const_fn` or `is_const_trait_impl` instead.
952    ///
953    /// Also note that neither of them takes into account feature gates, stability and
954    /// const predicates/conditions!
955    ///
956    /// </div>
957    ///
958    /// # Panics
959    ///
960    /// This query will panic if the given definition is not function-like[^1].
961    ///
962    /// [^1]: Tuple struct/variant constructors, closures and free, associated and foreign functions.
963    query constness(key: DefId) -> hir::Constness {
964        desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
965        separate_provide_extern
966        feedable
967    }
968
969    query asyncness(key: DefId) -> ty::Asyncness {
970        desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
971        separate_provide_extern
972    }
973
974    /// Returns `true` if calls to the function may be promoted.
975    ///
976    /// This is either because the function is e.g., a tuple-struct or tuple-variant
977    /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
978    /// be removed in the future in favour of some form of check which figures out whether the
979    /// function does not inspect the bits of any of its arguments (so is essentially just a
980    /// constructor function).
981    query is_promotable_const_fn(key: DefId) -> bool {
982        desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
983    }
984
985    /// The body of the coroutine, modified to take its upvars by move rather than by ref.
986    ///
987    /// This is used by coroutine-closures, which must return a different flavor of coroutine
988    /// when called using `AsyncFnOnce::call_once`. It is produced by the `ByMoveBody` pass which
989    /// is run right after building the initial MIR, and will only be populated for coroutines
990    /// which come out of the async closure desugaring.
991    query coroutine_by_move_body_def_id(def_id: DefId) -> DefId {
992        desc { |tcx| "looking up the coroutine by-move body for `{}`", tcx.def_path_str(def_id) }
993        separate_provide_extern
994    }
995
996    /// Returns `Some(coroutine_kind)` if the node pointed to by `def_id` is a coroutine.
997    query coroutine_kind(def_id: DefId) -> Option<hir::CoroutineKind> {
998        desc { |tcx| "looking up coroutine kind of `{}`", tcx.def_path_str(def_id) }
999        separate_provide_extern
1000        feedable
1001    }
1002
1003    query coroutine_for_closure(def_id: DefId) -> DefId {
1004        desc { |_tcx| "Given a coroutine-closure def id, return the def id of the coroutine returned by it" }
1005        separate_provide_extern
1006    }
1007
1008    query coroutine_hidden_types(
1009        def_id: DefId,
1010    ) -> ty::EarlyBinder<'tcx, ty::Binder<'tcx, ty::CoroutineWitnessTypes<TyCtxt<'tcx>>>> {
1011        desc { "looking up the hidden types stored across await points in a coroutine" }
1012    }
1013
1014    /// Gets a map with the variances of every item in the local crate.
1015    ///
1016    /// <div class="warning">
1017    ///
1018    /// **Do not call this query** directly, use [`Self::variances_of`] instead.
1019    ///
1020    /// </div>
1021    query crate_variances(_: ()) -> &'tcx ty::CrateVariancesMap<'tcx> {
1022        arena_cache
1023        desc { "computing the variances for items in this crate" }
1024    }
1025
1026    /// Returns the (inferred) variances of the item given by `DefId`.
1027    ///
1028    /// The list of variances corresponds to the list of (early-bound) generic
1029    /// parameters of the item (including its parents).
1030    ///
1031    /// **Tip**: You can use `#[rustc_variance]` on an item to basically print the
1032    /// result of this query for use in UI tests or for debugging purposes.
1033    query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
1034        desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
1035        cache_on_disk_if { def_id.is_local() }
1036        separate_provide_extern
1037        cycle_delay_bug
1038    }
1039
1040    /// Gets a map with the inferred outlives-predicates of every item in the local crate.
1041    ///
1042    /// <div class="warning">
1043    ///
1044    /// **Do not call this query** directly, use [`Self::inferred_outlives_of`] instead.
1045    ///
1046    /// </div>
1047    query inferred_outlives_crate(_: ()) -> &'tcx ty::CratePredicatesMap<'tcx> {
1048        arena_cache
1049        desc { "computing the inferred outlives-predicates for items in this crate" }
1050    }
1051
1052    /// Maps from an impl/trait or struct/variant `DefId`
1053    /// to a list of the `DefId`s of its associated items or fields.
1054    query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
1055        desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
1056        cache_on_disk_if { key.is_local() }
1057        separate_provide_extern
1058    }
1059
1060    /// Maps from a trait/impl item to the trait/impl item "descriptor".
1061    query associated_item(key: DefId) -> ty::AssocItem {
1062        desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
1063        cache_on_disk_if { key.is_local() }
1064        separate_provide_extern
1065        feedable
1066    }
1067
1068    /// Collects the associated items defined on a trait or impl.
1069    query associated_items(key: DefId) -> &'tcx ty::AssocItems {
1070        arena_cache
1071        desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
1072    }
1073
1074    /// Maps from associated items on a trait to the corresponding associated
1075    /// item on the impl specified by `impl_id`.
1076    ///
1077    /// For example, with the following code
1078    ///
1079    /// ```
1080    /// struct Type {}
1081    ///                         // DefId
1082    /// trait Trait {           // trait_id
1083    ///     fn f();             // trait_f
1084    ///     fn g() {}           // trait_g
1085    /// }
1086    ///
1087    /// impl Trait for Type {   // impl_id
1088    ///     fn f() {}           // impl_f
1089    ///     fn g() {}           // impl_g
1090    /// }
1091    /// ```
1092    ///
1093    /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
1094    ///`{ trait_f: impl_f, trait_g: impl_g }`
1095    query impl_item_implementor_ids(impl_id: DefId) -> &'tcx DefIdMap<DefId> {
1096        arena_cache
1097        desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
1098    }
1099
1100    /// Given the `item_def_id` of a trait or impl, return a mapping from associated fn def id
1101    /// to its associated type items that correspond to the RPITITs in its signature.
1102    query associated_types_for_impl_traits_in_trait_or_impl(item_def_id: DefId) -> &'tcx DefIdMap<Vec<DefId>> {
1103        arena_cache
1104        desc { |tcx| "synthesizing RPITIT items for the opaque types for methods in `{}`", tcx.def_path_str(item_def_id) }
1105        separate_provide_extern
1106    }
1107
1108    /// Given an `impl_id`, return the trait it implements along with some header information.
1109    /// Return `None` if this is an inherent impl.
1110    query impl_trait_header(impl_id: DefId) -> Option<ty::ImplTraitHeader<'tcx>> {
1111        desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
1112        cache_on_disk_if { impl_id.is_local() }
1113        separate_provide_extern
1114    }
1115
1116    /// Given an `impl_def_id`, return true if the self type is guaranteed to be unsized due
1117    /// to either being one of the built-in unsized types (str/slice/dyn) or to be a struct
1118    /// whose tail is one of those types.
1119    query impl_self_is_guaranteed_unsized(impl_def_id: DefId) -> bool {
1120        desc { |tcx| "computing whether `{}` has a guaranteed unsized self type", tcx.def_path_str(impl_def_id) }
1121    }
1122
1123    /// Maps a `DefId` of a type to a list of its inherent impls.
1124    /// Contains implementations of methods that are inherent to a type.
1125    /// Methods in these implementations don't need to be exported.
1126    query inherent_impls(key: DefId) -> &'tcx [DefId] {
1127        desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
1128        cache_on_disk_if { key.is_local() }
1129        separate_provide_extern
1130    }
1131
1132    query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
1133        desc { |tcx| "collecting all inherent impls for `{:?}`", key }
1134    }
1135
1136    /// Unsafety-check this `LocalDefId`.
1137    query check_transmutes(key: LocalDefId) {
1138        desc { |tcx| "check transmute calls inside `{}`", tcx.def_path_str(key) }
1139    }
1140
1141    /// Unsafety-check this `LocalDefId`.
1142    query check_unsafety(key: LocalDefId) {
1143        desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
1144    }
1145
1146    /// Checks well-formedness of tail calls (`become f()`).
1147    query check_tail_calls(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
1148        desc { |tcx| "tail-call-checking `{}`", tcx.def_path_str(key) }
1149        return_result_from_ensure_ok
1150    }
1151
1152    /// Returns the types assumed to be well formed while "inside" of the given item.
1153    ///
1154    /// Note that we've liberated the late bound regions of function signatures, so
1155    /// this can not be used to check whether these types are well formed.
1156    query assumed_wf_types(key: LocalDefId) -> &'tcx [(Ty<'tcx>, Span)] {
1157        desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
1158    }
1159
1160    /// We need to store the assumed_wf_types for an RPITIT so that impls of foreign
1161    /// traits with return-position impl trait in traits can inherit the right wf types.
1162    query assumed_wf_types_for_rpitit(key: DefId) -> &'tcx [(Ty<'tcx>, Span)] {
1163        desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
1164        separate_provide_extern
1165    }
1166
1167    /// Computes the signature of the function.
1168    query fn_sig(key: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
1169        desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
1170        cache_on_disk_if { key.is_local() }
1171        separate_provide_extern
1172        cycle_delay_bug
1173    }
1174
1175    /// Performs lint checking for the module.
1176    query lint_mod(key: LocalModDefId) {
1177        desc { |tcx| "linting {}", describe_as_module(key, tcx) }
1178    }
1179
1180    query check_unused_traits(_: ()) {
1181        desc { "checking unused trait imports in crate" }
1182    }
1183
1184    /// Checks the attributes in the module.
1185    query check_mod_attrs(key: LocalModDefId) {
1186        desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
1187    }
1188
1189    /// Checks for uses of unstable APIs in the module.
1190    query check_mod_unstable_api_usage(key: LocalModDefId) {
1191        desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
1192    }
1193
1194    query check_mod_privacy(key: LocalModDefId) {
1195        desc { |tcx| "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) }
1196    }
1197
1198    query check_liveness(key: LocalDefId) {
1199        desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
1200    }
1201
1202    /// Return the live symbols in the crate for dead code check.
1203    ///
1204    /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone).
1205    query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
1206        LocalDefIdSet,
1207        LocalDefIdMap<FxIndexSet<DefId>>,
1208    ) {
1209        arena_cache
1210        desc { "finding live symbols in crate" }
1211    }
1212
1213    query check_mod_deathness(key: LocalModDefId) {
1214        desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
1215    }
1216
1217    query check_type_wf(key: ()) -> Result<(), ErrorGuaranteed> {
1218        desc { "checking that types are well-formed" }
1219        return_result_from_ensure_ok
1220    }
1221
1222    /// Caches `CoerceUnsized` kinds for impls on custom types.
1223    query coerce_unsized_info(key: DefId) -> Result<ty::adjustment::CoerceUnsizedInfo, ErrorGuaranteed> {
1224        desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
1225        cache_on_disk_if { key.is_local() }
1226        separate_provide_extern
1227        return_result_from_ensure_ok
1228    }
1229
1230    query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
1231        desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
1232        cache_on_disk_if(tcx) { !tcx.is_typeck_child(key.to_def_id()) }
1233    }
1234
1235    query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
1236        desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key) }
1237        cache_on_disk_if { true }
1238    }
1239
1240    query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
1241        desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
1242        return_result_from_ensure_ok
1243    }
1244
1245    /// Borrow-checks the given typeck root, e.g. functions, const/static items,
1246    /// and its children, e.g. closures, inline consts.
1247    query mir_borrowck(key: LocalDefId) -> Result<&'tcx mir::ConcreteOpaqueTypes<'tcx>, ErrorGuaranteed> {
1248        desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) }
1249    }
1250
1251    /// Gets a complete map from all types to their inherent impls.
1252    ///
1253    /// <div class="warning">
1254    ///
1255    /// **Not meant to be used** directly outside of coherence.
1256    ///
1257    /// </div>
1258    query crate_inherent_impls(k: ()) -> (&'tcx CrateInherentImpls, Result<(), ErrorGuaranteed>) {
1259        desc { "finding all inherent impls defined in crate" }
1260    }
1261
1262    /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
1263    ///
1264    /// <div class="warning">
1265    ///
1266    /// **Not meant to be used** directly outside of coherence.
1267    ///
1268    /// </div>
1269    query crate_inherent_impls_validity_check(_: ()) -> Result<(), ErrorGuaranteed> {
1270        desc { "check for inherent impls that should not be defined in crate" }
1271        return_result_from_ensure_ok
1272    }
1273
1274    /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
1275    ///
1276    /// <div class="warning">
1277    ///
1278    /// **Not meant to be used** directly outside of coherence.
1279    ///
1280    /// </div>
1281    query crate_inherent_impls_overlap_check(_: ()) -> Result<(), ErrorGuaranteed> {
1282        desc { "check for overlap between inherent impls defined in this crate" }
1283        return_result_from_ensure_ok
1284    }
1285
1286    /// Checks whether all impls in the crate pass the overlap check, returning
1287    /// which impls fail it. If all impls are correct, the returned slice is empty.
1288    query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1289        desc { |tcx|
1290            "checking whether impl `{}` follows the orphan rules",
1291            tcx.def_path_str(key),
1292        }
1293        return_result_from_ensure_ok
1294    }
1295
1296    /// Return the set of (transitive) callees that may result in a recursive call to `key`.
1297    query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
1298        fatal_cycle
1299        arena_cache
1300        desc { |tcx|
1301            "computing (transitive) callees of `{}` that may recurse",
1302            tcx.def_path_str(key),
1303        }
1304        cache_on_disk_if { true }
1305    }
1306
1307    /// Obtain all the calls into other local functions
1308    query mir_inliner_callees(key: ty::InstanceKind<'tcx>) -> &'tcx [(DefId, GenericArgsRef<'tcx>)] {
1309        fatal_cycle
1310        desc { |tcx|
1311            "computing all local function calls in `{}`",
1312            tcx.def_path_str(key.def_id()),
1313        }
1314    }
1315
1316    /// Computes the tag (if any) for a given type and variant.
1317    ///
1318    /// `None` means that the variant doesn't need a tag (because it is niched).
1319    ///
1320    /// # Panics
1321    ///
1322    /// This query will panic for uninhabited variants and if the passed type is not an enum.
1323    query tag_for_variant(
1324        key: PseudoCanonicalInput<'tcx, (Ty<'tcx>, abi::VariantIdx)>,
1325    ) -> Option<ty::ScalarInt> {
1326        desc { "computing variant tag for enum" }
1327    }
1328
1329    /// Evaluates a constant and returns the computed allocation.
1330    ///
1331    /// <div class="warning">
1332    ///
1333    /// **Do not call this query** directly, use [`Self::eval_to_const_value_raw`] or
1334    /// [`Self::eval_to_valtree`] instead.
1335    ///
1336    /// </div>
1337    query eval_to_allocation_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>)
1338        -> EvalToAllocationRawResult<'tcx> {
1339        desc { |tcx|
1340            "const-evaluating + checking `{}`",
1341            key.value.display(tcx)
1342        }
1343        cache_on_disk_if { true }
1344    }
1345
1346    /// Evaluate a static's initializer, returning the allocation of the initializer's memory.
1347    query eval_static_initializer(key: DefId) -> EvalStaticInitializerRawResult<'tcx> {
1348        desc { |tcx|
1349            "evaluating initializer of static `{}`",
1350            tcx.def_path_str(key)
1351        }
1352        cache_on_disk_if { key.is_local() }
1353        separate_provide_extern
1354        feedable
1355    }
1356
1357    /// Evaluates const items or anonymous constants[^1] into a representation
1358    /// suitable for the type system and const generics.
1359    ///
1360    /// <div class="warning">
1361    ///
1362    /// **Do not call this** directly, use one of the following wrappers:
1363    /// [`TyCtxt::const_eval_poly`], [`TyCtxt::const_eval_resolve`],
1364    /// [`TyCtxt::const_eval_instance`], or [`TyCtxt::const_eval_global_id`].
1365    ///
1366    /// </div>
1367    ///
1368    /// [^1]: Such as enum variant explicit discriminants or array lengths.
1369    query eval_to_const_value_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>)
1370        -> EvalToConstValueResult<'tcx> {
1371        desc { |tcx|
1372            "simplifying constant for the type system `{}`",
1373            key.value.display(tcx)
1374        }
1375        depth_limit
1376        cache_on_disk_if { true }
1377    }
1378
1379    /// Evaluate a constant and convert it to a type level constant or
1380    /// return `None` if that is not possible.
1381    query eval_to_valtree(
1382        key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>
1383    ) -> EvalToValTreeResult<'tcx> {
1384        desc { "evaluating type-level constant" }
1385    }
1386
1387    /// Converts a type-level constant value into a MIR constant value.
1388    query valtree_to_const_val(key: ty::Value<'tcx>) -> mir::ConstValue {
1389        desc { "converting type-level constant value to MIR constant value"}
1390    }
1391
1392    /// Destructures array, ADT or tuple constants into the constants
1393    /// of their fields.
1394    query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1395        desc { "destructuring type level constant"}
1396    }
1397
1398    // FIXME get rid of this with valtrees
1399    query lit_to_const(
1400        key: LitToConstInput<'tcx>
1401    ) -> ty::Const<'tcx> {
1402        desc { "converting literal to const" }
1403    }
1404
1405    query check_match(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
1406        desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1407        return_result_from_ensure_ok
1408    }
1409
1410    /// Performs part of the privacy check and computes effective visibilities.
1411    query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1412        eval_always
1413        desc { "checking effective visibilities" }
1414    }
1415    query check_private_in_public(module_def_id: LocalModDefId) {
1416        desc { |tcx|
1417            "checking for private elements in public interfaces for {}",
1418            describe_as_module(module_def_id, tcx)
1419        }
1420    }
1421
1422    query reachable_set(_: ()) -> &'tcx LocalDefIdSet {
1423        arena_cache
1424        desc { "reachability" }
1425        cache_on_disk_if { true }
1426    }
1427
1428    /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1429    /// in the case of closures, this will be redirected to the enclosing function.
1430    query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1431        desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1432    }
1433
1434    /// Generates a MIR body for the shim.
1435    query mir_shims(key: ty::InstanceKind<'tcx>) -> &'tcx mir::Body<'tcx> {
1436        arena_cache
1437        desc {
1438            |tcx| "generating MIR shim for `{}`, instance={:?}",
1439            tcx.def_path_str(key.def_id()),
1440            key
1441        }
1442    }
1443
1444    /// The `symbol_name` query provides the symbol name for calling a
1445    /// given instance from the local crate. In particular, it will also
1446    /// look up the correct symbol name of instances from upstream crates.
1447    query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1448        desc { "computing the symbol for `{}`", key }
1449        cache_on_disk_if { true }
1450    }
1451
1452    query def_kind(def_id: DefId) -> DefKind {
1453        desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1454        cache_on_disk_if { def_id.is_local() }
1455        separate_provide_extern
1456        feedable
1457    }
1458
1459    /// Gets the span for the definition.
1460    query def_span(def_id: DefId) -> Span {
1461        desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1462        cache_on_disk_if { def_id.is_local() }
1463        separate_provide_extern
1464        feedable
1465    }
1466
1467    /// Gets the span for the identifier of the definition.
1468    query def_ident_span(def_id: DefId) -> Option<Span> {
1469        desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1470        cache_on_disk_if { def_id.is_local() }
1471        separate_provide_extern
1472        feedable
1473    }
1474
1475    /// Gets the span for the type of the definition.
1476    /// Panics if it is not a definition that has a single type.
1477    query ty_span(def_id: LocalDefId) -> Span {
1478        desc { |tcx| "looking up span for `{}`'s type", tcx.def_path_str(def_id) }
1479        cache_on_disk_if { true }
1480    }
1481
1482    query lookup_stability(def_id: DefId) -> Option<hir::Stability> {
1483        desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1484        cache_on_disk_if { def_id.is_local() }
1485        separate_provide_extern
1486    }
1487
1488    query lookup_const_stability(def_id: DefId) -> Option<hir::ConstStability> {
1489        desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1490        cache_on_disk_if { def_id.is_local() }
1491        separate_provide_extern
1492    }
1493
1494    query lookup_default_body_stability(def_id: DefId) -> Option<hir::DefaultBodyStability> {
1495        desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1496        separate_provide_extern
1497    }
1498
1499    query should_inherit_track_caller(def_id: DefId) -> bool {
1500        desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1501    }
1502
1503    query inherited_align(def_id: DefId) -> Option<Align> {
1504        desc { |tcx| "computing inherited_align of `{}`", tcx.def_path_str(def_id) }
1505    }
1506
1507    query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1508        desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1509        cache_on_disk_if { def_id.is_local() }
1510        separate_provide_extern
1511    }
1512
1513    /// Determines whether an item is annotated with `#[doc(hidden)]`.
1514    query is_doc_hidden(def_id: DefId) -> bool {
1515        desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1516        separate_provide_extern
1517    }
1518
1519    /// Determines whether an item is annotated with `#[doc(notable_trait)]`.
1520    query is_doc_notable_trait(def_id: DefId) -> bool {
1521        desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1522    }
1523
1524    /// Returns the attributes on the item at `def_id`.
1525    ///
1526    /// Do not use this directly, use `tcx.get_attrs` instead.
1527    query attrs_for_def(def_id: DefId) -> &'tcx [hir::Attribute] {
1528        desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1529        separate_provide_extern
1530    }
1531
1532    /// Returns the `CodegenFnAttrs` for the item at `def_id`.
1533    ///
1534    /// If possible, use `tcx.codegen_instance_attrs` instead. That function takes the
1535    /// instance kind into account.
1536    ///
1537    /// For example, the `#[naked]` attribute should be applied for `InstanceKind::Item`,
1538    /// but should not be applied if the instance kind is `InstanceKind::ReifyShim`.
1539    /// Using this query would include the attribute regardless of the actual instance
1540    /// kind at the call site.
1541    query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs {
1542        desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1543        arena_cache
1544        cache_on_disk_if { def_id.is_local() }
1545        separate_provide_extern
1546        feedable
1547    }
1548
1549    query asm_target_features(def_id: DefId) -> &'tcx FxIndexSet<Symbol> {
1550        desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1551    }
1552
1553    query fn_arg_idents(def_id: DefId) -> &'tcx [Option<rustc_span::Ident>] {
1554        desc { |tcx| "looking up function parameter identifiers for `{}`", tcx.def_path_str(def_id) }
1555        separate_provide_extern
1556    }
1557
1558    /// Gets the rendered value of the specified constant or associated constant.
1559    /// Used by rustdoc.
1560    query rendered_const(def_id: DefId) -> &'tcx String {
1561        arena_cache
1562        desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1563        separate_provide_extern
1564    }
1565
1566    /// Gets the rendered precise capturing args for an opaque for use in rustdoc.
1567    query rendered_precise_capturing_args(def_id: DefId) -> Option<&'tcx [PreciseCapturingArgKind<Symbol, Symbol>]> {
1568        desc { |tcx| "rendering precise capturing args for `{}`", tcx.def_path_str(def_id) }
1569        separate_provide_extern
1570    }
1571
1572    query impl_parent(def_id: DefId) -> Option<DefId> {
1573        desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1574        separate_provide_extern
1575    }
1576
1577    query is_ctfe_mir_available(key: DefId) -> bool {
1578        desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1579        cache_on_disk_if { key.is_local() }
1580        separate_provide_extern
1581    }
1582    query is_mir_available(key: DefId) -> bool {
1583        desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1584        cache_on_disk_if { key.is_local() }
1585        separate_provide_extern
1586    }
1587
1588    query own_existential_vtable_entries(
1589        key: DefId
1590    ) -> &'tcx [DefId] {
1591        desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1592    }
1593
1594    query vtable_entries(key: ty::TraitRef<'tcx>)
1595                        -> &'tcx [ty::VtblEntry<'tcx>] {
1596        desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id) }
1597    }
1598
1599    query first_method_vtable_slot(key: ty::TraitRef<'tcx>) -> usize {
1600        desc { |tcx| "finding the slot within the vtable of `{}` for the implementation of `{}`", key.self_ty(), key.print_only_trait_name() }
1601    }
1602
1603    query supertrait_vtable_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1604        desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1605            key.1, key.0 }
1606    }
1607
1608    query vtable_allocation(key: (Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1609        desc { |tcx| "vtable const allocation for <{} as {}>",
1610            key.0,
1611            key.1.map(|trait_ref| format!("{trait_ref}")).unwrap_or_else(|| "_".to_owned())
1612        }
1613    }
1614
1615    query codegen_select_candidate(
1616        key: PseudoCanonicalInput<'tcx, ty::TraitRef<'tcx>>
1617    ) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
1618        cache_on_disk_if { true }
1619        desc { |tcx| "computing candidate for `{}`", key.value }
1620    }
1621
1622    /// Return all `impl` blocks in the current crate.
1623    query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1624        desc { "finding local trait impls" }
1625    }
1626
1627    /// Return all `impl` blocks of the given trait in the current crate.
1628    query local_trait_impls(trait_id: DefId) -> &'tcx [LocalDefId] {
1629        desc { "finding local trait impls of `{}`", tcx.def_path_str(trait_id) }
1630    }
1631
1632    /// Given a trait `trait_id`, return all known `impl` blocks.
1633    query trait_impls_of(trait_id: DefId) -> &'tcx ty::trait_def::TraitImpls {
1634        arena_cache
1635        desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1636    }
1637
1638    query specialization_graph_of(trait_id: DefId) -> Result<&'tcx specialization_graph::Graph, ErrorGuaranteed> {
1639        desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1640        cache_on_disk_if { true }
1641        return_result_from_ensure_ok
1642    }
1643    query dyn_compatibility_violations(trait_id: DefId) -> &'tcx [DynCompatibilityViolation] {
1644        desc { |tcx| "determining dyn-compatibility of trait `{}`", tcx.def_path_str(trait_id) }
1645    }
1646    query is_dyn_compatible(trait_id: DefId) -> bool {
1647        desc { |tcx| "checking if trait `{}` is dyn-compatible", tcx.def_path_str(trait_id) }
1648    }
1649
1650    /// Gets the ParameterEnvironment for a given item; this environment
1651    /// will be in "user-facing" mode, meaning that it is suitable for
1652    /// type-checking etc, and it does not normalize specializable
1653    /// associated types.
1654    ///
1655    /// You should almost certainly not use this. If you already have an InferCtxt, then
1656    /// you should also probably have a `ParamEnv` from when it was built. If you don't,
1657    /// then you should take a `TypingEnv` to ensure that you handle opaque types correctly.
1658    query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1659        desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1660        feedable
1661    }
1662
1663    /// Like `param_env`, but returns the `ParamEnv` after all opaque types have been
1664    /// replaced with their hidden type. This is used in the old trait solver
1665    /// when in `PostAnalysis` mode and should not be called directly.
1666    query typing_env_normalized_for_post_analysis(def_id: DefId) -> ty::TypingEnv<'tcx> {
1667        desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1668    }
1669
1670    /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1671    /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1672    query is_copy_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1673        desc { "computing whether `{}` is `Copy`", env.value }
1674    }
1675    /// Trait selection queries. These are best used by invoking `ty.is_use_cloned_modulo_regions()`,
1676    /// `ty.is_use_cloned()`, etc, since that will prune the environment where possible.
1677    query is_use_cloned_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1678        desc { "computing whether `{}` is `UseCloned`", env.value }
1679    }
1680    /// Query backing `Ty::is_sized`.
1681    query is_sized_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1682        desc { "computing whether `{}` is `Sized`", env.value }
1683    }
1684    /// Query backing `Ty::is_freeze`.
1685    query is_freeze_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1686        desc { "computing whether `{}` is freeze", env.value }
1687    }
1688    /// Query backing `Ty::is_unpin`.
1689    query is_unpin_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1690        desc { "computing whether `{}` is `Unpin`", env.value }
1691    }
1692    /// Query backing `Ty::is_async_drop`.
1693    query is_async_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1694        desc { "computing whether `{}` is `AsyncDrop`", env.value }
1695    }
1696    /// Query backing `Ty::needs_drop`.
1697    query needs_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1698        desc { "computing whether `{}` needs drop", env.value }
1699    }
1700    /// Query backing `Ty::needs_async_drop`.
1701    query needs_async_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1702        desc { "computing whether `{}` needs async drop", env.value }
1703    }
1704    /// Query backing `Ty::has_significant_drop_raw`.
1705    query has_significant_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1706        desc { "computing whether `{}` has a significant drop", env.value }
1707    }
1708
1709    /// Query backing `Ty::is_structural_eq_shallow`.
1710    ///
1711    /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1712    /// correctly.
1713    query has_structural_eq_impl(ty: Ty<'tcx>) -> bool {
1714        desc {
1715            "computing whether `{}` implements `StructuralPartialEq`",
1716            ty
1717        }
1718    }
1719
1720    /// A list of types where the ADT requires drop if and only if any of
1721    /// those types require drop. If the ADT is known to always need drop
1722    /// then `Err(AlwaysRequiresDrop)` is returned.
1723    query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1724        desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1725        cache_on_disk_if { true }
1726    }
1727
1728    /// A list of types where the ADT requires async drop if and only if any of
1729    /// those types require async drop. If the ADT is known to always need async drop
1730    /// then `Err(AlwaysRequiresDrop)` is returned.
1731    query adt_async_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1732        desc { |tcx| "computing when `{}` needs async drop", tcx.def_path_str(def_id) }
1733        cache_on_disk_if { true }
1734    }
1735
1736    /// A list of types where the ADT requires drop if and only if any of those types
1737    /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1738    /// is considered to not be significant. A drop is significant if it is implemented
1739    /// by the user or does anything that will have any observable behavior (other than
1740    /// freeing up memory). If the ADT is known to have a significant destructor then
1741    /// `Err(AlwaysRequiresDrop)` is returned.
1742    query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1743        desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1744    }
1745
1746    /// Returns a list of types which (a) have a potentially significant destructor
1747    /// and (b) may be dropped as a result of dropping a value of some type `ty`
1748    /// (in the given environment).
1749    ///
1750    /// The idea of "significant" drop is somewhat informal and is used only for
1751    /// diagnostics and edition migrations. The idea is that a significant drop may have
1752    /// some visible side-effect on execution; freeing memory is NOT considered a side-effect.
1753    /// The rules are as follows:
1754    /// * Type with no explicit drop impl do not have significant drop.
1755    /// * Types with a drop impl are assumed to have significant drop unless they have a `#[rustc_insignificant_dtor]` annotation.
1756    ///
1757    /// Note that insignificant drop is a "shallow" property. A type like `Vec<LockGuard>` does not
1758    /// have significant drop but the type `LockGuard` does, and so if `ty  = Vec<LockGuard>`
1759    /// then the return value would be `&[LockGuard]`.
1760    /// *IMPORTANT*: *DO NOT* run this query before promoted MIR body is constructed,
1761    /// because this query partially depends on that query.
1762    /// Otherwise, there is a risk of query cycles.
1763    query list_significant_drop_tys(ty: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> &'tcx ty::List<Ty<'tcx>> {
1764        desc { |tcx| "computing when `{}` has a significant destructor", ty.value }
1765    }
1766
1767    /// Computes the layout of a type. Note that this implicitly
1768    /// executes in `TypingMode::PostAnalysis`, and will normalize the input type.
1769    query layout_of(
1770        key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>
1771    ) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
1772        depth_limit
1773        desc { "computing layout of `{}`", key.value }
1774        // we emit our own error during query cycle handling
1775        cycle_delay_bug
1776    }
1777
1778    /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1779    ///
1780    /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1781    /// instead, where the instance is an `InstanceKind::Virtual`.
1782    query fn_abi_of_fn_ptr(
1783        key: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1784    ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
1785        desc { "computing call ABI of `{}` function pointers", key.value.0 }
1786    }
1787
1788    /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1789    /// direct calls to an `fn`.
1790    ///
1791    /// NB: that includes virtual calls, which are represented by "direct calls"
1792    /// to an `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1793    query fn_abi_of_instance(
1794        key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1795    ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
1796        desc { "computing call ABI of `{}`", key.value.0 }
1797    }
1798
1799    query dylib_dependency_formats(_: CrateNum)
1800                                    -> &'tcx [(CrateNum, LinkagePreference)] {
1801        desc { "getting dylib dependency formats of crate" }
1802        separate_provide_extern
1803    }
1804
1805    query dependency_formats(_: ()) -> &'tcx Arc<crate::middle::dependency_format::Dependencies> {
1806        arena_cache
1807        desc { "getting the linkage format of all dependencies" }
1808    }
1809
1810    query is_compiler_builtins(_: CrateNum) -> bool {
1811        fatal_cycle
1812        desc { "checking if the crate is_compiler_builtins" }
1813        separate_provide_extern
1814    }
1815    query has_global_allocator(_: CrateNum) -> bool {
1816        // This query depends on untracked global state in CStore
1817        eval_always
1818        fatal_cycle
1819        desc { "checking if the crate has_global_allocator" }
1820        separate_provide_extern
1821    }
1822    query has_alloc_error_handler(_: CrateNum) -> bool {
1823        // This query depends on untracked global state in CStore
1824        eval_always
1825        fatal_cycle
1826        desc { "checking if the crate has_alloc_error_handler" }
1827        separate_provide_extern
1828    }
1829    query has_panic_handler(_: CrateNum) -> bool {
1830        fatal_cycle
1831        desc { "checking if the crate has_panic_handler" }
1832        separate_provide_extern
1833    }
1834    query is_profiler_runtime(_: CrateNum) -> bool {
1835        fatal_cycle
1836        desc { "checking if a crate is `#![profiler_runtime]`" }
1837        separate_provide_extern
1838    }
1839    query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1840        desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key) }
1841        cache_on_disk_if { true }
1842    }
1843    query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1844        fatal_cycle
1845        desc { "getting a crate's required panic strategy" }
1846        separate_provide_extern
1847    }
1848    query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1849        fatal_cycle
1850        desc { "getting a crate's configured panic-in-drop strategy" }
1851        separate_provide_extern
1852    }
1853    query is_no_builtins(_: CrateNum) -> bool {
1854        fatal_cycle
1855        desc { "getting whether a crate has `#![no_builtins]`" }
1856        separate_provide_extern
1857    }
1858    query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1859        fatal_cycle
1860        desc { "getting a crate's symbol mangling version" }
1861        separate_provide_extern
1862    }
1863
1864    query extern_crate(def_id: CrateNum) -> Option<&'tcx ExternCrate> {
1865        eval_always
1866        desc { "getting crate's ExternCrateData" }
1867        separate_provide_extern
1868    }
1869
1870    query specialization_enabled_in(cnum: CrateNum) -> bool {
1871        desc { "checking whether the crate enabled `specialization`/`min_specialization`" }
1872        separate_provide_extern
1873    }
1874
1875    query specializes(_: (DefId, DefId)) -> bool {
1876        desc { "computing whether impls specialize one another" }
1877    }
1878    query in_scope_traits_map(_: hir::OwnerId)
1879        -> Option<&'tcx ItemLocalMap<Box<[TraitCandidate]>>> {
1880        desc { "getting traits in scope at a block" }
1881    }
1882
1883    /// Returns whether the impl or associated function has the `default` keyword.
1884    /// Note: This will ICE on inherent impl items. Consider using `AssocItem::defaultness`.
1885    query defaultness(def_id: DefId) -> hir::Defaultness {
1886        desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) }
1887        separate_provide_extern
1888        feedable
1889    }
1890
1891    /// Returns whether the field corresponding to the `DefId` has a default field value.
1892    query default_field(def_id: DefId) -> Option<DefId> {
1893        desc { |tcx| "looking up the `const` corresponding to the default for `{}`", tcx.def_path_str(def_id) }
1894        separate_provide_extern
1895    }
1896
1897    query check_well_formed(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1898        desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
1899        return_result_from_ensure_ok
1900    }
1901
1902    query enforce_impl_non_lifetime_params_are_constrained(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1903        desc { |tcx| "checking that `{}`'s generics are constrained by the impl header", tcx.def_path_str(key) }
1904        return_result_from_ensure_ok
1905    }
1906
1907    // The `DefId`s of all non-generic functions and statics in the given crate
1908    // that can be reached from outside the crate.
1909    //
1910    // We expect this items to be available for being linked to.
1911    //
1912    // This query can also be called for `LOCAL_CRATE`. In this case it will
1913    // compute which items will be reachable to other crates, taking into account
1914    // the kind of crate that is currently compiled. Crates with only a
1915    // C interface have fewer reachable things.
1916    //
1917    // Does not include external symbols that don't have a corresponding DefId,
1918    // like the compiler-generated `main` function and so on.
1919    query reachable_non_generics(_: CrateNum)
1920        -> &'tcx DefIdMap<SymbolExportInfo> {
1921        arena_cache
1922        desc { "looking up the exported symbols of a crate" }
1923        separate_provide_extern
1924    }
1925    query is_reachable_non_generic(def_id: DefId) -> bool {
1926        desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1927        cache_on_disk_if { def_id.is_local() }
1928        separate_provide_extern
1929    }
1930    query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1931        desc { |tcx|
1932            "checking whether `{}` is reachable from outside the crate",
1933            tcx.def_path_str(def_id),
1934        }
1935    }
1936
1937    /// The entire set of monomorphizations the local crate can safely
1938    /// link to because they are exported from upstream crates. Do
1939    /// not depend on this directly, as its value changes anytime
1940    /// a monomorphization gets added or removed in any upstream
1941    /// crate. Instead use the narrower `upstream_monomorphizations_for`,
1942    /// `upstream_drop_glue_for`, `upstream_async_drop_glue_for`, or,
1943    /// even better, `Instance::upstream_monomorphization()`.
1944    query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<UnordMap<GenericArgsRef<'tcx>, CrateNum>> {
1945        arena_cache
1946        desc { "collecting available upstream monomorphizations" }
1947    }
1948
1949    /// Returns the set of upstream monomorphizations available for the
1950    /// generic function identified by the given `def_id`. The query makes
1951    /// sure to make a stable selection if the same monomorphization is
1952    /// available in multiple upstream crates.
1953    ///
1954    /// You likely want to call `Instance::upstream_monomorphization()`
1955    /// instead of invoking this query directly.
1956    query upstream_monomorphizations_for(def_id: DefId)
1957        -> Option<&'tcx UnordMap<GenericArgsRef<'tcx>, CrateNum>>
1958    {
1959        desc { |tcx|
1960            "collecting available upstream monomorphizations for `{}`",
1961            tcx.def_path_str(def_id),
1962        }
1963        separate_provide_extern
1964    }
1965
1966    /// Returns the upstream crate that exports drop-glue for the given
1967    /// type (`args` is expected to be a single-item list containing the
1968    /// type one wants drop-glue for).
1969    ///
1970    /// This is a subset of `upstream_monomorphizations_for` in order to
1971    /// increase dep-tracking granularity. Otherwise adding or removing any
1972    /// type with drop-glue in any upstream crate would invalidate all
1973    /// functions calling drop-glue of an upstream type.
1974    ///
1975    /// You likely want to call `Instance::upstream_monomorphization()`
1976    /// instead of invoking this query directly.
1977    ///
1978    /// NOTE: This query could easily be extended to also support other
1979    ///       common functions that have are large set of monomorphizations
1980    ///       (like `Clone::clone` for example).
1981    query upstream_drop_glue_for(args: GenericArgsRef<'tcx>) -> Option<CrateNum> {
1982        desc { "available upstream drop-glue for `{:?}`", args }
1983    }
1984
1985    /// Returns the upstream crate that exports async-drop-glue for
1986    /// the given type (`args` is expected to be a single-item list
1987    /// containing the type one wants async-drop-glue for).
1988    ///
1989    /// This is a subset of `upstream_monomorphizations_for` in order
1990    /// to increase dep-tracking granularity. Otherwise adding or
1991    /// removing any type with async-drop-glue in any upstream crate
1992    /// would invalidate all functions calling async-drop-glue of an
1993    /// upstream type.
1994    ///
1995    /// You likely want to call `Instance::upstream_monomorphization()`
1996    /// instead of invoking this query directly.
1997    ///
1998    /// NOTE: This query could easily be extended to also support other
1999    ///       common functions that have are large set of monomorphizations
2000    ///       (like `Clone::clone` for example).
2001    query upstream_async_drop_glue_for(args: GenericArgsRef<'tcx>) -> Option<CrateNum> {
2002        desc { "available upstream async-drop-glue for `{:?}`", args }
2003    }
2004
2005    /// Returns a list of all `extern` blocks of a crate.
2006    query foreign_modules(_: CrateNum) -> &'tcx FxIndexMap<DefId, ForeignModule> {
2007        arena_cache
2008        desc { "looking up the foreign modules of a linked crate" }
2009        separate_provide_extern
2010    }
2011
2012    /// Lint against `extern fn` declarations having incompatible types.
2013    query clashing_extern_declarations(_: ()) {
2014        desc { "checking `extern fn` declarations are compatible" }
2015    }
2016
2017    /// Identifies the entry-point (e.g., the `main` function) for a given
2018    /// crate, returning `None` if there is no entry point (such as for library crates).
2019    query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
2020        desc { "looking up the entry function of a crate" }
2021    }
2022
2023    /// Finds the `rustc_proc_macro_decls` item of a crate.
2024    query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
2025        desc { "looking up the proc macro declarations for a crate" }
2026    }
2027
2028    // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
2029    // Changing the name should cause a compiler error, but in case that changes, be aware.
2030    //
2031    // The hash should not be calculated before the `analysis` pass is complete, specifically
2032    // until `tcx.untracked().definitions.freeze()` has been called, otherwise if incremental
2033    // compilation is enabled calculating this hash can freeze this structure too early in
2034    // compilation and cause subsequent crashes when attempting to write to `definitions`
2035    query crate_hash(_: CrateNum) -> Svh {
2036        eval_always
2037        desc { "looking up the hash a crate" }
2038        separate_provide_extern
2039    }
2040
2041    /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
2042    query crate_host_hash(_: CrateNum) -> Option<Svh> {
2043        eval_always
2044        desc { "looking up the hash of a host version of a crate" }
2045        separate_provide_extern
2046    }
2047
2048    /// Gets the extra data to put in each output filename for a crate.
2049    /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
2050    query extra_filename(_: CrateNum) -> &'tcx String {
2051        arena_cache
2052        eval_always
2053        desc { "looking up the extra filename for a crate" }
2054        separate_provide_extern
2055    }
2056
2057    /// Gets the paths where the crate came from in the file system.
2058    query crate_extern_paths(_: CrateNum) -> &'tcx Vec<PathBuf> {
2059        arena_cache
2060        eval_always
2061        desc { "looking up the paths for extern crates" }
2062        separate_provide_extern
2063    }
2064
2065    /// Given a crate and a trait, look up all impls of that trait in the crate.
2066    /// Return `(impl_id, self_ty)`.
2067    query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
2068        desc { "looking up implementations of a trait in a crate" }
2069        separate_provide_extern
2070    }
2071
2072    /// Collects all incoherent impls for the given crate and type.
2073    ///
2074    /// Do not call this directly, but instead use the `incoherent_impls` query.
2075    /// This query is only used to get the data necessary for that query.
2076    query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
2077        desc { |tcx| "collecting all impls for a type in a crate" }
2078        separate_provide_extern
2079    }
2080
2081    /// Get the corresponding native library from the `native_libraries` query
2082    query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
2083        desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
2084    }
2085
2086    query inherit_sig_for_delegation_item(def_id: LocalDefId) -> &'tcx [Ty<'tcx>] {
2087        desc { "inheriting delegation signature" }
2088    }
2089
2090    /// Does lifetime resolution on items. Importantly, we can't resolve
2091    /// lifetimes directly on things like trait methods, because of trait params.
2092    /// See `rustc_resolve::late::lifetimes` for details.
2093    query resolve_bound_vars(owner_id: hir::OwnerId) -> &'tcx ResolveBoundVars {
2094        arena_cache
2095        desc { |tcx| "resolving lifetimes for `{}`", tcx.def_path_str(owner_id) }
2096    }
2097    query named_variable_map(owner_id: hir::OwnerId) -> &'tcx SortedMap<ItemLocalId, ResolvedArg> {
2098        desc { |tcx| "looking up a named region inside `{}`", tcx.def_path_str(owner_id) }
2099    }
2100    query is_late_bound_map(owner_id: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
2101        desc { |tcx| "testing if a region is late bound inside `{}`", tcx.def_path_str(owner_id) }
2102    }
2103    /// Returns the *default lifetime* to be used if a trait object type were to be passed for
2104    /// the type parameter given by `DefId`.
2105    ///
2106    /// **Tip**: You can use `#[rustc_object_lifetime_default]` on an item to basically
2107    /// print the result of this query for use in UI tests or for debugging purposes.
2108    ///
2109    /// # Examples
2110    ///
2111    /// - For `T` in `struct Foo<'a, T: 'a>(&'a T);`, this would be `Param('a)`
2112    /// - For `T` in `struct Bar<'a, T>(&'a T);`, this would be `Empty`
2113    ///
2114    /// # Panics
2115    ///
2116    /// This query will panic if the given definition is not a type parameter.
2117    query object_lifetime_default(def_id: DefId) -> ObjectLifetimeDefault {
2118        desc { "looking up lifetime defaults for type parameter `{}`", tcx.def_path_str(def_id) }
2119        separate_provide_extern
2120    }
2121    query late_bound_vars_map(owner_id: hir::OwnerId)
2122        -> &'tcx SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>> {
2123        desc { |tcx| "looking up late bound vars inside `{}`", tcx.def_path_str(owner_id) }
2124    }
2125    /// For an opaque type, return the list of (captured lifetime, inner generic param).
2126    /// ```ignore (illustrative)
2127    /// fn foo<'a: 'a, 'b, T>(&'b u8) -> impl Into<Self> + 'b { ... }
2128    /// ```
2129    ///
2130    /// We would return `[('a, '_a), ('b, '_b)]`, with `'a` early-bound and `'b` late-bound.
2131    ///
2132    /// After hir_ty_lowering, we get:
2133    /// ```ignore (pseudo-code)
2134    /// opaque foo::<'a>::opaque<'_a, '_b>: Into<Foo<'_a>> + '_b;
2135    ///                          ^^^^^^^^ inner generic params
2136    /// fn foo<'a>: for<'b> fn(&'b u8) -> foo::<'a>::opaque::<'a, 'b>
2137    ///                                                       ^^^^^^ captured lifetimes
2138    /// ```
2139    query opaque_captured_lifetimes(def_id: LocalDefId) -> &'tcx [(ResolvedArg, LocalDefId)] {
2140        desc { |tcx| "listing captured lifetimes for opaque `{}`", tcx.def_path_str(def_id) }
2141    }
2142
2143    /// Computes the visibility of the provided `def_id`.
2144    ///
2145    /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
2146    /// a generic type parameter will panic if you call this method on it:
2147    ///
2148    /// ```
2149    /// use std::fmt::Debug;
2150    ///
2151    /// pub trait Foo<T: Debug> {}
2152    /// ```
2153    ///
2154    /// In here, if you call `visibility` on `T`, it'll panic.
2155    query visibility(def_id: DefId) -> ty::Visibility<DefId> {
2156        desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
2157        separate_provide_extern
2158        feedable
2159    }
2160
2161    query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
2162        desc { "computing the uninhabited predicate of `{:?}`", key }
2163    }
2164
2165    /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
2166    query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
2167        desc { "computing the uninhabited predicate of `{}`", key }
2168    }
2169
2170    query dep_kind(_: CrateNum) -> CrateDepKind {
2171        eval_always
2172        desc { "fetching what a dependency looks like" }
2173        separate_provide_extern
2174    }
2175
2176    /// Gets the name of the crate.
2177    query crate_name(_: CrateNum) -> Symbol {
2178        feedable
2179        desc { "fetching what a crate is named" }
2180        separate_provide_extern
2181    }
2182    query module_children(def_id: DefId) -> &'tcx [ModChild] {
2183        desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
2184        separate_provide_extern
2185    }
2186
2187    /// Gets the number of definitions in a foreign crate.
2188    ///
2189    /// This allows external tools to iterate over all definitions in a foreign crate.
2190    ///
2191    /// This should never be used for the local crate, instead use `iter_local_def_id`.
2192    query num_extern_def_ids(_: CrateNum) -> usize {
2193        desc { "fetching the number of definitions in a crate" }
2194        separate_provide_extern
2195    }
2196
2197    query lib_features(_: CrateNum) -> &'tcx LibFeatures {
2198        desc { "calculating the lib features defined in a crate" }
2199        separate_provide_extern
2200        arena_cache
2201    }
2202    /// Mapping from feature name to feature name based on the `implied_by` field of `#[unstable]`
2203    /// attributes. If a `#[unstable(feature = "implier", implied_by = "impliee")]` attribute
2204    /// exists, then this map will have a `impliee -> implier` entry.
2205    ///
2206    /// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should
2207    /// specify their implications (both `implies` and `implied_by`). If only one of the two
2208    /// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this
2209    /// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is
2210    /// reported, only the `#[stable]` attribute information is available, so the map is necessary
2211    /// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
2212    /// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
2213    /// unstable feature" error for a feature that was implied.
2214    query stability_implications(_: CrateNum) -> &'tcx UnordMap<Symbol, Symbol> {
2215        arena_cache
2216        desc { "calculating the implications between `#[unstable]` features defined in a crate" }
2217        separate_provide_extern
2218    }
2219    /// Whether the function is an intrinsic
2220    query intrinsic_raw(def_id: DefId) -> Option<rustc_middle::ty::IntrinsicDef> {
2221        desc { |tcx| "fetch intrinsic name if `{}` is an intrinsic", tcx.def_path_str(def_id) }
2222        separate_provide_extern
2223    }
2224    /// Returns the lang items defined in another crate by loading it from metadata.
2225    query get_lang_items(_: ()) -> &'tcx LanguageItems {
2226        arena_cache
2227        eval_always
2228        desc { "calculating the lang items map" }
2229    }
2230
2231    /// Returns all diagnostic items defined in all crates.
2232    query all_diagnostic_items(_: ()) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
2233        arena_cache
2234        eval_always
2235        desc { "calculating the diagnostic items map" }
2236    }
2237
2238    /// Returns the lang items defined in another crate by loading it from metadata.
2239    query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
2240        desc { "calculating the lang items defined in a crate" }
2241        separate_provide_extern
2242    }
2243
2244    /// Returns the diagnostic items defined in a crate.
2245    query diagnostic_items(_: CrateNum) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
2246        arena_cache
2247        desc { "calculating the diagnostic items map in a crate" }
2248        separate_provide_extern
2249    }
2250
2251    query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
2252        desc { "calculating the missing lang items in a crate" }
2253        separate_provide_extern
2254    }
2255
2256    /// The visible parent map is a map from every item to a visible parent.
2257    /// It prefers the shortest visible path to an item.
2258    /// Used for diagnostics, for example path trimming.
2259    /// The parents are modules, enums or traits.
2260    query visible_parent_map(_: ()) -> &'tcx DefIdMap<DefId> {
2261        arena_cache
2262        desc { "calculating the visible parent map" }
2263    }
2264    /// Collects the "trimmed", shortest accessible paths to all items for diagnostics.
2265    /// See the [provider docs](`rustc_middle::ty::print::trimmed_def_paths`) for more info.
2266    query trimmed_def_paths(_: ()) -> &'tcx DefIdMap<Symbol> {
2267        arena_cache
2268        desc { "calculating trimmed def paths" }
2269    }
2270    query missing_extern_crate_item(_: CrateNum) -> bool {
2271        eval_always
2272        desc { "seeing if we're missing an `extern crate` item for this crate" }
2273        separate_provide_extern
2274    }
2275    query used_crate_source(_: CrateNum) -> &'tcx Arc<CrateSource> {
2276        arena_cache
2277        eval_always
2278        desc { "looking at the source for a crate" }
2279        separate_provide_extern
2280    }
2281
2282    /// Returns the debugger visualizers defined for this crate.
2283    /// NOTE: This query has to be marked `eval_always` because it reads data
2284    ///       directly from disk that is not tracked anywhere else. I.e. it
2285    ///       represents a genuine input to the query system.
2286    query debugger_visualizers(_: CrateNum) -> &'tcx Vec<DebuggerVisualizerFile> {
2287        arena_cache
2288        desc { "looking up the debugger visualizers for this crate" }
2289        separate_provide_extern
2290        eval_always
2291    }
2292
2293    query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
2294        eval_always
2295        desc { "generating a postorder list of CrateNums" }
2296    }
2297    /// Returns whether or not the crate with CrateNum 'cnum'
2298    /// is marked as a private dependency
2299    query is_private_dep(c: CrateNum) -> bool {
2300        eval_always
2301        desc { "checking whether crate `{}` is a private dependency", c }
2302        separate_provide_extern
2303    }
2304    query allocator_kind(_: ()) -> Option<AllocatorKind> {
2305        eval_always
2306        desc { "getting the allocator kind for the current crate" }
2307    }
2308    query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
2309        eval_always
2310        desc { "alloc error handler kind for the current crate" }
2311    }
2312
2313    query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
2314        desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
2315    }
2316
2317    /// All available crates in the graph, including those that should not be user-facing
2318    /// (such as private crates).
2319    query crates(_: ()) -> &'tcx [CrateNum] {
2320        eval_always
2321        desc { "fetching all foreign CrateNum instances" }
2322    }
2323    // Crates that are loaded non-speculatively (not for diagnostics or doc links).
2324    // FIXME: This is currently only used for collecting lang items, but should be used instead of
2325    // `crates` in most other cases too.
2326    query used_crates(_: ()) -> &'tcx [CrateNum] {
2327        eval_always
2328        desc { "fetching `CrateNum`s for all crates loaded non-speculatively" }
2329    }
2330
2331    /// A list of all traits in a crate, used by rustdoc and error reporting.
2332    query traits(_: CrateNum) -> &'tcx [DefId] {
2333        desc { "fetching all traits in a crate" }
2334        separate_provide_extern
2335    }
2336
2337    query trait_impls_in_crate(_: CrateNum) -> &'tcx [DefId] {
2338        desc { "fetching all trait impls in a crate" }
2339        separate_provide_extern
2340    }
2341
2342    query stable_order_of_exportable_impls(_: CrateNum) -> &'tcx FxIndexMap<DefId, usize> {
2343        desc { "fetching the stable impl's order" }
2344        separate_provide_extern
2345    }
2346
2347    query exportable_items(_: CrateNum) -> &'tcx [DefId] {
2348        desc { "fetching all exportable items in a crate" }
2349        separate_provide_extern
2350    }
2351
2352    /// The list of non-generic symbols exported from the given crate.
2353    ///
2354    /// This is separate from exported_generic_symbols to avoid having
2355    /// to deserialize all non-generic symbols too for upstream crates
2356    /// in the upstream_monomorphizations query.
2357    ///
2358    /// - All names contained in `exported_non_generic_symbols(cnum)` are
2359    ///   guaranteed to correspond to a publicly visible symbol in `cnum`
2360    ///   machine code.
2361    /// - The `exported_non_generic_symbols` and `exported_generic_symbols`
2362    ///   sets of different crates do not intersect.
2363    query exported_non_generic_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
2364        desc { "collecting exported non-generic symbols for crate `{}`", cnum}
2365        cache_on_disk_if { *cnum == LOCAL_CRATE }
2366        separate_provide_extern
2367    }
2368
2369    /// The list of generic symbols exported from the given crate.
2370    ///
2371    /// - All names contained in `exported_generic_symbols(cnum)` are
2372    ///   guaranteed to correspond to a publicly visible symbol in `cnum`
2373    ///   machine code.
2374    /// - The `exported_non_generic_symbols` and `exported_generic_symbols`
2375    ///   sets of different crates do not intersect.
2376    query exported_generic_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
2377        desc { "collecting exported generic symbols for crate `{}`", cnum}
2378        cache_on_disk_if { *cnum == LOCAL_CRATE }
2379        separate_provide_extern
2380    }
2381
2382    query collect_and_partition_mono_items(_: ()) -> MonoItemPartitions<'tcx> {
2383        eval_always
2384        desc { "collect_and_partition_mono_items" }
2385    }
2386
2387    query is_codegened_item(def_id: DefId) -> bool {
2388        desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
2389    }
2390
2391    query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
2392        desc { "getting codegen unit `{sym}`" }
2393    }
2394
2395    query backend_optimization_level(_: ()) -> OptLevel {
2396        desc { "optimization level used by backend" }
2397    }
2398
2399    /// Return the filenames where output artefacts shall be stored.
2400    ///
2401    /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
2402    /// has been destroyed.
2403    query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
2404        feedable
2405        desc { "getting output filenames" }
2406        arena_cache
2407    }
2408
2409    /// <div class="warning">
2410    ///
2411    /// Do not call this query directly: Invoke `normalize` instead.
2412    ///
2413    /// </div>
2414    query normalize_canonicalized_projection_ty(
2415        goal: CanonicalAliasGoal<'tcx>
2416    ) -> Result<
2417        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2418        NoSolution,
2419    > {
2420        desc { "normalizing `{}`", goal.canonical.value.value }
2421    }
2422
2423    /// <div class="warning">
2424    ///
2425    /// Do not call this query directly: Invoke `normalize` instead.
2426    ///
2427    /// </div>
2428    query normalize_canonicalized_free_alias(
2429        goal: CanonicalAliasGoal<'tcx>
2430    ) -> Result<
2431        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2432        NoSolution,
2433    > {
2434        desc { "normalizing `{}`", goal.canonical.value.value }
2435    }
2436
2437    /// <div class="warning">
2438    ///
2439    /// Do not call this query directly: Invoke `normalize` instead.
2440    ///
2441    /// </div>
2442    query normalize_canonicalized_inherent_projection_ty(
2443        goal: CanonicalAliasGoal<'tcx>
2444    ) -> Result<
2445        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2446        NoSolution,
2447    > {
2448        desc { "normalizing `{}`", goal.canonical.value.value }
2449    }
2450
2451    /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
2452    query try_normalize_generic_arg_after_erasing_regions(
2453        goal: PseudoCanonicalInput<'tcx, GenericArg<'tcx>>
2454    ) -> Result<GenericArg<'tcx>, NoSolution> {
2455        desc { "normalizing `{}`", goal.value }
2456    }
2457
2458    query implied_outlives_bounds(
2459        key: (CanonicalImpliedOutlivesBoundsGoal<'tcx>, bool)
2460    ) -> Result<
2461        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
2462        NoSolution,
2463    > {
2464        desc { "computing implied outlives bounds for `{}` (hack disabled = {:?})", key.0.canonical.value.value.ty, key.1 }
2465    }
2466
2467    /// Do not call this query directly:
2468    /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
2469    query dropck_outlives(
2470        goal: CanonicalDropckOutlivesGoal<'tcx>
2471    ) -> Result<
2472        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
2473        NoSolution,
2474    > {
2475        desc { "computing dropck types for `{}`", goal.canonical.value.value.dropped_ty }
2476    }
2477
2478    /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
2479    /// `infcx.predicate_must_hold()` instead.
2480    query evaluate_obligation(
2481        goal: CanonicalPredicateGoal<'tcx>
2482    ) -> Result<EvaluationResult, OverflowError> {
2483        desc { "evaluating trait selection obligation `{}`", goal.canonical.value.value }
2484    }
2485
2486    /// Do not call this query directly: part of the `Eq` type-op
2487    query type_op_ascribe_user_type(
2488        goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
2489    ) -> Result<
2490        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
2491        NoSolution,
2492    > {
2493        desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.canonical.value.value }
2494    }
2495
2496    /// Do not call this query directly: part of the `ProvePredicate` type-op
2497    query type_op_prove_predicate(
2498        goal: CanonicalTypeOpProvePredicateGoal<'tcx>
2499    ) -> Result<
2500        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
2501        NoSolution,
2502    > {
2503        desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.canonical.value.value }
2504    }
2505
2506    /// Do not call this query directly: part of the `Normalize` type-op
2507    query type_op_normalize_ty(
2508        goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
2509    ) -> Result<
2510        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
2511        NoSolution,
2512    > {
2513        desc { "normalizing `{}`", goal.canonical.value.value.value }
2514    }
2515
2516    /// Do not call this query directly: part of the `Normalize` type-op
2517    query type_op_normalize_clause(
2518        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Clause<'tcx>>
2519    ) -> Result<
2520        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Clause<'tcx>>>,
2521        NoSolution,
2522    > {
2523        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2524    }
2525
2526    /// Do not call this query directly: part of the `Normalize` type-op
2527    query type_op_normalize_poly_fn_sig(
2528        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
2529    ) -> Result<
2530        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
2531        NoSolution,
2532    > {
2533        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2534    }
2535
2536    /// Do not call this query directly: part of the `Normalize` type-op
2537    query type_op_normalize_fn_sig(
2538        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2539    ) -> Result<
2540        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2541        NoSolution,
2542    > {
2543        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2544    }
2545
2546    query instantiate_and_check_impossible_predicates(key: (DefId, GenericArgsRef<'tcx>)) -> bool {
2547        desc { |tcx|
2548            "checking impossible instantiated predicates: `{}`",
2549            tcx.def_path_str(key.0)
2550        }
2551    }
2552
2553    query is_impossible_associated_item(key: (DefId, DefId)) -> bool {
2554        desc { |tcx|
2555            "checking if `{}` is impossible to reference within `{}`",
2556            tcx.def_path_str(key.1),
2557            tcx.def_path_str(key.0),
2558        }
2559    }
2560
2561    query method_autoderef_steps(
2562        goal: CanonicalTyGoal<'tcx>
2563    ) -> MethodAutoderefStepsResult<'tcx> {
2564        desc { "computing autoderef types for `{}`", goal.canonical.value.value }
2565    }
2566
2567    /// Used by `-Znext-solver` to compute proof trees.
2568    query evaluate_root_goal_for_proof_tree_raw(
2569        goal: solve::CanonicalInput<'tcx>,
2570    ) -> (solve::QueryResult<'tcx>, &'tcx solve::inspect::Probe<TyCtxt<'tcx>>) {
2571        no_hash
2572        desc { "computing proof tree for `{}`", goal.canonical.value.goal.predicate }
2573    }
2574
2575    /// Returns the Rust target features for the current target. These are not always the same as LLVM target features!
2576    query rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
2577        arena_cache
2578        eval_always
2579        desc { "looking up Rust target features" }
2580    }
2581
2582    query implied_target_features(feature: Symbol) -> &'tcx Vec<Symbol> {
2583        arena_cache
2584        eval_always
2585        desc { "looking up implied target features" }
2586    }
2587
2588    query features_query(_: ()) -> &'tcx rustc_feature::Features {
2589        feedable
2590        desc { "looking up enabled feature gates" }
2591    }
2592
2593    query crate_for_resolver((): ()) -> &'tcx Steal<(rustc_ast::Crate, rustc_ast::AttrVec)> {
2594        feedable
2595        no_hash
2596        desc { "the ast before macro expansion and name resolution" }
2597    }
2598
2599    /// Attempt to resolve the given `DefId` to an `Instance`, for the
2600    /// given generics args (`GenericArgsRef`), returning one of:
2601    ///  * `Ok(Some(instance))` on success
2602    ///  * `Ok(None)` when the `GenericArgsRef` are still too generic,
2603    ///    and therefore don't allow finding the final `Instance`
2604    ///  * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2605    ///    couldn't complete due to errors elsewhere - this is distinct
2606    ///    from `Ok(None)` to avoid misleading diagnostics when an error
2607    ///    has already been/will be emitted, for the original cause.
2608    query resolve_instance_raw(
2609        key: ty::PseudoCanonicalInput<'tcx, (DefId, GenericArgsRef<'tcx>)>
2610    ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2611        desc { "resolving instance `{}`", ty::Instance::new_raw(key.value.0, key.value.1) }
2612    }
2613
2614    query reveal_opaque_types_in_bounds(key: ty::Clauses<'tcx>) -> ty::Clauses<'tcx> {
2615        desc { "revealing opaque types in `{:?}`", key }
2616    }
2617
2618    query limits(key: ()) -> Limits {
2619        desc { "looking up limits" }
2620    }
2621
2622    /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2623    /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2624    /// the cause of the newly created obligation.
2625    ///
2626    /// This is only used by error-reporting code to get a better cause (in particular, a better
2627    /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2628    /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2629    /// because the `ty::Ty`-based wfcheck is always run.
2630    query diagnostic_hir_wf_check(
2631        key: (ty::Predicate<'tcx>, WellFormedLoc)
2632    ) -> Option<&'tcx ObligationCause<'tcx>> {
2633        arena_cache
2634        eval_always
2635        no_hash
2636        desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2637    }
2638
2639    /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2640    /// `--target` and similar).
2641    query global_backend_features(_: ()) -> &'tcx Vec<String> {
2642        arena_cache
2643        eval_always
2644        desc { "computing the backend features for CLI flags" }
2645    }
2646
2647    query check_validity_requirement(key: (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>)) -> Result<bool, &'tcx ty::layout::LayoutError<'tcx>> {
2648        desc { "checking validity requirement for `{}`: {}", key.1.value, key.0 }
2649    }
2650
2651    /// This takes the def-id of an associated item from a impl of a trait,
2652    /// and checks its validity against the trait item it corresponds to.
2653    ///
2654    /// Any other def id will ICE.
2655    query compare_impl_item(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
2656        desc { |tcx| "checking assoc item `{}` is compatible with trait definition", tcx.def_path_str(key) }
2657        return_result_from_ensure_ok
2658    }
2659
2660    query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2661        desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2662        separate_provide_extern
2663    }
2664
2665    query doc_link_resolutions(def_id: DefId) -> &'tcx DocLinkResMap {
2666        eval_always
2667        desc { "resolutions for documentation links for a module" }
2668        separate_provide_extern
2669    }
2670
2671    query doc_link_traits_in_scope(def_id: DefId) -> &'tcx [DefId] {
2672        eval_always
2673        desc { "traits in scope for documentation links for a module" }
2674        separate_provide_extern
2675    }
2676
2677    /// Get all item paths that were stripped by a `#[cfg]` in a particular crate.
2678    /// Should not be called for the local crate before the resolver outputs are created, as it
2679    /// is only fed there.
2680    query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
2681        desc { "getting cfg-ed out item names" }
2682        separate_provide_extern
2683    }
2684
2685    query generics_require_sized_self(def_id: DefId) -> bool {
2686        desc { "check whether the item has a `where Self: Sized` bound" }
2687    }
2688
2689    query cross_crate_inlinable(def_id: DefId) -> bool {
2690        desc { "whether the item should be made inlinable across crates" }
2691        separate_provide_extern
2692    }
2693
2694    /// Perform monomorphization-time checking on this item.
2695    /// This is used for lints/errors that can only be checked once the instance is fully
2696    /// monomorphized.
2697    query check_mono_item(key: ty::Instance<'tcx>) {
2698        desc { "monomorphization-time checking" }
2699    }
2700
2701    /// Builds the set of functions that should be skipped for the move-size check.
2702    query skip_move_check_fns(_: ()) -> &'tcx FxIndexSet<DefId> {
2703        arena_cache
2704        desc { "functions to skip for move-size check" }
2705    }
2706
2707    query items_of_instance(key: (ty::Instance<'tcx>, CollectionMode)) -> (&'tcx [Spanned<MonoItem<'tcx>>], &'tcx [Spanned<MonoItem<'tcx>>]) {
2708        desc { "collecting items used by `{}`", key.0 }
2709        cache_on_disk_if { true }
2710    }
2711
2712    query size_estimate(key: ty::Instance<'tcx>) -> usize {
2713        desc { "estimating codegen size of `{}`", key }
2714        cache_on_disk_if { true }
2715    }
2716
2717    query anon_const_kind(def_id: DefId) -> ty::AnonConstKind {
2718        desc { |tcx| "looking up anon const kind of `{}`", tcx.def_path_str(def_id) }
2719        separate_provide_extern
2720    }
2721
2722    /// Checks for the nearest `#[sanitize(xyz = "off")]` or
2723    /// `#[sanitize(xyz = "on")]` on this def and any enclosing defs, up to the
2724    /// crate root.
2725    ///
2726    /// Returns the set of sanitizers that is explicitly disabled for this def.
2727    query disabled_sanitizers_for(key: LocalDefId) -> SanitizerSet {
2728        desc { |tcx| "checking what set of sanitizers are enabled on `{}`", tcx.def_path_str(key) }
2729        feedable
2730    }
2731}
2732
2733rustc_with_all_queries! { define_callbacks! }
2734rustc_feedable_queries! { define_feedable! }
2735
2736fn describe_as_module(def_id: impl Into<LocalDefId>, tcx: TyCtxt<'_>) -> String {
2737    let def_id = def_id.into();
2738    if def_id.is_top_level_module() {
2739        "top-level module".to_string()
2740    } else {
2741        format!("module `{}`", tcx.def_path_str(def_id))
2742    }
2743}