CodeVetter · Repo Unpack · Extension points
rust-lang/rust
rustc is unusually extensible: the CodegenBackend trait supports drop-in backends loaded as dylibs, Config exposes override_queries/register_lints/file_loader/make_codegen_backend/track_state/psess_created hooks for custom drivers, and the query system is a registry where adding a query is a declaration plus a provider. Bootstrap adds steps via the Step trait + describe! macro; compiletest adds modes via the TestMode enum + a runtest module + directives; tidy adds checks as modules; new targets are TOML-less spec modules; lints, features, attributes, and diagnostics are all declare-and-register tables.
- New codegen backend: implement rustc_codegen_ssa::traits::CodegenBackend (name, init, target_config, provide, codegen/link methods) and expose it via the __rustc_codegen_backend symbol in a dylib loadable by -Zcodegen-backend, or inject it via Config::make_codegen_backend in a custom driver.
- Custom drivers can override individual queries through Config::override_queries (fn(&Session, &mut Providers)) invoked after codegen_backend.provide in create_and_enter_global_ctxt — the mechanism rustc tools use to intercept analysis.
- New queries: add a `query` block in compiler/rustc_middle/src/queries.rs with key/value types and modifiers; rustc_macros::rustc_queries generates the TyCtxt accessor and Providers field; implement the provider fn and register it in the owning crate's provide() chained into DEFAULT_QUERY_PROVIDERS.
- New lints: declare_lint!/declare_lint_pass!/impl_lint_pass from rustc_lint_defs, implement an EarlyLintPass or LateLintPass in rustc_lint, and register via register_builtins' lint_vec() lists; drivers can add out-of-tree lints through Config::register_lints.
- Driver hooks in interface::Config: file_loader (custom source loading, designed for rust-analyzer's VFS), psess_created (mutate ParseSess), track_state (record env/file deps into sess.env_depinfo/file_depinfo), extra_symbols (pre-interned symbols after PREDEFINED_SYMBOLS_COUNT), using_internal_features.
- New bootstrap step: implement the Step trait (run/should_run/make_run metadata) and list it in Builder::get_step_descriptions' describe! macro for the relevant Kind; step bodies live in src/bootstrap/src/core/build_steps/.
- New compiletest suite/mode: add a TestMode variant in common.rs, a runner module under runtest/ (mod list is tidy-alphabetized), directive names in directives/directive_names.rs, and handlers in directives/handlers.rs' DIRECTIVE_HANDLERS_MAP.
- New tidy check: add a module in src/tools/tidy/src/ and spawn it from main.rs' scoped-thread section; existing examples cover style, deps, extdeps allowlists, ui_tests conventions, target_policy, edition, and alphabetical ordering.
- New compiler flag: add entries in rustc_session's options table (compiler/rustc_session/src/options.rs and options/ submodules); dep_tracking macros (hash_opt!/insert!) tie each option into incremental-crate-hash computation, and untracked options are marked [UNTRACKED]/[TRACKED_NO_CRATE_HASH].
- New target: add a spec module under compiler/rustc_target/src/spec/targets/ (335 existing target modules) — spec/json.rs also supports JSON target descriptions loaded at runtime.
- New language feature: register it in rustc_feature/src/unstable.rs (and move to accepted.rs/removed.rs on stabilization/removal); builtin attributes live in builtin_attrs.rs.
- New diagnostics: derive Diagnostic/Subdiagnostic via rustc_macros' diagnostics module and use inline Fluent DiagMessage strings; rustc_error_messages::register_functions exposes custom Fluent functions (e.g. STREQ).
- New CI job: edit src/ci/github-actions/jobs.yml (runner anchors like &job-linux-4c plus job entries); citool's calculate-job-matrix turns it into the matrix consumed by ci.yml — ci.yml itself says to modify jobs.yml rather than the workflow.
- Custom rustc-like binaries: link rustc_driver (dylib) and call rustc_driver_impl::run_compiler(at_args, callbacks) with a Callbacks impl (config/after_crate_root_parsing/after_expansion/after_analysis) — the pattern used by clippy/rustdoc-style drivers, with rustc_driver::main as the minimal example.