{"id":"6097e400ac6b61b7","repo":"rust-lang/cargo","slug":"rustc-load-ok","errorCode":null,"errorMessage":"rustc load ok","messagePattern":"rustc load ok","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_context/mod.rs","lineNumber":176,"sourceCode":"    }\n\n    /// Extra compiler args for either `rustc` or `rustdoc`.\n    ///\n    /// As of now, these flags come from the trailing args of either\n    /// `cargo rustc` or `cargo rustdoc`.\n    pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> {\n        self.extra_compiler_args.get(unit)\n    }\n\n    /// Gets the path to the sysroot.\n    ///\n    /// Helper function that uses GlobalContext.\n    pub fn get_sysroot(&self) -> &'gctx Path {\n        // cfg::bad_cfg_discovery tests that these panics aren't reachable\n        let rustc = self\n            .gctx\n            .load_global_rustc(Some(self.ws))\n            .expect(\"rustc load ok\");\n        self.gctx.get_sysroot(&rustc).expect(\"sysroot fetch ok\")\n    }\n}\n\n#[derive(Copy, Clone, Default, Debug)]\npub struct DepKindSet {\n    pub build: bool,\n    pub normal: bool,\n    pub dev: bool,\n}\n\nimpl DepKindSet {\n    pub fn contains(&self, kind: DepKind) -> bool {\n        match kind {\n            DepKind::Build => self.build,\n            DepKind::Normal => self.normal,\n            DepKind::Development => self.dev,\n        }","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/build_context/mod.rs#L158-L194","documentation":"`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.","triggerScenarios":"`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`.","commonSituations":"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.","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."],"exampleFix":"// before\nlet rustc = self\n    .gctx\n    .load_global_rustc(Some(self.ws))\n    .expect(\"rustc load ok\");\n// after (propagate as an error; callers of get_sysroot are rare and can surface it)\nlet rustc = self.gctx.load_global_rustc(Some(self.ws))?;","handlingStrategy":"validation","validationCode":"// Verify the rustc binary is stable before building:\nuse std::process::Command;\nfn rustc_invocable() -> bool {\n    Command::new(\"rustc\").arg(\"--version\").output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the toolchain via `rust-toolchain.toml`.","Do not change `RUSTC`/`RUSTC_WRAPPER`/`RUSTUP_TOOLCHAIN` during a build.","Run `cargo clean` after switching toolchains."],"tags":["cargo","rustc","toolchain","sysroot","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}