rust-lang/cargo · error
does not exist, unable to build with the standard library…
Error message
{:?} does not exist, unable to build with the standard library, try:
rustup component add rust-src --toolchain {} What it means
Cargo's `-Zbuild-std` / standard-library build path resolves a `library/Cargo.lock` under the rust-src component, and it does not exist. Because `RUSTUP_TOOLCHAIN` is set in the environment, the error appends `--toolchain <id>` to the suggested `rustup component add rust-src` command.
Solutions
- Install the source for the active toolchain: `rustup component add rust-src --toolchain <id>` (use the exact value from the message).
- Verify with `rustup component list --toolchain <id> | grep rust-src`.
- If the toolchain is custom (not rustup-managed), ensure `library/Cargo.lock` is vendored alongside the source.
- Re-run `rustup update` to refresh components.
Example fix
// before cargo +nightly build -Zbuild-std # error: ... try: rustup component add rust-src --toolchain nightly-x86_64-... // after rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu cargo +nightly build -Zbuild-std
Defensive patterns
Strategy: validation
Validate before calling
fn rust_src_installed(toolchain: &str) -> bool {
let out = std::process::Command::new("rustup").args(["component", "list", "--toolchain", toolchain]).output();
matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).contains("rust-src (installed)"))
} Type guard
null
Try / catch
null
Prevention
- Add a CI step: `rustup component add rust-src --toolchain <pinned>`.
- Pin the toolchain in `rust-toolchain.toml` with `components = ["rust-src"]`.
- Re-verify after `rustup update`.
When it happens
Trigger: Invoking `cargo +nightly build -Zbuild-std` without having added `rust-src` for that toolchain; using a custom toolchain path that has `lib/rustlib/src/rust/library` but lacks `Cargo.lock`.
Common situations: Fresh CI runners; switching toolchains after adding rust-src to a different one; partial rustup installations where the `rust-src` component is missing for the active toolchain.
Related errors
- does not exist, unable to build with the standard library…
- could not find specification for target
- malformed output when learning about crate-type
- output of --print= missing when learning about…
- parsing ` ` requires `-Zscript
AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-09-08).
Data as JSON: /api/errors/9ce6b123615f5e9b.
Report an issue: GitHub.
Appendix: source
Thrown at src/compiler/standard_lib.rs:243
// NOTE: This is temporary until we figure out how to acquire the source.
let src_path = target_data
.info(CompileKind::Host)
.sysroot
.join("lib")
.join("rustlib")
.join("src")
.join("rust")
.join("library");
let lock = src_path.join("Cargo.lock");
if !lock.exists() {
let msg = format!(
"{:?} does not exist, unable to build with the standard \
library, try:\n rustup component add rust-src",
lock
);
match target_data.gctx.get_env("RUSTUP_TOOLCHAIN") {
Ok(rustup_toolchain) => {
anyhow::bail!("{} --toolchain {}", msg, rustup_toolchain);
}
Err(_) => {
anyhow::bail!(msg);
}
}
}
Ok(src_path)
}
View on GitHub (pinned to 42eee92bc9)