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;
10 // Each of these queries corresponds to a function pointer field in the
11 // `Providers` struct for requesting a value of that type, and a method
12 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
13 // which memoizes and does dep-graph tracking, wrapping around the actual
14 // `Providers` that the driver creates (using several `rustc_*` crates).
16 // The result type of each query must implement `Clone`, and additionally
17 // `ty::query::values::Value`, which produces an appropriate placeholder
18 // (error) value if the query resulted in a query cycle.
19 // Queries marked with `fatal_cycle` do not need the latter implementation,
20 // as they will raise an fatal error on query cycles instead.
22 query trigger_delay_span_bug(key: DefId) -> () {
23 desc { "triggering a delay span bug" }
26 query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
29 desc { "getting the resolver outputs" }
32 query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
35 desc { "getting the resolver for lowering" }
38 /// Return the span for a definition.
39 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
40 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
41 /// of rustc_middle::hir::source_map.
42 query source_span(key: LocalDefId) -> Span {
43 desc { "getting the source span" }
46 /// Represents crate as a whole (as distinct from the top-level crate module).
47 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
48 /// we will have to assume that any change means that you need to be recompiled.
49 /// This is because the `hir_crate` query gives you access to all other items.
50 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
51 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
52 query hir_crate(key: ()) -> Crate<'tcx> {
55 desc { "getting the crate HIR" }
58 /// All items in the crate.
59 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
62 desc { "getting HIR crate items" }
65 /// The items in a module.
67 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
68 /// Avoid calling this query directly.
69 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
71 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
72 cache_on_disk_if { true }
75 /// Gives access to the HIR node for the HIR owner `key`.
77 /// This can be conveniently accessed by methods on `tcx.hir()`.
78 /// Avoid calling this query directly.
79 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
80 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
83 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
85 /// This can be conveniently accessed by methods on `tcx.hir()`.
86 /// Avoid calling this query directly.
87 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
88 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
91 /// Gives access to the HIR node's parent for the HIR owner `key`.
93 /// This can be conveniently accessed by methods on `tcx.hir()`.
94 /// Avoid calling this query directly.
95 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
96 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
99 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
101 /// This can be conveniently accessed by methods on `tcx.hir()`.
102 /// Avoid calling this query directly.
103 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
104 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
107 /// Gives access to the HIR attributes inside the HIR owner `key`.
109 /// This can be conveniently accessed by methods on `tcx.hir()`.
110 /// Avoid calling this query directly.
111 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
112 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
115 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
116 /// const argument and returns `None` otherwise.
118 /// ```ignore (incomplete)
119 /// let a = foo::<7>();
120 /// // ^ Calling `opt_const_param_of` for this argument,
122 /// fn foo<const N: usize>()
123 /// // ^ returns this `DefId`.
126 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
129 // It looks like caching this query on disk actually slightly
130 // worsened performance in #74376.
132 // Once const generics are more prevalently used, we might want to
133 // consider only caching calls returning `Some`.
134 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
135 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
138 /// Given the def_id of a const-generic parameter, computes the associated default const
139 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
140 query const_param_default(param: DefId) -> ty::Const<'tcx> {
141 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
142 cache_on_disk_if { param.is_local() }
143 separate_provide_extern
146 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
147 /// to an alias, it will "skip" this alias to return the aliased type.
149 /// [`DefId`]: rustc_hir::def_id::DefId
150 query type_of(key: DefId) -> Ty<'tcx> {
154 use rustc_hir::def::DefKind;
155 match tcx.def_kind(key) {
156 DefKind::TyAlias => "expanding type alias",
157 DefKind::TraitAlias => "expanding trait alias",
158 _ => "computing type of",
161 path = tcx.def_path_str(key),
163 cache_on_disk_if { key.is_local() }
164 separate_provide_extern
167 query collect_trait_impl_trait_tys(key: DefId)
168 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
170 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
171 cache_on_disk_if { key.is_local() }
172 separate_provide_extern
175 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
177 desc { "running analysis passes on this crate" }
180 /// This query checks the fulfillment of collected lint expectations.
181 /// All lint emitting queries have to be done before this is executed
182 /// to ensure that all expectations can be fulfilled.
184 /// This is an extra query to enable other drivers (like rustdoc) to
185 /// only execute a small subset of the `analysis` query, while allowing
186 /// lints to be expected. In rustc, this query will be executed as part of
187 /// the `analysis` query and doesn't have to be called a second time.
189 /// Tools can additionally pass in a tool filter. That will restrict the
190 /// expectations to only trigger for lints starting with the listed tool
191 /// name. This is useful for cases were not all linting code from rustc
192 /// was called. With the default `None` all registered lints will also
193 /// be checked for expectation fulfillment.
194 query check_expectations(key: Option<Symbol>) -> () {
196 desc { "checking lint expectations (RFC 2383)" }
199 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
200 /// associated generics.
201 query generics_of(key: DefId) -> ty::Generics {
202 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
204 cache_on_disk_if { key.is_local() }
205 separate_provide_extern
208 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
209 /// predicates (where-clauses) that must be proven true in order
210 /// to reference it. This is almost always the "predicates query"
213 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
214 /// it is almost always the same as that query, except for the
215 /// case of traits. For traits, `predicates_of` contains
216 /// an additional `Self: Trait<...>` predicate that users don't
217 /// actually write. This reflects the fact that to invoke the
218 /// trait (e.g., via `Default::default`) you must supply types
219 /// that actually implement the trait. (However, this extra
220 /// predicate gets in the way of some checks, which are intended
221 /// to operate over only the actual where-clauses written by the
223 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
224 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
225 cache_on_disk_if { key.is_local() }
228 /// Returns the list of bounds that can be used for
229 /// `SelectionCandidate::ProjectionCandidate(_)` and
230 /// `ProjectionTyCandidate::TraitDef`.
231 /// Specifically this is the bounds written on the trait's type
232 /// definition, or those after the `impl` keyword
234 /// ```ignore (incomplete)
235 /// type X: Bound + 'lt
237 /// impl Debug + Display
238 /// // ^^^^^^^^^^^^^^^
241 /// `key` is the `DefId` of the associated type or opaque type.
243 /// Bounds from the parent (e.g. with nested impl trait) are not included.
244 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
245 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
246 cache_on_disk_if { key.is_local() }
247 separate_provide_extern
250 /// Elaborated version of the predicates from `explicit_item_bounds`.
256 /// type MyAType: Eq + ?Sized;
260 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
261 /// and `item_bounds` returns
264 /// <Self as Trait>::MyAType: Eq,
265 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
269 /// Bounds from the parent (e.g. with nested impl trait) are not included.
270 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
271 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
274 /// Look up all native libraries this crate depends on.
275 /// These are assembled from the following places:
276 /// - `extern` blocks (depending on their `link` attributes)
277 /// - the `libs` (`-l`) option
278 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
280 desc { "looking up the native libraries of a linked crate" }
281 separate_provide_extern
284 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
285 eval_always // fetches `resolutions`
287 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
290 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
292 desc { "computing `#[expect]`ed lints in this crate" }
295 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
297 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
300 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
301 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
302 separate_provide_extern
305 query is_panic_runtime(_: CrateNum) -> bool {
307 desc { "checking if the crate is_panic_runtime" }
308 separate_provide_extern
311 /// Checks whether a type is representable or infinitely sized
312 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
313 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
314 // infinitely sized types will cause a cycle
316 // we don't want recursive representability calls to be forced with
317 // incremental compilation because, if a cycle occurs, we need the
318 // entire cycle to be in memory for diagnostics
322 /// An implementation detail for the `representability` query
323 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
324 desc { "checking if `{}` is representable", key }
329 /// Set of param indexes for type params that are in the type's representation
330 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
331 desc { "finding type parameters in the representation" }
334 separate_provide_extern
337 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
338 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
339 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
341 // Perf tests revealed that hashing THIR is inefficient (see #85729).
343 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
346 /// Create a THIR tree for debugging.
347 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
350 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
353 /// Set of all the `DefId`s in this crate that have MIR associated with
354 /// them. This includes all the body owners, but also things like struct
356 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
358 desc { "getting a list of all mir_keys" }
361 /// Maps DefId's that have an associated `mir::Body` to the result
362 /// of the MIR const-checking pass. This is the set of qualifs in
363 /// the final value of a `const`.
364 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
365 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
366 cache_on_disk_if { key.is_local() }
367 separate_provide_extern
369 query mir_const_qualif_const_arg(
370 key: (LocalDefId, DefId)
371 ) -> mir::ConstQualifs {
373 |tcx| "const checking the const argument `{}`",
374 tcx.def_path_str(key.0.to_def_id())
378 /// Fetch the MIR for a given `DefId` right after it's built - this includes
379 /// unreachable code.
380 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
381 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
384 /// Fetch the MIR for a given `DefId` up till the point where it is
385 /// ready for const qualification.
387 /// See the README for the `mir` module for details.
388 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
390 |tcx| "preparing {}`{}` for borrow checking",
391 if key.const_param_did.is_some() { "the const argument " } else { "" },
392 tcx.def_path_str(key.did.to_def_id()),
397 /// Try to build an abstract representation of the given constant.
398 query thir_abstract_const(
400 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
402 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
404 separate_provide_extern
406 /// Try to build an abstract representation of the given constant.
407 query thir_abstract_const_of_const_arg(
408 key: (LocalDefId, DefId)
409 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
412 "building an abstract representation for the const argument `{}`",
413 tcx.def_path_str(key.0.to_def_id()),
417 query try_unify_abstract_consts(key:
418 ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
421 |tcx| "trying to unify the generic constants `{}` and `{}`",
422 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
426 query mir_drops_elaborated_and_const_checked(
427 key: ty::WithOptConstParam<LocalDefId>
428 ) -> &'tcx Steal<mir::Body<'tcx>> {
430 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
435 ) -> &'tcx mir::Body<'tcx> {
436 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
437 cache_on_disk_if { key.is_local() }
438 separate_provide_extern
441 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
443 |tcx| "caching MIR for CTFE of the const argument `{}`",
444 tcx.def_path_str(key.0.to_def_id())
448 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
450 &'tcx Steal<mir::Body<'tcx>>,
451 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
455 |tcx| "processing MIR for {}`{}`",
456 if key.const_param_did.is_some() { "the const argument " } else { "" },
457 tcx.def_path_str(key.did.to_def_id()),
461 query symbols_for_closure_captures(
462 key: (LocalDefId, LocalDefId)
463 ) -> Vec<rustc_span::Symbol> {
466 |tcx| "finding symbols for captures of closure `{}` in `{}`",
467 tcx.def_path_str(key.1.to_def_id()),
468 tcx.def_path_str(key.0.to_def_id())
472 /// MIR after our optimization passes have run. This is MIR that is ready
473 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
474 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
475 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
476 cache_on_disk_if { key.is_local() }
477 separate_provide_extern
480 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
481 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
482 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
483 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
487 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
488 /// function was optimized out before codegen, and before being added to the Coverage Map.
489 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
491 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
492 tcx.def_path_str(key)
495 cache_on_disk_if { key.is_local() }
498 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
499 /// `DefId`. This function returns all promoteds in the specified body. The body references
500 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
501 /// after inlining a body may refer to promoteds from other bodies. In that case you still
502 /// need to use the `DefId` of the original body.
503 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
504 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
505 cache_on_disk_if { key.is_local() }
506 separate_provide_extern
508 query promoted_mir_of_const_arg(
509 key: (LocalDefId, DefId)
510 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
512 |tcx| "optimizing promoted MIR for the const argument `{}`",
513 tcx.def_path_str(key.0.to_def_id()),
517 /// Erases regions from `ty` to yield a new type.
518 /// Normally you would just use `tcx.erase_regions(value)`,
519 /// however, which uses this query as a kind of cache.
520 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
521 // This query is not expected to have input -- as a result, it
522 // is not a good candidates for "replay" because it is essentially a
523 // pure function of its input (and hence the expectation is that
524 // no caller would be green **apart** from just these
525 // queries). Making it anonymous avoids hashing the result, which
526 // may save a bit of time.
528 desc { "erasing regions from `{}`", ty }
531 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
533 desc { "getting wasm import module map" }
536 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
537 /// predicates (where-clauses) directly defined on it. This is
538 /// equal to the `explicit_predicates_of` predicates plus the
539 /// `inferred_outlives_of` predicates.
540 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
541 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
544 /// Returns everything that looks like a predicate written explicitly
545 /// by the user on a trait item.
547 /// Traits are unusual, because predicates on associated types are
548 /// converted into bounds on that type for backwards compatibility:
550 /// trait X where Self::U: Copy { type U; }
554 /// trait X { type U: Copy; }
556 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
557 /// the appropriate subsets of the predicates here.
558 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
559 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
562 /// Returns the predicates written explicitly by the user.
563 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
564 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
565 cache_on_disk_if { key.is_local() }
566 separate_provide_extern
569 /// Returns the inferred outlives predicates (e.g., for `struct
570 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
571 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
572 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
573 cache_on_disk_if { key.is_local() }
574 separate_provide_extern
577 /// Maps from the `DefId` of a trait to the list of
578 /// super-predicates. This is a subset of the full list of
579 /// predicates. We store these in a separate map because we must
580 /// evaluate them even during type conversion, often before the
581 /// full predicates are available (note that supertraits have
582 /// additional acyclicity requirements).
583 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
584 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
585 cache_on_disk_if { key.is_local() }
586 separate_provide_extern
589 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
590 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
591 /// subset of super-predicates that reference traits that define the given associated type.
592 /// This is used to avoid cycles in resolving types like `T::Item`.
593 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
594 desc { |tcx| "computing the super traits of `{}`{}",
595 tcx.def_path_str(key.0),
596 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
600 /// To avoid cycles within the predicates of a single item we compute
601 /// per-type-parameter predicates for resolving `T::AssocTy`.
602 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
603 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
606 query trait_def(key: DefId) -> ty::TraitDef {
607 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
609 cache_on_disk_if { key.is_local() }
610 separate_provide_extern
612 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
613 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
614 cache_on_disk_if { key.is_local() }
615 separate_provide_extern
617 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
618 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
619 cache_on_disk_if { key.is_local() }
620 separate_provide_extern
623 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
624 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
627 query adt_dtorck_constraint(
629 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
630 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
633 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
634 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
635 /// not have the feature gate active).
637 /// **Do not call this function manually.** It is only meant to cache the base data for the
638 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
639 query constness(key: DefId) -> hir::Constness {
640 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
641 cache_on_disk_if { key.is_local() }
642 separate_provide_extern
645 query asyncness(key: DefId) -> hir::IsAsync {
646 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
647 cache_on_disk_if { key.is_local() }
648 separate_provide_extern
651 /// Returns `true` if calls to the function may be promoted.
653 /// This is either because the function is e.g., a tuple-struct or tuple-variant
654 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
655 /// be removed in the future in favour of some form of check which figures out whether the
656 /// function does not inspect the bits of any of its arguments (so is essentially just a
657 /// constructor function).
658 query is_promotable_const_fn(key: DefId) -> bool {
659 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
662 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
663 query is_foreign_item(key: DefId) -> bool {
664 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
665 cache_on_disk_if { key.is_local() }
666 separate_provide_extern
669 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
670 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
671 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
672 cache_on_disk_if { def_id.is_local() }
673 separate_provide_extern
676 /// Gets a map with the variance of every item; use `item_variance` instead.
677 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
679 desc { "computing the variances for items in this crate" }
682 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
683 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
684 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
685 cache_on_disk_if { def_id.is_local() }
686 separate_provide_extern
689 /// Maps from thee `DefId` of a type to its (inferred) outlives.
690 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
692 desc { "computing the inferred outlives predicates for items in this crate" }
695 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
696 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
697 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
698 cache_on_disk_if { key.is_local() }
699 separate_provide_extern
702 /// Maps from a trait item to the trait item "descriptor".
703 query associated_item(key: DefId) -> ty::AssocItem {
704 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
706 cache_on_disk_if { key.is_local() }
707 separate_provide_extern
710 /// Collects the associated items defined on a trait or impl.
711 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
713 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
716 /// Maps from associated items on a trait to the corresponding associated
717 /// item on the impl specified by `impl_id`.
719 /// For example, with the following code
724 /// trait Trait { // trait_id
725 /// fn f(); // trait_f
726 /// fn g() {} // trait_g
729 /// impl Trait for Type { // impl_id
730 /// fn f() {} // impl_f
731 /// fn g() {} // impl_g
735 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
736 ///`{ trait_f: impl_f, trait_g: impl_g }`
737 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
739 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
742 /// Given an `impl_id`, return the trait it implements.
743 /// Return `None` if this is an inherent impl.
744 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
745 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
746 cache_on_disk_if { impl_id.is_local() }
747 separate_provide_extern
749 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
750 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
751 cache_on_disk_if { impl_id.is_local() }
752 separate_provide_extern
755 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
756 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
759 /// Maps a `DefId` of a type to a list of its inherent impls.
760 /// Contains implementations of methods that are inherent to a type.
761 /// Methods in these implementations don't need to be exported.
762 query inherent_impls(key: DefId) -> &'tcx [DefId] {
763 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
764 cache_on_disk_if { key.is_local() }
765 separate_provide_extern
768 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
769 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
772 /// The result of unsafety-checking this `LocalDefId`.
773 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
774 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
775 cache_on_disk_if { true }
777 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
779 |tcx| "unsafety-checking the const argument `{}`",
780 tcx.def_path_str(key.0.to_def_id())
784 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
785 /// used with `-Zthir-unsafeck`.
786 query thir_check_unsafety(key: LocalDefId) {
787 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
788 cache_on_disk_if { true }
790 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
792 |tcx| "unsafety-checking the const argument `{}`",
793 tcx.def_path_str(key.0.to_def_id())
797 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
799 /// Unsafety checking is executed for each method separately, but we only want
800 /// to emit this error once per derive. As there are some impls with multiple
801 /// methods, we use a query for deduplication.
802 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
803 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
806 /// Returns the types assumed to be well formed while "inside" of the given item.
808 /// Note that we've liberated the late bound regions of function signatures, so
809 /// this can not be used to check whether these types are well formed.
810 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
811 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
814 /// Computes the signature of the function.
815 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
816 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
817 cache_on_disk_if { key.is_local() }
818 separate_provide_extern
822 /// Performs lint checking for the module.
823 query lint_mod(key: LocalDefId) -> () {
824 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
827 /// Checks the attributes in the module.
828 query check_mod_attrs(key: LocalDefId) -> () {
829 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
832 /// Checks for uses of unstable APIs in the module.
833 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
834 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
837 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
838 query check_mod_const_bodies(key: LocalDefId) -> () {
839 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
842 /// Checks the loops in the module.
843 query check_mod_loops(key: LocalDefId) -> () {
844 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
847 query check_mod_naked_functions(key: LocalDefId) -> () {
848 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
851 query check_mod_item_types(key: LocalDefId) -> () {
852 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
855 query check_mod_privacy(key: LocalDefId) -> () {
856 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
859 query check_liveness(key: DefId) {
860 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
863 /// Return the live symbols in the crate for dead code check.
865 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
866 /// their respective impl (i.e., part of the derive macro)
867 query live_symbols_and_ignored_derived_traits(_: ()) -> (
868 FxHashSet<LocalDefId>,
869 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
872 desc { "finding live symbols in crate" }
875 query check_mod_deathness(key: LocalDefId) -> () {
876 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
879 query check_mod_impl_wf(key: LocalDefId) -> () {
880 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
883 query check_mod_type_wf(key: LocalDefId) -> () {
884 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
887 query collect_mod_item_types(key: LocalDefId) -> () {
888 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
891 /// Caches `CoerceUnsized` kinds for impls on custom types.
892 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
893 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
894 cache_on_disk_if { key.is_local() }
895 separate_provide_extern
898 query typeck_item_bodies(_: ()) -> () {
899 desc { "type-checking all item bodies" }
902 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
903 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
904 cache_on_disk_if { true }
906 query typeck_const_arg(
907 key: (LocalDefId, DefId)
908 ) -> &'tcx ty::TypeckResults<'tcx> {
910 |tcx| "type-checking the const argument `{}`",
911 tcx.def_path_str(key.0.to_def_id()),
914 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
915 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
916 cache_on_disk_if { true }
919 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
920 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
921 cache_on_disk_if { true }
924 query has_typeck_results(def_id: DefId) -> bool {
925 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
928 query coherent_trait(def_id: DefId) -> () {
929 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
932 /// Borrow-checks the function body. If this is a closure, returns
933 /// additional requirements that the closure's creator must verify.
934 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
935 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
936 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
938 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
940 |tcx| "borrow-checking the const argument`{}`",
941 tcx.def_path_str(key.0.to_def_id())
945 /// Gets a complete map from all types to their inherent impls.
946 /// Not meant to be used directly outside of coherence.
947 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
949 desc { "finding all inherent impls defined in crate" }
952 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
953 /// Not meant to be used directly outside of coherence.
954 query crate_inherent_impls_overlap_check(_: ()) -> () {
955 desc { "check for overlap between inherent impls defined in this crate" }
958 /// Checks whether all impls in the crate pass the overlap check, returning
959 /// which impls fail it. If all impls are correct, the returned slice is empty.
960 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
962 "checking whether impl `{}` follows the orphan rules",
963 tcx.def_path_str(key.to_def_id()),
967 /// Check whether the function has any recursion that could cause the inliner to trigger
968 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
969 /// current function, just all intermediate functions.
970 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
973 "computing if `{}` (transitively) calls `{}`",
975 tcx.def_path_str(key.1.to_def_id()),
979 /// Obtain all the calls into other local functions
980 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
983 "computing all local function calls in `{}`",
984 tcx.def_path_str(key.def_id()),
988 /// Evaluates a constant and returns the computed allocation.
990 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
991 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
992 -> EvalToAllocationRawResult<'tcx> {
994 "const-evaluating + checking `{}`",
995 key.value.display(tcx)
997 cache_on_disk_if { true }
1000 /// Evaluates const items or anonymous constants
1001 /// (such as enum variant explicit discriminants or array lengths)
1002 /// into a representation suitable for the type system and const generics.
1004 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1005 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1006 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1007 -> EvalToConstValueResult<'tcx> {
1009 "simplifying constant for the type system `{}`",
1010 key.value.display(tcx)
1012 cache_on_disk_if { true }
1015 /// Evaluate a constant and convert it to a type level constant or
1016 /// return `None` if that is not possible.
1017 query eval_to_valtree(
1018 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1019 ) -> EvalToValTreeResult<'tcx> {
1020 desc { "evaluating type-level constant" }
1023 /// Converts a type level constant value into `ConstValue`
1024 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1025 desc { "converting type-level constant value to mir constant value"}
1028 /// Destructures array, ADT or tuple constants into the constants
1029 /// of their fields.
1030 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1031 desc { "destructuring type level constant"}
1034 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1035 /// and its field values.
1036 query try_destructure_mir_constant(
1037 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1038 ) -> Option<mir::DestructuredConstant<'tcx>> {
1039 desc { "destructuring MIR constant"}
1043 /// Dereference a constant reference or raw pointer and turn the result into a constant
1045 query deref_mir_constant(
1046 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1047 ) -> mir::ConstantKind<'tcx> {
1048 desc { "dereferencing MIR constant" }
1052 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1053 desc { "getting a &core::panic::Location referring to a span" }
1056 // FIXME get rid of this with valtrees
1058 key: LitToConstInput<'tcx>
1059 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1060 desc { "converting literal to const" }
1063 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1064 desc { "converting literal to mir constant" }
1067 query check_match(key: DefId) {
1068 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1069 cache_on_disk_if { key.is_local() }
1072 /// Performs part of the privacy check and computes effective visibilities.
1073 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1075 desc { "checking effective visibilities" }
1077 query check_private_in_public(_: ()) -> () {
1079 desc { "checking for private elements in public interfaces" }
1082 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1084 desc { "reachability" }
1087 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1088 /// in the case of closures, this will be redirected to the enclosing function.
1089 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1090 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1093 /// Generates a MIR body for the shim.
1094 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1096 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1099 /// The `symbol_name` query provides the symbol name for calling a
1100 /// given instance from the local crate. In particular, it will also
1101 /// look up the correct symbol name of instances from upstream crates.
1102 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1103 desc { "computing the symbol for `{}`", key }
1104 cache_on_disk_if { true }
1107 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1108 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1109 cache_on_disk_if { def_id.is_local() }
1110 separate_provide_extern
1113 /// Gets the span for the definition.
1114 query def_span(def_id: DefId) -> Span {
1115 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1116 cache_on_disk_if { def_id.is_local() }
1117 separate_provide_extern
1120 /// Gets the span for the identifier of the definition.
1121 query def_ident_span(def_id: DefId) -> Option<Span> {
1122 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1123 cache_on_disk_if { def_id.is_local() }
1124 separate_provide_extern
1127 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1128 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1129 cache_on_disk_if { def_id.is_local() }
1130 separate_provide_extern
1133 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1134 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1135 cache_on_disk_if { def_id.is_local() }
1136 separate_provide_extern
1139 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1140 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1141 separate_provide_extern
1144 query should_inherit_track_caller(def_id: DefId) -> bool {
1145 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1148 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1149 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1150 cache_on_disk_if { def_id.is_local() }
1151 separate_provide_extern
1154 /// Determines whether an item is annotated with `doc(hidden)`.
1155 query is_doc_hidden(def_id: DefId) -> bool {
1156 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1159 /// Determines whether an item is annotated with `doc(notable_trait)`.
1160 query is_doc_notable_trait(def_id: DefId) -> bool {
1161 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1164 /// Returns the attributes on the item at `def_id`.
1166 /// Do not use this directly, use `tcx.get_attrs` instead.
1167 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1168 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1169 separate_provide_extern
1172 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1173 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1175 cache_on_disk_if { def_id.is_local() }
1176 separate_provide_extern
1179 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1180 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1183 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1184 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1185 cache_on_disk_if { def_id.is_local() }
1186 separate_provide_extern
1188 /// Gets the rendered value of the specified constant or associated constant.
1189 /// Used by rustdoc.
1190 query rendered_const(def_id: DefId) -> String {
1192 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1193 cache_on_disk_if { def_id.is_local() }
1194 separate_provide_extern
1196 query impl_parent(def_id: DefId) -> Option<DefId> {
1197 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1198 cache_on_disk_if { def_id.is_local() }
1199 separate_provide_extern
1202 query is_ctfe_mir_available(key: DefId) -> bool {
1203 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1204 cache_on_disk_if { key.is_local() }
1205 separate_provide_extern
1207 query is_mir_available(key: DefId) -> bool {
1208 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1209 cache_on_disk_if { key.is_local() }
1210 separate_provide_extern
1213 query own_existential_vtable_entries(
1215 ) -> &'tcx [DefId] {
1216 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1219 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1220 -> &'tcx [ty::VtblEntry<'tcx>] {
1221 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1224 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1225 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1229 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1230 desc { |tcx| "vtable const allocation for <{} as {}>",
1232 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1236 query codegen_select_candidate(
1237 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1238 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1239 cache_on_disk_if { true }
1240 desc { |tcx| "computing candidate for `{}`", key.1 }
1243 /// Return all `impl` blocks in the current crate.
1244 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1245 desc { "finding local trait impls" }
1248 /// Given a trait `trait_id`, return all known `impl` blocks.
1249 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1251 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1254 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1256 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1257 cache_on_disk_if { true }
1259 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1260 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1263 /// Gets the ParameterEnvironment for a given item; this environment
1264 /// will be in "user-facing" mode, meaning that it is suitable for
1265 /// type-checking etc, and it does not normalize specializable
1266 /// associated types. This is almost always what you want,
1267 /// unless you are doing MIR optimizations, in which case you
1268 /// might want to use `reveal_all()` method to change modes.
1269 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1270 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1273 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1274 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1275 /// as this method is more efficient.
1276 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1277 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1280 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1281 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1282 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1283 desc { "computing whether `{}` is `Copy`", env.value }
1286 /// Query backing `Ty::is_sized`.
1287 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1288 desc { "computing whether `{}` is `Sized`", env.value }
1291 /// Query backing `Ty::is_freeze`.
1292 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1293 desc { "computing whether `{}` is freeze", env.value }
1296 /// Query backing `Ty::is_unpin`.
1297 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1298 desc { "computing whether `{}` is `Unpin`", env.value }
1301 /// Query backing `Ty::needs_drop`.
1302 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1303 desc { "computing whether `{}` needs drop", env.value }
1306 /// Query backing `Ty::has_significant_drop_raw`.
1307 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1308 desc { "computing whether `{}` has a significant drop", env.value }
1312 /// Query backing `Ty::is_structural_eq_shallow`.
1314 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1316 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1318 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1323 /// A list of types where the ADT requires drop if and only if any of
1324 /// those types require drop. If the ADT is known to always need drop
1325 /// then `Err(AlwaysRequiresDrop)` is returned.
1326 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1327 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1328 cache_on_disk_if { true }
1331 /// A list of types where the ADT requires drop if and only if any of those types
1332 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1333 /// is considered to not be significant. A drop is significant if it is implemented
1334 /// by the user or does anything that will have any observable behavior (other than
1335 /// freeing up memory). If the ADT is known to have a significant destructor then
1336 /// `Err(AlwaysRequiresDrop)` is returned.
1337 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1338 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1339 cache_on_disk_if { false }
1342 /// Computes the layout of a type. Note that this implicitly
1343 /// executes in "reveal all" mode, and will normalize the input type.
1345 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1346 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1348 desc { "computing layout of `{}`", key.value }
1352 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1354 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1355 /// instead, where the instance is an `InstanceDef::Virtual`.
1356 query fn_abi_of_fn_ptr(
1357 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1358 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1359 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1363 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1364 /// direct calls to an `fn`.
1366 /// NB: that includes virtual calls, which are represented by "direct calls"
1367 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1368 query fn_abi_of_instance(
1369 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1370 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1371 desc { "computing call ABI of `{}`", key.value.0 }
1375 query dylib_dependency_formats(_: CrateNum)
1376 -> &'tcx [(CrateNum, LinkagePreference)] {
1377 desc { "getting dylib dependency formats of crate" }
1378 separate_provide_extern
1381 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1383 desc { "getting the linkage format of all dependencies" }
1386 query is_compiler_builtins(_: CrateNum) -> bool {
1388 desc { "checking if the crate is_compiler_builtins" }
1389 separate_provide_extern
1391 query has_global_allocator(_: CrateNum) -> bool {
1392 // This query depends on untracked global state in CStore
1395 desc { "checking if the crate has_global_allocator" }
1396 separate_provide_extern
1398 query has_alloc_error_handler(_: CrateNum) -> bool {
1399 // This query depends on untracked global state in CStore
1402 desc { "checking if the crate has_alloc_error_handler" }
1403 separate_provide_extern
1405 query has_panic_handler(_: CrateNum) -> bool {
1407 desc { "checking if the crate has_panic_handler" }
1408 separate_provide_extern
1410 query is_profiler_runtime(_: CrateNum) -> bool {
1412 desc { "checking if a crate is `#![profiler_runtime]`" }
1413 separate_provide_extern
1415 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1416 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1417 cache_on_disk_if { true }
1419 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1421 desc { "getting a crate's required panic strategy" }
1422 separate_provide_extern
1424 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1426 desc { "getting a crate's configured panic-in-drop strategy" }
1427 separate_provide_extern
1429 query is_no_builtins(_: CrateNum) -> bool {
1431 desc { "getting whether a crate has `#![no_builtins]`" }
1432 separate_provide_extern
1434 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1436 desc { "getting a crate's symbol mangling version" }
1437 separate_provide_extern
1440 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1442 desc { "getting crate's ExternCrateData" }
1443 separate_provide_extern
1446 query specializes(_: (DefId, DefId)) -> bool {
1447 desc { "computing whether impls specialize one another" }
1449 query in_scope_traits_map(_: hir::OwnerId)
1450 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1451 desc { "getting traits in scope at a block" }
1454 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1455 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1458 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1459 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1460 cache_on_disk_if { def_id.is_local() }
1461 separate_provide_extern
1464 query check_well_formed(key: hir::OwnerId) -> () {
1465 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1468 // The `DefId`s of all non-generic functions and statics in the given crate
1469 // that can be reached from outside the crate.
1471 // We expect this items to be available for being linked to.
1473 // This query can also be called for `LOCAL_CRATE`. In this case it will
1474 // compute which items will be reachable to other crates, taking into account
1475 // the kind of crate that is currently compiled. Crates with only a
1476 // C interface have fewer reachable things.
1478 // Does not include external symbols that don't have a corresponding DefId,
1479 // like the compiler-generated `main` function and so on.
1480 query reachable_non_generics(_: CrateNum)
1481 -> DefIdMap<SymbolExportInfo> {
1483 desc { "looking up the exported symbols of a crate" }
1484 separate_provide_extern
1486 query is_reachable_non_generic(def_id: DefId) -> bool {
1487 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1488 cache_on_disk_if { def_id.is_local() }
1489 separate_provide_extern
1491 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1493 "checking whether `{}` is reachable from outside the crate",
1494 tcx.def_path_str(def_id.to_def_id()),
1498 /// The entire set of monomorphizations the local crate can safely link
1499 /// to because they are exported from upstream crates. Do not depend on
1500 /// this directly, as its value changes anytime a monomorphization gets
1501 /// added or removed in any upstream crate. Instead use the narrower
1502 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1503 /// better, `Instance::upstream_monomorphization()`.
1504 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1506 desc { "collecting available upstream monomorphizations" }
1509 /// Returns the set of upstream monomorphizations available for the
1510 /// generic function identified by the given `def_id`. The query makes
1511 /// sure to make a stable selection if the same monomorphization is
1512 /// available in multiple upstream crates.
1514 /// You likely want to call `Instance::upstream_monomorphization()`
1515 /// instead of invoking this query directly.
1516 query upstream_monomorphizations_for(def_id: DefId)
1517 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1521 "collecting available upstream monomorphizations for `{}`",
1522 tcx.def_path_str(def_id),
1524 separate_provide_extern
1527 /// Returns the upstream crate that exports drop-glue for the given
1528 /// type (`substs` is expected to be a single-item list containing the
1529 /// type one wants drop-glue for).
1531 /// This is a subset of `upstream_monomorphizations_for` in order to
1532 /// increase dep-tracking granularity. Otherwise adding or removing any
1533 /// type with drop-glue in any upstream crate would invalidate all
1534 /// functions calling drop-glue of an upstream type.
1536 /// You likely want to call `Instance::upstream_monomorphization()`
1537 /// instead of invoking this query directly.
1539 /// NOTE: This query could easily be extended to also support other
1540 /// common functions that have are large set of monomorphizations
1541 /// (like `Clone::clone` for example).
1542 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1543 desc { "available upstream drop-glue for `{:?}`", substs }
1546 /// Returns a list of all `extern` blocks of a crate.
1547 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1549 desc { "looking up the foreign modules of a linked crate" }
1550 separate_provide_extern
1553 /// Identifies the entry-point (e.g., the `main` function) for a given
1554 /// crate, returning `None` if there is no entry point (such as for library crates).
1555 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1556 desc { "looking up the entry function of a crate" }
1559 /// Finds the `rustc_proc_macro_decls` item of a crate.
1560 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1561 desc { "looking up the proc macro declarations for a crate" }
1564 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1565 // Changing the name should cause a compiler error, but in case that changes, be aware.
1566 query crate_hash(_: CrateNum) -> Svh {
1568 desc { "looking up the hash a crate" }
1569 separate_provide_extern
1572 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1573 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1575 desc { "looking up the hash of a host version of a crate" }
1576 separate_provide_extern
1579 /// Gets the extra data to put in each output filename for a crate.
1580 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1581 query extra_filename(_: CrateNum) -> String {
1584 desc { "looking up the extra filename for a crate" }
1585 separate_provide_extern
1588 /// Gets the paths where the crate came from in the file system.
1589 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1592 desc { "looking up the paths for extern crates" }
1593 separate_provide_extern
1596 /// Given a crate and a trait, look up all impls of that trait in the crate.
1597 /// Return `(impl_id, self_ty)`.
1598 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1599 desc { "looking up implementations of a trait in a crate" }
1600 separate_provide_extern
1603 /// Collects all incoherent impls for the given crate and type.
1605 /// Do not call this directly, but instead use the `incoherent_impls` query.
1606 /// This query is only used to get the data necessary for that query.
1607 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1608 desc { |tcx| "collecting all impls for a type in a crate" }
1609 separate_provide_extern
1612 /// Get the corresponding native library from the `native_libraries` query
1613 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1614 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1617 /// Does lifetime resolution on items. Importantly, we can't resolve
1618 /// lifetimes directly on things like trait methods, because of trait params.
1619 /// See `rustc_resolve::late::lifetimes for details.
1620 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1622 desc { "resolving lifetimes" }
1624 query named_region_map(_: hir::OwnerId) ->
1625 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1626 desc { "looking up a named region" }
1628 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1629 desc { "testing if a region is late bound" }
1631 /// For a given item's generic parameter, gets the default lifetimes to be used
1632 /// for each parameter if a trait object were to be passed for that parameter.
1633 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1634 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1635 /// This query will panic if passed something that is not a type parameter.
1636 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1637 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1638 separate_provide_extern
1640 query late_bound_vars_map(_: hir::OwnerId)
1641 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1642 desc { "looking up late bound vars" }
1645 /// Computes the visibility of the provided `def_id`.
1647 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1648 /// a generic type parameter will panic if you call this method on it:
1651 /// use std::fmt::Debug;
1653 /// pub trait Foo<T: Debug> {}
1656 /// In here, if you call `visibility` on `T`, it'll panic.
1657 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1658 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1659 separate_provide_extern
1662 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1663 desc { "computing the uninhabited predicate of `{:?}`", key }
1666 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1667 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1668 desc { "computing the uninhabited predicate of `{}`", key }
1671 query dep_kind(_: CrateNum) -> CrateDepKind {
1673 desc { "fetching what a dependency looks like" }
1674 separate_provide_extern
1677 /// Gets the name of the crate.
1678 query crate_name(_: CrateNum) -> Symbol {
1680 desc { "fetching what a crate is named" }
1681 separate_provide_extern
1683 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1684 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1685 separate_provide_extern
1687 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1688 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1691 query lib_features(_: ()) -> LibFeatures {
1693 desc { "calculating the lib features map" }
1695 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1696 desc { "calculating the lib features defined in a crate" }
1697 separate_provide_extern
1699 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1701 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1702 separate_provide_extern
1704 /// Whether the function is an intrinsic
1705 query is_intrinsic(def_id: DefId) -> bool {
1706 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1707 separate_provide_extern
1709 /// Returns the lang items defined in another crate by loading it from metadata.
1710 query get_lang_items(_: ()) -> LanguageItems {
1713 desc { "calculating the lang items map" }
1716 /// Returns all diagnostic items defined in all crates.
1717 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1720 desc { "calculating the diagnostic items map" }
1723 /// Returns the lang items defined in another crate by loading it from metadata.
1724 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1725 desc { "calculating the lang items defined in a crate" }
1726 separate_provide_extern
1729 /// Returns the diagnostic items defined in a crate.
1730 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1732 desc { "calculating the diagnostic items map in a crate" }
1733 separate_provide_extern
1736 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1737 desc { "calculating the missing lang items in a crate" }
1738 separate_provide_extern
1740 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1742 desc { "calculating the visible parent map" }
1744 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1746 desc { "calculating trimmed def paths" }
1748 query missing_extern_crate_item(_: CrateNum) -> bool {
1750 desc { "seeing if we're missing an `extern crate` item for this crate" }
1751 separate_provide_extern
1753 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1756 desc { "looking at the source for a crate" }
1757 separate_provide_extern
1759 /// Returns the debugger visualizers defined for this crate.
1760 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1762 desc { "looking up the debugger visualizers for this crate" }
1763 separate_provide_extern
1765 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1767 desc { "generating a postorder list of CrateNums" }
1769 /// Returns whether or not the crate with CrateNum 'cnum'
1770 /// is marked as a private dependency
1771 query is_private_dep(c: CrateNum) -> bool {
1773 desc { "checking whether crate `{}` is a private dependency", c }
1774 separate_provide_extern
1776 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1778 desc { "getting the allocator kind for the current crate" }
1780 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1782 desc { "alloc error handler kind for the current crate" }
1785 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1786 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1788 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1789 desc { "fetching potentially unused trait imports" }
1791 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1792 desc { "looking up all possibly unused extern crates" }
1794 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1795 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1798 query stability_index(_: ()) -> stability::Index {
1801 desc { "calculating the stability index for the local crate" }
1803 query crates(_: ()) -> &'tcx [CrateNum] {
1805 desc { "fetching all foreign CrateNum instances" }
1808 /// A list of all traits in a crate, used by rustdoc and error reporting.
1809 /// NOTE: Not named just `traits` due to a naming conflict.
1810 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1811 desc { "fetching all traits in a crate" }
1812 separate_provide_extern
1815 /// The list of symbols exported from the given crate.
1817 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1818 /// correspond to a publicly visible symbol in `cnum` machine code.
1819 /// - The `exported_symbols` sets of different crates do not intersect.
1820 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1821 desc { "collecting exported symbols for crate `{}`", cnum}
1822 cache_on_disk_if { *cnum == LOCAL_CRATE }
1823 separate_provide_extern
1826 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1828 desc { "collect_and_partition_mono_items" }
1831 query is_codegened_item(def_id: DefId) -> bool {
1832 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1835 /// All items participating in code generation together with items inlined into them.
1836 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1838 desc { "collecting codegened and inlined items" }
1841 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1842 desc { "getting codegen unit `{sym}`" }
1845 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1846 cache_on_disk_if { key.def_id().is_local() }
1848 |tcx| "determining which generic parameters are unused by `{}`",
1849 tcx.def_path_str(key.def_id())
1851 separate_provide_extern
1854 query backend_optimization_level(_: ()) -> OptLevel {
1855 desc { "optimization level used by backend" }
1858 /// Return the filenames where output artefacts shall be stored.
1860 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1861 /// has been destroyed.
1862 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1864 desc { "getting output filenames" }
1867 /// Do not call this query directly: invoke `normalize` instead.
1868 query normalize_projection_ty(
1869 goal: CanonicalProjectionGoal<'tcx>
1871 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1874 desc { "normalizing `{}`", goal.value.value }
1878 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1879 query try_normalize_generic_arg_after_erasing_regions(
1880 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1881 ) -> Result<GenericArg<'tcx>, NoSolution> {
1882 desc { "normalizing `{}`", goal.value }
1886 query implied_outlives_bounds(
1887 goal: CanonicalTyGoal<'tcx>
1889 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1892 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1896 /// Do not call this query directly:
1897 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1898 query dropck_outlives(
1899 goal: CanonicalTyGoal<'tcx>
1901 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1904 desc { "computing dropck types for `{}`", goal.value.value }
1908 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1909 /// `infcx.predicate_must_hold()` instead.
1910 query evaluate_obligation(
1911 goal: CanonicalPredicateGoal<'tcx>
1912 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1913 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1916 query evaluate_goal(
1917 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1919 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1922 desc { "evaluating trait selection obligation `{}`", goal.value }
1925 /// Do not call this query directly: part of the `Eq` type-op
1926 query type_op_ascribe_user_type(
1927 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1929 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1932 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1936 /// Do not call this query directly: part of the `Eq` type-op
1938 goal: CanonicalTypeOpEqGoal<'tcx>
1940 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1943 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1947 /// Do not call this query directly: part of the `Subtype` type-op
1948 query type_op_subtype(
1949 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1951 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1954 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1958 /// Do not call this query directly: part of the `ProvePredicate` type-op
1959 query type_op_prove_predicate(
1960 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1962 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1965 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1968 /// Do not call this query directly: part of the `Normalize` type-op
1969 query type_op_normalize_ty(
1970 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1972 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1975 desc { "normalizing `{}`", goal.value.value.value }
1979 /// Do not call this query directly: part of the `Normalize` type-op
1980 query type_op_normalize_predicate(
1981 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1983 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1986 desc { "normalizing `{:?}`", goal.value.value.value }
1990 /// Do not call this query directly: part of the `Normalize` type-op
1991 query type_op_normalize_poly_fn_sig(
1992 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1994 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1997 desc { "normalizing `{:?}`", goal.value.value.value }
2001 /// Do not call this query directly: part of the `Normalize` type-op
2002 query type_op_normalize_fn_sig(
2003 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2005 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2008 desc { "normalizing `{:?}`", goal.value.value.value }
2012 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2014 "checking impossible substituted predicates: `{}`",
2015 tcx.def_path_str(key.0)
2019 query is_impossible_method(key: (DefId, DefId)) -> bool {
2021 "checking if `{}` is impossible to call within `{}`",
2022 tcx.def_path_str(key.1),
2023 tcx.def_path_str(key.0),
2027 query method_autoderef_steps(
2028 goal: CanonicalTyGoal<'tcx>
2029 ) -> MethodAutoderefStepsResult<'tcx> {
2030 desc { "computing autoderef types for `{}`", goal.value.value }
2034 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2037 desc { "looking up supported target features" }
2040 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2041 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2043 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2046 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2048 desc { "looking up enabled feature gates" }
2051 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2052 /// given generics args (`SubstsRef`), returning one of:
2053 /// * `Ok(Some(instance))` on success
2054 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2055 /// and therefore don't allow finding the final `Instance`
2056 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2057 /// couldn't complete due to errors elsewhere - this is distinct
2058 /// from `Ok(None)` to avoid misleading diagnostics when an error
2059 /// has already been/will be emitted, for the original cause
2060 query resolve_instance(
2061 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2062 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2063 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2067 query resolve_instance_of_const_arg(
2068 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2069 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2071 "resolving instance of the const argument `{}`",
2072 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2077 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2078 desc { "normalizing opaque types in `{:?}`", key }
2081 /// Checks whether a type is definitely uninhabited. This is
2082 /// conservative: for some types that are uninhabited we return `false`,
2083 /// but we only return `true` for types that are definitely uninhabited.
2084 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2085 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2086 /// size, to account for partial initialisation. See #49298 for details.)
2087 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2088 desc { "conservatively checking if `{}` is privately uninhabited", key.value }
2092 query limits(key: ()) -> Limits {
2093 desc { "looking up limits" }
2096 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2097 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2098 /// the cause of the newly created obligation.
2100 /// This is only used by error-reporting code to get a better cause (in particular, a better
2101 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2102 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2103 /// because the `ty::Ty`-based wfcheck is always run.
2104 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2108 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2112 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2113 /// `--target` and similar).
2114 query global_backend_features(_: ()) -> Vec<String> {
2117 desc { "computing the backend features for CLI flags" }
2120 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2122 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2123 separate_provide_extern
2126 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2127 desc { "checking to see if `{}` permits being left uninit", key.ty }
2130 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2131 desc { "checking to see if `{}` permits being left zeroed", key.ty }
2134 query compare_assoc_const_impl_item_with_trait_item(
2135 key: (LocalDefId, DefId)
2136 ) -> Result<(), ErrorGuaranteed> {
2137 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2140 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2141 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2142 separate_provide_extern