1 //! Defines the various compiler queries.
3 //! For more information on the query system, see
4 //! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html).
5 //! This chapter includes instructions for adding new queries.
7 use crate::ty::{self, print::describe_as_module, TyCtxt};
8 use rustc_span::def_id::LOCAL_CRATE;
13 // Each of these queries corresponds to a function pointer field in the
14 // `Providers` struct for requesting a value of that type, and a method
15 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
16 // which memoizes and does dep-graph tracking, wrapping around the actual
17 // `Providers` that the driver creates (using several `rustc_*` crates).
19 // The result type of each query must implement `Clone`, and additionally
20 // `ty::query::values::Value`, which produces an appropriate placeholder
21 // (error) value if the query resulted in a query cycle.
22 // Queries marked with `fatal_cycle` do not need the latter implementation,
23 // as they will raise an fatal error on query cycles instead.
25 query trigger_delay_span_bug(key: DefId) -> () {
26 desc { "triggering a delay span bug" }
29 query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
32 desc { "getting the resolver outputs" }
35 query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
38 desc { "getting the resolver for lowering" }
41 /// Return the span for a definition.
42 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
43 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
44 /// of rustc_middle::hir::source_map.
45 query source_span(key: LocalDefId) -> Span {
46 // Accesses untracked data
48 desc { "getting the source span" }
51 /// Represents crate as a whole (as distinct from the top-level crate module).
52 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
53 /// we will have to assume that any change means that you need to be recompiled.
54 /// This is because the `hir_crate` query gives you access to all other items.
55 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
56 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
57 query hir_crate(key: ()) -> Crate<'tcx> {
60 desc { "getting the crate HIR" }
63 /// All items in the crate.
64 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
67 desc { "getting HIR crate items" }
70 /// The items in a module.
72 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
73 /// Avoid calling this query directly.
74 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
76 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
77 cache_on_disk_if { true }
80 /// Gives access to the HIR node for the HIR owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
85 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
88 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
90 /// This can be conveniently accessed by methods on `tcx.hir()`.
91 /// Avoid calling this query directly.
92 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
93 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Gives access to the HIR node's parent for the HIR owner `key`.
98 /// This can be conveniently accessed by methods on `tcx.hir()`.
99 /// Avoid calling this query directly.
100 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
101 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
104 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
106 /// This can be conveniently accessed by methods on `tcx.hir()`.
107 /// Avoid calling this query directly.
108 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
109 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Gives access to the HIR attributes inside the HIR owner `key`.
114 /// This can be conveniently accessed by methods on `tcx.hir()`.
115 /// Avoid calling this query directly.
116 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
117 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
120 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
121 /// const argument and returns `None` otherwise.
123 /// ```ignore (incomplete)
124 /// let a = foo::<7>();
125 /// // ^ Calling `opt_const_param_of` for this argument,
127 /// fn foo<const N: usize>()
128 /// // ^ returns this `DefId`.
131 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
134 // It looks like caching this query on disk actually slightly
135 // worsened performance in #74376.
137 // Once const generics are more prevalently used, we might want to
138 // consider only caching calls returning `Some`.
139 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
140 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
143 /// Given the def_id of a const-generic parameter, computes the associated default const
144 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
145 query const_param_default(param: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
146 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
147 cache_on_disk_if { param.is_local() }
148 separate_provide_extern
151 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
152 /// to an alias, it will "skip" this alias to return the aliased type.
154 /// [`DefId`]: rustc_hir::def_id::DefId
155 query type_of(key: DefId) -> Ty<'tcx> {
159 use rustc_hir::def::DefKind;
160 match tcx.def_kind(key) {
161 DefKind::TyAlias => "expanding type alias",
162 DefKind::TraitAlias => "expanding trait alias",
163 _ => "computing type of",
166 path = tcx.def_path_str(key),
168 cache_on_disk_if { key.is_local() }
169 separate_provide_extern
172 query collect_return_position_impl_trait_in_trait_tys(key: DefId)
173 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
175 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
176 cache_on_disk_if { key.is_local() }
177 separate_provide_extern
180 query is_type_alias_impl_trait(key: DefId) -> bool
182 desc { "determine whether the opaque is a type-alias impl trait" }
183 separate_provide_extern
186 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
188 desc { "running analysis passes on this crate" }
191 /// This query checks the fulfillment of collected lint expectations.
192 /// All lint emitting queries have to be done before this is executed
193 /// to ensure that all expectations can be fulfilled.
195 /// This is an extra query to enable other drivers (like rustdoc) to
196 /// only execute a small subset of the `analysis` query, while allowing
197 /// lints to be expected. In rustc, this query will be executed as part of
198 /// the `analysis` query and doesn't have to be called a second time.
200 /// Tools can additionally pass in a tool filter. That will restrict the
201 /// expectations to only trigger for lints starting with the listed tool
202 /// name. This is useful for cases were not all linting code from rustc
203 /// was called. With the default `None` all registered lints will also
204 /// be checked for expectation fulfillment.
205 query check_expectations(key: Option<Symbol>) -> () {
207 desc { "checking lint expectations (RFC 2383)" }
210 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
211 /// associated generics.
212 query generics_of(key: DefId) -> ty::Generics {
213 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
215 cache_on_disk_if { key.is_local() }
216 separate_provide_extern
219 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
220 /// predicates (where-clauses) that must be proven true in order
221 /// to reference it. This is almost always the "predicates query"
224 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
225 /// it is almost always the same as that query, except for the
226 /// case of traits. For traits, `predicates_of` contains
227 /// an additional `Self: Trait<...>` predicate that users don't
228 /// actually write. This reflects the fact that to invoke the
229 /// trait (e.g., via `Default::default`) you must supply types
230 /// that actually implement the trait. (However, this extra
231 /// predicate gets in the way of some checks, which are intended
232 /// to operate over only the actual where-clauses written by the
234 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
235 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
236 cache_on_disk_if { key.is_local() }
239 /// Returns the list of bounds that can be used for
240 /// `SelectionCandidate::ProjectionCandidate(_)` and
241 /// `ProjectionTyCandidate::TraitDef`.
242 /// Specifically this is the bounds written on the trait's type
243 /// definition, or those after the `impl` keyword
245 /// ```ignore (incomplete)
246 /// type X: Bound + 'lt
248 /// impl Debug + Display
249 /// // ^^^^^^^^^^^^^^^
252 /// `key` is the `DefId` of the associated type or opaque type.
254 /// Bounds from the parent (e.g. with nested impl trait) are not included.
255 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
256 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
257 cache_on_disk_if { key.is_local() }
258 separate_provide_extern
261 /// Elaborated version of the predicates from `explicit_item_bounds`.
267 /// type MyAType: Eq + ?Sized;
271 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
272 /// and `item_bounds` returns
275 /// <Self as Trait>::MyAType: Eq,
276 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
280 /// Bounds from the parent (e.g. with nested impl trait) are not included.
281 query item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
282 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
285 /// Look up all native libraries this crate depends on.
286 /// These are assembled from the following places:
287 /// - `extern` blocks (depending on their `link` attributes)
288 /// - the `libs` (`-l`) option
289 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
291 desc { "looking up the native libraries of a linked crate" }
292 separate_provide_extern
295 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
296 eval_always // fetches `resolutions`
298 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
301 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
303 desc { "computing `#[expect]`ed lints in this crate" }
306 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
308 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
311 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
312 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
313 separate_provide_extern
316 query is_panic_runtime(_: CrateNum) -> bool {
318 desc { "checking if the crate is_panic_runtime" }
319 separate_provide_extern
322 /// Checks whether a type is representable or infinitely sized
323 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
324 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
325 // infinitely sized types will cause a cycle
327 // we don't want recursive representability calls to be forced with
328 // incremental compilation because, if a cycle occurs, we need the
329 // entire cycle to be in memory for diagnostics
333 /// An implementation detail for the `representability` query
334 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
335 desc { "checking if `{}` is representable", key }
340 /// Set of param indexes for type params that are in the type's representation
341 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
342 desc { "finding type parameters in the representation" }
345 separate_provide_extern
348 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
349 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
350 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
352 // Perf tests revealed that hashing THIR is inefficient (see #85729).
354 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
357 /// Create a THIR tree for debugging.
358 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
361 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
364 /// Set of all the `DefId`s in this crate that have MIR associated with
365 /// them. This includes all the body owners, but also things like struct
367 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
369 desc { "getting a list of all mir_keys" }
372 /// Maps DefId's that have an associated `mir::Body` to the result
373 /// of the MIR const-checking pass. This is the set of qualifs in
374 /// the final value of a `const`.
375 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
376 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
377 cache_on_disk_if { key.is_local() }
378 separate_provide_extern
380 query mir_const_qualif_const_arg(
381 key: (LocalDefId, DefId)
382 ) -> mir::ConstQualifs {
384 |tcx| "const checking the const argument `{}`",
385 tcx.def_path_str(key.0.to_def_id())
389 /// Fetch the MIR for a given `DefId` right after it's built - this includes
390 /// unreachable code.
391 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
392 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
395 /// Fetch the MIR for a given `DefId` up till the point where it is
396 /// ready for const qualification.
398 /// See the README for the `mir` module for details.
399 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
401 |tcx| "preparing {}`{}` for borrow checking",
402 if key.const_param_did.is_some() { "the const argument " } else { "" },
403 tcx.def_path_str(key.did.to_def_id()),
408 /// Try to build an abstract representation of the given constant.
409 query thir_abstract_const(
411 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
413 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
415 separate_provide_extern
417 /// Try to build an abstract representation of the given constant.
418 query thir_abstract_const_of_const_arg(
419 key: (LocalDefId, DefId)
420 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
423 "building an abstract representation for the const argument `{}`",
424 tcx.def_path_str(key.0.to_def_id()),
428 query mir_drops_elaborated_and_const_checked(
429 key: ty::WithOptConstParam<LocalDefId>
430 ) -> &'tcx Steal<mir::Body<'tcx>> {
432 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
437 ) -> &'tcx mir::Body<'tcx> {
438 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
439 cache_on_disk_if { key.is_local() }
440 separate_provide_extern
443 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
445 |tcx| "caching MIR for CTFE of the const argument `{}`",
446 tcx.def_path_str(key.0.to_def_id())
450 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
452 &'tcx Steal<mir::Body<'tcx>>,
453 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
457 |tcx| "processing MIR for {}`{}`",
458 if key.const_param_did.is_some() { "the const argument " } else { "" },
459 tcx.def_path_str(key.did.to_def_id()),
463 query symbols_for_closure_captures(
464 key: (LocalDefId, LocalDefId)
465 ) -> Vec<rustc_span::Symbol> {
468 |tcx| "finding symbols for captures of closure `{}` in `{}`",
469 tcx.def_path_str(key.1.to_def_id()),
470 tcx.def_path_str(key.0.to_def_id())
474 query mir_generator_witnesses(key: DefId) -> mir::GeneratorLayout<'tcx> {
476 desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
477 cache_on_disk_if { key.is_local() }
478 separate_provide_extern
481 query check_generator_obligations(key: LocalDefId) {
482 desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key.to_def_id()) }
485 /// MIR after our optimization passes have run. This is MIR that is ready
486 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
487 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
488 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
489 cache_on_disk_if { key.is_local() }
490 separate_provide_extern
493 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
494 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
495 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
496 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
500 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
501 /// function was optimized out before codegen, and before being added to the Coverage Map.
502 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
504 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
505 tcx.def_path_str(key)
508 cache_on_disk_if { key.is_local() }
511 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
512 /// `DefId`. This function returns all promoteds in the specified body. The body references
513 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
514 /// after inlining a body may refer to promoteds from other bodies. In that case you still
515 /// need to use the `DefId` of the original body.
516 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
517 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
518 cache_on_disk_if { key.is_local() }
519 separate_provide_extern
521 query promoted_mir_of_const_arg(
522 key: (LocalDefId, DefId)
523 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
525 |tcx| "optimizing promoted MIR for the const argument `{}`",
526 tcx.def_path_str(key.0.to_def_id()),
530 /// Erases regions from `ty` to yield a new type.
531 /// Normally you would just use `tcx.erase_regions(value)`,
532 /// however, which uses this query as a kind of cache.
533 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
534 // This query is not expected to have input -- as a result, it
535 // is not a good candidates for "replay" because it is essentially a
536 // pure function of its input (and hence the expectation is that
537 // no caller would be green **apart** from just these
538 // queries). Making it anonymous avoids hashing the result, which
539 // may save a bit of time.
541 desc { "erasing regions from `{}`", ty }
544 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
546 desc { "getting wasm import module map" }
549 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
550 /// predicates (where-clauses) directly defined on it. This is
551 /// equal to the `explicit_predicates_of` predicates plus the
552 /// `inferred_outlives_of` predicates.
553 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
554 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
557 /// Returns everything that looks like a predicate written explicitly
558 /// by the user on a trait item.
560 /// Traits are unusual, because predicates on associated types are
561 /// converted into bounds on that type for backwards compatibility:
563 /// trait X where Self::U: Copy { type U; }
567 /// trait X { type U: Copy; }
569 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
570 /// the appropriate subsets of the predicates here.
571 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
572 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
575 /// Returns the predicates written explicitly by the user.
576 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
577 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
578 cache_on_disk_if { key.is_local() }
579 separate_provide_extern
582 /// Returns the inferred outlives predicates (e.g., for `struct
583 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
584 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
585 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
586 cache_on_disk_if { key.is_local() }
587 separate_provide_extern
590 /// Maps from the `DefId` of a trait to the list of
591 /// super-predicates. This is a subset of the full list of
592 /// predicates. We store these in a separate map because we must
593 /// evaluate them even during type conversion, often before the
594 /// full predicates are available (note that supertraits have
595 /// additional acyclicity requirements).
596 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
597 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
598 cache_on_disk_if { key.is_local() }
599 separate_provide_extern
602 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
603 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
604 /// subset of super-predicates that reference traits that define the given associated type.
605 /// This is used to avoid cycles in resolving types like `T::Item`.
606 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
607 desc { |tcx| "computing the super traits of `{}`{}",
608 tcx.def_path_str(key.0),
609 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
613 /// To avoid cycles within the predicates of a single item we compute
614 /// per-type-parameter predicates for resolving `T::AssocTy`.
615 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
616 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
619 query trait_def(key: DefId) -> ty::TraitDef {
620 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
622 cache_on_disk_if { key.is_local() }
623 separate_provide_extern
625 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
626 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
627 cache_on_disk_if { key.is_local() }
628 separate_provide_extern
630 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
631 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
632 cache_on_disk_if { key.is_local() }
633 separate_provide_extern
636 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
637 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
640 query adt_dtorck_constraint(
642 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
643 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
646 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
647 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
648 /// not have the feature gate active).
650 /// **Do not call this function manually.** It is only meant to cache the base data for the
651 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
652 query constness(key: DefId) -> hir::Constness {
653 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
654 cache_on_disk_if { key.is_local() }
655 separate_provide_extern
658 query asyncness(key: DefId) -> hir::IsAsync {
659 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
660 cache_on_disk_if { key.is_local() }
661 separate_provide_extern
664 /// Returns `true` if calls to the function may be promoted.
666 /// This is either because the function is e.g., a tuple-struct or tuple-variant
667 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
668 /// be removed in the future in favour of some form of check which figures out whether the
669 /// function does not inspect the bits of any of its arguments (so is essentially just a
670 /// constructor function).
671 query is_promotable_const_fn(key: DefId) -> bool {
672 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
675 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
676 query is_foreign_item(key: DefId) -> bool {
677 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
678 cache_on_disk_if { key.is_local() }
679 separate_provide_extern
682 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
683 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
684 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
685 cache_on_disk_if { def_id.is_local() }
686 separate_provide_extern
689 /// Gets a map with the variance of every item; use `item_variance` instead.
690 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
692 desc { "computing the variances for items in this crate" }
695 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
696 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
697 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
698 cache_on_disk_if { def_id.is_local() }
699 separate_provide_extern
702 /// Maps from thee `DefId` of a type to its (inferred) outlives.
703 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
705 desc { "computing the inferred outlives predicates for items in this crate" }
708 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
709 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
710 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
711 cache_on_disk_if { key.is_local() }
712 separate_provide_extern
715 /// Maps from a trait item to the trait item "descriptor".
716 query associated_item(key: DefId) -> ty::AssocItem {
717 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
719 cache_on_disk_if { key.is_local() }
720 separate_provide_extern
723 /// Collects the associated items defined on a trait or impl.
724 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
726 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
729 /// Maps from associated items on a trait to the corresponding associated
730 /// item on the impl specified by `impl_id`.
732 /// For example, with the following code
737 /// trait Trait { // trait_id
738 /// fn f(); // trait_f
739 /// fn g() {} // trait_g
742 /// impl Trait for Type { // impl_id
743 /// fn f() {} // impl_f
744 /// fn g() {} // impl_g
748 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
749 ///`{ trait_f: impl_f, trait_g: impl_g }`
750 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
752 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
755 /// Given an `impl_id`, return the trait it implements.
756 /// Return `None` if this is an inherent impl.
757 query impl_trait_ref(impl_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
758 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
759 cache_on_disk_if { impl_id.is_local() }
760 separate_provide_extern
762 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
763 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
764 cache_on_disk_if { impl_id.is_local() }
765 separate_provide_extern
768 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
769 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
772 /// Maps a `DefId` of a type to a list of its inherent impls.
773 /// Contains implementations of methods that are inherent to a type.
774 /// Methods in these implementations don't need to be exported.
775 query inherent_impls(key: DefId) -> &'tcx [DefId] {
776 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
777 cache_on_disk_if { key.is_local() }
778 separate_provide_extern
781 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
782 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
785 /// The result of unsafety-checking this `LocalDefId`.
786 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
787 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
788 cache_on_disk_if { true }
790 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
792 |tcx| "unsafety-checking the const argument `{}`",
793 tcx.def_path_str(key.0.to_def_id())
797 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
798 /// used with `-Zthir-unsafeck`.
799 query thir_check_unsafety(key: LocalDefId) {
800 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
801 cache_on_disk_if { true }
803 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
805 |tcx| "unsafety-checking the const argument `{}`",
806 tcx.def_path_str(key.0.to_def_id())
810 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
812 /// Unsafety checking is executed for each method separately, but we only want
813 /// to emit this error once per derive. As there are some impls with multiple
814 /// methods, we use a query for deduplication.
815 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
816 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
819 /// Returns the types assumed to be well formed while "inside" of the given item.
821 /// Note that we've liberated the late bound regions of function signatures, so
822 /// this can not be used to check whether these types are well formed.
823 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
824 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
827 /// Computes the signature of the function.
828 query fn_sig(key: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'tcx>> {
829 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
830 cache_on_disk_if { key.is_local() }
831 separate_provide_extern
835 /// Performs lint checking for the module.
836 query lint_mod(key: LocalDefId) -> () {
837 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
840 /// Checks the attributes in the module.
841 query check_mod_attrs(key: LocalDefId) -> () {
842 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
845 /// Checks for uses of unstable APIs in the module.
846 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
847 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
850 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
851 query check_mod_const_bodies(key: LocalDefId) -> () {
852 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
855 /// Checks the loops in the module.
856 query check_mod_loops(key: LocalDefId) -> () {
857 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
860 query check_mod_naked_functions(key: LocalDefId) -> () {
861 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
864 query check_mod_item_types(key: LocalDefId) -> () {
865 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
868 query check_mod_privacy(key: LocalDefId) -> () {
869 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
872 query check_liveness(key: DefId) {
873 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
876 /// Return the live symbols in the crate for dead code check.
878 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
879 /// their respective impl (i.e., part of the derive macro)
880 query live_symbols_and_ignored_derived_traits(_: ()) -> (
881 FxHashSet<LocalDefId>,
882 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
885 desc { "finding live symbols in crate" }
888 query check_mod_deathness(key: LocalDefId) -> () {
889 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
892 query check_mod_impl_wf(key: LocalDefId) -> () {
893 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
896 query check_mod_type_wf(key: LocalDefId) -> () {
897 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
900 query collect_mod_item_types(key: LocalDefId) -> () {
901 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
904 /// Caches `CoerceUnsized` kinds for impls on custom types.
905 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
906 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
907 cache_on_disk_if { key.is_local() }
908 separate_provide_extern
911 query typeck_item_bodies(_: ()) -> () {
912 desc { "type-checking all item bodies" }
915 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
916 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
917 cache_on_disk_if { true }
919 query typeck_const_arg(
920 key: (LocalDefId, DefId)
921 ) -> &'tcx ty::TypeckResults<'tcx> {
923 |tcx| "type-checking the const argument `{}`",
924 tcx.def_path_str(key.0.to_def_id()),
927 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
928 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
929 cache_on_disk_if { true }
932 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
933 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
934 cache_on_disk_if { true }
937 query has_typeck_results(def_id: DefId) -> bool {
938 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
941 query coherent_trait(def_id: DefId) -> () {
942 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
945 /// Borrow-checks the function body. If this is a closure, returns
946 /// additional requirements that the closure's creator must verify.
947 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
948 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
949 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
951 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
953 |tcx| "borrow-checking the const argument`{}`",
954 tcx.def_path_str(key.0.to_def_id())
958 /// Gets a complete map from all types to their inherent impls.
959 /// Not meant to be used directly outside of coherence.
960 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
962 desc { "finding all inherent impls defined in crate" }
965 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
966 /// Not meant to be used directly outside of coherence.
967 query crate_inherent_impls_overlap_check(_: ()) -> () {
968 desc { "check for overlap between inherent impls defined in this crate" }
971 /// Checks whether all impls in the crate pass the overlap check, returning
972 /// which impls fail it. If all impls are correct, the returned slice is empty.
973 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
975 "checking whether impl `{}` follows the orphan rules",
976 tcx.def_path_str(key.to_def_id()),
980 /// Check whether the function has any recursion that could cause the inliner to trigger
981 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
982 /// current function, just all intermediate functions.
983 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
986 "computing if `{}` (transitively) calls `{}`",
988 tcx.def_path_str(key.1.to_def_id()),
992 /// Obtain all the calls into other local functions
993 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
996 "computing all local function calls in `{}`",
997 tcx.def_path_str(key.def_id()),
1001 /// Evaluates a constant and returns the computed allocation.
1003 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
1004 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1005 -> EvalToAllocationRawResult<'tcx> {
1007 "const-evaluating + checking `{}`",
1008 key.value.display(tcx)
1010 cache_on_disk_if { true }
1013 /// Evaluates const items or anonymous constants
1014 /// (such as enum variant explicit discriminants or array lengths)
1015 /// into a representation suitable for the type system and const generics.
1017 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1018 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1019 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1020 -> EvalToConstValueResult<'tcx> {
1022 "simplifying constant for the type system `{}`",
1023 key.value.display(tcx)
1025 cache_on_disk_if { true }
1028 /// Evaluate a constant and convert it to a type level constant or
1029 /// return `None` if that is not possible.
1030 query eval_to_valtree(
1031 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1032 ) -> EvalToValTreeResult<'tcx> {
1033 desc { "evaluating type-level constant" }
1036 /// Converts a type level constant value into `ConstValue`
1037 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1038 desc { "converting type-level constant value to mir constant value"}
1041 /// Destructures array, ADT or tuple constants into the constants
1042 /// of their fields.
1043 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1044 desc { "destructuring type level constant"}
1047 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1048 /// and its field values.
1049 query try_destructure_mir_constant(
1050 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1051 ) -> Option<mir::DestructuredConstant<'tcx>> {
1052 desc { "destructuring MIR constant"}
1056 /// Dereference a constant reference or raw pointer and turn the result into a constant
1058 query deref_mir_constant(
1059 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1060 ) -> mir::ConstantKind<'tcx> {
1061 desc { "dereferencing MIR constant" }
1065 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1066 desc { "getting a &core::panic::Location referring to a span" }
1069 // FIXME get rid of this with valtrees
1071 key: LitToConstInput<'tcx>
1072 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1073 desc { "converting literal to const" }
1076 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1077 desc { "converting literal to mir constant" }
1080 query check_match(key: DefId) {
1081 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1082 cache_on_disk_if { key.is_local() }
1085 /// Performs part of the privacy check and computes effective visibilities.
1086 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1088 desc { "checking effective visibilities" }
1090 query check_private_in_public(_: ()) -> () {
1092 desc { "checking for private elements in public interfaces" }
1095 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1097 desc { "reachability" }
1100 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1101 /// in the case of closures, this will be redirected to the enclosing function.
1102 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1103 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1106 /// Generates a MIR body for the shim.
1107 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1109 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1112 /// The `symbol_name` query provides the symbol name for calling a
1113 /// given instance from the local crate. In particular, it will also
1114 /// look up the correct symbol name of instances from upstream crates.
1115 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1116 desc { "computing the symbol for `{}`", key }
1117 cache_on_disk_if { true }
1120 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1121 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1122 cache_on_disk_if { def_id.is_local() }
1123 separate_provide_extern
1126 /// Gets the span for the definition.
1127 query def_span(def_id: DefId) -> Span {
1128 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1129 cache_on_disk_if { def_id.is_local() }
1130 separate_provide_extern
1134 /// Gets the span for the identifier of the definition.
1135 query def_ident_span(def_id: DefId) -> Option<Span> {
1136 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1137 cache_on_disk_if { def_id.is_local() }
1138 separate_provide_extern
1141 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1142 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1143 cache_on_disk_if { def_id.is_local() }
1144 separate_provide_extern
1147 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1148 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1149 cache_on_disk_if { def_id.is_local() }
1150 separate_provide_extern
1153 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1154 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1155 separate_provide_extern
1158 query should_inherit_track_caller(def_id: DefId) -> bool {
1159 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1162 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1163 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1164 cache_on_disk_if { def_id.is_local() }
1165 separate_provide_extern
1168 /// Determines whether an item is annotated with `doc(hidden)`.
1169 query is_doc_hidden(def_id: DefId) -> bool {
1170 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1171 separate_provide_extern
1174 /// Determines whether an item is annotated with `doc(notable_trait)`.
1175 query is_doc_notable_trait(def_id: DefId) -> bool {
1176 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1179 /// Returns the attributes on the item at `def_id`.
1181 /// Do not use this directly, use `tcx.get_attrs` instead.
1182 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1183 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1184 separate_provide_extern
1187 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1188 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1190 cache_on_disk_if { def_id.is_local() }
1191 separate_provide_extern
1194 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1195 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1198 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1199 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1200 cache_on_disk_if { def_id.is_local() }
1201 separate_provide_extern
1203 /// Gets the rendered value of the specified constant or associated constant.
1204 /// Used by rustdoc.
1205 query rendered_const(def_id: DefId) -> String {
1207 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1208 cache_on_disk_if { def_id.is_local() }
1209 separate_provide_extern
1211 query impl_parent(def_id: DefId) -> Option<DefId> {
1212 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1213 cache_on_disk_if { def_id.is_local() }
1214 separate_provide_extern
1217 query is_ctfe_mir_available(key: DefId) -> bool {
1218 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1219 cache_on_disk_if { key.is_local() }
1220 separate_provide_extern
1222 query is_mir_available(key: DefId) -> bool {
1223 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1224 cache_on_disk_if { key.is_local() }
1225 separate_provide_extern
1228 query own_existential_vtable_entries(
1230 ) -> &'tcx [DefId] {
1231 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1234 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1235 -> &'tcx [ty::VtblEntry<'tcx>] {
1236 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1239 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1240 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1244 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1245 desc { |tcx| "vtable const allocation for <{} as {}>",
1247 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1251 query codegen_select_candidate(
1252 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1253 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1254 cache_on_disk_if { true }
1255 desc { |tcx| "computing candidate for `{}`", key.1 }
1258 /// Return all `impl` blocks in the current crate.
1259 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1260 desc { "finding local trait impls" }
1263 /// Given a trait `trait_id`, return all known `impl` blocks.
1264 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1266 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1269 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1271 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1272 cache_on_disk_if { true }
1274 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1275 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1278 /// Gets the ParameterEnvironment for a given item; this environment
1279 /// will be in "user-facing" mode, meaning that it is suitable for
1280 /// type-checking etc, and it does not normalize specializable
1281 /// associated types. This is almost always what you want,
1282 /// unless you are doing MIR optimizations, in which case you
1283 /// might want to use `reveal_all()` method to change modes.
1284 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1285 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1288 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1289 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1290 /// as this method is more efficient.
1291 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1292 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1295 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1296 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1297 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1298 desc { "computing whether `{}` is `Copy`", env.value }
1301 /// Query backing `Ty::is_sized`.
1302 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1303 desc { "computing whether `{}` is `Sized`", env.value }
1306 /// Query backing `Ty::is_freeze`.
1307 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1308 desc { "computing whether `{}` is freeze", env.value }
1311 /// Query backing `Ty::is_unpin`.
1312 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1313 desc { "computing whether `{}` is `Unpin`", env.value }
1316 /// Query backing `Ty::needs_drop`.
1317 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1318 desc { "computing whether `{}` needs drop", env.value }
1321 /// Query backing `Ty::has_significant_drop_raw`.
1322 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1323 desc { "computing whether `{}` has a significant drop", env.value }
1327 /// Query backing `Ty::is_structural_eq_shallow`.
1329 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1331 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1333 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1338 /// A list of types where the ADT requires drop if and only if any of
1339 /// those types require drop. If the ADT is known to always need drop
1340 /// then `Err(AlwaysRequiresDrop)` is returned.
1341 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1342 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1343 cache_on_disk_if { true }
1346 /// A list of types where the ADT requires drop if and only if any of those types
1347 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1348 /// is considered to not be significant. A drop is significant if it is implemented
1349 /// by the user or does anything that will have any observable behavior (other than
1350 /// freeing up memory). If the ADT is known to have a significant destructor then
1351 /// `Err(AlwaysRequiresDrop)` is returned.
1352 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1353 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1354 cache_on_disk_if { false }
1357 /// Computes the layout of a type. Note that this implicitly
1358 /// executes in "reveal all" mode, and will normalize the input type.
1360 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1361 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1363 desc { "computing layout of `{}`", key.value }
1367 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1369 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1370 /// instead, where the instance is an `InstanceDef::Virtual`.
1371 query fn_abi_of_fn_ptr(
1372 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1373 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1374 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1378 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1379 /// direct calls to an `fn`.
1381 /// NB: that includes virtual calls, which are represented by "direct calls"
1382 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1383 query fn_abi_of_instance(
1384 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1385 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1386 desc { "computing call ABI of `{}`", key.value.0 }
1390 query dylib_dependency_formats(_: CrateNum)
1391 -> &'tcx [(CrateNum, LinkagePreference)] {
1392 desc { "getting dylib dependency formats of crate" }
1393 separate_provide_extern
1396 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1398 desc { "getting the linkage format of all dependencies" }
1401 query is_compiler_builtins(_: CrateNum) -> bool {
1403 desc { "checking if the crate is_compiler_builtins" }
1404 separate_provide_extern
1406 query has_global_allocator(_: CrateNum) -> bool {
1407 // This query depends on untracked global state in CStore
1410 desc { "checking if the crate has_global_allocator" }
1411 separate_provide_extern
1413 query has_alloc_error_handler(_: CrateNum) -> bool {
1414 // This query depends on untracked global state in CStore
1417 desc { "checking if the crate has_alloc_error_handler" }
1418 separate_provide_extern
1420 query has_panic_handler(_: CrateNum) -> bool {
1422 desc { "checking if the crate has_panic_handler" }
1423 separate_provide_extern
1425 query is_profiler_runtime(_: CrateNum) -> bool {
1427 desc { "checking if a crate is `#![profiler_runtime]`" }
1428 separate_provide_extern
1430 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1431 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1432 cache_on_disk_if { true }
1434 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1436 desc { "getting a crate's required panic strategy" }
1437 separate_provide_extern
1439 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1441 desc { "getting a crate's configured panic-in-drop strategy" }
1442 separate_provide_extern
1444 query is_no_builtins(_: CrateNum) -> bool {
1446 desc { "getting whether a crate has `#![no_builtins]`" }
1447 separate_provide_extern
1449 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1451 desc { "getting a crate's symbol mangling version" }
1452 separate_provide_extern
1455 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1457 desc { "getting crate's ExternCrateData" }
1458 separate_provide_extern
1461 query specializes(_: (DefId, DefId)) -> bool {
1462 desc { "computing whether impls specialize one another" }
1464 query in_scope_traits_map(_: hir::OwnerId)
1465 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1466 desc { "getting traits in scope at a block" }
1469 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1470 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1473 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1474 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1475 cache_on_disk_if { def_id.is_local() }
1476 separate_provide_extern
1479 query check_well_formed(key: hir::OwnerId) -> () {
1480 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1483 // The `DefId`s of all non-generic functions and statics in the given crate
1484 // that can be reached from outside the crate.
1486 // We expect this items to be available for being linked to.
1488 // This query can also be called for `LOCAL_CRATE`. In this case it will
1489 // compute which items will be reachable to other crates, taking into account
1490 // the kind of crate that is currently compiled. Crates with only a
1491 // C interface have fewer reachable things.
1493 // Does not include external symbols that don't have a corresponding DefId,
1494 // like the compiler-generated `main` function and so on.
1495 query reachable_non_generics(_: CrateNum)
1496 -> DefIdMap<SymbolExportInfo> {
1498 desc { "looking up the exported symbols of a crate" }
1499 separate_provide_extern
1501 query is_reachable_non_generic(def_id: DefId) -> bool {
1502 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1503 cache_on_disk_if { def_id.is_local() }
1504 separate_provide_extern
1506 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1508 "checking whether `{}` is reachable from outside the crate",
1509 tcx.def_path_str(def_id.to_def_id()),
1513 /// The entire set of monomorphizations the local crate can safely link
1514 /// to because they are exported from upstream crates. Do not depend on
1515 /// this directly, as its value changes anytime a monomorphization gets
1516 /// added or removed in any upstream crate. Instead use the narrower
1517 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1518 /// better, `Instance::upstream_monomorphization()`.
1519 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1521 desc { "collecting available upstream monomorphizations" }
1524 /// Returns the set of upstream monomorphizations available for the
1525 /// generic function identified by the given `def_id`. The query makes
1526 /// sure to make a stable selection if the same monomorphization is
1527 /// available in multiple upstream crates.
1529 /// You likely want to call `Instance::upstream_monomorphization()`
1530 /// instead of invoking this query directly.
1531 query upstream_monomorphizations_for(def_id: DefId)
1532 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1536 "collecting available upstream monomorphizations for `{}`",
1537 tcx.def_path_str(def_id),
1539 separate_provide_extern
1542 /// Returns the upstream crate that exports drop-glue for the given
1543 /// type (`substs` is expected to be a single-item list containing the
1544 /// type one wants drop-glue for).
1546 /// This is a subset of `upstream_monomorphizations_for` in order to
1547 /// increase dep-tracking granularity. Otherwise adding or removing any
1548 /// type with drop-glue in any upstream crate would invalidate all
1549 /// functions calling drop-glue of an upstream type.
1551 /// You likely want to call `Instance::upstream_monomorphization()`
1552 /// instead of invoking this query directly.
1554 /// NOTE: This query could easily be extended to also support other
1555 /// common functions that have are large set of monomorphizations
1556 /// (like `Clone::clone` for example).
1557 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1558 desc { "available upstream drop-glue for `{:?}`", substs }
1561 /// Returns a list of all `extern` blocks of a crate.
1562 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1564 desc { "looking up the foreign modules of a linked crate" }
1565 separate_provide_extern
1568 /// Identifies the entry-point (e.g., the `main` function) for a given
1569 /// crate, returning `None` if there is no entry point (such as for library crates).
1570 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1571 desc { "looking up the entry function of a crate" }
1574 /// Finds the `rustc_proc_macro_decls` item of a crate.
1575 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1576 desc { "looking up the proc macro declarations for a crate" }
1579 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1580 // Changing the name should cause a compiler error, but in case that changes, be aware.
1581 query crate_hash(_: CrateNum) -> Svh {
1583 desc { "looking up the hash a crate" }
1584 separate_provide_extern
1587 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1588 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1590 desc { "looking up the hash of a host version of a crate" }
1591 separate_provide_extern
1594 /// Gets the extra data to put in each output filename for a crate.
1595 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1596 query extra_filename(_: CrateNum) -> String {
1599 desc { "looking up the extra filename for a crate" }
1600 separate_provide_extern
1603 /// Gets the paths where the crate came from in the file system.
1604 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1607 desc { "looking up the paths for extern crates" }
1608 separate_provide_extern
1611 /// Given a crate and a trait, look up all impls of that trait in the crate.
1612 /// Return `(impl_id, self_ty)`.
1613 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1614 desc { "looking up implementations of a trait in a crate" }
1615 separate_provide_extern
1618 /// Collects all incoherent impls for the given crate and type.
1620 /// Do not call this directly, but instead use the `incoherent_impls` query.
1621 /// This query is only used to get the data necessary for that query.
1622 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1623 desc { |tcx| "collecting all impls for a type in a crate" }
1624 separate_provide_extern
1627 /// Get the corresponding native library from the `native_libraries` query
1628 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1629 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1632 /// Does lifetime resolution on items. Importantly, we can't resolve
1633 /// lifetimes directly on things like trait methods, because of trait params.
1634 /// See `rustc_resolve::late::lifetimes for details.
1635 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1637 desc { "resolving lifetimes" }
1639 query named_region_map(_: hir::OwnerId) ->
1640 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1641 desc { "looking up a named region" }
1643 query is_late_bound_map(_: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
1644 desc { "testing if a region is late bound" }
1646 /// For a given item's generic parameter, gets the default lifetimes to be used
1647 /// for each parameter if a trait object were to be passed for that parameter.
1648 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1649 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1650 /// This query will panic if passed something that is not a type parameter.
1651 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1652 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1653 separate_provide_extern
1655 query late_bound_vars_map(_: hir::OwnerId)
1656 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1657 desc { "looking up late bound vars" }
1660 /// Computes the visibility of the provided `def_id`.
1662 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1663 /// a generic type parameter will panic if you call this method on it:
1666 /// use std::fmt::Debug;
1668 /// pub trait Foo<T: Debug> {}
1671 /// In here, if you call `visibility` on `T`, it'll panic.
1672 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1673 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1674 separate_provide_extern
1677 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1678 desc { "computing the uninhabited predicate of `{:?}`", key }
1681 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1682 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1683 desc { "computing the uninhabited predicate of `{}`", key }
1686 query dep_kind(_: CrateNum) -> CrateDepKind {
1688 desc { "fetching what a dependency looks like" }
1689 separate_provide_extern
1692 /// Gets the name of the crate.
1693 query crate_name(_: CrateNum) -> Symbol {
1695 desc { "fetching what a crate is named" }
1696 separate_provide_extern
1698 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1699 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1700 separate_provide_extern
1702 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1703 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1706 query lib_features(_: ()) -> LibFeatures {
1708 desc { "calculating the lib features map" }
1710 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1711 desc { "calculating the lib features defined in a crate" }
1712 separate_provide_extern
1714 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1716 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1717 separate_provide_extern
1719 /// Whether the function is an intrinsic
1720 query is_intrinsic(def_id: DefId) -> bool {
1721 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1722 separate_provide_extern
1724 /// Returns the lang items defined in another crate by loading it from metadata.
1725 query get_lang_items(_: ()) -> LanguageItems {
1728 desc { "calculating the lang items map" }
1731 /// Returns all diagnostic items defined in all crates.
1732 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1735 desc { "calculating the diagnostic items map" }
1738 /// Returns the lang items defined in another crate by loading it from metadata.
1739 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1740 desc { "calculating the lang items defined in a crate" }
1741 separate_provide_extern
1744 /// Returns the diagnostic items defined in a crate.
1745 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1747 desc { "calculating the diagnostic items map in a crate" }
1748 separate_provide_extern
1751 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1752 desc { "calculating the missing lang items in a crate" }
1753 separate_provide_extern
1755 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1757 desc { "calculating the visible parent map" }
1759 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1761 desc { "calculating trimmed def paths" }
1763 query missing_extern_crate_item(_: CrateNum) -> bool {
1765 desc { "seeing if we're missing an `extern crate` item for this crate" }
1766 separate_provide_extern
1768 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1771 desc { "looking at the source for a crate" }
1772 separate_provide_extern
1774 /// Returns the debugger visualizers defined for this crate.
1775 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1777 desc { "looking up the debugger visualizers for this crate" }
1778 separate_provide_extern
1780 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1782 desc { "generating a postorder list of CrateNums" }
1784 /// Returns whether or not the crate with CrateNum 'cnum'
1785 /// is marked as a private dependency
1786 query is_private_dep(c: CrateNum) -> bool {
1788 desc { "checking whether crate `{}` is a private dependency", c }
1789 separate_provide_extern
1791 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1793 desc { "getting the allocator kind for the current crate" }
1795 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1797 desc { "alloc error handler kind for the current crate" }
1800 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1801 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1803 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1804 desc { "fetching potentially unused trait imports" }
1806 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1807 desc { "looking up all possibly unused extern crates" }
1809 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1810 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1813 query stability_index(_: ()) -> stability::Index {
1816 desc { "calculating the stability index for the local crate" }
1818 query crates(_: ()) -> &'tcx [CrateNum] {
1820 desc { "fetching all foreign CrateNum instances" }
1823 /// A list of all traits in a crate, used by rustdoc and error reporting.
1824 /// NOTE: Not named just `traits` due to a naming conflict.
1825 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1826 desc { "fetching all traits in a crate" }
1827 separate_provide_extern
1830 /// The list of symbols exported from the given crate.
1832 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1833 /// correspond to a publicly visible symbol in `cnum` machine code.
1834 /// - The `exported_symbols` sets of different crates do not intersect.
1835 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1836 desc { "collecting exported symbols for crate `{}`", cnum}
1837 cache_on_disk_if { *cnum == LOCAL_CRATE }
1838 separate_provide_extern
1841 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1843 desc { "collect_and_partition_mono_items" }
1846 query is_codegened_item(def_id: DefId) -> bool {
1847 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1850 /// All items participating in code generation together with items inlined into them.
1851 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1853 desc { "collecting codegened and inlined items" }
1856 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1857 desc { "getting codegen unit `{sym}`" }
1860 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> UnusedGenericParams {
1861 cache_on_disk_if { key.def_id().is_local() }
1863 |tcx| "determining which generic parameters are unused by `{}`",
1864 tcx.def_path_str(key.def_id())
1866 separate_provide_extern
1869 query backend_optimization_level(_: ()) -> OptLevel {
1870 desc { "optimization level used by backend" }
1873 /// Return the filenames where output artefacts shall be stored.
1875 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1876 /// has been destroyed.
1877 query output_filenames(_: ()) -> Arc<OutputFilenames> {
1879 desc { "getting output filenames" }
1883 /// Do not call this query directly: invoke `normalize` instead.
1884 query normalize_projection_ty(
1885 goal: CanonicalProjectionGoal<'tcx>
1887 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1890 desc { "normalizing `{}`", goal.value.value }
1894 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1895 query try_normalize_generic_arg_after_erasing_regions(
1896 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1897 ) -> Result<GenericArg<'tcx>, NoSolution> {
1898 desc { "normalizing `{}`", goal.value }
1902 query implied_outlives_bounds(
1903 goal: CanonicalTyGoal<'tcx>
1905 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1908 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1912 /// Do not call this query directly:
1913 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1914 query dropck_outlives(
1915 goal: CanonicalTyGoal<'tcx>
1917 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1920 desc { "computing dropck types for `{}`", goal.value.value }
1924 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1925 /// `infcx.predicate_must_hold()` instead.
1926 query evaluate_obligation(
1927 goal: CanonicalPredicateGoal<'tcx>
1928 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1929 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1932 query evaluate_goal(
1933 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1935 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1938 desc { "evaluating trait selection obligation `{}`", goal.value }
1941 /// Do not call this query directly: part of the `Eq` type-op
1942 query type_op_ascribe_user_type(
1943 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1945 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1948 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1952 /// Do not call this query directly: part of the `Eq` type-op
1954 goal: CanonicalTypeOpEqGoal<'tcx>
1956 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1959 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1963 /// Do not call this query directly: part of the `Subtype` type-op
1964 query type_op_subtype(
1965 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1967 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1970 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1974 /// Do not call this query directly: part of the `ProvePredicate` type-op
1975 query type_op_prove_predicate(
1976 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1978 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1981 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1984 /// Do not call this query directly: part of the `Normalize` type-op
1985 query type_op_normalize_ty(
1986 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1988 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1991 desc { "normalizing `{}`", goal.value.value.value }
1995 /// Do not call this query directly: part of the `Normalize` type-op
1996 query type_op_normalize_predicate(
1997 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1999 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
2002 desc { "normalizing `{:?}`", goal.value.value.value }
2006 /// Do not call this query directly: part of the `Normalize` type-op
2007 query type_op_normalize_poly_fn_sig(
2008 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
2010 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
2013 desc { "normalizing `{:?}`", goal.value.value.value }
2017 /// Do not call this query directly: part of the `Normalize` type-op
2018 query type_op_normalize_fn_sig(
2019 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2021 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2024 desc { "normalizing `{:?}`", goal.value.value.value }
2028 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2030 "checking impossible substituted predicates: `{}`",
2031 tcx.def_path_str(key.0)
2035 query is_impossible_method(key: (DefId, DefId)) -> bool {
2037 "checking if `{}` is impossible to call within `{}`",
2038 tcx.def_path_str(key.1),
2039 tcx.def_path_str(key.0),
2043 query method_autoderef_steps(
2044 goal: CanonicalTyGoal<'tcx>
2045 ) -> MethodAutoderefStepsResult<'tcx> {
2046 desc { "computing autoderef types for `{}`", goal.value.value }
2050 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2053 desc { "looking up supported target features" }
2056 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2057 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2059 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2062 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2064 desc { "looking up enabled feature gates" }
2067 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2068 /// given generics args (`SubstsRef`), returning one of:
2069 /// * `Ok(Some(instance))` on success
2070 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2071 /// and therefore don't allow finding the final `Instance`
2072 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2073 /// couldn't complete due to errors elsewhere - this is distinct
2074 /// from `Ok(None)` to avoid misleading diagnostics when an error
2075 /// has already been/will be emitted, for the original cause
2076 query resolve_instance(
2077 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2078 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2079 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2083 query resolve_instance_of_const_arg(
2084 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2085 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2087 "resolving instance of the const argument `{}`",
2088 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2093 query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2094 desc { "revealing opaque types in `{:?}`", key }
2097 query limits(key: ()) -> Limits {
2098 desc { "looking up limits" }
2101 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2102 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2103 /// the cause of the newly created obligation.
2105 /// This is only used by error-reporting code to get a better cause (in particular, a better
2106 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2107 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2108 /// because the `ty::Ty`-based wfcheck is always run.
2109 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2113 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2117 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2118 /// `--target` and similar).
2119 query global_backend_features(_: ()) -> Vec<String> {
2122 desc { "computing the backend features for CLI flags" }
2125 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2127 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2128 separate_provide_extern
2131 query permits_uninit_init(key: ty::ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool {
2132 desc { "checking to see if `{}` permits being left uninit", key.value.ty }
2135 query permits_zero_init(key: ty::ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool {
2136 desc { "checking to see if `{}` permits being left zeroed", key.value.ty }
2139 query compare_impl_const(
2140 key: (LocalDefId, DefId)
2141 ) -> Result<(), ErrorGuaranteed> {
2142 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2145 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2146 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2147 separate_provide_extern