{"id":"21b6792f2c017f42","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","messagePattern":"(.+?) does not exist, unable to build with the standard library, try:\n        rustup component add rust-src","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/standard_lib.rs","lineNumber":248,"sourceCode":"        .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":230,"sourceCodeEnd":254,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/standard_lib.rs#L230-L254","documentation":"Identical to [44] but emitted when `RUSTUP_TOOLCHAIN` is not set (standard_lib.rs:247-249). The standard library source Cargo.lock is missing and Cargo cannot suggest a specific toolchain, so it bails with the plain message recommending `rustup component add rust-src`.","triggerScenarios":"Building with `-Zbuild-std` on a hand-built (non-rustup) toolchain, or a rustup setup where RUSTUP_TOOLCHAIN is unset, without rust-src installed.","commonSituations":"Custom/dev toolchain without rust-src; rustup where the toolchain was selected via `default` rather than `+toolchain` and the env var is absent; stripped containers.","solutions":["Install rust-src for the active toolchain: `rustup component add rust-src` (or your distro's equivalent).","If using a non-rustup toolchain, point `__CARGO_TESTS_ONLY_SRC_ROOT` (tests) or obtain the source via the toolchain's documentation.","Remove `-Zbuild-std*` flags if building std is not required."],"exampleFix":"# before\ncargo build -Zbuild-std\n# after\nrustup component add rust-src\ncargo build -Zbuild-std","handlingStrategy":"validation","validationCode":"# For non-rustup toolchains, verify the source is present:\nSYSROOT=$(rustc --print sysroot)\ntest -f \"$SYSROOT/lib/rustlib/src/rust/library/Cargo.lock\" || \\\n  echo \"missing rust-src: install via your toolchain provider\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install rust-src whenever you install a toolchain you intend to use with -Zbuild-std.","In Dockerfiles, add the rust-src component in the same layer as rustup.","Avoid -Zbuild-std unless you actually need to rebuild std."],"tags":["build-std","rust-src","sysroot","unstable"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}