rust-lang/cargo · error
rustc load ok
Error message
rustc load ok
What it means
`BuildContext::get_sysroot` re-invokes `gctx.load_global_rustc(Some(self.ws)).expect("rustc load ok")`. The rustc used to compute target info has already been loaded successfully earlier in the build, and the result is cached on the `GlobalContext`, so a second call is expected to return the cached value. Failure indicates the cached rustc was cleared, the toolchain changed under the build, or `load_global_rustc` is non-deterministic for the environment.
Source
Thrown at src/compiler/build_context/mod.rs:176
}
/// Extra compiler args for either `rustc` or `rustdoc`.
///
/// As of now, these flags come from the trailing args of either
/// `cargo rustc` or `cargo rustdoc`.
pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> {
self.extra_compiler_args.get(unit)
}
/// Gets the path to the sysroot.
///
/// Helper function that uses GlobalContext.
pub fn get_sysroot(&self) -> &'gctx Path {
// cfg::bad_cfg_discovery tests that these panics aren't reachable
let rustc = self
.gctx
.load_global_rustc(Some(self.ws))
.expect("rustc load ok");
self.gctx.get_sysroot(&rustc).expect("sysroot fetch ok")
}
}
#[derive(Copy, Clone, Default, Debug)]
pub struct DepKindSet {
pub build: bool,
pub normal: bool,
pub dev: bool,
}
impl DepKindSet {
pub fn contains(&self, kind: DepKind) -> bool {
match kind {
DepKind::Build => self.build,
DepKind::Normal => self.normal,
DepKind::Development => self.dev,
}View on GitHub (pinned to 0e07a15537)
Solutions
- Pin the toolchain with `rustup override set <channel>` or a `rust-toolchain.toml` file before building.
- Avoid changing `RUSTC`/`RUSTC_WRAPPER`/`RUSTUP_TOOLCHAIN` while a build runs.
- Run `cargo clean` after switching toolchains, then rebuild.
Example fix
// before
let rustc = self
.gctx
.load_global_rustc(Some(self.ws))
.expect("rustc load ok");
// after (propagate as an error; callers of get_sysroot are rare and can surface it)
let rustc = self.gctx.load_global_rustc(Some(self.ws))?; Defensive patterns
Strategy: validation
Validate before calling
// Verify the rustc binary is stable before building:
use std::process::Command;
fn rustc_invocable() -> bool {
Command::new("rustc").arg("--version").output().map(|o| o.status.success()).unwrap_or(false)
} Prevention
- Pin the toolchain via `rust-toolchain.toml`.
- Do not change `RUSTC`/`RUSTC_WRAPPER`/`RUSTUP_TOOLCHAIN` during a build.
- Run `cargo clean` after switching toolchains.
When it happens
Trigger: `rustup override`/default toolchain changing while a build is in progress; `RUSTC`/`RUSTC_WRAPPER` env vars mutated mid-build; sysroot relocation between the initial probe and `get_sysroot`; a concurrent `rustup toolchain uninstall`.
Common situations: Long-running builds under `rustup` while the active toolchain is swapped; CI that re-points `RUSTUP_TOOLCHAIN` between steps sharing a `target/` dir; editor integrations that change `RUSTC` env.
Related errors
- able to invoke rustc
- able to invoke rustc
- malformed output when learning about crate-type {} informati
- output of --print={request} missing when learning about targ
- must be a host tuple
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/6097e400ac6b61b7.json.
Report an issue: GitHub.