{"record":{"id":"9ce6b123615f5e9b","repo":"rust-lang/cargo","slug":"does-not-exist-unable-to-build-with-the-stan","errorCode":null,"errorMessage":"{:?} does not exist, unable to build with the standard library, try:\n        rustup component add rust-src --toolchain {}","messagePattern":"(.+?) does not exist, unable to build with the standard library, try:\n        rustup component add rust-src --toolchain (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/standard_lib.rs","lineNumber":243,"sourceCode":"    // NOTE: This is temporary until we figure out how to acquire the source.\n    let src_path = target_data\n        .info(CompileKind::Host)\n        .sysroot\n        .join(\"lib\")\n        .join(\"rustlib\")\n        .join(\"src\")\n        .join(\"rust\")\n        .join(\"library\");\n    let lock = src_path.join(\"Cargo.lock\");\n    if !lock.exists() {\n        let msg = format!(\n            \"{:?} does not exist, unable to build with the standard \\\n             library, try:\\n        rustup component add rust-src\",\n            lock\n        );\n        match target_data.gctx.get_env(\"RUSTUP_TOOLCHAIN\") {\n            Ok(rustup_toolchain) => {\n                anyhow::bail!(\"{} --toolchain {}\", msg, rustup_toolchain);\n            }\n            Err(_) => {\n                anyhow::bail!(msg);\n            }\n        }\n    }\n    Ok(src_path)\n}\n","sourceCodeStart":225,"sourceCodeEnd":252,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/compiler/standard_lib.rs#L225-L252","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\ncargo +nightly build -Zbuild-std\n# error: ... try: rustup component add rust-src --toolchain nightly-x86_64-...\n\n// after\nrustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu\ncargo +nightly build -Zbuild-std","handlingStrategy":"validation","validationCode":"fn rust_src_installed(toolchain: &str) -> bool {\n    let out = std::process::Command::new(\"rustup\").args([\"component\", \"list\", \"--toolchain\", toolchain]).output();\n    matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).contains(\"rust-src (installed)\"))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["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`."],"tags":["cargo","build-std","rust-src","rustup","toolchain"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-09-08T04:50:20.151Z","contentChangedAt":"2026-09-08T04:50:20.151Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}