{"record":{"id":"5a4c410475cd17bf","repo":"rust-lang/cargo","slug":"probably-rustup-rustc-but-without-rustup-s-env-va","errorCode":null,"errorMessage":"probably rustup rustc, but without rustup's env vars","messagePattern":"probably rustup rustc, but without rustup's env vars","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/util/rustc.rs","lineNumber":378,"sourceCode":"    let maybe_rustup = rustup_rustc == rustc;\n    match (\n        maybe_rustup,\n        gctx.get_env(\"RUSTUP_HOME\"),\n        gctx.get_env(\"RUSTUP_TOOLCHAIN\"),\n    ) {\n        (_, Ok(rustup_home), Ok(rustup_toolchain)) => {\n            debug!(\"adding rustup info to rustc fingerprint\");\n            rustup_toolchain.hash(&mut hasher);\n            rustup_home.hash(&mut hasher);\n            let real_rustc = Path::new(&rustup_home)\n                .join(\"toolchains\")\n                .join(rustup_toolchain)\n                .join(\"bin\")\n                .join(\"rustc\")\n                .with_extension(env::consts::EXE_EXTENSION);\n            paths::mtime(&real_rustc)?.hash(&mut hasher);\n        }\n        (true, _, _) => anyhow::bail!(\"probably rustup rustc, but without rustup's env vars\"),\n        _ => (),\n    }\n\n    Ok(Hasher::finish(&hasher))\n}\n\nfn process_fingerprint(cmd: &ProcessBuilder, extra_fingerprint: u64) -> u64 {\n    let mut hasher = StableHasher::new();\n    extra_fingerprint.hash(&mut hasher);\n    cmd.get_args().for_each(|arg| arg.hash(&mut hasher));\n    let mut env = cmd.get_envs().iter().collect::<Vec<_>>();\n    env.sort_unstable();\n    env.hash(&mut hasher);\n    Hasher::finish(&hasher)\n}\n","sourceCodeStart":360,"sourceCodeEnd":394,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/util/rustc.rs#L360-L394","documentation":"When computing the rustc fingerprint, Cargo detects that the resolved rustc is the rustup shim (rustup_rustc == rustc) but neither RUSTUP_HOME nor RUSTUP_TOOLCHAIN is set. Without those env vars Cargo cannot mix the real toolchain's identity/mtime into the fingerprint, so it conservatively bails rather than risk stale caches when rustup swaps the compiler.","triggerScenarios":"Cargo invoked such that rustup's shim is used but rustup's environment variables are absent — e.g. cargo started by a parent that scrubbed env, invoking ~/.cargo/bin/rustc directly as RUSTC, or a broken rustup install.","commonSituations":"IDE/build-server env sanitization stripping RUSTUP_*; sandboxed/containerized runs that copy the shim but not the env; pinning RUSTC to the rustup proxy manually.","solutions":["Let cargo be launched through rustup normally so RUSTUP_HOME/RUSTUP_TOOLCHAIN are set.","Set RUSTC to the concrete toolchain binary (e.g. ~/.rustup/toolchains/stable-.../bin/rustc) instead of the shim.","Export RUSTUP_HOME and RUSTUP_TOOLCHAIN explicitly in the launch environment.","Run `rustup which rustc` to confirm rustup can resolve the toolchain."],"exampleFix":"# before\n# RUSTC=~/.cargo/bin/rustc cargo build   # shim without env\n\n# after\n# unset RUSTC\n# cargo build   # let rustup set RUSTUP_HOME / RUSTUP_TOOLCHAIN","handlingStrategy":"validation","validationCode":"fn rustup_env_present() -> bool {\n    std::env::var(\"RUSTUP_HOME\").is_ok() && std::env::var(\"RUSTUP_TOOLCHAIN\").is_ok()\n}\n\n// if std::env::var(\"RUSTC\").map(|p| p.ends_with(\"rustup\") || p.contains(\"cargo/bin/rustc\")).unwrap_or(false) {\n//     assert!(rustup_env_present(), \"rustup shim selected without RUSTUP_HOME/RUSTUP_TOOLCHAIN\");\n// }","typeGuard":"fn resolves_to_rustup_shim(rustc: &std::path::Path) -> bool {\n    rustc.file_name() == Some(std::ffi::OsStr::new(\"rustc\"))\n        && rustc.starts_with(home::cargo_home().unwrap_or_default().join(\"bin\"))\n}","tryCatchPattern":null,"preventionTips":["Do not pin RUSTC to the rustup proxy; let rustup choose the toolchain.","In IDEs/servers, preserve RUSTUP_HOME and RUSTUP_TOOLCHAIN in the child env.","If you must bypass rustup, set RUSTC to the concrete toolchain binary."],"tags":["rustup","environment","fingerprint","toolchain"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}