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> {
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 desc { "getting the source span" }
49 /// Represents crate as a whole (as distinct from the top-level crate module).
50 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
51 /// we will have to assume that any change means that you need to be recompiled.
52 /// This is because the `hir_crate` query gives you access to all other items.
53 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
54 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
55 query hir_crate(key: ()) -> Crate<'tcx> {
58 desc { "getting the crate HIR" }
61 /// All items in the crate.
62 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
65 desc { "getting HIR crate items" }
68 /// The items in a module.
70 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
71 /// Avoid calling this query directly.
72 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
74 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
75 cache_on_disk_if { true }
78 /// Gives access to the HIR node for the HIR owner `key`.
80 /// This can be conveniently accessed by methods on `tcx.hir()`.
81 /// Avoid calling this query directly.
82 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
83 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
86 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
88 /// This can be conveniently accessed by methods on `tcx.hir()`.
89 /// Avoid calling this query directly.
90 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
91 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
94 /// Gives access to the HIR node's parent for the HIR owner `key`.
96 /// This can be conveniently accessed by methods on `tcx.hir()`.
97 /// Avoid calling this query directly.
98 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
99 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
102 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
104 /// This can be conveniently accessed by methods on `tcx.hir()`.
105 /// Avoid calling this query directly.
106 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
107 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
110 /// Gives access to the HIR attributes inside the HIR owner `key`.
112 /// This can be conveniently accessed by methods on `tcx.hir()`.
113 /// Avoid calling this query directly.
114 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
115 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
118 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
119 /// const argument and returns `None` otherwise.
121 /// ```ignore (incomplete)
122 /// let a = foo::<7>();
123 /// // ^ Calling `opt_const_param_of` for this argument,
125 /// fn foo<const N: usize>()
126 /// // ^ returns this `DefId`.
129 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
132 // It looks like caching this query on disk actually slightly
133 // worsened performance in #74376.
135 // Once const generics are more prevalently used, we might want to
136 // consider only caching calls returning `Some`.
137 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
138 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
141 /// Given the def_id of a const-generic parameter, computes the associated default const
142 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
143 query const_param_default(param: DefId) -> ty::Const<'tcx> {
144 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
145 cache_on_disk_if { param.is_local() }
146 separate_provide_extern
149 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
150 /// to an alias, it will "skip" this alias to return the aliased type.
152 /// [`DefId`]: rustc_hir::def_id::DefId
153 query type_of(key: DefId) -> Ty<'tcx> {
157 use rustc_hir::def::DefKind;
158 match tcx.def_kind(key) {
159 DefKind::TyAlias => "expanding type alias",
160 DefKind::TraitAlias => "expanding trait alias",
161 _ => "computing type of",
164 path = tcx.def_path_str(key),
166 cache_on_disk_if { key.is_local() }
167 separate_provide_extern
170 query collect_trait_impl_trait_tys(key: DefId)
171 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
173 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
174 cache_on_disk_if { key.is_local() }
175 separate_provide_extern
178 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
180 desc { "running analysis passes on this crate" }
183 /// This query checks the fulfillment of collected lint expectations.
184 /// All lint emitting queries have to be done before this is executed
185 /// to ensure that all expectations can be fulfilled.
187 /// This is an extra query to enable other drivers (like rustdoc) to
188 /// only execute a small subset of the `analysis` query, while allowing
189 /// lints to be expected. In rustc, this query will be executed as part of
190 /// the `analysis` query and doesn't have to be called a second time.
192 /// Tools can additionally pass in a tool filter. That will restrict the
193 /// expectations to only trigger for lints starting with the listed tool
194 /// name. This is useful for cases were not all linting code from rustc
195 /// was called. With the default `None` all registered lints will also
196 /// be checked for expectation fulfillment.
197 query check_expectations(key: Option<Symbol>) -> () {
199 desc { "checking lint expectations (RFC 2383)" }
202 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
203 /// associated generics.
204 query generics_of(key: DefId) -> ty::Generics {
205 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
207 cache_on_disk_if { key.is_local() }
208 separate_provide_extern
211 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
212 /// predicates (where-clauses) that must be proven true in order
213 /// to reference it. This is almost always the "predicates query"
216 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
217 /// it is almost always the same as that query, except for the
218 /// case of traits. For traits, `predicates_of` contains
219 /// an additional `Self: Trait<...>` predicate that users don't
220 /// actually write. This reflects the fact that to invoke the
221 /// trait (e.g., via `Default::default`) you must supply types
222 /// that actually implement the trait. (However, this extra
223 /// predicate gets in the way of some checks, which are intended
224 /// to operate over only the actual where-clauses written by the
226 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
227 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
228 cache_on_disk_if { key.is_local() }
231 /// Returns the list of bounds that can be used for
232 /// `SelectionCandidate::ProjectionCandidate(_)` and
233 /// `ProjectionTyCandidate::TraitDef`.
234 /// Specifically this is the bounds written on the trait's type
235 /// definition, or those after the `impl` keyword
237 /// ```ignore (incomplete)
238 /// type X: Bound + 'lt
240 /// impl Debug + Display
241 /// // ^^^^^^^^^^^^^^^
244 /// `key` is the `DefId` of the associated type or opaque type.
246 /// Bounds from the parent (e.g. with nested impl trait) are not included.
247 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
248 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
249 cache_on_disk_if { key.is_local() }
250 separate_provide_extern
253 /// Elaborated version of the predicates from `explicit_item_bounds`.
259 /// type MyAType: Eq + ?Sized;
263 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
264 /// and `item_bounds` returns
267 /// <Self as Trait>::MyAType: Eq,
268 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
272 /// Bounds from the parent (e.g. with nested impl trait) are not included.
273 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
274 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
277 /// Look up all native libraries this crate depends on.
278 /// These are assembled from the following places:
279 /// - `extern` blocks (depending on their `link` attributes)
280 /// - the `libs` (`-l`) option
281 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
283 desc { "looking up the native libraries of a linked crate" }
284 separate_provide_extern
287 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
288 eval_always // fetches `resolutions`
290 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
293 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
295 desc { "computing `#[expect]`ed lints in this crate" }
298 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
300 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
303 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
304 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
305 separate_provide_extern
308 query is_panic_runtime(_: CrateNum) -> bool {
310 desc { "checking if the crate is_panic_runtime" }
311 separate_provide_extern
314 /// Checks whether a type is representable or infinitely sized
315 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
316 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
317 // infinitely sized types will cause a cycle
319 // we don't want recursive representability calls to be forced with
320 // incremental compilation because, if a cycle occurs, we need the
321 // entire cycle to be in memory for diagnostics
325 /// An implementation detail for the `representability` query
326 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
327 desc { "checking if `{}` is representable", key }
332 /// Set of param indexes for type params that are in the type's representation
333 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
334 desc { "finding type parameters in the representation" }
337 separate_provide_extern
340 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
341 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
342 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
344 // Perf tests revealed that hashing THIR is inefficient (see #85729).
346 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
349 /// Create a THIR tree for debugging.
350 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
353 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
356 /// Set of all the `DefId`s in this crate that have MIR associated with
357 /// them. This includes all the body owners, but also things like struct
359 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
361 desc { "getting a list of all mir_keys" }
364 /// Maps DefId's that have an associated `mir::Body` to the result
365 /// of the MIR const-checking pass. This is the set of qualifs in
366 /// the final value of a `const`.
367 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
368 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
369 cache_on_disk_if { key.is_local() }
370 separate_provide_extern
372 query mir_const_qualif_const_arg(
373 key: (LocalDefId, DefId)
374 ) -> mir::ConstQualifs {
376 |tcx| "const checking the const argument `{}`",
377 tcx.def_path_str(key.0.to_def_id())
381 /// Fetch the MIR for a given `DefId` right after it's built - this includes
382 /// unreachable code.
383 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
384 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
387 /// Fetch the MIR for a given `DefId` up till the point where it is
388 /// ready for const qualification.
390 /// See the README for the `mir` module for details.
391 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
393 |tcx| "preparing {}`{}` for borrow checking",
394 if key.const_param_did.is_some() { "the const argument " } else { "" },
395 tcx.def_path_str(key.did.to_def_id()),
400 /// Try to build an abstract representation of the given constant.
401 query thir_abstract_const(
403 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
405 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
407 separate_provide_extern
409 /// Try to build an abstract representation of the given constant.
410 query thir_abstract_const_of_const_arg(
411 key: (LocalDefId, DefId)
412 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
415 "building an abstract representation for the const argument `{}`",
416 tcx.def_path_str(key.0.to_def_id()),
420 query mir_drops_elaborated_and_const_checked(
421 key: ty::WithOptConstParam<LocalDefId>
422 ) -> &'tcx Steal<mir::Body<'tcx>> {
424 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
429 ) -> &'tcx mir::Body<'tcx> {
430 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
431 cache_on_disk_if { key.is_local() }
432 separate_provide_extern
435 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
437 |tcx| "caching MIR for CTFE of the const argument `{}`",
438 tcx.def_path_str(key.0.to_def_id())
442 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
444 &'tcx Steal<mir::Body<'tcx>>,
445 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
449 |tcx| "processing MIR for {}`{}`",
450 if key.const_param_did.is_some() { "the const argument " } else { "" },
451 tcx.def_path_str(key.did.to_def_id()),
455 query symbols_for_closure_captures(
456 key: (LocalDefId, LocalDefId)
457 ) -> Vec<rustc_span::Symbol> {
460 |tcx| "finding symbols for captures of closure `{}` in `{}`",
461 tcx.def_path_str(key.1.to_def_id()),
462 tcx.def_path_str(key.0.to_def_id())
466 /// MIR after our optimization passes have run. This is MIR that is ready
467 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
468 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
469 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
470 cache_on_disk_if { key.is_local() }
471 separate_provide_extern
474 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
475 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
476 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
477 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
481 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
482 /// function was optimized out before codegen, and before being added to the Coverage Map.
483 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
485 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
486 tcx.def_path_str(key)
489 cache_on_disk_if { key.is_local() }
492 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
493 /// `DefId`. This function returns all promoteds in the specified body. The body references
494 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
495 /// after inlining a body may refer to promoteds from other bodies. In that case you still
496 /// need to use the `DefId` of the original body.
497 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
498 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
499 cache_on_disk_if { key.is_local() }
500 separate_provide_extern
502 query promoted_mir_of_const_arg(
503 key: (LocalDefId, DefId)
504 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
506 |tcx| "optimizing promoted MIR for the const argument `{}`",
507 tcx.def_path_str(key.0.to_def_id()),
511 /// Erases regions from `ty` to yield a new type.
512 /// Normally you would just use `tcx.erase_regions(value)`,
513 /// however, which uses this query as a kind of cache.
514 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
515 // This query is not expected to have input -- as a result, it
516 // is not a good candidates for "replay" because it is essentially a
517 // pure function of its input (and hence the expectation is that
518 // no caller would be green **apart** from just these
519 // queries). Making it anonymous avoids hashing the result, which
520 // may save a bit of time.
522 desc { "erasing regions from `{}`", ty }
525 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
527 desc { "getting wasm import module map" }
530 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
531 /// predicates (where-clauses) directly defined on it. This is
532 /// equal to the `explicit_predicates_of` predicates plus the
533 /// `inferred_outlives_of` predicates.
534 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
535 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
538 /// Returns everything that looks like a predicate written explicitly
539 /// by the user on a trait item.
541 /// Traits are unusual, because predicates on associated types are
542 /// converted into bounds on that type for backwards compatibility:
544 /// trait X where Self::U: Copy { type U; }
548 /// trait X { type U: Copy; }
550 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
551 /// the appropriate subsets of the predicates here.
552 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
553 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
556 /// Returns the predicates written explicitly by the user.
557 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
558 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
559 cache_on_disk_if { key.is_local() }
560 separate_provide_extern
563 /// Returns the inferred outlives predicates (e.g., for `struct
564 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
565 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
566 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
567 cache_on_disk_if { key.is_local() }
568 separate_provide_extern
571 /// Maps from the `DefId` of a trait to the list of
572 /// super-predicates. This is a subset of the full list of
573 /// predicates. We store these in a separate map because we must
574 /// evaluate them even during type conversion, often before the
575 /// full predicates are available (note that supertraits have
576 /// additional acyclicity requirements).
577 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
578 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
579 cache_on_disk_if { key.is_local() }
580 separate_provide_extern
583 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
584 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
585 /// subset of super-predicates that reference traits that define the given associated type.
586 /// This is used to avoid cycles in resolving types like `T::Item`.
587 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
588 desc { |tcx| "computing the super traits of `{}`{}",
589 tcx.def_path_str(key.0),
590 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
594 /// To avoid cycles within the predicates of a single item we compute
595 /// per-type-parameter predicates for resolving `T::AssocTy`.
596 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
597 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
600 query trait_def(key: DefId) -> ty::TraitDef {
601 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
603 cache_on_disk_if { key.is_local() }
604 separate_provide_extern
606 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
607 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
608 cache_on_disk_if { key.is_local() }
609 separate_provide_extern
611 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
612 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
613 cache_on_disk_if { key.is_local() }
614 separate_provide_extern
617 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
618 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
621 query adt_dtorck_constraint(
623 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
624 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
627 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
628 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
629 /// not have the feature gate active).
631 /// **Do not call this function manually.** It is only meant to cache the base data for the
632 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
633 query constness(key: DefId) -> hir::Constness {
634 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
635 cache_on_disk_if { key.is_local() }
636 separate_provide_extern
639 query asyncness(key: DefId) -> hir::IsAsync {
640 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
641 cache_on_disk_if { key.is_local() }
642 separate_provide_extern
645 /// Returns `true` if calls to the function may be promoted.
647 /// This is either because the function is e.g., a tuple-struct or tuple-variant
648 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
649 /// be removed in the future in favour of some form of check which figures out whether the
650 /// function does not inspect the bits of any of its arguments (so is essentially just a
651 /// constructor function).
652 query is_promotable_const_fn(key: DefId) -> bool {
653 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
656 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
657 query is_foreign_item(key: DefId) -> bool {
658 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
659 cache_on_disk_if { key.is_local() }
660 separate_provide_extern
663 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
664 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
665 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
666 cache_on_disk_if { def_id.is_local() }
667 separate_provide_extern
670 /// Gets a map with the variance of every item; use `item_variance` instead.
671 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
673 desc { "computing the variances for items in this crate" }
676 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
677 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
678 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
679 cache_on_disk_if { def_id.is_local() }
680 separate_provide_extern
683 /// Maps from thee `DefId` of a type to its (inferred) outlives.
684 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
686 desc { "computing the inferred outlives predicates for items in this crate" }
689 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
690 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
691 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
692 cache_on_disk_if { key.is_local() }
693 separate_provide_extern
696 /// Maps from a trait item to the trait item "descriptor".
697 query associated_item(key: DefId) -> ty::AssocItem {
698 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
700 cache_on_disk_if { key.is_local() }
701 separate_provide_extern
704 /// Collects the associated items defined on a trait or impl.
705 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
707 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
710 /// Maps from associated items on a trait to the corresponding associated
711 /// item on the impl specified by `impl_id`.
713 /// For example, with the following code
718 /// trait Trait { // trait_id
719 /// fn f(); // trait_f
720 /// fn g() {} // trait_g
723 /// impl Trait for Type { // impl_id
724 /// fn f() {} // impl_f
725 /// fn g() {} // impl_g
729 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
730 ///`{ trait_f: impl_f, trait_g: impl_g }`
731 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
733 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
736 /// Given an `impl_id`, return the trait it implements.
737 /// Return `None` if this is an inherent impl.
738 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
739 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
740 cache_on_disk_if { impl_id.is_local() }
741 separate_provide_extern
743 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
744 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
745 cache_on_disk_if { impl_id.is_local() }
746 separate_provide_extern
749 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
750 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
753 /// Maps a `DefId` of a type to a list of its inherent impls.
754 /// Contains implementations of methods that are inherent to a type.
755 /// Methods in these implementations don't need to be exported.
756 query inherent_impls(key: DefId) -> &'tcx [DefId] {
757 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
758 cache_on_disk_if { key.is_local() }
759 separate_provide_extern
762 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
763 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
766 /// The result of unsafety-checking this `LocalDefId`.
767 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
768 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
769 cache_on_disk_if { true }
771 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
773 |tcx| "unsafety-checking the const argument `{}`",
774 tcx.def_path_str(key.0.to_def_id())
778 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
779 /// used with `-Zthir-unsafeck`.
780 query thir_check_unsafety(key: LocalDefId) {
781 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
782 cache_on_disk_if { true }
784 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
786 |tcx| "unsafety-checking the const argument `{}`",
787 tcx.def_path_str(key.0.to_def_id())
791 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
793 /// Unsafety checking is executed for each method separately, but we only want
794 /// to emit this error once per derive. As there are some impls with multiple
795 /// methods, we use a query for deduplication.
796 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
797 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
800 /// Returns the types assumed to be well formed while "inside" of the given item.
802 /// Note that we've liberated the late bound regions of function signatures, so
803 /// this can not be used to check whether these types are well formed.
804 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
805 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
808 /// Computes the signature of the function.
809 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
810 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
811 cache_on_disk_if { key.is_local() }
812 separate_provide_extern
816 /// Performs lint checking for the module.
817 query lint_mod(key: LocalDefId) -> () {
818 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
821 /// Checks the attributes in the module.
822 query check_mod_attrs(key: LocalDefId) -> () {
823 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
826 /// Checks for uses of unstable APIs in the module.
827 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
828 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
831 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
832 query check_mod_const_bodies(key: LocalDefId) -> () {
833 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
836 /// Checks the loops in the module.
837 query check_mod_loops(key: LocalDefId) -> () {
838 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
841 query check_mod_naked_functions(key: LocalDefId) -> () {
842 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
845 query check_mod_item_types(key: LocalDefId) -> () {
846 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
849 query check_mod_privacy(key: LocalDefId) -> () {
850 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
853 query check_liveness(key: DefId) {
854 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
857 /// Return the live symbols in the crate for dead code check.
859 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
860 /// their respective impl (i.e., part of the derive macro)
861 query live_symbols_and_ignored_derived_traits(_: ()) -> (
862 FxHashSet<LocalDefId>,
863 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
866 desc { "finding live symbols in crate" }
869 query check_mod_deathness(key: LocalDefId) -> () {
870 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
873 query check_mod_impl_wf(key: LocalDefId) -> () {
874 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
877 query check_mod_type_wf(key: LocalDefId) -> () {
878 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
881 query collect_mod_item_types(key: LocalDefId) -> () {
882 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
885 /// Caches `CoerceUnsized` kinds for impls on custom types.
886 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
887 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
888 cache_on_disk_if { key.is_local() }
889 separate_provide_extern
892 query typeck_item_bodies(_: ()) -> () {
893 desc { "type-checking all item bodies" }
896 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
897 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
898 cache_on_disk_if { true }
900 query typeck_const_arg(
901 key: (LocalDefId, DefId)
902 ) -> &'tcx ty::TypeckResults<'tcx> {
904 |tcx| "type-checking the const argument `{}`",
905 tcx.def_path_str(key.0.to_def_id()),
908 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
909 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
910 cache_on_disk_if { true }
913 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
914 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
915 cache_on_disk_if { true }
918 query has_typeck_results(def_id: DefId) -> bool {
919 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
922 query coherent_trait(def_id: DefId) -> () {
923 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
926 /// Borrow-checks the function body. If this is a closure, returns
927 /// additional requirements that the closure's creator must verify.
928 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
929 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
930 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
932 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
934 |tcx| "borrow-checking the const argument`{}`",
935 tcx.def_path_str(key.0.to_def_id())
939 /// Gets a complete map from all types to their inherent impls.
940 /// Not meant to be used directly outside of coherence.
941 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
943 desc { "finding all inherent impls defined in crate" }
946 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
947 /// Not meant to be used directly outside of coherence.
948 query crate_inherent_impls_overlap_check(_: ()) -> () {
949 desc { "check for overlap between inherent impls defined in this crate" }
952 /// Checks whether all impls in the crate pass the overlap check, returning
953 /// which impls fail it. If all impls are correct, the returned slice is empty.
954 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
956 "checking whether impl `{}` follows the orphan rules",
957 tcx.def_path_str(key.to_def_id()),
961 /// Check whether the function has any recursion that could cause the inliner to trigger
962 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
963 /// current function, just all intermediate functions.
964 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
967 "computing if `{}` (transitively) calls `{}`",
969 tcx.def_path_str(key.1.to_def_id()),
973 /// Obtain all the calls into other local functions
974 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
977 "computing all local function calls in `{}`",
978 tcx.def_path_str(key.def_id()),
982 /// Evaluates a constant and returns the computed allocation.
984 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
985 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
986 -> EvalToAllocationRawResult<'tcx> {
988 "const-evaluating + checking `{}`",
989 key.value.display(tcx)
991 cache_on_disk_if { true }
994 /// Evaluates const items or anonymous constants
995 /// (such as enum variant explicit discriminants or array lengths)
996 /// into a representation suitable for the type system and const generics.
998 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
999 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1000 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1001 -> EvalToConstValueResult<'tcx> {
1003 "simplifying constant for the type system `{}`",
1004 key.value.display(tcx)
1006 cache_on_disk_if { true }
1009 /// Evaluate a constant and convert it to a type level constant or
1010 /// return `None` if that is not possible.
1011 query eval_to_valtree(
1012 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1013 ) -> EvalToValTreeResult<'tcx> {
1014 desc { "evaluating type-level constant" }
1017 /// Converts a type level constant value into `ConstValue`
1018 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1019 desc { "converting type-level constant value to mir constant value"}
1022 /// Destructures array, ADT or tuple constants into the constants
1023 /// of their fields.
1024 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1025 desc { "destructuring type level constant"}
1028 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1029 /// and its field values.
1030 query try_destructure_mir_constant(
1031 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1032 ) -> Option<mir::DestructuredConstant<'tcx>> {
1033 desc { "destructuring MIR constant"}
1037 /// Dereference a constant reference or raw pointer and turn the result into a constant
1039 query deref_mir_constant(
1040 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1041 ) -> mir::ConstantKind<'tcx> {
1042 desc { "dereferencing MIR constant" }
1046 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1047 desc { "getting a &core::panic::Location referring to a span" }
1050 // FIXME get rid of this with valtrees
1052 key: LitToConstInput<'tcx>
1053 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1054 desc { "converting literal to const" }
1057 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1058 desc { "converting literal to mir constant" }
1061 query check_match(key: DefId) {
1062 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1063 cache_on_disk_if { key.is_local() }
1066 /// Performs part of the privacy check and computes effective visibilities.
1067 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1069 desc { "checking effective visibilities" }
1071 query check_private_in_public(_: ()) -> () {
1073 desc { "checking for private elements in public interfaces" }
1076 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1078 desc { "reachability" }
1081 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1082 /// in the case of closures, this will be redirected to the enclosing function.
1083 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1084 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1087 /// Generates a MIR body for the shim.
1088 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1090 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1093 /// The `symbol_name` query provides the symbol name for calling a
1094 /// given instance from the local crate. In particular, it will also
1095 /// look up the correct symbol name of instances from upstream crates.
1096 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1097 desc { "computing the symbol for `{}`", key }
1098 cache_on_disk_if { true }
1101 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1102 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1103 cache_on_disk_if { def_id.is_local() }
1104 separate_provide_extern
1107 /// Gets the span for the definition.
1108 query def_span(def_id: DefId) -> Span {
1109 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1110 cache_on_disk_if { def_id.is_local() }
1111 separate_provide_extern
1115 /// Gets the span for the identifier of the definition.
1116 query def_ident_span(def_id: DefId) -> Option<Span> {
1117 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1118 cache_on_disk_if { def_id.is_local() }
1119 separate_provide_extern
1122 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1123 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1124 cache_on_disk_if { def_id.is_local() }
1125 separate_provide_extern
1128 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1129 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1130 cache_on_disk_if { def_id.is_local() }
1131 separate_provide_extern
1134 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1135 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1136 separate_provide_extern
1139 query should_inherit_track_caller(def_id: DefId) -> bool {
1140 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1143 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1144 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1145 cache_on_disk_if { def_id.is_local() }
1146 separate_provide_extern
1149 /// Determines whether an item is annotated with `doc(hidden)`.
1150 query is_doc_hidden(def_id: DefId) -> bool {
1151 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1154 /// Determines whether an item is annotated with `doc(notable_trait)`.
1155 query is_doc_notable_trait(def_id: DefId) -> bool {
1156 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1159 /// Returns the attributes on the item at `def_id`.
1161 /// Do not use this directly, use `tcx.get_attrs` instead.
1162 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1163 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1164 separate_provide_extern
1167 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1168 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1170 cache_on_disk_if { def_id.is_local() }
1171 separate_provide_extern
1174 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1175 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1178 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1179 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1180 cache_on_disk_if { def_id.is_local() }
1181 separate_provide_extern
1183 /// Gets the rendered value of the specified constant or associated constant.
1184 /// Used by rustdoc.
1185 query rendered_const(def_id: DefId) -> String {
1187 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1188 cache_on_disk_if { def_id.is_local() }
1189 separate_provide_extern
1191 query impl_parent(def_id: DefId) -> Option<DefId> {
1192 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1193 cache_on_disk_if { def_id.is_local() }
1194 separate_provide_extern
1197 query is_ctfe_mir_available(key: DefId) -> bool {
1198 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1199 cache_on_disk_if { key.is_local() }
1200 separate_provide_extern
1202 query is_mir_available(key: DefId) -> bool {
1203 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1204 cache_on_disk_if { key.is_local() }
1205 separate_provide_extern
1208 query own_existential_vtable_entries(
1210 ) -> &'tcx [DefId] {
1211 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1214 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1215 -> &'tcx [ty::VtblEntry<'tcx>] {
1216 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1219 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1220 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1224 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1225 desc { |tcx| "vtable const allocation for <{} as {}>",
1227 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1231 query codegen_select_candidate(
1232 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1233 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1234 cache_on_disk_if { true }
1235 desc { |tcx| "computing candidate for `{}`", key.1 }
1238 /// Return all `impl` blocks in the current crate.
1239 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1240 desc { "finding local trait impls" }
1243 /// Given a trait `trait_id`, return all known `impl` blocks.
1244 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1246 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1249 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1251 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1252 cache_on_disk_if { true }
1254 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1255 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1258 /// Gets the ParameterEnvironment for a given item; this environment
1259 /// will be in "user-facing" mode, meaning that it is suitable for
1260 /// type-checking etc, and it does not normalize specializable
1261 /// associated types. This is almost always what you want,
1262 /// unless you are doing MIR optimizations, in which case you
1263 /// might want to use `reveal_all()` method to change modes.
1264 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1265 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1268 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1269 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1270 /// as this method is more efficient.
1271 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1272 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1275 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1276 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1277 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1278 desc { "computing whether `{}` is `Copy`", env.value }
1281 /// Query backing `Ty::is_sized`.
1282 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1283 desc { "computing whether `{}` is `Sized`", env.value }
1286 /// Query backing `Ty::is_freeze`.
1287 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1288 desc { "computing whether `{}` is freeze", env.value }
1291 /// Query backing `Ty::is_unpin`.
1292 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1293 desc { "computing whether `{}` is `Unpin`", env.value }
1296 /// Query backing `Ty::needs_drop`.
1297 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1298 desc { "computing whether `{}` needs drop", env.value }
1301 /// Query backing `Ty::has_significant_drop_raw`.
1302 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1303 desc { "computing whether `{}` has a significant drop", env.value }
1307 /// Query backing `Ty::is_structural_eq_shallow`.
1309 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1311 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1313 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1318 /// A list of types where the ADT requires drop if and only if any of
1319 /// those types require drop. If the ADT is known to always need drop
1320 /// then `Err(AlwaysRequiresDrop)` is returned.
1321 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1322 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1323 cache_on_disk_if { true }
1326 /// A list of types where the ADT requires drop if and only if any of those types
1327 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1328 /// is considered to not be significant. A drop is significant if it is implemented
1329 /// by the user or does anything that will have any observable behavior (other than
1330 /// freeing up memory). If the ADT is known to have a significant destructor then
1331 /// `Err(AlwaysRequiresDrop)` is returned.
1332 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1333 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1334 cache_on_disk_if { false }
1337 /// Computes the layout of a type. Note that this implicitly
1338 /// executes in "reveal all" mode, and will normalize the input type.
1340 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1341 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1343 desc { "computing layout of `{}`", key.value }
1347 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1349 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1350 /// instead, where the instance is an `InstanceDef::Virtual`.
1351 query fn_abi_of_fn_ptr(
1352 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1353 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1354 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1358 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1359 /// direct calls to an `fn`.
1361 /// NB: that includes virtual calls, which are represented by "direct calls"
1362 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1363 query fn_abi_of_instance(
1364 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1365 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1366 desc { "computing call ABI of `{}`", key.value.0 }
1370 query dylib_dependency_formats(_: CrateNum)
1371 -> &'tcx [(CrateNum, LinkagePreference)] {
1372 desc { "getting dylib dependency formats of crate" }
1373 separate_provide_extern
1376 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1378 desc { "getting the linkage format of all dependencies" }
1381 query is_compiler_builtins(_: CrateNum) -> bool {
1383 desc { "checking if the crate is_compiler_builtins" }
1384 separate_provide_extern
1386 query has_global_allocator(_: CrateNum) -> bool {
1387 // This query depends on untracked global state in CStore
1390 desc { "checking if the crate has_global_allocator" }
1391 separate_provide_extern
1393 query has_alloc_error_handler(_: CrateNum) -> bool {
1394 // This query depends on untracked global state in CStore
1397 desc { "checking if the crate has_alloc_error_handler" }
1398 separate_provide_extern
1400 query has_panic_handler(_: CrateNum) -> bool {
1402 desc { "checking if the crate has_panic_handler" }
1403 separate_provide_extern
1405 query is_profiler_runtime(_: CrateNum) -> bool {
1407 desc { "checking if a crate is `#![profiler_runtime]`" }
1408 separate_provide_extern
1410 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1411 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1412 cache_on_disk_if { true }
1414 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1416 desc { "getting a crate's required panic strategy" }
1417 separate_provide_extern
1419 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1421 desc { "getting a crate's configured panic-in-drop strategy" }
1422 separate_provide_extern
1424 query is_no_builtins(_: CrateNum) -> bool {
1426 desc { "getting whether a crate has `#![no_builtins]`" }
1427 separate_provide_extern
1429 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1431 desc { "getting a crate's symbol mangling version" }
1432 separate_provide_extern
1435 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1437 desc { "getting crate's ExternCrateData" }
1438 separate_provide_extern
1441 query specializes(_: (DefId, DefId)) -> bool {
1442 desc { "computing whether impls specialize one another" }
1444 query in_scope_traits_map(_: hir::OwnerId)
1445 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1446 desc { "getting traits in scope at a block" }
1449 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1450 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1453 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1454 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1455 cache_on_disk_if { def_id.is_local() }
1456 separate_provide_extern
1459 query check_well_formed(key: hir::OwnerId) -> () {
1460 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1463 // The `DefId`s of all non-generic functions and statics in the given crate
1464 // that can be reached from outside the crate.
1466 // We expect this items to be available for being linked to.
1468 // This query can also be called for `LOCAL_CRATE`. In this case it will
1469 // compute which items will be reachable to other crates, taking into account
1470 // the kind of crate that is currently compiled. Crates with only a
1471 // C interface have fewer reachable things.
1473 // Does not include external symbols that don't have a corresponding DefId,
1474 // like the compiler-generated `main` function and so on.
1475 query reachable_non_generics(_: CrateNum)
1476 -> DefIdMap<SymbolExportInfo> {
1478 desc { "looking up the exported symbols of a crate" }
1479 separate_provide_extern
1481 query is_reachable_non_generic(def_id: DefId) -> bool {
1482 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1483 cache_on_disk_if { def_id.is_local() }
1484 separate_provide_extern
1486 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1488 "checking whether `{}` is reachable from outside the crate",
1489 tcx.def_path_str(def_id.to_def_id()),
1493 /// The entire set of monomorphizations the local crate can safely link
1494 /// to because they are exported from upstream crates. Do not depend on
1495 /// this directly, as its value changes anytime a monomorphization gets
1496 /// added or removed in any upstream crate. Instead use the narrower
1497 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1498 /// better, `Instance::upstream_monomorphization()`.
1499 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1501 desc { "collecting available upstream monomorphizations" }
1504 /// Returns the set of upstream monomorphizations available for the
1505 /// generic function identified by the given `def_id`. The query makes
1506 /// sure to make a stable selection if the same monomorphization is
1507 /// available in multiple upstream crates.
1509 /// You likely want to call `Instance::upstream_monomorphization()`
1510 /// instead of invoking this query directly.
1511 query upstream_monomorphizations_for(def_id: DefId)
1512 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1516 "collecting available upstream monomorphizations for `{}`",
1517 tcx.def_path_str(def_id),
1519 separate_provide_extern
1522 /// Returns the upstream crate that exports drop-glue for the given
1523 /// type (`substs` is expected to be a single-item list containing the
1524 /// type one wants drop-glue for).
1526 /// This is a subset of `upstream_monomorphizations_for` in order to
1527 /// increase dep-tracking granularity. Otherwise adding or removing any
1528 /// type with drop-glue in any upstream crate would invalidate all
1529 /// functions calling drop-glue of an upstream type.
1531 /// You likely want to call `Instance::upstream_monomorphization()`
1532 /// instead of invoking this query directly.
1534 /// NOTE: This query could easily be extended to also support other
1535 /// common functions that have are large set of monomorphizations
1536 /// (like `Clone::clone` for example).
1537 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1538 desc { "available upstream drop-glue for `{:?}`", substs }
1541 /// Returns a list of all `extern` blocks of a crate.
1542 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1544 desc { "looking up the foreign modules of a linked crate" }
1545 separate_provide_extern
1548 /// Identifies the entry-point (e.g., the `main` function) for a given
1549 /// crate, returning `None` if there is no entry point (such as for library crates).
1550 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1551 desc { "looking up the entry function of a crate" }
1554 /// Finds the `rustc_proc_macro_decls` item of a crate.
1555 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1556 desc { "looking up the proc macro declarations for a crate" }
1559 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1560 // Changing the name should cause a compiler error, but in case that changes, be aware.
1561 query crate_hash(_: CrateNum) -> Svh {
1563 desc { "looking up the hash a crate" }
1564 separate_provide_extern
1567 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1568 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1570 desc { "looking up the hash of a host version of a crate" }
1571 separate_provide_extern
1574 /// Gets the extra data to put in each output filename for a crate.
1575 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1576 query extra_filename(_: CrateNum) -> String {
1579 desc { "looking up the extra filename for a crate" }
1580 separate_provide_extern
1583 /// Gets the paths where the crate came from in the file system.
1584 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1587 desc { "looking up the paths for extern crates" }
1588 separate_provide_extern
1591 /// Given a crate and a trait, look up all impls of that trait in the crate.
1592 /// Return `(impl_id, self_ty)`.
1593 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1594 desc { "looking up implementations of a trait in a crate" }
1595 separate_provide_extern
1598 /// Collects all incoherent impls for the given crate and type.
1600 /// Do not call this directly, but instead use the `incoherent_impls` query.
1601 /// This query is only used to get the data necessary for that query.
1602 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1603 desc { |tcx| "collecting all impls for a type in a crate" }
1604 separate_provide_extern
1607 /// Get the corresponding native library from the `native_libraries` query
1608 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1609 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1612 /// Does lifetime resolution on items. Importantly, we can't resolve
1613 /// lifetimes directly on things like trait methods, because of trait params.
1614 /// See `rustc_resolve::late::lifetimes for details.
1615 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1617 desc { "resolving lifetimes" }
1619 query named_region_map(_: hir::OwnerId) ->
1620 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1621 desc { "looking up a named region" }
1623 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1624 desc { "testing if a region is late bound" }
1626 /// For a given item's generic parameter, gets the default lifetimes to be used
1627 /// for each parameter if a trait object were to be passed for that parameter.
1628 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1629 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1630 /// This query will panic if passed something that is not a type parameter.
1631 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1632 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1633 separate_provide_extern
1635 query late_bound_vars_map(_: hir::OwnerId)
1636 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1637 desc { "looking up late bound vars" }
1640 /// Computes the visibility of the provided `def_id`.
1642 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1643 /// a generic type parameter will panic if you call this method on it:
1646 /// use std::fmt::Debug;
1648 /// pub trait Foo<T: Debug> {}
1651 /// In here, if you call `visibility` on `T`, it'll panic.
1652 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1653 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1654 separate_provide_extern
1657 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1658 desc { "computing the uninhabited predicate of `{:?}`", key }
1661 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1662 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1663 desc { "computing the uninhabited predicate of `{}`", key }
1666 query dep_kind(_: CrateNum) -> CrateDepKind {
1668 desc { "fetching what a dependency looks like" }
1669 separate_provide_extern
1672 /// Gets the name of the crate.
1673 query crate_name(_: CrateNum) -> Symbol {
1675 desc { "fetching what a crate is named" }
1676 separate_provide_extern
1678 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1679 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1680 separate_provide_extern
1682 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1683 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1686 query lib_features(_: ()) -> LibFeatures {
1688 desc { "calculating the lib features map" }
1690 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1691 desc { "calculating the lib features defined in a crate" }
1692 separate_provide_extern
1694 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1696 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1697 separate_provide_extern
1699 /// Whether the function is an intrinsic
1700 query is_intrinsic(def_id: DefId) -> bool {
1701 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1702 separate_provide_extern
1704 /// Returns the lang items defined in another crate by loading it from metadata.
1705 query get_lang_items(_: ()) -> LanguageItems {
1708 desc { "calculating the lang items map" }
1711 /// Returns all diagnostic items defined in all crates.
1712 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1715 desc { "calculating the diagnostic items map" }
1718 /// Returns the lang items defined in another crate by loading it from metadata.
1719 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1720 desc { "calculating the lang items defined in a crate" }
1721 separate_provide_extern
1724 /// Returns the diagnostic items defined in a crate.
1725 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1727 desc { "calculating the diagnostic items map in a crate" }
1728 separate_provide_extern
1731 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1732 desc { "calculating the missing lang items in a crate" }
1733 separate_provide_extern
1735 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1737 desc { "calculating the visible parent map" }
1739 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1741 desc { "calculating trimmed def paths" }
1743 query missing_extern_crate_item(_: CrateNum) -> bool {
1745 desc { "seeing if we're missing an `extern crate` item for this crate" }
1746 separate_provide_extern
1748 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1751 desc { "looking at the source for a crate" }
1752 separate_provide_extern
1754 /// Returns the debugger visualizers defined for this crate.
1755 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1757 desc { "looking up the debugger visualizers for this crate" }
1758 separate_provide_extern
1760 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1762 desc { "generating a postorder list of CrateNums" }
1764 /// Returns whether or not the crate with CrateNum 'cnum'
1765 /// is marked as a private dependency
1766 query is_private_dep(c: CrateNum) -> bool {
1768 desc { "checking whether crate `{}` is a private dependency", c }
1769 separate_provide_extern
1771 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1773 desc { "getting the allocator kind for the current crate" }
1775 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1777 desc { "alloc error handler kind for the current crate" }
1780 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1781 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1783 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1784 desc { "fetching potentially unused trait imports" }
1786 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1787 desc { "looking up all possibly unused extern crates" }
1789 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1790 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1793 query stability_index(_: ()) -> stability::Index {
1796 desc { "calculating the stability index for the local crate" }
1798 query crates(_: ()) -> &'tcx [CrateNum] {
1800 desc { "fetching all foreign CrateNum instances" }
1803 /// A list of all traits in a crate, used by rustdoc and error reporting.
1804 /// NOTE: Not named just `traits` due to a naming conflict.
1805 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1806 desc { "fetching all traits in a crate" }
1807 separate_provide_extern
1810 /// The list of symbols exported from the given crate.
1812 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1813 /// correspond to a publicly visible symbol in `cnum` machine code.
1814 /// - The `exported_symbols` sets of different crates do not intersect.
1815 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1816 desc { "collecting exported symbols for crate `{}`", cnum}
1817 cache_on_disk_if { *cnum == LOCAL_CRATE }
1818 separate_provide_extern
1821 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1823 desc { "collect_and_partition_mono_items" }
1826 query is_codegened_item(def_id: DefId) -> bool {
1827 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1830 /// All items participating in code generation together with items inlined into them.
1831 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1833 desc { "collecting codegened and inlined items" }
1836 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1837 desc { "getting codegen unit `{sym}`" }
1840 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1841 cache_on_disk_if { key.def_id().is_local() }
1843 |tcx| "determining which generic parameters are unused by `{}`",
1844 tcx.def_path_str(key.def_id())
1846 separate_provide_extern
1849 query backend_optimization_level(_: ()) -> OptLevel {
1850 desc { "optimization level used by backend" }
1853 /// Return the filenames where output artefacts shall be stored.
1855 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1856 /// has been destroyed.
1857 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1859 desc { "getting output filenames" }
1862 /// Do not call this query directly: invoke `normalize` instead.
1863 query normalize_projection_ty(
1864 goal: CanonicalProjectionGoal<'tcx>
1866 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1869 desc { "normalizing `{}`", goal.value.value }
1873 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1874 query try_normalize_generic_arg_after_erasing_regions(
1875 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1876 ) -> Result<GenericArg<'tcx>, NoSolution> {
1877 desc { "normalizing `{}`", goal.value }
1881 query implied_outlives_bounds(
1882 goal: CanonicalTyGoal<'tcx>
1884 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1887 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1891 /// Do not call this query directly:
1892 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1893 query dropck_outlives(
1894 goal: CanonicalTyGoal<'tcx>
1896 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1899 desc { "computing dropck types for `{}`", goal.value.value }
1903 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1904 /// `infcx.predicate_must_hold()` instead.
1905 query evaluate_obligation(
1906 goal: CanonicalPredicateGoal<'tcx>
1907 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1908 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1911 query evaluate_goal(
1912 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1914 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1917 desc { "evaluating trait selection obligation `{}`", goal.value }
1920 /// Do not call this query directly: part of the `Eq` type-op
1921 query type_op_ascribe_user_type(
1922 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1924 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1927 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1931 /// Do not call this query directly: part of the `Eq` type-op
1933 goal: CanonicalTypeOpEqGoal<'tcx>
1935 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1938 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1942 /// Do not call this query directly: part of the `Subtype` type-op
1943 query type_op_subtype(
1944 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1946 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1949 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1953 /// Do not call this query directly: part of the `ProvePredicate` type-op
1954 query type_op_prove_predicate(
1955 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1957 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1960 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1963 /// Do not call this query directly: part of the `Normalize` type-op
1964 query type_op_normalize_ty(
1965 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1967 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1970 desc { "normalizing `{}`", goal.value.value.value }
1974 /// Do not call this query directly: part of the `Normalize` type-op
1975 query type_op_normalize_predicate(
1976 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1978 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1981 desc { "normalizing `{:?}`", goal.value.value.value }
1985 /// Do not call this query directly: part of the `Normalize` type-op
1986 query type_op_normalize_poly_fn_sig(
1987 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1989 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1992 desc { "normalizing `{:?}`", goal.value.value.value }
1996 /// Do not call this query directly: part of the `Normalize` type-op
1997 query type_op_normalize_fn_sig(
1998 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2000 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2003 desc { "normalizing `{:?}`", goal.value.value.value }
2007 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2009 "checking impossible substituted predicates: `{}`",
2010 tcx.def_path_str(key.0)
2014 query is_impossible_method(key: (DefId, DefId)) -> bool {
2016 "checking if `{}` is impossible to call within `{}`",
2017 tcx.def_path_str(key.1),
2018 tcx.def_path_str(key.0),
2022 query method_autoderef_steps(
2023 goal: CanonicalTyGoal<'tcx>
2024 ) -> MethodAutoderefStepsResult<'tcx> {
2025 desc { "computing autoderef types for `{}`", goal.value.value }
2029 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2032 desc { "looking up supported target features" }
2035 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2036 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2038 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2041 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2043 desc { "looking up enabled feature gates" }
2046 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2047 /// given generics args (`SubstsRef`), returning one of:
2048 /// * `Ok(Some(instance))` on success
2049 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2050 /// and therefore don't allow finding the final `Instance`
2051 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2052 /// couldn't complete due to errors elsewhere - this is distinct
2053 /// from `Ok(None)` to avoid misleading diagnostics when an error
2054 /// has already been/will be emitted, for the original cause
2055 query resolve_instance(
2056 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2057 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2058 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2062 query resolve_instance_of_const_arg(
2063 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2064 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2066 "resolving instance of the const argument `{}`",
2067 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2072 query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2073 desc { "revealing opaque types in `{:?}`", key }
2076 query limits(key: ()) -> Limits {
2077 desc { "looking up limits" }
2080 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2081 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2082 /// the cause of the newly created obligation.
2084 /// This is only used by error-reporting code to get a better cause (in particular, a better
2085 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2086 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2087 /// because the `ty::Ty`-based wfcheck is always run.
2088 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2092 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2096 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2097 /// `--target` and similar).
2098 query global_backend_features(_: ()) -> Vec<String> {
2101 desc { "computing the backend features for CLI flags" }
2104 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2106 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2107 separate_provide_extern
2110 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2111 desc { "checking to see if `{}` permits being left uninit", key.ty }
2114 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2115 desc { "checking to see if `{}` permits being left zeroed", key.ty }
2118 query compare_assoc_const_impl_item_with_trait_item(
2119 key: (LocalDefId, DefId)
2120 ) -> Result<(), ErrorGuaranteed> {
2121 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2124 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2125 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2126 separate_provide_extern