{"id":"968852bf01035c96","repo":"rust-lang/cargo","slug":"toolchain","errorCode":null,"errorMessage":"{} --toolchain {}","messagePattern":"(.+?) --toolchain (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/standard_lib.rs","lineNumber":245,"sourceCode":"    let src_path = ws\n        .gctx()\n        .get_sysroot(&rustc)\n        .expect(\"able to invoke rustc\")\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 ws.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":227,"sourceCodeEnd":254,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/standard_lib.rs#L227-L254","documentation":"detect_sysroot_src_path (standard_lib.rs:220-252) locates the standard library source at `<sysroot>/lib/rustlib/src/rust/library/Cargo.lock` (used by `-Zbuild-std`). If that Cargo.lock does not exist, the rust-src component is missing. When `RUSTUP_TOOLCHAIN` is set, Cargo bails suggesting `rustup component add rust-src --toolchain <toolchain>` so the command targets the correct toolchain.","triggerScenarios":"Invoking a build that needs the standard library source (e.g. `cargo build -Zbuild-std`) without the `rust-src` rustup component installed for the active nightly toolchain.","commonSituations":"First-time `-Zbuild-std` use; switching toolchains where rust-src was added to one but not another; CI image that installs rustc but not rust-src.","solutions":["Install the source: `rustup component add rust-src --toolchain <toolchain>` (use the toolchain shown in the message).","If you don't need to build the std library, drop the `-Zbuild-std*` flags.","Verify with `rustup component list --toolchain <toolchain>` that `rust-src` is installed."],"exampleFix":"# before\ncargo +nightly build -Zbuild-std\n# after\nrustup component add rust-src --toolchain nightly\ncargo +nightly build -Zbuild-std","handlingStrategy":"validation","validationCode":"# Provision rust-src for the active nightly before -Zbuild-std:\nrustup component add rust-src --toolchain nightly || true\ncargo +nightly build -Zbuild-std","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add `rust-src` to your rustup component list in CI setup scripts.","Pin the nightly toolchain with rust-toolchain.toml so rust-src targets the right toolchain.","Document -Zbuild-std prerequisites for contributors."],"tags":["build-std","rust-src","rustup","sysroot","unstable"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}