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