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 // Accesses untracked data
48 desc { "getting the source span" }
51 /// Represents crate as a whole (as distinct from the top-level crate module).
52 /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
53 /// we will have to assume that any change means that you need to be recompiled.
54 /// This is because the `hir_crate` query gives you access to all other items.
55 /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
56 /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
57 query hir_crate(key: ()) -> Crate<'tcx> {
60 desc { "getting the crate HIR" }
63 /// All items in the crate.
64 query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
67 desc { "getting HIR crate items" }
70 /// The items in a module.
72 /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
73 /// Avoid calling this query directly.
74 query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
76 desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
77 cache_on_disk_if { true }
80 /// Gives access to the HIR node for the HIR owner `key`.
82 /// This can be conveniently accessed by methods on `tcx.hir()`.
83 /// Avoid calling this query directly.
84 query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
85 desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
88 /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
90 /// This can be conveniently accessed by methods on `tcx.hir()`.
91 /// Avoid calling this query directly.
92 query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
93 desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
96 /// Gives access to the HIR node's parent for the HIR owner `key`.
98 /// This can be conveniently accessed by methods on `tcx.hir()`.
99 /// Avoid calling this query directly.
100 query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
101 desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
104 /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
106 /// This can be conveniently accessed by methods on `tcx.hir()`.
107 /// Avoid calling this query directly.
108 query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
109 desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
112 /// Gives access to the HIR attributes inside the HIR owner `key`.
114 /// This can be conveniently accessed by methods on `tcx.hir()`.
115 /// Avoid calling this query directly.
116 query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
117 desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
120 /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
121 /// const argument and returns `None` otherwise.
123 /// ```ignore (incomplete)
124 /// let a = foo::<7>();
125 /// // ^ Calling `opt_const_param_of` for this argument,
127 /// fn foo<const N: usize>()
128 /// // ^ returns this `DefId`.
131 /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
134 // It looks like caching this query on disk actually slightly
135 // worsened performance in #74376.
137 // Once const generics are more prevalently used, we might want to
138 // consider only caching calls returning `Some`.
139 query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
140 desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
143 /// Given the def_id of a const-generic parameter, computes the associated default const
144 /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
145 query const_param_default(param: DefId) -> ty::Const<'tcx> {
146 desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
147 cache_on_disk_if { param.is_local() }
148 separate_provide_extern
151 /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
152 /// to an alias, it will "skip" this alias to return the aliased type.
154 /// [`DefId`]: rustc_hir::def_id::DefId
155 query type_of(key: DefId) -> Ty<'tcx> {
159 use rustc_hir::def::DefKind;
160 match tcx.def_kind(key) {
161 DefKind::TyAlias => "expanding type alias",
162 DefKind::TraitAlias => "expanding trait alias",
163 _ => "computing type of",
166 path = tcx.def_path_str(key),
168 cache_on_disk_if { key.is_local() }
169 separate_provide_extern
172 query collect_return_position_impl_trait_in_trait_tys(key: DefId)
173 -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
175 desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
176 cache_on_disk_if { key.is_local() }
177 separate_provide_extern
180 query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
182 desc { "running analysis passes on this crate" }
185 /// This query checks the fulfillment of collected lint expectations.
186 /// All lint emitting queries have to be done before this is executed
187 /// to ensure that all expectations can be fulfilled.
189 /// This is an extra query to enable other drivers (like rustdoc) to
190 /// only execute a small subset of the `analysis` query, while allowing
191 /// lints to be expected. In rustc, this query will be executed as part of
192 /// the `analysis` query and doesn't have to be called a second time.
194 /// Tools can additionally pass in a tool filter. That will restrict the
195 /// expectations to only trigger for lints starting with the listed tool
196 /// name. This is useful for cases were not all linting code from rustc
197 /// was called. With the default `None` all registered lints will also
198 /// be checked for expectation fulfillment.
199 query check_expectations(key: Option<Symbol>) -> () {
201 desc { "checking lint expectations (RFC 2383)" }
204 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
205 /// associated generics.
206 query generics_of(key: DefId) -> ty::Generics {
207 desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
209 cache_on_disk_if { key.is_local() }
210 separate_provide_extern
213 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
214 /// predicates (where-clauses) that must be proven true in order
215 /// to reference it. This is almost always the "predicates query"
218 /// `predicates_of` builds on `predicates_defined_on` -- in fact,
219 /// it is almost always the same as that query, except for the
220 /// case of traits. For traits, `predicates_of` contains
221 /// an additional `Self: Trait<...>` predicate that users don't
222 /// actually write. This reflects the fact that to invoke the
223 /// trait (e.g., via `Default::default`) you must supply types
224 /// that actually implement the trait. (However, this extra
225 /// predicate gets in the way of some checks, which are intended
226 /// to operate over only the actual where-clauses written by the
228 query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
229 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
230 cache_on_disk_if { key.is_local() }
233 /// Returns the list of bounds that can be used for
234 /// `SelectionCandidate::ProjectionCandidate(_)` and
235 /// `ProjectionTyCandidate::TraitDef`.
236 /// Specifically this is the bounds written on the trait's type
237 /// definition, or those after the `impl` keyword
239 /// ```ignore (incomplete)
240 /// type X: Bound + 'lt
242 /// impl Debug + Display
243 /// // ^^^^^^^^^^^^^^^
246 /// `key` is the `DefId` of the associated type or opaque type.
248 /// Bounds from the parent (e.g. with nested impl trait) are not included.
249 query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
250 desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
251 cache_on_disk_if { key.is_local() }
252 separate_provide_extern
255 /// Elaborated version of the predicates from `explicit_item_bounds`.
261 /// type MyAType: Eq + ?Sized;
265 /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
266 /// and `item_bounds` returns
269 /// <Self as Trait>::MyAType: Eq,
270 /// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
274 /// Bounds from the parent (e.g. with nested impl trait) are not included.
275 query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
276 desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
279 /// Look up all native libraries this crate depends on.
280 /// These are assembled from the following places:
281 /// - `extern` blocks (depending on their `link` attributes)
282 /// - the `libs` (`-l`) option
283 query native_libraries(_: CrateNum) -> Vec<NativeLib> {
285 desc { "looking up the native libraries of a linked crate" }
286 separate_provide_extern
289 query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
290 eval_always // fetches `resolutions`
292 desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
295 query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
297 desc { "computing `#[expect]`ed lints in this crate" }
300 query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
302 desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
305 query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
306 desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
307 separate_provide_extern
310 query is_panic_runtime(_: CrateNum) -> bool {
312 desc { "checking if the crate is_panic_runtime" }
313 separate_provide_extern
316 /// Checks whether a type is representable or infinitely sized
317 query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
318 desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
319 // infinitely sized types will cause a cycle
321 // we don't want recursive representability calls to be forced with
322 // incremental compilation because, if a cycle occurs, we need the
323 // entire cycle to be in memory for diagnostics
327 /// An implementation detail for the `representability` query
328 query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
329 desc { "checking if `{}` is representable", key }
334 /// Set of param indexes for type params that are in the type's representation
335 query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
336 desc { "finding type parameters in the representation" }
339 separate_provide_extern
342 /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
343 query thir_body(key: ty::WithOptConstParam<LocalDefId>)
344 -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
346 // Perf tests revealed that hashing THIR is inefficient (see #85729).
348 desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
351 /// Create a THIR tree for debugging.
352 query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
355 desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
358 /// Set of all the `DefId`s in this crate that have MIR associated with
359 /// them. This includes all the body owners, but also things like struct
361 query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
363 desc { "getting a list of all mir_keys" }
366 /// Maps DefId's that have an associated `mir::Body` to the result
367 /// of the MIR const-checking pass. This is the set of qualifs in
368 /// the final value of a `const`.
369 query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
370 desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
371 cache_on_disk_if { key.is_local() }
372 separate_provide_extern
374 query mir_const_qualif_const_arg(
375 key: (LocalDefId, DefId)
376 ) -> mir::ConstQualifs {
378 |tcx| "const checking the const argument `{}`",
379 tcx.def_path_str(key.0.to_def_id())
383 /// Fetch the MIR for a given `DefId` right after it's built - this includes
384 /// unreachable code.
385 query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
386 desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
389 /// Fetch the MIR for a given `DefId` up till the point where it is
390 /// ready for const qualification.
392 /// See the README for the `mir` module for details.
393 query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
395 |tcx| "preparing {}`{}` for borrow checking",
396 if key.const_param_did.is_some() { "the const argument " } else { "" },
397 tcx.def_path_str(key.did.to_def_id()),
402 /// Try to build an abstract representation of the given constant.
403 query thir_abstract_const(
405 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
407 |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
409 separate_provide_extern
411 /// Try to build an abstract representation of the given constant.
412 query thir_abstract_const_of_const_arg(
413 key: (LocalDefId, DefId)
414 ) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
417 "building an abstract representation for the const argument `{}`",
418 tcx.def_path_str(key.0.to_def_id()),
422 query mir_drops_elaborated_and_const_checked(
423 key: ty::WithOptConstParam<LocalDefId>
424 ) -> &'tcx Steal<mir::Body<'tcx>> {
426 desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
431 ) -> &'tcx mir::Body<'tcx> {
432 desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
433 cache_on_disk_if { key.is_local() }
434 separate_provide_extern
437 query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
439 |tcx| "caching MIR for CTFE of the const argument `{}`",
440 tcx.def_path_str(key.0.to_def_id())
444 query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
446 &'tcx Steal<mir::Body<'tcx>>,
447 &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
451 |tcx| "processing MIR for {}`{}`",
452 if key.const_param_did.is_some() { "the const argument " } else { "" },
453 tcx.def_path_str(key.did.to_def_id()),
457 query symbols_for_closure_captures(
458 key: (LocalDefId, LocalDefId)
459 ) -> Vec<rustc_span::Symbol> {
462 |tcx| "finding symbols for captures of closure `{}` in `{}`",
463 tcx.def_path_str(key.1.to_def_id()),
464 tcx.def_path_str(key.0.to_def_id())
468 /// MIR after our optimization passes have run. This is MIR that is ready
469 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
470 query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
471 desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
472 cache_on_disk_if { key.is_local() }
473 separate_provide_extern
476 /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
477 /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
478 query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
479 desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
483 /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
484 /// function was optimized out before codegen, and before being added to the Coverage Map.
485 query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
487 |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
488 tcx.def_path_str(key)
491 cache_on_disk_if { key.is_local() }
494 /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
495 /// `DefId`. This function returns all promoteds in the specified body. The body references
496 /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
497 /// after inlining a body may refer to promoteds from other bodies. In that case you still
498 /// need to use the `DefId` of the original body.
499 query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
500 desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
501 cache_on_disk_if { key.is_local() }
502 separate_provide_extern
504 query promoted_mir_of_const_arg(
505 key: (LocalDefId, DefId)
506 ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
508 |tcx| "optimizing promoted MIR for the const argument `{}`",
509 tcx.def_path_str(key.0.to_def_id()),
513 /// Erases regions from `ty` to yield a new type.
514 /// Normally you would just use `tcx.erase_regions(value)`,
515 /// however, which uses this query as a kind of cache.
516 query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
517 // This query is not expected to have input -- as a result, it
518 // is not a good candidates for "replay" because it is essentially a
519 // pure function of its input (and hence the expectation is that
520 // no caller would be green **apart** from just these
521 // queries). Making it anonymous avoids hashing the result, which
522 // may save a bit of time.
524 desc { "erasing regions from `{}`", ty }
527 query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
529 desc { "getting wasm import module map" }
532 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
533 /// predicates (where-clauses) directly defined on it. This is
534 /// equal to the `explicit_predicates_of` predicates plus the
535 /// `inferred_outlives_of` predicates.
536 query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
537 desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
540 /// Returns everything that looks like a predicate written explicitly
541 /// by the user on a trait item.
543 /// Traits are unusual, because predicates on associated types are
544 /// converted into bounds on that type for backwards compatibility:
546 /// trait X where Self::U: Copy { type U; }
550 /// trait X { type U: Copy; }
552 /// `explicit_predicates_of` and `explicit_item_bounds` will then take
553 /// the appropriate subsets of the predicates here.
554 query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
555 desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
558 /// Returns the predicates written explicitly by the user.
559 query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
560 desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
561 cache_on_disk_if { key.is_local() }
562 separate_provide_extern
565 /// Returns the inferred outlives predicates (e.g., for `struct
566 /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
567 query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
568 desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
569 cache_on_disk_if { key.is_local() }
570 separate_provide_extern
573 /// Maps from the `DefId` of a trait to the list of
574 /// super-predicates. This is a subset of the full list of
575 /// predicates. We store these in a separate map because we must
576 /// evaluate them even during type conversion, often before the
577 /// full predicates are available (note that supertraits have
578 /// additional acyclicity requirements).
579 query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
580 desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
581 cache_on_disk_if { key.is_local() }
582 separate_provide_extern
585 /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
586 /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
587 /// subset of super-predicates that reference traits that define the given associated type.
588 /// This is used to avoid cycles in resolving types like `T::Item`.
589 query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
590 desc { |tcx| "computing the super traits of `{}`{}",
591 tcx.def_path_str(key.0),
592 if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
596 /// To avoid cycles within the predicates of a single item we compute
597 /// per-type-parameter predicates for resolving `T::AssocTy`.
598 query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
599 desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
602 query trait_def(key: DefId) -> ty::TraitDef {
603 desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
605 cache_on_disk_if { key.is_local() }
606 separate_provide_extern
608 query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
609 desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
610 cache_on_disk_if { key.is_local() }
611 separate_provide_extern
613 query adt_destructor(key: DefId) -> Option<ty::Destructor> {
614 desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
615 cache_on_disk_if { key.is_local() }
616 separate_provide_extern
619 query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
620 desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
623 query adt_dtorck_constraint(
625 ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
626 desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
629 /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
630 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
631 /// not have the feature gate active).
633 /// **Do not call this function manually.** It is only meant to cache the base data for the
634 /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
635 query constness(key: DefId) -> hir::Constness {
636 desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
637 cache_on_disk_if { key.is_local() }
638 separate_provide_extern
641 query asyncness(key: DefId) -> hir::IsAsync {
642 desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
643 cache_on_disk_if { key.is_local() }
644 separate_provide_extern
647 /// Returns `true` if calls to the function may be promoted.
649 /// This is either because the function is e.g., a tuple-struct or tuple-variant
650 /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
651 /// be removed in the future in favour of some form of check which figures out whether the
652 /// function does not inspect the bits of any of its arguments (so is essentially just a
653 /// constructor function).
654 query is_promotable_const_fn(key: DefId) -> bool {
655 desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
658 /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
659 query is_foreign_item(key: DefId) -> bool {
660 desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
661 cache_on_disk_if { key.is_local() }
662 separate_provide_extern
665 /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
666 query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
667 desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
668 cache_on_disk_if { def_id.is_local() }
669 separate_provide_extern
672 /// Gets a map with the variance of every item; use `item_variance` instead.
673 query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
675 desc { "computing the variances for items in this crate" }
678 /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
679 query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
680 desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
681 cache_on_disk_if { def_id.is_local() }
682 separate_provide_extern
685 /// Maps from thee `DefId` of a type to its (inferred) outlives.
686 query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
688 desc { "computing the inferred outlives predicates for items in this crate" }
691 /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
692 query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
693 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
694 cache_on_disk_if { key.is_local() }
695 separate_provide_extern
698 /// Maps from a trait item to the trait item "descriptor".
699 query associated_item(key: DefId) -> ty::AssocItem {
700 desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
702 cache_on_disk_if { key.is_local() }
703 separate_provide_extern
706 /// Collects the associated items defined on a trait or impl.
707 query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
709 desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
712 /// Maps from associated items on a trait to the corresponding associated
713 /// item on the impl specified by `impl_id`.
715 /// For example, with the following code
720 /// trait Trait { // trait_id
721 /// fn f(); // trait_f
722 /// fn g() {} // trait_g
725 /// impl Trait for Type { // impl_id
726 /// fn f() {} // impl_f
727 /// fn g() {} // impl_g
731 /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
732 ///`{ trait_f: impl_f, trait_g: impl_g }`
733 query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
735 desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
738 /// Given an `impl_id`, return the trait it implements.
739 /// Return `None` if this is an inherent impl.
740 query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
741 desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
742 cache_on_disk_if { impl_id.is_local() }
743 separate_provide_extern
745 query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
746 desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
747 cache_on_disk_if { impl_id.is_local() }
748 separate_provide_extern
751 query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
752 desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
755 /// Maps a `DefId` of a type to a list of its inherent impls.
756 /// Contains implementations of methods that are inherent to a type.
757 /// Methods in these implementations don't need to be exported.
758 query inherent_impls(key: DefId) -> &'tcx [DefId] {
759 desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
760 cache_on_disk_if { key.is_local() }
761 separate_provide_extern
764 query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
765 desc { |tcx| "collecting all inherent impls for `{:?}`", key }
768 /// The result of unsafety-checking this `LocalDefId`.
769 query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
770 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
771 cache_on_disk_if { true }
773 query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
775 |tcx| "unsafety-checking the const argument `{}`",
776 tcx.def_path_str(key.0.to_def_id())
780 /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
781 /// used with `-Zthir-unsafeck`.
782 query thir_check_unsafety(key: LocalDefId) {
783 desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
784 cache_on_disk_if { true }
786 query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
788 |tcx| "unsafety-checking the const argument `{}`",
789 tcx.def_path_str(key.0.to_def_id())
793 /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
795 /// Unsafety checking is executed for each method separately, but we only want
796 /// to emit this error once per derive. As there are some impls with multiple
797 /// methods, we use a query for deduplication.
798 query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
799 desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
802 /// Returns the types assumed to be well formed while "inside" of the given item.
804 /// Note that we've liberated the late bound regions of function signatures, so
805 /// this can not be used to check whether these types are well formed.
806 query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
807 desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
810 /// Computes the signature of the function.
811 query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
812 desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
813 cache_on_disk_if { key.is_local() }
814 separate_provide_extern
818 /// Performs lint checking for the module.
819 query lint_mod(key: LocalDefId) -> () {
820 desc { |tcx| "linting {}", describe_as_module(key, tcx) }
823 /// Checks the attributes in the module.
824 query check_mod_attrs(key: LocalDefId) -> () {
825 desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
828 /// Checks for uses of unstable APIs in the module.
829 query check_mod_unstable_api_usage(key: LocalDefId) -> () {
830 desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
833 /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
834 query check_mod_const_bodies(key: LocalDefId) -> () {
835 desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
838 /// Checks the loops in the module.
839 query check_mod_loops(key: LocalDefId) -> () {
840 desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
843 query check_mod_naked_functions(key: LocalDefId) -> () {
844 desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
847 query check_mod_item_types(key: LocalDefId) -> () {
848 desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
851 query check_mod_privacy(key: LocalDefId) -> () {
852 desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
855 query check_liveness(key: DefId) {
856 desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
859 /// Return the live symbols in the crate for dead code check.
861 /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
862 /// their respective impl (i.e., part of the derive macro)
863 query live_symbols_and_ignored_derived_traits(_: ()) -> (
864 FxHashSet<LocalDefId>,
865 FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
868 desc { "finding live symbols in crate" }
871 query check_mod_deathness(key: LocalDefId) -> () {
872 desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
875 query check_mod_impl_wf(key: LocalDefId) -> () {
876 desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
879 query check_mod_type_wf(key: LocalDefId) -> () {
880 desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
883 query collect_mod_item_types(key: LocalDefId) -> () {
884 desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
887 /// Caches `CoerceUnsized` kinds for impls on custom types.
888 query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
889 desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
890 cache_on_disk_if { key.is_local() }
891 separate_provide_extern
894 query typeck_item_bodies(_: ()) -> () {
895 desc { "type-checking all item bodies" }
898 query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
899 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
900 cache_on_disk_if { true }
902 query typeck_const_arg(
903 key: (LocalDefId, DefId)
904 ) -> &'tcx ty::TypeckResults<'tcx> {
906 |tcx| "type-checking the const argument `{}`",
907 tcx.def_path_str(key.0.to_def_id()),
910 query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
911 desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
912 cache_on_disk_if { true }
915 query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
916 desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
917 cache_on_disk_if { true }
920 query has_typeck_results(def_id: DefId) -> bool {
921 desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
924 query coherent_trait(def_id: DefId) -> () {
925 desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
928 /// Borrow-checks the function body. If this is a closure, returns
929 /// additional requirements that the closure's creator must verify.
930 query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
931 desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
932 cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
934 query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
936 |tcx| "borrow-checking the const argument`{}`",
937 tcx.def_path_str(key.0.to_def_id())
941 /// Gets a complete map from all types to their inherent impls.
942 /// Not meant to be used directly outside of coherence.
943 query crate_inherent_impls(k: ()) -> CrateInherentImpls {
945 desc { "finding all inherent impls defined in crate" }
948 /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
949 /// Not meant to be used directly outside of coherence.
950 query crate_inherent_impls_overlap_check(_: ()) -> () {
951 desc { "check for overlap between inherent impls defined in this crate" }
954 /// Checks whether all impls in the crate pass the overlap check, returning
955 /// which impls fail it. If all impls are correct, the returned slice is empty.
956 query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
958 "checking whether impl `{}` follows the orphan rules",
959 tcx.def_path_str(key.to_def_id()),
963 /// Check whether the function has any recursion that could cause the inliner to trigger
964 /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
965 /// current function, just all intermediate functions.
966 query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
969 "computing if `{}` (transitively) calls `{}`",
971 tcx.def_path_str(key.1.to_def_id()),
975 /// Obtain all the calls into other local functions
976 query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
979 "computing all local function calls in `{}`",
980 tcx.def_path_str(key.def_id()),
984 /// Evaluates a constant and returns the computed allocation.
986 /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
987 query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
988 -> EvalToAllocationRawResult<'tcx> {
990 "const-evaluating + checking `{}`",
991 key.value.display(tcx)
993 cache_on_disk_if { true }
996 /// Evaluates const items or anonymous constants
997 /// (such as enum variant explicit discriminants or array lengths)
998 /// into a representation suitable for the type system and const generics.
1000 /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1001 /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1002 query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1003 -> EvalToConstValueResult<'tcx> {
1005 "simplifying constant for the type system `{}`",
1006 key.value.display(tcx)
1008 cache_on_disk_if { true }
1011 /// Evaluate a constant and convert it to a type level constant or
1012 /// return `None` if that is not possible.
1013 query eval_to_valtree(
1014 key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1015 ) -> EvalToValTreeResult<'tcx> {
1016 desc { "evaluating type-level constant" }
1019 /// Converts a type level constant value into `ConstValue`
1020 query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1021 desc { "converting type-level constant value to mir constant value"}
1024 /// Destructures array, ADT or tuple constants into the constants
1025 /// of their fields.
1026 query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1027 desc { "destructuring type level constant"}
1030 /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1031 /// and its field values.
1032 query try_destructure_mir_constant(
1033 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1034 ) -> Option<mir::DestructuredConstant<'tcx>> {
1035 desc { "destructuring MIR constant"}
1039 /// Dereference a constant reference or raw pointer and turn the result into a constant
1041 query deref_mir_constant(
1042 key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1043 ) -> mir::ConstantKind<'tcx> {
1044 desc { "dereferencing MIR constant" }
1048 query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1049 desc { "getting a &core::panic::Location referring to a span" }
1052 // FIXME get rid of this with valtrees
1054 key: LitToConstInput<'tcx>
1055 ) -> Result<ty::Const<'tcx>, LitToConstError> {
1056 desc { "converting literal to const" }
1059 query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1060 desc { "converting literal to mir constant" }
1063 query check_match(key: DefId) {
1064 desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1065 cache_on_disk_if { key.is_local() }
1068 /// Performs part of the privacy check and computes effective visibilities.
1069 query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1071 desc { "checking effective visibilities" }
1073 query check_private_in_public(_: ()) -> () {
1075 desc { "checking for private elements in public interfaces" }
1078 query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1080 desc { "reachability" }
1083 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1084 /// in the case of closures, this will be redirected to the enclosing function.
1085 query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1086 desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1089 /// Generates a MIR body for the shim.
1090 query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1092 desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1095 /// The `symbol_name` query provides the symbol name for calling a
1096 /// given instance from the local crate. In particular, it will also
1097 /// look up the correct symbol name of instances from upstream crates.
1098 query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1099 desc { "computing the symbol for `{}`", key }
1100 cache_on_disk_if { true }
1103 query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1104 desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1105 cache_on_disk_if { def_id.is_local() }
1106 separate_provide_extern
1109 /// Gets the span for the definition.
1110 query def_span(def_id: DefId) -> Span {
1111 desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1112 cache_on_disk_if { def_id.is_local() }
1113 separate_provide_extern
1117 /// Gets the span for the identifier of the definition.
1118 query def_ident_span(def_id: DefId) -> Option<Span> {
1119 desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1120 cache_on_disk_if { def_id.is_local() }
1121 separate_provide_extern
1124 query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1125 desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1126 cache_on_disk_if { def_id.is_local() }
1127 separate_provide_extern
1130 query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1131 desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1132 cache_on_disk_if { def_id.is_local() }
1133 separate_provide_extern
1136 query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1137 desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1138 separate_provide_extern
1141 query should_inherit_track_caller(def_id: DefId) -> bool {
1142 desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1145 query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1146 desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1147 cache_on_disk_if { def_id.is_local() }
1148 separate_provide_extern
1151 /// Determines whether an item is annotated with `doc(hidden)`.
1152 query is_doc_hidden(def_id: DefId) -> bool {
1153 desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1156 /// Determines whether an item is annotated with `doc(notable_trait)`.
1157 query is_doc_notable_trait(def_id: DefId) -> bool {
1158 desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1161 /// Returns the attributes on the item at `def_id`.
1163 /// Do not use this directly, use `tcx.get_attrs` instead.
1164 query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1165 desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1166 separate_provide_extern
1169 query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1170 desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1172 cache_on_disk_if { def_id.is_local() }
1173 separate_provide_extern
1176 query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1177 desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1180 query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1181 desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1182 cache_on_disk_if { def_id.is_local() }
1183 separate_provide_extern
1185 /// Gets the rendered value of the specified constant or associated constant.
1186 /// Used by rustdoc.
1187 query rendered_const(def_id: DefId) -> String {
1189 desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1190 cache_on_disk_if { def_id.is_local() }
1191 separate_provide_extern
1193 query impl_parent(def_id: DefId) -> Option<DefId> {
1194 desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1195 cache_on_disk_if { def_id.is_local() }
1196 separate_provide_extern
1199 query is_ctfe_mir_available(key: DefId) -> bool {
1200 desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1201 cache_on_disk_if { key.is_local() }
1202 separate_provide_extern
1204 query is_mir_available(key: DefId) -> bool {
1205 desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1206 cache_on_disk_if { key.is_local() }
1207 separate_provide_extern
1210 query own_existential_vtable_entries(
1212 ) -> &'tcx [DefId] {
1213 desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1216 query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1217 -> &'tcx [ty::VtblEntry<'tcx>] {
1218 desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1221 query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1222 desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1226 query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1227 desc { |tcx| "vtable const allocation for <{} as {}>",
1229 key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1233 query codegen_select_candidate(
1234 key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1235 ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1236 cache_on_disk_if { true }
1237 desc { |tcx| "computing candidate for `{}`", key.1 }
1240 /// Return all `impl` blocks in the current crate.
1241 query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1242 desc { "finding local trait impls" }
1245 /// Given a trait `trait_id`, return all known `impl` blocks.
1246 query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1248 desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1251 query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1253 desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1254 cache_on_disk_if { true }
1256 query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1257 desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1260 /// Gets the ParameterEnvironment for a given item; this environment
1261 /// will be in "user-facing" mode, meaning that it is suitable for
1262 /// type-checking etc, and it does not normalize specializable
1263 /// associated types. This is almost always what you want,
1264 /// unless you are doing MIR optimizations, in which case you
1265 /// might want to use `reveal_all()` method to change modes.
1266 query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1267 desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1270 /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1271 /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1272 /// as this method is more efficient.
1273 query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1274 desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1277 /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1278 /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1279 query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1280 desc { "computing whether `{}` is `Copy`", env.value }
1283 /// Query backing `Ty::is_sized`.
1284 query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1285 desc { "computing whether `{}` is `Sized`", env.value }
1288 /// Query backing `Ty::is_freeze`.
1289 query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1290 desc { "computing whether `{}` is freeze", env.value }
1293 /// Query backing `Ty::is_unpin`.
1294 query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1295 desc { "computing whether `{}` is `Unpin`", env.value }
1298 /// Query backing `Ty::needs_drop`.
1299 query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1300 desc { "computing whether `{}` needs drop", env.value }
1303 /// Query backing `Ty::has_significant_drop_raw`.
1304 query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1305 desc { "computing whether `{}` has a significant drop", env.value }
1309 /// Query backing `Ty::is_structural_eq_shallow`.
1311 /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1313 query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1315 "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1320 /// A list of types where the ADT requires drop if and only if any of
1321 /// those types require drop. If the ADT is known to always need drop
1322 /// then `Err(AlwaysRequiresDrop)` is returned.
1323 query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1324 desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1325 cache_on_disk_if { true }
1328 /// A list of types where the ADT requires drop if and only if any of those types
1329 /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1330 /// is considered to not be significant. A drop is significant if it is implemented
1331 /// by the user or does anything that will have any observable behavior (other than
1332 /// freeing up memory). If the ADT is known to have a significant destructor then
1333 /// `Err(AlwaysRequiresDrop)` is returned.
1334 query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1335 desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1336 cache_on_disk_if { false }
1339 /// Computes the layout of a type. Note that this implicitly
1340 /// executes in "reveal all" mode, and will normalize the input type.
1342 key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1343 ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1345 desc { "computing layout of `{}`", key.value }
1349 /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1351 /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1352 /// instead, where the instance is an `InstanceDef::Virtual`.
1353 query fn_abi_of_fn_ptr(
1354 key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1355 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1356 desc { "computing call ABI of `{}` function pointers", key.value.0 }
1360 /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1361 /// direct calls to an `fn`.
1363 /// NB: that includes virtual calls, which are represented by "direct calls"
1364 /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1365 query fn_abi_of_instance(
1366 key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1367 ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1368 desc { "computing call ABI of `{}`", key.value.0 }
1372 query dylib_dependency_formats(_: CrateNum)
1373 -> &'tcx [(CrateNum, LinkagePreference)] {
1374 desc { "getting dylib dependency formats of crate" }
1375 separate_provide_extern
1378 query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1380 desc { "getting the linkage format of all dependencies" }
1383 query is_compiler_builtins(_: CrateNum) -> bool {
1385 desc { "checking if the crate is_compiler_builtins" }
1386 separate_provide_extern
1388 query has_global_allocator(_: CrateNum) -> bool {
1389 // This query depends on untracked global state in CStore
1392 desc { "checking if the crate has_global_allocator" }
1393 separate_provide_extern
1395 query has_alloc_error_handler(_: CrateNum) -> bool {
1396 // This query depends on untracked global state in CStore
1399 desc { "checking if the crate has_alloc_error_handler" }
1400 separate_provide_extern
1402 query has_panic_handler(_: CrateNum) -> bool {
1404 desc { "checking if the crate has_panic_handler" }
1405 separate_provide_extern
1407 query is_profiler_runtime(_: CrateNum) -> bool {
1409 desc { "checking if a crate is `#![profiler_runtime]`" }
1410 separate_provide_extern
1412 query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1413 desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1414 cache_on_disk_if { true }
1416 query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1418 desc { "getting a crate's required panic strategy" }
1419 separate_provide_extern
1421 query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1423 desc { "getting a crate's configured panic-in-drop strategy" }
1424 separate_provide_extern
1426 query is_no_builtins(_: CrateNum) -> bool {
1428 desc { "getting whether a crate has `#![no_builtins]`" }
1429 separate_provide_extern
1431 query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1433 desc { "getting a crate's symbol mangling version" }
1434 separate_provide_extern
1437 query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1439 desc { "getting crate's ExternCrateData" }
1440 separate_provide_extern
1443 query specializes(_: (DefId, DefId)) -> bool {
1444 desc { "computing whether impls specialize one another" }
1446 query in_scope_traits_map(_: hir::OwnerId)
1447 -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1448 desc { "getting traits in scope at a block" }
1451 query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1452 desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1455 query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1456 desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1457 cache_on_disk_if { def_id.is_local() }
1458 separate_provide_extern
1461 query check_well_formed(key: hir::OwnerId) -> () {
1462 desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1465 // The `DefId`s of all non-generic functions and statics in the given crate
1466 // that can be reached from outside the crate.
1468 // We expect this items to be available for being linked to.
1470 // This query can also be called for `LOCAL_CRATE`. In this case it will
1471 // compute which items will be reachable to other crates, taking into account
1472 // the kind of crate that is currently compiled. Crates with only a
1473 // C interface have fewer reachable things.
1475 // Does not include external symbols that don't have a corresponding DefId,
1476 // like the compiler-generated `main` function and so on.
1477 query reachable_non_generics(_: CrateNum)
1478 -> DefIdMap<SymbolExportInfo> {
1480 desc { "looking up the exported symbols of a crate" }
1481 separate_provide_extern
1483 query is_reachable_non_generic(def_id: DefId) -> bool {
1484 desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1485 cache_on_disk_if { def_id.is_local() }
1486 separate_provide_extern
1488 query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1490 "checking whether `{}` is reachable from outside the crate",
1491 tcx.def_path_str(def_id.to_def_id()),
1495 /// The entire set of monomorphizations the local crate can safely link
1496 /// to because they are exported from upstream crates. Do not depend on
1497 /// this directly, as its value changes anytime a monomorphization gets
1498 /// added or removed in any upstream crate. Instead use the narrower
1499 /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1500 /// better, `Instance::upstream_monomorphization()`.
1501 query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1503 desc { "collecting available upstream monomorphizations" }
1506 /// Returns the set of upstream monomorphizations available for the
1507 /// generic function identified by the given `def_id`. The query makes
1508 /// sure to make a stable selection if the same monomorphization is
1509 /// available in multiple upstream crates.
1511 /// You likely want to call `Instance::upstream_monomorphization()`
1512 /// instead of invoking this query directly.
1513 query upstream_monomorphizations_for(def_id: DefId)
1514 -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1518 "collecting available upstream monomorphizations for `{}`",
1519 tcx.def_path_str(def_id),
1521 separate_provide_extern
1524 /// Returns the upstream crate that exports drop-glue for the given
1525 /// type (`substs` is expected to be a single-item list containing the
1526 /// type one wants drop-glue for).
1528 /// This is a subset of `upstream_monomorphizations_for` in order to
1529 /// increase dep-tracking granularity. Otherwise adding or removing any
1530 /// type with drop-glue in any upstream crate would invalidate all
1531 /// functions calling drop-glue of an upstream type.
1533 /// You likely want to call `Instance::upstream_monomorphization()`
1534 /// instead of invoking this query directly.
1536 /// NOTE: This query could easily be extended to also support other
1537 /// common functions that have are large set of monomorphizations
1538 /// (like `Clone::clone` for example).
1539 query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1540 desc { "available upstream drop-glue for `{:?}`", substs }
1543 /// Returns a list of all `extern` blocks of a crate.
1544 query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1546 desc { "looking up the foreign modules of a linked crate" }
1547 separate_provide_extern
1550 /// Identifies the entry-point (e.g., the `main` function) for a given
1551 /// crate, returning `None` if there is no entry point (such as for library crates).
1552 query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1553 desc { "looking up the entry function of a crate" }
1556 /// Finds the `rustc_proc_macro_decls` item of a crate.
1557 query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1558 desc { "looking up the proc macro declarations for a crate" }
1561 // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1562 // Changing the name should cause a compiler error, but in case that changes, be aware.
1563 query crate_hash(_: CrateNum) -> Svh {
1565 desc { "looking up the hash a crate" }
1566 separate_provide_extern
1569 /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1570 query crate_host_hash(_: CrateNum) -> Option<Svh> {
1572 desc { "looking up the hash of a host version of a crate" }
1573 separate_provide_extern
1576 /// Gets the extra data to put in each output filename for a crate.
1577 /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1578 query extra_filename(_: CrateNum) -> String {
1581 desc { "looking up the extra filename for a crate" }
1582 separate_provide_extern
1585 /// Gets the paths where the crate came from in the file system.
1586 query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1589 desc { "looking up the paths for extern crates" }
1590 separate_provide_extern
1593 /// Given a crate and a trait, look up all impls of that trait in the crate.
1594 /// Return `(impl_id, self_ty)`.
1595 query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1596 desc { "looking up implementations of a trait in a crate" }
1597 separate_provide_extern
1600 /// Collects all incoherent impls for the given crate and type.
1602 /// Do not call this directly, but instead use the `incoherent_impls` query.
1603 /// This query is only used to get the data necessary for that query.
1604 query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1605 desc { |tcx| "collecting all impls for a type in a crate" }
1606 separate_provide_extern
1609 /// Get the corresponding native library from the `native_libraries` query
1610 query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1611 desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1614 /// Does lifetime resolution on items. Importantly, we can't resolve
1615 /// lifetimes directly on things like trait methods, because of trait params.
1616 /// See `rustc_resolve::late::lifetimes for details.
1617 query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1619 desc { "resolving lifetimes" }
1621 query named_region_map(_: hir::OwnerId) ->
1622 Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1623 desc { "looking up a named region" }
1625 query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1626 desc { "testing if a region is late bound" }
1628 /// For a given item's generic parameter, gets the default lifetimes to be used
1629 /// for each parameter if a trait object were to be passed for that parameter.
1630 /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1631 /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1632 /// This query will panic if passed something that is not a type parameter.
1633 query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1634 desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1635 separate_provide_extern
1637 query late_bound_vars_map(_: hir::OwnerId)
1638 -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1639 desc { "looking up late bound vars" }
1642 /// Computes the visibility of the provided `def_id`.
1644 /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1645 /// a generic type parameter will panic if you call this method on it:
1648 /// use std::fmt::Debug;
1650 /// pub trait Foo<T: Debug> {}
1653 /// In here, if you call `visibility` on `T`, it'll panic.
1654 query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1655 desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1656 separate_provide_extern
1659 query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1660 desc { "computing the uninhabited predicate of `{:?}`", key }
1663 /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1664 query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1665 desc { "computing the uninhabited predicate of `{}`", key }
1668 query dep_kind(_: CrateNum) -> CrateDepKind {
1670 desc { "fetching what a dependency looks like" }
1671 separate_provide_extern
1674 /// Gets the name of the crate.
1675 query crate_name(_: CrateNum) -> Symbol {
1677 desc { "fetching what a crate is named" }
1678 separate_provide_extern
1680 query module_children(def_id: DefId) -> &'tcx [ModChild] {
1681 desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1682 separate_provide_extern
1684 query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1685 desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1688 query lib_features(_: ()) -> LibFeatures {
1690 desc { "calculating the lib features map" }
1692 query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1693 desc { "calculating the lib features defined in a crate" }
1694 separate_provide_extern
1696 query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1698 desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1699 separate_provide_extern
1701 /// Whether the function is an intrinsic
1702 query is_intrinsic(def_id: DefId) -> bool {
1703 desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1704 separate_provide_extern
1706 /// Returns the lang items defined in another crate by loading it from metadata.
1707 query get_lang_items(_: ()) -> LanguageItems {
1710 desc { "calculating the lang items map" }
1713 /// Returns all diagnostic items defined in all crates.
1714 query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1717 desc { "calculating the diagnostic items map" }
1720 /// Returns the lang items defined in another crate by loading it from metadata.
1721 query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1722 desc { "calculating the lang items defined in a crate" }
1723 separate_provide_extern
1726 /// Returns the diagnostic items defined in a crate.
1727 query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1729 desc { "calculating the diagnostic items map in a crate" }
1730 separate_provide_extern
1733 query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1734 desc { "calculating the missing lang items in a crate" }
1735 separate_provide_extern
1737 query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1739 desc { "calculating the visible parent map" }
1741 query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1743 desc { "calculating trimmed def paths" }
1745 query missing_extern_crate_item(_: CrateNum) -> bool {
1747 desc { "seeing if we're missing an `extern crate` item for this crate" }
1748 separate_provide_extern
1750 query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1753 desc { "looking at the source for a crate" }
1754 separate_provide_extern
1756 /// Returns the debugger visualizers defined for this crate.
1757 query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1759 desc { "looking up the debugger visualizers for this crate" }
1760 separate_provide_extern
1762 query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1764 desc { "generating a postorder list of CrateNums" }
1766 /// Returns whether or not the crate with CrateNum 'cnum'
1767 /// is marked as a private dependency
1768 query is_private_dep(c: CrateNum) -> bool {
1770 desc { "checking whether crate `{}` is a private dependency", c }
1771 separate_provide_extern
1773 query allocator_kind(_: ()) -> Option<AllocatorKind> {
1775 desc { "getting the allocator kind for the current crate" }
1777 query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1779 desc { "alloc error handler kind for the current crate" }
1782 query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1783 desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1785 query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1786 desc { "fetching potentially unused trait imports" }
1788 query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1789 desc { "looking up all possibly unused extern crates" }
1791 query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1792 desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1795 query stability_index(_: ()) -> stability::Index {
1798 desc { "calculating the stability index for the local crate" }
1800 query crates(_: ()) -> &'tcx [CrateNum] {
1802 desc { "fetching all foreign CrateNum instances" }
1805 /// A list of all traits in a crate, used by rustdoc and error reporting.
1806 /// NOTE: Not named just `traits` due to a naming conflict.
1807 query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1808 desc { "fetching all traits in a crate" }
1809 separate_provide_extern
1812 /// The list of symbols exported from the given crate.
1814 /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1815 /// correspond to a publicly visible symbol in `cnum` machine code.
1816 /// - The `exported_symbols` sets of different crates do not intersect.
1817 query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1818 desc { "collecting exported symbols for crate `{}`", cnum}
1819 cache_on_disk_if { *cnum == LOCAL_CRATE }
1820 separate_provide_extern
1823 query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1825 desc { "collect_and_partition_mono_items" }
1828 query is_codegened_item(def_id: DefId) -> bool {
1829 desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1832 /// All items participating in code generation together with items inlined into them.
1833 query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1835 desc { "collecting codegened and inlined items" }
1838 query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1839 desc { "getting codegen unit `{sym}`" }
1842 query unused_generic_params(key: ty::InstanceDef<'tcx>) -> UnusedGenericParams {
1843 cache_on_disk_if { key.def_id().is_local() }
1845 |tcx| "determining which generic parameters are unused by `{}`",
1846 tcx.def_path_str(key.def_id())
1848 separate_provide_extern
1851 query backend_optimization_level(_: ()) -> OptLevel {
1852 desc { "optimization level used by backend" }
1855 /// Return the filenames where output artefacts shall be stored.
1857 /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1858 /// has been destroyed.
1859 query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1861 desc { "getting output filenames" }
1864 /// Do not call this query directly: invoke `normalize` instead.
1865 query normalize_projection_ty(
1866 goal: CanonicalProjectionGoal<'tcx>
1868 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1871 desc { "normalizing `{}`", goal.value.value }
1875 /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1876 query try_normalize_generic_arg_after_erasing_regions(
1877 goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1878 ) -> Result<GenericArg<'tcx>, NoSolution> {
1879 desc { "normalizing `{}`", goal.value }
1883 query implied_outlives_bounds(
1884 goal: CanonicalTyGoal<'tcx>
1886 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1889 desc { "computing implied outlives bounds for `{}`", goal.value.value }
1893 /// Do not call this query directly:
1894 /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1895 query dropck_outlives(
1896 goal: CanonicalTyGoal<'tcx>
1898 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1901 desc { "computing dropck types for `{}`", goal.value.value }
1905 /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1906 /// `infcx.predicate_must_hold()` instead.
1907 query evaluate_obligation(
1908 goal: CanonicalPredicateGoal<'tcx>
1909 ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1910 desc { "evaluating trait selection obligation `{}`", goal.value.value }
1913 query evaluate_goal(
1914 goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1916 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1919 desc { "evaluating trait selection obligation `{}`", goal.value }
1922 /// Do not call this query directly: part of the `Eq` type-op
1923 query type_op_ascribe_user_type(
1924 goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1926 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1929 desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1933 /// Do not call this query directly: part of the `Eq` type-op
1935 goal: CanonicalTypeOpEqGoal<'tcx>
1937 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1940 desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1944 /// Do not call this query directly: part of the `Subtype` type-op
1945 query type_op_subtype(
1946 goal: CanonicalTypeOpSubtypeGoal<'tcx>
1948 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1951 desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1955 /// Do not call this query directly: part of the `ProvePredicate` type-op
1956 query type_op_prove_predicate(
1957 goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1959 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1962 desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1965 /// Do not call this query directly: part of the `Normalize` type-op
1966 query type_op_normalize_ty(
1967 goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1969 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1972 desc { "normalizing `{}`", goal.value.value.value }
1976 /// Do not call this query directly: part of the `Normalize` type-op
1977 query type_op_normalize_predicate(
1978 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1980 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1983 desc { "normalizing `{:?}`", goal.value.value.value }
1987 /// Do not call this query directly: part of the `Normalize` type-op
1988 query type_op_normalize_poly_fn_sig(
1989 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1991 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1994 desc { "normalizing `{:?}`", goal.value.value.value }
1998 /// Do not call this query directly: part of the `Normalize` type-op
1999 query type_op_normalize_fn_sig(
2000 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2002 &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2005 desc { "normalizing `{:?}`", goal.value.value.value }
2009 query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2011 "checking impossible substituted predicates: `{}`",
2012 tcx.def_path_str(key.0)
2016 query is_impossible_method(key: (DefId, DefId)) -> bool {
2018 "checking if `{}` is impossible to call within `{}`",
2019 tcx.def_path_str(key.1),
2020 tcx.def_path_str(key.0),
2024 query method_autoderef_steps(
2025 goal: CanonicalTyGoal<'tcx>
2026 ) -> MethodAutoderefStepsResult<'tcx> {
2027 desc { "computing autoderef types for `{}`", goal.value.value }
2031 query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2034 desc { "looking up supported target features" }
2037 /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2038 query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2040 desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2043 query features_query(_: ()) -> &'tcx rustc_feature::Features {
2045 desc { "looking up enabled feature gates" }
2048 /// Attempt to resolve the given `DefId` to an `Instance`, for the
2049 /// given generics args (`SubstsRef`), returning one of:
2050 /// * `Ok(Some(instance))` on success
2051 /// * `Ok(None)` when the `SubstsRef` are still too generic,
2052 /// and therefore don't allow finding the final `Instance`
2053 /// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2054 /// couldn't complete due to errors elsewhere - this is distinct
2055 /// from `Ok(None)` to avoid misleading diagnostics when an error
2056 /// has already been/will be emitted, for the original cause
2057 query resolve_instance(
2058 key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2059 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2060 desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2064 query resolve_instance_of_const_arg(
2065 key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2066 ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2068 "resolving instance of the const argument `{}`",
2069 ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2074 query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2075 desc { "revealing opaque types in `{:?}`", key }
2078 query limits(key: ()) -> Limits {
2079 desc { "looking up limits" }
2082 /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2083 /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2084 /// the cause of the newly created obligation.
2086 /// This is only used by error-reporting code to get a better cause (in particular, a better
2087 /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2088 /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2089 /// because the `ty::Ty`-based wfcheck is always run.
2090 query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2094 desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2098 /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2099 /// `--target` and similar).
2100 query global_backend_features(_: ()) -> Vec<String> {
2103 desc { "computing the backend features for CLI flags" }
2106 query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2108 desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2109 separate_provide_extern
2112 query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2113 desc { "checking to see if `{}` permits being left uninit", key.ty }
2116 query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2117 desc { "checking to see if `{}` permits being left zeroed", key.ty }
2120 query compare_impl_const(
2121 key: (LocalDefId, DefId)
2122 ) -> Result<(), ErrorGuaranteed> {
2123 desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2126 query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2127 desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2128 separate_provide_extern