Use this file to discover all available pages before exploring further.
The Rust compiler uses a demand-driven query system where compilation work is organized as queries. Each query is a memoized function from a key to a value, with automatic caching and dependency tracking.
Query modifiers control query behavior. From the query system documentation:
desc - Description (Required)
Sets the human-readable description for diagnostics and profiling.
query type_of(key: DefId) -> Ty<'tcx> { desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }}
The tcx and query key are available within the block.
arena_cache - Arena Allocation
Use an arena for in-memory caching of the query result.Results are allocated in a typed arena and share the same lifetime as the TyCtxt.Use when: Query results contain references with 'tcx lifetime
cache_on_disk_if - Disk Caching
Cache the query result to disk if the condition evaluates to true.
Enables incremental compilation by persisting results between runs.
cycle_* - Cycle Handling
Controls behavior when a dependency cycle is detected:
cycle_fatal - Abort with fatal error (default)
cycle_delay_bug - Emit delayed bug instead of aborting
cycle_stash - Stash error for later handling
Example: Type checking can encounter cycles in recursive types
no_hash - Skip Hashing
Do not hash the query result for incremental compilation.Instead, mark as dirty if the query is recomputed.Use when: Results are not stable across compilations
anon - Anonymous Queries
Make the query anonymous in the dependency graph (no dep node created).Use when: Query is internal and doesn’t need tracking
eval_always - Always Evaluate
Always evaluate the query, ignoring dependencies and cached results.Use when: Query has side effects or depends on external state
depth_limit - Recursion Limit
Impose a recursion depth limit to prevent stack overflows.Use when: Query can recurse deeply (e.g., trait resolution)
separate_provide_extern - Separate Providers
Use separate provider functions for local and external crates.Allows different implementations for current crate vs dependencies.
feedable - External Input
Allow the query result to be “fed” from another query.Enables setting query results externally without running the provider.
early_lint_checks - Runs early lint checks on the ASTregistered_tools - Returns registered tool lints (clippy, rustfmt, etc.)resolutions - Returns name resolution resultsresolver_for_lowering_raw - Provides resolver data for AST loweringenv_var_os - Queries environment variables at compile timeThese queries process the raw source code and prepare for HIR generation.
hir_crate - Returns the complete HIR cratehir_crate_items - Returns all items in the cratehir_module_items - Returns items in a specific modulelocal_def_id_to_hir_id - Converts DefId to HirIdhir_owner_parent_q - Returns parent of HIR owneropt_hir_owner_nodes - Returns HIR nodes for an ownerhir_attr_map - Returns attribute map for HIR nodesThese queries provide access to the High-Level Intermediate Representation.
type_of - Computes the type of a definitiongenerics_of - Returns generic parameters of an itempredicates_of - Returns trait bounds and where clausestype_of_opaque - Computes concrete type of opaque typesitem_bounds - Returns bounds on associated typesexplicit_item_bounds - Returns explicitly written boundsconst_param_default - Returns default value for const parametersThese queries build and query the type system.
Trait and Impl Queries
trait_def - Returns trait definitiontrait_impls_of - Returns all implementations of a traitimpl_trait_header - Returns trait being implementedinherent_impls - Returns inherent implementations for a typeassociated_items - Returns associated items (methods, types, consts)These queries support trait resolution and method dispatch.
mir_keys - Returns all items that need MIRmir_built - Builds unoptimized MIR for a functionmir_const_qualif - Checks if MIR is const-qualifiablemir_promoted - Returns promoted constants from MIRmir_borrowck - Performs borrow checkingoptimized_mir - Returns optimized MIRmir_for_ctfe - Returns MIR for compile-time function evaluationThese queries build and optimize the Mid-level IR.
const_eval_global_id - Evaluates a constanteval_to_allocation_raw - Evaluates to raw memory allocationeval_to_const_value_raw - Evaluates to const valueeval_to_valtree - Evaluates to value tree representationThese queries handle constant evaluation at compile time.
Providers are registered during compiler initialization:
// From various crates:rustc_passes::provide(&mut providers);rustc_hir_analysis::provide(&mut providers);rustc_mir_build::provide(&mut providers);// etc.
When a query panics or cycles, the compiler prints the query stack:
query stack during panic:#0 [type_of] computing type of `MyStruct`#1 [check_item_type] checking item type `MyStruct` #2 [analysis] running analysis passes