Open-Source Wikis

/

Rust

/

Compiler

rust-lang/rust

Compiler

The compiler/ directory contains the rustc compiler itself, split across roughly seventy rustc_* crates. This index gives a fly-over of what each crate is for and how they fit into the pipeline. Detailed coverage of the most important areas lives in the dedicated pages linked below.

Pages in this section

Pipeline at a glance

graph LR
    Src["source.rs"] --> Lex[rustc_lexer]
    Lex --> Parse[rustc_parse]
    Parse --> Expand[rustc_expand + rustc_builtin_macros]
    Expand --> Resolve[rustc_resolve]
    Resolve --> Lower[rustc_ast_lowering]
    Lower --> HIR[(HIR)]
    HIR --> HirAna[rustc_hir_analysis]
    HirAna --> HirCk[rustc_hir_typeck]
    HirCk --> MIRBuild[rustc_mir_build]
    MIRBuild --> MIR[(MIR)]
    MIR --> Borrowck[rustc_borrowck]
    MIR --> Const[rustc_const_eval]
    Borrowck --> MIROpt[rustc_mir_transform]
    MIROpt --> Mono[rustc_monomorphize]
    Mono --> CodegenSSA[rustc_codegen_ssa]
    CodegenSSA --> LLVM[rustc_codegen_llvm]
    CodegenSSA --> Cranelift[rustc_codegen_cranelift]
    CodegenSSA --> GCC[rustc_codegen_gcc]

The query system threads through the entire diagram: most edges in the graph above are query invocations, and rustc_middle is the central hub that holds all the data they read and write.

Crate map by phase

The following table groups all rustc_* crates by what they do.

Driver and infrastructure

Crate Role
rustc The thin main binary; calls rustc_driver::main()
rustc_driver Public driver API
rustc_driver_impl Implementation: command-line dispatch, --print modes, batch compilation
rustc_interface Phase orchestration; "run a compilation" abstraction
rustc_session Session, command-line options, target selection
rustc_log tracing setup
rustc_data_structures FxHashMap, IndexVec, BitSet, sync primitives
rustc_arena Typed arena allocators
rustc_index IndexVec and newtyped indices
rustc_macros proc-macros for diagnostic derives, Encodable, query keys
rustc_serialize Internal binary serialization (incremental cache, .rmeta)
rustc_fs_util Filesystem helpers
rustc_thread_pool rustc's fork of Rayon (with deadlock detection)
rustc_graphviz Graphviz emission for debug dumps
rustc_hashes Hashing primitives (FxHash, etc.)
rustc_baked_icu_data Pre-compiled ICU locale data for diagnostics

Frontend

Crate Role
rustc_lexer Tokenizer
rustc_ast AST data types
rustc_ast_ir Shared AST utilities
rustc_ast_pretty AST pretty-printer
rustc_parse Parser
rustc_parse_format Parser for the format! mini-language
rustc_attr_parsing Attribute parsing
rustc_expand Macro expansion engine
rustc_builtin_macros format_args!, derive(...), panic!, cfg!, etc.
rustc_proc_macro Server side of the proc-macro bridge
rustc_resolve Name resolution
rustc_ast_lowering AST → HIR
rustc_ast_passes Post-parse AST validation

HIR and analysis

Crate Role
rustc_hir HIR data types
rustc_hir_id Stable HIR identifiers
rustc_hir_pretty HIR pretty-printer
rustc_hir_analysis Coherence, well-formedness, item-level checks
rustc_hir_typeck Type checking and inference for function bodies
rustc_passes A grab-bag of HIR-level passes (lang-item check, diagnostic items, dead code, etc.)
rustc_privacy Visibility checking
rustc_lint Lint pass framework + built-in lints
rustc_lint_defs Lint definitions (separate to break a cycle)
rustc_pattern_analysis Exhaustiveness checking for match

Type system

Crate Role
rustc_middle The central data structures (TyCtxt, Ty, Body, …)
rustc_type_ir Generic type-system traits used by rustc_middle and rustc_next_trait_solver
rustc_type_ir_macros proc-macros for rustc_type_ir
rustc_infer Type inference engine
rustc_trait_selection Classic trait solver
rustc_next_trait_solver Next-generation trait solver (behind -Znext-solver)
rustc_traits Glue exposing trait queries
rustc_ty_utils Type-related query providers
rustc_transmute transmute validity checking

MIR pipeline

Crate Role
rustc_mir_build HIR → THIR → MIR construction; pattern lowering
rustc_mir_dataflow Generic dataflow framework
rustc_borrowck Borrow checker (NLL)
rustc_mir_transform MIR optimizations and lints
rustc_const_eval MIR interpreter; powers const fn and Miri
rustc_monomorphize Generic instantiation, codegen-unit partitioning

Codegen and metadata

Crate Role
rustc_codegen_ssa Backend-agnostic codegen (linking, debuginfo, target spec, …)
rustc_codegen_llvm LLVM backend
rustc_codegen_cranelift Cranelift backend (separate workspace)
rustc_codegen_gcc GCC (libgccjit) backend (separate workspace)
rustc_llvm FFI bindings to in-tree LLVM (src/llvm-project/)
rustc_metadata .rmeta / .rlib reading and writing
rustc_symbol_mangling Stable symbol mangling (legacy and v0)
rustc_target Built-in target triples and target spec types
rustc_abi Target-agnostic ABI / layout types
rustc_sanitizers ASan / TSan / MSan / others

Errors

Crate Role
rustc_errors Diagnostic infrastructure (Diag, DiagCtxt, Subdiagnostic)
rustc_error_messages Fluent loading and translation
rustc_error_codes Long-form error code descriptions (E0XXX)
rustc_span Span, Symbol, source-map handling

Incremental and queries

Crate Role
rustc_query_impl Query implementation (separated for compile-time isolation)
rustc_incremental On-disk incremental compilation cache

Public APIs (experimental)

Crate Role
rustc_public Stable Mid-level IR API (formerly StableMIR)
rustc_public_bridge Bridge between rustc internals and the stable API
rustc_windows_rc Windows resource compiler integration

Reading order

If you're new to the compiler, the rustc-dev-guide recommends reading in pipeline order: lexer → parser → resolver → AST lowering → HIR → type checking → MIR build → borrow check → MIR opt → codegen. The pages in this section are organized to support that progression — start with Driver and interface, then Frontend, then Type checking and Type system, then MIR, then Codegen.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Compiler – Rust wiki | Factory