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 // Each of these queries corresponds to a function pointer field in the
8 // `Providers` struct for requesting a value of that type, and a method
9 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
10 // which memoizes and does dep-graph tracking, wrapping around the actual
11 // `Providers` that the driver creates (using several `rustc_*` crates).
13 // The result type of each query must implement `Clone`, and additionally
14 // `ty::query::values::Value`, which produces an appropriate placeholder
15 // (error) value if the query resulted in a query cycle.
16 // Queries marked with `fatal_cycle` do not need the latter implementation,
17 // as they will raise an fatal error on query cycles instead.
19 query trigger_delay_span_bug(key: DefId) -> () {
20 desc { "trigger a delay span bug" }
23 query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
26 desc { "get the resolver outputs" }
29 query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
32 desc { "get the resolver for lowering" }
35 /// Return the span for a definition.
36 /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
37 /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
38 /// of rustc_middle::hir::source_map.
39 query source_span(key: LocalDefId) -> Span {
40 desc { "get the source span" }
43 /// Represents crate as a whole (as distinct from the top-level crate module).
44 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
45 /// we will have to assume that any change means that you need to be recompiled.
46 /// This is because the `hir_crate` query gives you access to all other items.
47 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
48 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
49 query hir_crate(key: ()) -> Crate<'tcx> {
52 desc { "get the crate HIR" }
55 /// All items in the crate.
56 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
59 desc { "get HIR crate items" }
62 /// The items in a module.
64 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
65 /// Avoid calling this query directly.
66 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
68 desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
69 cache_on_disk_if { true }
72 /// Gives access to the HIR node for the HIR owner `key`.
74 /// This can be conveniently accessed by methods on `tcx.hir()`.
75 /// Avoid calling this query directly.
76 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
77 desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
80 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
85 desc { |tcx| "HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
88 /// Gives access to the HIR node's parent for the HIR owner `key`.
90 /// This can be conveniently accessed by methods on `tcx.hir()`.
91 /// Avoid calling this query directly.
92 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
93 desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
98 /// This can be conveniently accessed by methods on `tcx.hir()`.
99 /// Avoid calling this query directly.
100 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
101 desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
104 /// Gives access to the HIR attributes inside the HIR owner `key`.
106 /// This can be conveniently accessed by methods on `tcx.hir()`.
107 /// Avoid calling this query directly.
108 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
109 desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
113 /// const argument and returns `None` otherwise.
115 /// ```ignore (incomplete)
116 /// let a = foo::<7>();
117 /// // ^ Calling `opt_const_param_of` for this argument,
119 /// fn foo<const N: usize>()
120 /// // ^ returns this `DefId`.
123 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
126 // It looks like caching this query on disk actually slightly
127 // worsened performance in #74376.
129 // Once const generics are more prevalently used, we might want to
130 // consider only caching calls returning `Some`.
131 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
132 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
135 /// Given the def_id of a const-generic parameter, computes the associated default const
136 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
137 query const_param_default(param: DefId) -> ty::Const<'tcx> {
138 desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
139 cache_on_disk_if { param.is_local() }
140 separate_provide_extern
143 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
144 /// to an alias, it will "skip" this alias to return the aliased type.
146 /// [`DefId`]: rustc_hir::def_id::DefId
147 query type_of(key: DefId) -> Ty<'tcx> {
151 use rustc_hir::def::DefKind;
152 match tcx.def_kind(key) {
153 DefKind::TyAlias => "expanding type alias",
154 DefKind::TraitAlias => "expanding trait alias",
155 _ => "computing type of",
158 path = tcx.def_path_str(key),
160 cache_on_disk_if { key.is_local() }
161 separate_provide_extern
164 query collect_trait_impl_trait_tys(key: DefId)
165 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
167 desc { "compare an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
168 cache_on_disk_if { key.is_local() }
169 separate_provide_extern
172 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
174 desc { "running analysis passes on this crate" }
177 /// This query checks the fulfillment of collected lint expectations.
178 /// All lint emitting queries have to be done before this is executed
179 /// to ensure that all expectations can be fulfilled.
181 /// This is an extra query to enable other drivers (like rustdoc) to
182 /// only execute a small subset of the `analysis` query, while allowing
183 /// lints to be expected. In rustc, this query will be executed as part of
184 /// the `analysis` query and doesn't have to be called a second time.
186 /// Tools can additionally pass in a tool filter. That will restrict the
187 /// expectations to only trigger for lints starting with the listed tool
188 /// name. This is useful for cases were not all linting code from rustc
189 /// was called. With the default `None` all registered lints will also
190 /// be checked for expectation fulfillment.
191 query check_expectations(key: Option<Symbol>) -> () {
193 desc { "checking lint expectations (RFC 2383)" }
196 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
197 /// associated generics.
198 query generics_of(key: DefId) -> ty::Generics {
199 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
201 cache_on_disk_if { key.is_local() }
202 separate_provide_extern
205 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
206 /// predicates (where-clauses) that must be proven true in order
207 /// to reference it. This is almost always the "predicates query"
210 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
211 /// it is almost always the same as that query, except for the
212 /// case of traits. For traits, `predicates_of` contains
213 /// an additional `Self: Trait<...>` predicate that users don't
214 /// actually write. This reflects the fact that to invoke the
215 /// trait (e.g., via `Default::default`) you must supply types
216 /// that actually implement the trait. (However, this extra
217 /// predicate gets in the way of some checks, which are intended
218 /// to operate over only the actual where-clauses written by the
220 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
221 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
222 cache_on_disk_if { key.is_local() }
225 /// Returns the list of bounds that can be used for
226 /// `SelectionCandidate::ProjectionCandidate(_)` and
227 /// `ProjectionTyCandidate::TraitDef`.
228 /// Specifically this is the bounds written on the trait's type
229 /// definition, or those after the `impl` keyword
231 /// ```ignore (incomplete)
232 /// type X: Bound + 'lt
234 /// impl Debug + Display
235 /// // ^^^^^^^^^^^^^^^
238 /// `key` is the `DefId` of the associated type or opaque type.
240 /// Bounds from the parent (e.g. with nested impl trait) are not included.
241 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
242 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
243 cache_on_disk_if { key.is_local() }
244 separate_provide_extern
247 /// Elaborated version of the predicates from `explicit_item_bounds`.
253 /// type MyAType: Eq + ?Sized;
257 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
258 /// and `item_bounds` returns
261 /// <Self as Trait>::MyAType: Eq,
262 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
266 /// Bounds from the parent (e.g. with nested impl trait) are not included.
267 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
268 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
271 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
273 desc { "looking up the native libraries of a linked crate" }
274 separate_provide_extern
277 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
278 eval_always // fetches `resolutions`
280 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
283 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
285 desc { "computing `#[expect]`ed lints in this crate" }
288 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
290 desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
293 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
294 desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
295 separate_provide_extern
298 query is_panic_runtime(_: CrateNum) -> bool {
300 desc { "checking if the crate is_panic_runtime" }
301 separate_provide_extern
304 /// Checks whether a type is representable or infinitely sized
305 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
306 desc { "checking if {:?} is representable", tcx.def_path_str(key.to_def_id()) }
307 // infinitely sized types will cause a cycle
309 // we don't want recursive representability calls to be forced with
310 // incremental compilation because, if a cycle occurs, we need the
311 // entire cycle to be in memory for diagnostics
315 /// An implementation detail for the `representability` query
316 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
317 desc { "checking if {:?} is representable", key }
322 /// Set of param indexes for type params that are in the type's representation
323 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
324 desc { "finding type parameters in the representation" }
327 separate_provide_extern
330 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
331 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
332 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
334 // Perf tests revealed that hashing THIR is inefficient (see #85729).
336 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
339 /// Create a THIR tree for debugging.
340 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
343 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
346 /// Set of all the `DefId`s in this crate that have MIR associated with
347 /// them. This includes all the body owners, but also things like struct
349 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
351 desc { "getting a list of all mir_keys" }
354 /// Maps DefId's that have an associated `mir::Body` to the result
355 /// of the MIR const-checking pass. This is the set of qualifs in
356 /// the final value of a `const`.
357 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
358 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
359 cache_on_disk_if { key.is_local() }
360 separate_provide_extern
362 query mir_const_qualif_const_arg(
363 key: (LocalDefId, DefId)
364 ) -> mir::ConstQualifs {
366 |tcx| "const checking the const argument `{}`",
367 tcx.def_path_str(key.0.to_def_id())
371 /// Fetch the MIR for a given `DefId` right after it's built - this includes
372 /// unreachable code.
373 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
374 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
377 /// Fetch the MIR for a given `DefId` up till the point where it is
378 /// ready for const qualification.
380 /// See the README for the `mir` module for details.
381 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
383 |tcx| "processing MIR for {}`{}`",
384 if key.const_param_did.is_some() { "the const argument " } else { "" },
385 tcx.def_path_str(key.did.to_def_id()),
390 /// Try to build an abstract representation of the given constant.
391 query thir_abstract_const(
393 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
395 |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
397 separate_provide_extern
399 /// Try to build an abstract representation of the given constant.
400 query thir_abstract_const_of_const_arg(
401 key: (LocalDefId, DefId)
402 ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
405 "building an abstract representation for the const argument {}",
406 tcx.def_path_str(key.0.to_def_id()),
410 query try_unify_abstract_consts(key:
411 ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
414 |tcx| "trying to unify the generic constants {} and {}",
415 tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
419 query mir_drops_elaborated_and_const_checked(
420 key: ty::WithOptConstParam<LocalDefId>
421 ) -> &'tcx Steal<mir::Body<'tcx>> {
423 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
428 ) -> &'tcx mir::Body<'tcx> {
429 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
430 cache_on_disk_if { key.is_local() }
431 separate_provide_extern
434 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
436 |tcx| "MIR for CTFE of the const argument `{}`",
437 tcx.def_path_str(key.0.to_def_id())
441 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
443 &'tcx Steal<mir::Body<'tcx>>,
444 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
448 |tcx| "processing {}`{}`",
449 if key.const_param_did.is_some() { "the const argument " } else { "" },
450 tcx.def_path_str(key.did.to_def_id()),
454 query symbols_for_closure_captures(
455 key: (LocalDefId, LocalDefId)
456 ) -> Vec<rustc_span::Symbol> {
459 |tcx| "symbols for captures of closure `{}` in `{}`",
460 tcx.def_path_str(key.1.to_def_id()),
461 tcx.def_path_str(key.0.to_def_id())
465 /// MIR after our optimization passes have run. This is MIR that is ready
466 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
467 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
468 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
469 cache_on_disk_if { key.is_local() }
470 separate_provide_extern
473 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
474 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
475 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
476 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
480 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
481 /// function was optimized out before codegen, and before being added to the Coverage Map.
482 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
484 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
485 tcx.def_path_str(key)
488 cache_on_disk_if { key.is_local() }
491 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
492 /// `DefId`. This function returns all promoteds in the specified body. The body references
493 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
494 /// after inlining a body may refer to promoteds from other bodies. In that case you still
495 /// need to use the `DefId` of the original body.
496 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
497 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
498 cache_on_disk_if { key.is_local() }
499 separate_provide_extern
501 query promoted_mir_of_const_arg(
502 key: (LocalDefId, DefId)
503 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
505 |tcx| "optimizing promoted MIR for the const argument `{}`",
506 tcx.def_path_str(key.0.to_def_id()),
510 /// Erases regions from `ty` to yield a new type.
511 /// Normally you would just use `tcx.erase_regions(value)`,
512 /// however, which uses this query as a kind of cache.
513 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
514 // This query is not expected to have input -- as a result, it
515 // is not a good candidates for "replay" because it is essentially a
516 // pure function of its input (and hence the expectation is that
517 // no caller would be green **apart** from just these
518 // queries). Making it anonymous avoids hashing the result, which
519 // may save a bit of time.
521 desc { "erasing regions from `{:?}`", ty }
524 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
526 desc { "wasm import module map" }
529 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
530 /// predicates (where-clauses) directly defined on it. This is
531 /// equal to the `explicit_predicates_of` predicates plus the
532 /// `inferred_outlives_of` predicates.
533 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
534 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
537 /// Returns everything that looks like a predicate written explicitly
538 /// by the user on a trait item.
540 /// Traits are unusual, because predicates on associated types are
541 /// converted into bounds on that type for backwards compatibility:
543 /// trait X where Self::U: Copy { type U; }
547 /// trait X { type U: Copy; }
549 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
550 /// the appropriate subsets of the predicates here.
551 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
552 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
555 /// Returns the predicates written explicitly by the user.
556 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
557 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
558 cache_on_disk_if { key.is_local() }
559 separate_provide_extern
562 /// Returns the inferred outlives predicates (e.g., for `struct
563 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
564 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
565 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
566 cache_on_disk_if { key.is_local() }
567 separate_provide_extern
570 /// Maps from the `DefId` of a trait to the list of
571 /// super-predicates. This is a subset of the full list of
572 /// predicates. We store these in a separate map because we must
573 /// evaluate them even during type conversion, often before the
574 /// full predicates are available (note that supertraits have
575 /// additional acyclicity requirements).
576 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
577 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
578 cache_on_disk_if { key.is_local() }
579 separate_provide_extern
582 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
583 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
584 /// subset of super-predicates that reference traits that define the given associated type.
585 /// This is used to avoid cycles in resolving types like `T::Item`.
586 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
587 desc { |tcx| "computing the super traits of `{}`{}",
588 tcx.def_path_str(key.0),
589 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
593 /// To avoid cycles within the predicates of a single item we compute
594 /// per-type-parameter predicates for resolving `T::AssocTy`.
595 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
596 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
599 query trait_def(key: DefId) -> ty::TraitDef {
600 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
602 cache_on_disk_if { key.is_local() }
603 separate_provide_extern
605 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
606 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
607 cache_on_disk_if { key.is_local() }
608 separate_provide_extern
610 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
611 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
612 cache_on_disk_if { key.is_local() }
613 separate_provide_extern
616 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
617 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
620 query adt_dtorck_constraint(
622 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
623 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
626 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
627 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
628 /// not have the feature gate active).
630 /// **Do not call this function manually.** It is only meant to cache the base data for the
631 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
632 query constness(key: DefId) -> hir::Constness {
633 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
634 cache_on_disk_if { key.is_local() }
635 separate_provide_extern
638 query asyncness(key: DefId) -> hir::IsAsync {
639 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
640 cache_on_disk_if { key.is_local() }
641 separate_provide_extern
644 /// Returns `true` if calls to the function may be promoted.
646 /// This is either because the function is e.g., a tuple-struct or tuple-variant
647 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
648 /// be removed in the future in favour of some form of check which figures out whether the
649 /// function does not inspect the bits of any of its arguments (so is essentially just a
650 /// constructor function).
651 query is_promotable_const_fn(key: DefId) -> bool {
652 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
655 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
656 query is_foreign_item(key: DefId) -> bool {
657 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
658 cache_on_disk_if { key.is_local() }
659 separate_provide_extern
662 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
663 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
664 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
665 cache_on_disk_if { def_id.is_local() }
666 separate_provide_extern
669 /// Gets a map with the variance of every item; use `item_variance` instead.
670 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
672 desc { "computing the variances for items in this crate" }
675 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
676 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
677 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
678 cache_on_disk_if { def_id.is_local() }
679 separate_provide_extern
682 /// Maps from thee `DefId` of a type to its (inferred) outlives.
683 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
685 desc { "computing the inferred outlives predicates for items in this crate" }
688 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
689 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
690 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
691 cache_on_disk_if { key.is_local() }
692 separate_provide_extern
695 /// Maps from a trait item to the trait item "descriptor".
696 query associated_item(key: DefId) -> ty::AssocItem {
697 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
699 cache_on_disk_if { key.is_local() }
700 separate_provide_extern
703 /// Collects the associated items defined on a trait or impl.
704 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
706 desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
709 /// Maps from associated items on a trait to the corresponding associated
710 /// item on the impl specified by `impl_id`.
712 /// For example, with the following code
717 /// trait Trait { // trait_id
718 /// fn f(); // trait_f
719 /// fn g() {} // trait_g
722 /// impl Trait for Type { // impl_id
723 /// fn f() {} // impl_f
724 /// fn g() {} // impl_g
728 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
729 ///`{ trait_f: impl_f, trait_g: impl_g }`
730 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
732 desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
735 /// Given an `impl_id`, return the trait it implements.
736 /// Return `None` if this is an inherent impl.
737 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
738 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
739 cache_on_disk_if { impl_id.is_local() }
740 separate_provide_extern
742 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
743 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
744 cache_on_disk_if { impl_id.is_local() }
745 separate_provide_extern
748 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
749 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
752 /// Maps a `DefId` of a type to a list of its inherent impls.
753 /// Contains implementations of methods that are inherent to a type.
754 /// Methods in these implementations don't need to be exported.
755 query inherent_impls(key: DefId) -> &'tcx [DefId] {
756 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
757 cache_on_disk_if { key.is_local() }
758 separate_provide_extern
761 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
762 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
765 /// The result of unsafety-checking this `LocalDefId`.
766 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
767 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
768 cache_on_disk_if { true }
770 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
772 |tcx| "unsafety-checking the const argument `{}`",
773 tcx.def_path_str(key.0.to_def_id())
777 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
778 /// used with `-Zthir-unsafeck`.
779 query thir_check_unsafety(key: LocalDefId) {
780 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
781 cache_on_disk_if { true }
783 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
785 |tcx| "unsafety-checking the const argument `{}`",
786 tcx.def_path_str(key.0.to_def_id())
790 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
792 /// Unsafety checking is executed for each method separately, but we only want
793 /// to emit this error once per derive. As there are some impls with multiple
794 /// methods, we use a query for deduplication.
795 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
796 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
799 /// Returns the types assumed to be well formed while "inside" of the given item.
801 /// Note that we've liberated the late bound regions of function signatures, so
802 /// this can not be used to check whether these types are well formed.
803 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
804 desc { |tcx| "computing the implied bounds of {}", tcx.def_path_str(key) }
807 /// Computes the signature of the function.
808 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
809 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
810 cache_on_disk_if { key.is_local() }
811 separate_provide_extern
815 /// Performs lint checking for the module.
816 query lint_mod(key: LocalDefId) -> () {
817 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
820 /// Checks the attributes in the module.
821 query check_mod_attrs(key: LocalDefId) -> () {
822 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
825 /// Checks for uses of unstable APIs in the module.
826 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
827 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
830 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
831 query check_mod_const_bodies(key: LocalDefId) -> () {
832 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
835 /// Checks the loops in the module.
836 query check_mod_loops(key: LocalDefId) -> () {
837 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
840 query check_mod_naked_functions(key: LocalDefId) -> () {
841 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
844 query check_mod_item_types(key: LocalDefId) -> () {
845 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
848 query check_mod_privacy(key: LocalDefId) -> () {
849 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
852 query check_liveness(key: DefId) {
853 desc { |tcx| "checking liveness of variables in {}", tcx.def_path_str(key) }
856 /// Return the live symbols in the crate for dead code check.
858 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
859 /// their respective impl (i.e., part of the derive macro)
860 query live_symbols_and_ignored_derived_traits(_: ()) -> (
861 FxHashSet<LocalDefId>,
862 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
865 desc { "find live symbols in crate" }
868 query check_mod_deathness(key: LocalDefId) -> () {
869 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
872 query check_mod_impl_wf(key: LocalDefId) -> () {
873 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
876 query check_mod_type_wf(key: LocalDefId) -> () {
877 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
880 query collect_mod_item_types(key: LocalDefId) -> () {
881 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
884 /// Caches `CoerceUnsized` kinds for impls on custom types.
885 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
886 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
887 cache_on_disk_if { key.is_local() }
888 separate_provide_extern
891 query typeck_item_bodies(_: ()) -> () {
892 desc { "type-checking all item bodies" }
895 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
896 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
897 cache_on_disk_if { true }
899 query typeck_const_arg(
900 key: (LocalDefId, DefId)
901 ) -> &'tcx ty::TypeckResults<'tcx> {
903 |tcx| "type-checking the const argument `{}`",
904 tcx.def_path_str(key.0.to_def_id()),
907 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
908 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
909 cache_on_disk_if { true }
912 query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
913 desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
914 cache_on_disk_if { true }
917 query has_typeck_results(def_id: DefId) -> bool {
918 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
921 query coherent_trait(def_id: DefId) -> () {
922 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
925 /// Borrow-checks the function body. If this is a closure, returns
926 /// additional requirements that the closure's creator must verify.
927 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
928 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
929 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
931 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
933 |tcx| "borrow-checking the const argument`{}`",
934 tcx.def_path_str(key.0.to_def_id())
938 /// Gets a complete map from all types to their inherent impls.
939 /// Not meant to be used directly outside of coherence.
940 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
942 desc { "all inherent impls defined in crate" }
945 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
946 /// Not meant to be used directly outside of coherence.
947 query crate_inherent_impls_overlap_check(_: ()) -> () {
948 desc { "check for overlap between inherent impls defined in this crate" }
951 /// Checks whether all impls in the crate pass the overlap check, returning
952 /// which impls fail it. If all impls are correct, the returned slice is empty.
953 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
955 "checking whether impl `{}` follows the orphan rules",
956 tcx.def_path_str(key.to_def_id()),
960 /// Check whether the function has any recursion that could cause the inliner to trigger
961 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
962 /// current function, just all intermediate functions.
963 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
966 "computing if `{}` (transitively) calls `{}`",
968 tcx.def_path_str(key.1.to_def_id()),
972 /// Obtain all the calls into other local functions
973 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
976 "computing all local function calls in `{}`",
977 tcx.def_path_str(key.def_id()),
981 /// Evaluates a constant and returns the computed allocation.
983 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
984 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
985 -> EvalToAllocationRawResult<'tcx> {
987 "const-evaluating + checking `{}`",
988 key.value.display(tcx)
990 cache_on_disk_if { true }
993 /// Evaluates const items or anonymous constants
994 /// (such as enum variant explicit discriminants or array lengths)
995 /// into a representation suitable for the type system and const generics.
997 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
998 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
999 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1000 -> EvalToConstValueResult<'tcx> {
1002 "simplifying constant for the type system `{}`",
1003 key.value.display(tcx)
1005 cache_on_disk_if { true }
1008 /// Evaluate a constant and convert it to a type level constant or
1009 /// return `None` if that is not possible.
1010 query eval_to_valtree(
1011 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1012 ) -> EvalToValTreeResult<'tcx> {
1013 desc { "evaluating type-level constant" }
1016 /// Converts a type level constant value into `ConstValue`
1017 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1018 desc { "converting type-level constant value to mir constant value"}
1021 /// Destructures array, ADT or tuple constants into the constants
1022 /// of their fields.
1023 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1024 desc { "destructuring type level constant"}
1027 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1028 /// and its field values.
1029 query try_destructure_mir_constant(
1030 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1031 ) -> Option<mir::DestructuredConstant<'tcx>> {
1032 desc { "destructuring mir constant"}
1036 /// Dereference a constant reference or raw pointer and turn the result into a constant
1038 query deref_mir_constant(
1039 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1040 ) -> mir::ConstantKind<'tcx> {
1041 desc { "dereferencing mir constant" }
1045 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1046 desc { "get a &core::panic::Location referring to a span" }
1049 // FIXME get rid of this with valtrees
1051 key: LitToConstInput<'tcx>
1052 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1053 desc { "converting literal to const" }
1056 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1057 desc { "converting literal to mir constant" }
1060 query check_match(key: DefId) {
1061 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1062 cache_on_disk_if { key.is_local() }
1065 /// Performs part of the privacy check and computes "access levels".
1066 query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
1068 desc { "privacy access levels" }
1070 query check_private_in_public(_: ()) -> () {
1072 desc { "checking for private elements in public interfaces" }
1075 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1077 desc { "reachability" }
1080 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1081 /// in the case of closures, this will be redirected to the enclosing function.
1082 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1083 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1086 /// Generates a MIR body for the shim.
1087 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1089 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1092 /// The `symbol_name` query provides the symbol name for calling a
1093 /// given instance from the local crate. In particular, it will also
1094 /// look up the correct symbol name of instances from upstream crates.
1095 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1096 desc { "computing the symbol for `{}`", key }
1097 cache_on_disk_if { true }
1100 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1101 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1102 cache_on_disk_if { def_id.is_local() }
1103 separate_provide_extern
1106 /// Gets the span for the definition.
1107 query def_span(def_id: DefId) -> Span {
1108 desc { |tcx| "looking up span for `{}`", 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 identifier of the definition.
1114 query def_ident_span(def_id: DefId) -> Option<Span> {
1115 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1116 cache_on_disk_if { def_id.is_local() }
1117 separate_provide_extern
1120 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1121 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1122 cache_on_disk_if { def_id.is_local() }
1123 separate_provide_extern
1126 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1127 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1128 cache_on_disk_if { def_id.is_local() }
1129 separate_provide_extern
1132 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1133 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1134 separate_provide_extern
1137 query should_inherit_track_caller(def_id: DefId) -> bool {
1138 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1141 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1142 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1143 cache_on_disk_if { def_id.is_local() }
1144 separate_provide_extern
1147 /// Determines whether an item is annotated with `doc(hidden)`.
1148 query is_doc_hidden(def_id: DefId) -> bool {
1149 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1152 /// Determines whether an item is annotated with `doc(notable_trait)`.
1153 query is_doc_notable_trait(def_id: DefId) -> bool {
1154 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1157 /// Returns the attributes on the item at `def_id`.
1159 /// Do not use this directly, use `tcx.get_attrs` instead.
1160 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1161 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1162 separate_provide_extern
1165 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1166 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1168 cache_on_disk_if { def_id.is_local() }
1169 separate_provide_extern
1172 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1173 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1176 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1177 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1178 cache_on_disk_if { def_id.is_local() }
1179 separate_provide_extern
1181 /// Gets the rendered value of the specified constant or associated constant.
1182 /// Used by rustdoc.
1183 query rendered_const(def_id: DefId) -> String {
1185 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1186 cache_on_disk_if { def_id.is_local() }
1187 separate_provide_extern
1189 query impl_parent(def_id: DefId) -> Option<DefId> {
1190 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1191 cache_on_disk_if { def_id.is_local() }
1192 separate_provide_extern
1195 query is_ctfe_mir_available(key: DefId) -> bool {
1196 desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1197 cache_on_disk_if { key.is_local() }
1198 separate_provide_extern
1200 query is_mir_available(key: DefId) -> bool {
1201 desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1202 cache_on_disk_if { key.is_local() }
1203 separate_provide_extern
1206 query own_existential_vtable_entries(
1207 key: ty::PolyExistentialTraitRef<'tcx>
1208 ) -> &'tcx [DefId] {
1209 desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1212 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1213 -> &'tcx [ty::VtblEntry<'tcx>] {
1214 desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1217 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1218 desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1222 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1223 desc { |tcx| "vtable const allocation for <{} as {}>",
1225 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1229 query codegen_select_candidate(
1230 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1231 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1232 cache_on_disk_if { true }
1233 desc { |tcx| "computing candidate for `{}`", key.1 }
1236 /// Return all `impl` blocks in the current crate.
1237 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1238 desc { "local trait impls" }
1241 /// Given a trait `trait_id`, return all known `impl` blocks.
1242 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1244 desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1247 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1249 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1250 cache_on_disk_if { true }
1252 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1253 desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1256 /// Gets the ParameterEnvironment for a given item; this environment
1257 /// will be in "user-facing" mode, meaning that it is suitable for
1258 /// type-checking etc, and it does not normalize specializable
1259 /// associated types. This is almost always what you want,
1260 /// unless you are doing MIR optimizations, in which case you
1261 /// might want to use `reveal_all()` method to change modes.
1262 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1263 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1266 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1267 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1268 /// as this method is more efficient.
1269 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1270 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1273 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1274 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1275 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1276 desc { "computing whether `{}` is `Copy`", env.value }
1279 /// Query backing `Ty::is_sized`.
1280 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1281 desc { "computing whether `{}` is `Sized`", env.value }
1284 /// Query backing `Ty::is_freeze`.
1285 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1286 desc { "computing whether `{}` is freeze", env.value }
1289 /// Query backing `Ty::is_unpin`.
1290 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1291 desc { "computing whether `{}` is `Unpin`", env.value }
1294 /// Query backing `Ty::needs_drop`.
1295 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1296 desc { "computing whether `{}` needs drop", env.value }
1299 /// Query backing `Ty::has_significant_drop_raw`.
1300 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1301 desc { "computing whether `{}` has a significant drop", env.value }
1305 /// Query backing `Ty::is_structural_eq_shallow`.
1307 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1309 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1311 "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1316 /// A list of types where the ADT requires drop if and only if any of
1317 /// those types require drop. If the ADT is known to always need drop
1318 /// then `Err(AlwaysRequiresDrop)` is returned.
1319 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1320 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1321 cache_on_disk_if { true }
1324 /// A list of types where the ADT requires drop if and only if any of those types
1325 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1326 /// is considered to not be significant. A drop is significant if it is implemented
1327 /// by the user or does anything that will have any observable behavior (other than
1328 /// freeing up memory). If the ADT is known to have a significant destructor then
1329 /// `Err(AlwaysRequiresDrop)` is returned.
1330 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1331 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1332 cache_on_disk_if { false }
1335 /// Computes the layout of a type. Note that this implicitly
1336 /// executes in "reveal all" mode, and will normalize the input type.
1338 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1339 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1341 desc { "computing layout of `{}`", key.value }
1345 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1347 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1348 /// instead, where the instance is an `InstanceDef::Virtual`.
1349 query fn_abi_of_fn_ptr(
1350 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1351 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1352 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1356 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1357 /// direct calls to an `fn`.
1359 /// NB: that includes virtual calls, which are represented by "direct calls"
1360 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1361 query fn_abi_of_instance(
1362 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1363 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1364 desc { "computing call ABI of `{}`", key.value.0 }
1368 query dylib_dependency_formats(_: CrateNum)
1369 -> &'tcx [(CrateNum, LinkagePreference)] {
1370 desc { "dylib dependency formats of crate" }
1371 separate_provide_extern
1374 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1376 desc { "get the linkage format of all dependencies" }
1379 query is_compiler_builtins(_: CrateNum) -> bool {
1381 desc { "checking if the crate is_compiler_builtins" }
1382 separate_provide_extern
1384 query has_global_allocator(_: CrateNum) -> bool {
1385 // This query depends on untracked global state in CStore
1388 desc { "checking if the crate has_global_allocator" }
1389 separate_provide_extern
1391 query has_panic_handler(_: CrateNum) -> bool {
1393 desc { "checking if the crate has_panic_handler" }
1394 separate_provide_extern
1396 query is_profiler_runtime(_: CrateNum) -> bool {
1398 desc { "query a crate is `#![profiler_runtime]`" }
1399 separate_provide_extern
1401 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1402 desc { |tcx| "check if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1403 cache_on_disk_if { true }
1405 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1407 desc { "query a crate's required panic strategy" }
1408 separate_provide_extern
1410 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1412 desc { "query a crate's configured panic-in-drop strategy" }
1413 separate_provide_extern
1415 query is_no_builtins(_: CrateNum) -> bool {
1417 desc { "test whether a crate has `#![no_builtins]`" }
1418 separate_provide_extern
1420 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1422 desc { "query a crate's symbol mangling version" }
1423 separate_provide_extern
1426 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1428 desc { "getting crate's ExternCrateData" }
1429 separate_provide_extern
1432 query specializes(_: (DefId, DefId)) -> bool {
1433 desc { "computing whether impls specialize one another" }
1435 query in_scope_traits_map(_: hir::OwnerId)
1436 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1437 desc { "traits in scope at a block" }
1440 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1441 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1444 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1445 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1446 cache_on_disk_if { def_id.is_local() }
1447 separate_provide_extern
1450 query check_well_formed(key: hir::OwnerId) -> () {
1451 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1454 // The `DefId`s of all non-generic functions and statics in the given crate
1455 // that can be reached from outside the crate.
1457 // We expect this items to be available for being linked to.
1459 // This query can also be called for `LOCAL_CRATE`. In this case it will
1460 // compute which items will be reachable to other crates, taking into account
1461 // the kind of crate that is currently compiled. Crates with only a
1462 // C interface have fewer reachable things.
1464 // Does not include external symbols that don't have a corresponding DefId,
1465 // like the compiler-generated `main` function and so on.
1466 query reachable_non_generics(_: CrateNum)
1467 -> DefIdMap<SymbolExportInfo> {
1469 desc { "looking up the exported symbols of a crate" }
1470 separate_provide_extern
1472 query is_reachable_non_generic(def_id: DefId) -> bool {
1473 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1474 cache_on_disk_if { def_id.is_local() }
1475 separate_provide_extern
1477 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1479 "checking whether `{}` is reachable from outside the crate",
1480 tcx.def_path_str(def_id.to_def_id()),
1484 /// The entire set of monomorphizations the local crate can safely link
1485 /// to because they are exported from upstream crates. Do not depend on
1486 /// this directly, as its value changes anytime a monomorphization gets
1487 /// added or removed in any upstream crate. Instead use the narrower
1488 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1489 /// better, `Instance::upstream_monomorphization()`.
1490 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1492 desc { "collecting available upstream monomorphizations" }
1495 /// Returns the set of upstream monomorphizations available for the
1496 /// generic function identified by the given `def_id`. The query makes
1497 /// sure to make a stable selection if the same monomorphization is
1498 /// available in multiple upstream crates.
1500 /// You likely want to call `Instance::upstream_monomorphization()`
1501 /// instead of invoking this query directly.
1502 query upstream_monomorphizations_for(def_id: DefId)
1503 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1507 "collecting available upstream monomorphizations for `{}`",
1508 tcx.def_path_str(def_id),
1510 separate_provide_extern
1513 /// Returns the upstream crate that exports drop-glue for the given
1514 /// type (`substs` is expected to be a single-item list containing the
1515 /// type one wants drop-glue for).
1517 /// This is a subset of `upstream_monomorphizations_for` in order to
1518 /// increase dep-tracking granularity. Otherwise adding or removing any
1519 /// type with drop-glue in any upstream crate would invalidate all
1520 /// functions calling drop-glue of an upstream type.
1522 /// You likely want to call `Instance::upstream_monomorphization()`
1523 /// instead of invoking this query directly.
1525 /// NOTE: This query could easily be extended to also support other
1526 /// common functions that have are large set of monomorphizations
1527 /// (like `Clone::clone` for example).
1528 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1529 desc { "available upstream drop-glue for `{:?}`", substs }
1532 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1534 desc { "looking up the foreign modules of a linked crate" }
1535 separate_provide_extern
1538 /// Identifies the entry-point (e.g., the `main` function) for a given
1539 /// crate, returning `None` if there is no entry point (such as for library crates).
1540 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1541 desc { "looking up the entry function of a crate" }
1543 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1544 desc { "looking up the derive registrar for a crate" }
1546 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1547 // Changing the name should cause a compiler error, but in case that changes, be aware.
1548 query crate_hash(_: CrateNum) -> Svh {
1550 desc { "looking up the hash a crate" }
1551 separate_provide_extern
1553 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1555 desc { "looking up the hash of a host version of a crate" }
1556 separate_provide_extern
1558 query extra_filename(_: CrateNum) -> String {
1561 desc { "looking up the extra filename for a crate" }
1562 separate_provide_extern
1564 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1567 desc { "looking up the paths for extern crates" }
1568 separate_provide_extern
1571 /// Given a crate and a trait, look up all impls of that trait in the crate.
1572 /// Return `(impl_id, self_ty)`.
1573 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1574 desc { "looking up implementations of a trait in a crate" }
1575 separate_provide_extern
1578 /// Collects all incoherent impls for the given crate and type.
1580 /// Do not call this directly, but instead use the `incoherent_impls` query.
1581 /// This query is only used to get the data necessary for that query.
1582 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1583 desc { |tcx| "collecting all impls for a type in a crate" }
1584 separate_provide_extern
1587 query is_dllimport_foreign_item(def_id: DefId) -> bool {
1588 desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1590 query is_statically_included_foreign_item(def_id: DefId) -> bool {
1591 desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1593 query native_library_kind(def_id: DefId)
1594 -> Option<NativeLibKind> {
1595 desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1597 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1598 desc { |tcx| "native_library({})", tcx.def_path_str(def_id) }
1601 /// Does lifetime resolution, but does not descend into trait items. This
1602 /// should only be used for resolving lifetimes of on trait definitions,
1603 /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1604 /// the same lifetimes and is responsible for diagnostics.
1605 /// See `rustc_resolve::late::lifetimes for details.
1606 query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1608 desc { "resolving lifetimes for a trait definition" }
1610 /// Does lifetime resolution on items. Importantly, we can't resolve
1611 /// lifetimes directly on things like trait methods, because of trait params.
1612 /// See `rustc_resolve::late::lifetimes for details.
1613 query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1615 desc { "resolving lifetimes" }
1617 query named_region_map(_: hir::OwnerId) ->
1618 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1619 desc { "looking up a named region" }
1621 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1622 desc { "testing if a region is late bound" }
1624 /// For a given item's generic parameter, gets the default lifetimes to be used
1625 /// for each parameter if a trait object were to be passed for that parameter.
1626 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1627 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1628 /// This query will panic if passed something that is not a type parameter.
1629 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1630 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1631 separate_provide_extern
1633 query late_bound_vars_map(_: hir::OwnerId)
1634 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1635 desc { "looking up late bound vars" }
1638 /// Computes the visibility of the provided `def_id`.
1640 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1641 /// a generic type parameter will panic if you call this method on it:
1644 /// pub trait Foo<T: Debug> {}
1647 /// In here, if you call `visibility` on `T`, it'll panic.
1648 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1649 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1650 separate_provide_extern
1653 /// Computes the set of modules from which this type is visibly uninhabited.
1654 /// To check whether a type is uninhabited at all (not just from a given module), you could
1655 /// check whether the forest is empty.
1656 query type_uninhabited_from(
1657 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1658 ) -> ty::inhabitedness::DefIdForest<'tcx> {
1659 desc { "computing the inhabitedness of `{:?}`", key }
1663 query dep_kind(_: CrateNum) -> CrateDepKind {
1665 desc { "fetching what a dependency looks like" }
1666 separate_provide_extern
1669 /// Gets the name of the crate.
1670 query crate_name(_: CrateNum) -> Symbol {
1672 desc { "fetching what a crate is named" }
1673 separate_provide_extern
1675 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1676 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1677 separate_provide_extern
1679 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1680 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1683 query lib_features(_: ()) -> LibFeatures {
1685 desc { "calculating the lib features map" }
1687 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1688 desc { "calculating the lib features defined in a crate" }
1689 separate_provide_extern
1691 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1693 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1694 separate_provide_extern
1696 /// Whether the function is an intrinsic
1697 query is_intrinsic(def_id: DefId) -> bool {
1698 desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
1699 separate_provide_extern
1701 /// Returns the lang items defined in another crate by loading it from metadata.
1702 query get_lang_items(_: ()) -> LanguageItems {
1705 desc { "calculating the lang items map" }
1708 /// Returns all diagnostic items defined in all crates.
1709 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1712 desc { "calculating the diagnostic items map" }
1715 /// Returns the lang items defined in another crate by loading it from metadata.
1716 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1717 desc { "calculating the lang items defined in a crate" }
1718 separate_provide_extern
1721 /// Returns the diagnostic items defined in a crate.
1722 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1724 desc { "calculating the diagnostic items map in a crate" }
1725 separate_provide_extern
1728 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1729 desc { "calculating the missing lang items in a crate" }
1730 separate_provide_extern
1732 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1734 desc { "calculating the visible parent map" }
1736 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1738 desc { "calculating trimmed def paths" }
1740 query missing_extern_crate_item(_: CrateNum) -> bool {
1742 desc { "seeing if we're missing an `extern crate` item for this crate" }
1743 separate_provide_extern
1745 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1748 desc { "looking at the source for a crate" }
1749 separate_provide_extern
1751 /// Returns the debugger visualizers defined for this crate.
1752 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1754 desc { "looking up the debugger visualizers for this crate" }
1755 separate_provide_extern
1757 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1759 desc { "generating a postorder list of CrateNums" }
1761 /// Returns whether or not the crate with CrateNum 'cnum'
1762 /// is marked as a private dependency
1763 query is_private_dep(c: CrateNum) -> bool {
1765 desc { "check whether crate {} is a private dependency", c }
1766 separate_provide_extern
1768 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1770 desc { "allocator kind for the current crate" }
1773 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1774 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1776 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1777 desc { "fetching potentially unused trait imports" }
1779 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1780 desc { "looking up all possibly unused extern crates" }
1782 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1783 desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1786 query stability_index(_: ()) -> stability::Index {
1789 desc { "calculating the stability index for the local crate" }
1791 query crates(_: ()) -> &'tcx [CrateNum] {
1793 desc { "fetching all foreign CrateNum instances" }
1796 /// A list of all traits in a crate, used by rustdoc and error reporting.
1797 /// NOTE: Not named just `traits` due to a naming conflict.
1798 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1799 desc { "fetching all traits in a crate" }
1800 separate_provide_extern
1803 /// The list of symbols exported from the given crate.
1805 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1806 /// correspond to a publicly visible symbol in `cnum` machine code.
1807 /// - The `exported_symbols` sets of different crates do not intersect.
1808 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1809 desc { "exported_symbols" }
1810 cache_on_disk_if { *cnum == LOCAL_CRATE }
1811 separate_provide_extern
1814 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1816 desc { "collect_and_partition_mono_items" }
1818 query is_codegened_item(def_id: DefId) -> bool {
1819 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1822 /// All items participating in code generation together with items inlined into them.
1823 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1825 desc { "codegened_and_inlined_items" }
1828 query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1829 desc { "codegen_unit" }
1831 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1832 cache_on_disk_if { key.def_id().is_local() }
1834 |tcx| "determining which generic parameters are unused by `{}`",
1835 tcx.def_path_str(key.def_id())
1837 separate_provide_extern
1839 query backend_optimization_level(_: ()) -> OptLevel {
1840 desc { "optimization level used by backend" }
1843 /// Return the filenames where output artefacts shall be stored.
1845 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1846 /// has been destroyed.
1847 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1849 desc { "output_filenames" }
1852 /// Do not call this query directly: invoke `normalize` instead.
1853 query normalize_projection_ty(
1854 goal: CanonicalProjectionGoal<'tcx>
1856 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1859 desc { "normalizing `{:?}`", goal }
1863 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1864 query try_normalize_generic_arg_after_erasing_regions(
1865 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1866 ) -> Result<GenericArg<'tcx>, NoSolution> {
1867 desc { "normalizing `{}`", goal.value }
1871 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1872 query try_normalize_mir_const_after_erasing_regions(
1873 goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1874 ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1875 desc { "normalizing `{}`", goal.value }
1879 query implied_outlives_bounds(
1880 goal: CanonicalTyGoal<'tcx>
1882 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1885 desc { "computing implied outlives bounds for `{:?}`", goal }
1889 /// Do not call this query directly:
1890 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1891 query dropck_outlives(
1892 goal: CanonicalTyGoal<'tcx>
1894 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1897 desc { "computing dropck types for `{:?}`", goal }
1901 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1902 /// `infcx.predicate_must_hold()` instead.
1903 query evaluate_obligation(
1904 goal: CanonicalPredicateGoal<'tcx>
1905 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1906 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1909 query evaluate_goal(
1910 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1912 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1915 desc { "evaluating trait selection obligation `{}`", goal.value }
1918 /// Do not call this query directly: part of the `Eq` type-op
1919 query type_op_ascribe_user_type(
1920 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1922 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1925 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1929 /// Do not call this query directly: part of the `Eq` type-op
1931 goal: CanonicalTypeOpEqGoal<'tcx>
1933 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1936 desc { "evaluating `type_op_eq` `{:?}`", goal }
1940 /// Do not call this query directly: part of the `Subtype` type-op
1941 query type_op_subtype(
1942 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1944 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1947 desc { "evaluating `type_op_subtype` `{:?}`", goal }
1951 /// Do not call this query directly: part of the `ProvePredicate` type-op
1952 query type_op_prove_predicate(
1953 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1955 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1958 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1961 /// Do not call this query directly: part of the `Normalize` type-op
1962 query type_op_normalize_ty(
1963 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1965 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1968 desc { "normalizing `{:?}`", goal }
1972 /// Do not call this query directly: part of the `Normalize` type-op
1973 query type_op_normalize_predicate(
1974 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1976 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1979 desc { "normalizing `{:?}`", goal }
1983 /// Do not call this query directly: part of the `Normalize` type-op
1984 query type_op_normalize_poly_fn_sig(
1985 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1987 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1990 desc { "normalizing `{:?}`", goal }
1994 /// Do not call this query directly: part of the `Normalize` type-op
1995 query type_op_normalize_fn_sig(
1996 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1998 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2001 desc { "normalizing `{:?}`", goal }
2005 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2007 "impossible substituted predicates:`{}`",
2008 tcx.def_path_str(key.0)
2012 query is_impossible_method(key: (DefId, DefId)) -> bool {
2014 "checking if {} is impossible to call within {}",
2015 tcx.def_path_str(key.1),
2016 tcx.def_path_str(key.0),
2020 query method_autoderef_steps(
2021 goal: CanonicalTyGoal<'tcx>
2022 ) -> MethodAutoderefStepsResult<'tcx> {
2023 desc { "computing autoderef types for `{:?}`", goal }
2027 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2030 desc { "looking up supported target features" }
2033 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2034 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2036 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2039 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2041 desc { "looking up enabled feature gates" }
2044 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2045 /// given generics args (`SubstsRef`), returning one of:
2046 /// * `Ok(Some(instance))` on success
2047 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2048 /// and therefore don't allow finding the final `Instance`
2049 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2050 /// couldn't complete due to errors elsewhere - this is distinct
2051 /// from `Ok(None)` to avoid misleading diagnostics when an error
2052 /// has already been/will be emitted, for the original cause
2053 query resolve_instance(
2054 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2055 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2056 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2060 query resolve_instance_of_const_arg(
2061 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2062 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2064 "resolving instance of the const argument `{}`",
2065 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2070 query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2071 desc { "normalizing opaque types in {:?}", key }
2074 /// Checks whether a type is definitely uninhabited. This is
2075 /// conservative: for some types that are uninhabited we return `false`,
2076 /// but we only return `true` for types that are definitely uninhabited.
2077 /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2078 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2079 /// size, to account for partial initialisation. See #49298 for details.)
2080 query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2081 desc { "conservatively checking if {:?} is privately uninhabited", key }
2085 query limits(key: ()) -> Limits {
2086 desc { "looking up limits" }
2089 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2090 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2091 /// the cause of the newly created obligation.
2093 /// This is only used by error-reporting code to get a better cause (in particular, a better
2094 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2095 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2096 /// because the `ty::Ty`-based wfcheck is always run.
2097 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2101 desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
2105 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2106 /// `--target` and similar).
2107 query global_backend_features(_: ()) -> Vec<String> {
2110 desc { "computing the backend features for CLI flags" }
2113 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2115 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2116 separate_provide_extern
2119 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2120 desc { "checking to see if {:?} permits being left uninit", key.ty }
2123 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2124 desc { "checking to see if {:?} permits being left zeroed", key.ty }
2127 query compare_assoc_const_impl_item_with_trait_item(
2128 key: (LocalDefId, DefId)
2129 ) -> Result<(), ErrorGuaranteed> {
2130 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }