The rustc_private feature allows external crates to use compiler internals.
When using the rustc_private feature with official Rust toolchains distributed via rustup, you need to install two additional components:
rustc-dev: Provides compiler librariesllvm-tools: Provides LLVM libraries required for linking
Install both components using rustup:
rustup component add rustc-dev llvm-tools
Without the llvm-tools component, you'll encounter linking errors like:
error: linking with `cc` failed: exit status: 1
|
= note: rust-lld: error: unable to find library -lLLVM-{version}
For custom-built toolchains or environments not using rustup, additional configuration is typically required:
- LLVM libraries must be available in your system's library search paths
- The LLVM version must match the one used to build your Rust toolchain
- Verify LLVM is installed and accessible
- Ensure that library paths are set:
export LD_LIBRARY_PATH=/path/to/llvm/lib:$LD_LIBRARY_PATH
- Ensure your LLVM version is compatible with your Rust toolchain
When developing out-of-tree projects that use rustc_private crates, you can configure rust-analyzer to recognize these crates.
-
Configure
rust-analyzer.rustc.sourceto"discover"in your editor settings.
For VS Code, add torust_analyzer_settings.json:{ "rust-analyzer.rustc.source": "discover" } -
Add the following to the
Cargo.tomlof every crate that usesrustc_private:[package.metadata.rust-analyzer] rustc_private = true
This configuration allows rust-analyzer to properly recognize and provide IDE support for rustc_private crates in out-of-tree projects.
The nightly-rustc internal crates' documentation is only available for the latest nightly. If you depend on compiler internals from an older nightly, you may want to refer to the internal documentation from that particular nightly. The only way to do this is to generate the documentation locally. For example, to get documentation for nightly-2025-11-08:
Get the Git commit hash for that nightly:
rustup toolchain install nightly-2025-11-08
rustc +nightly-2025-11-08 --version --verboseThe output will include a commit-hash line identifying the exact source revision. Check out rust-lang/rust at that commit, then follow the steps in compiler documentation.
- GitHub Issue #137421 explains that
rustc_privatelinker failures often occur becausellvm-toolsis not installed