{"id":"47f138803cdbd57f","repo":"rust-lang/cargo","slug":"able-to-invoke-rustc-47f138","errorCode":null,"errorMessage":"able to invoke rustc","messagePattern":"able to invoke rustc","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_fix/mod.rs","lineNumber":188,"sourceCode":"    let mut wrapper = ProcessBuilder::new(env::current_exe()?);\n    wrapper.env(FIX_ENV_INTERNAL, lock_server.addr().to_string());\n    let _started = lock_server.start()?;\n\n    opts.compile_opts.build_config.force_rebuild = true;\n\n    if opts.broken_code {\n        wrapper.env(BROKEN_CODE_ENV_INTERNAL, \"1\");\n    }\n\n    if let Some(mode) = &opts.edition {\n        wrapper.env(EDITION_ENV_INTERNAL, mode.to_string());\n    }\n    if opts.idioms {\n        wrapper.env(IDIOMS_ENV_INTERNAL, \"1\");\n    }\n\n    let rustc = gctx.load_global_rustc(Some(original_ws))?;\n    let sysroot = gctx.get_sysroot(&rustc).expect(\"able to invoke rustc\");\n    if sysroot.is_dir() {\n        wrapper.env(SYSROOT_INTERNAL, sysroot);\n    }\n\n    *opts\n        .compile_opts\n        .build_config\n        .rustfix_diagnostic_server\n        .borrow_mut() = Some(RustfixDiagnosticServer::new()?);\n\n    if let Some(server) = opts\n        .compile_opts\n        .build_config\n        .rustfix_diagnostic_server\n        .borrow()\n        .as_ref()\n    {\n        server.configure(&mut wrapper);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_fix/mod.rs#L170-L206","documentation":"This panic is in cargo fix's execute() method. On line 187 it calls gctx.load_global_rustc(Some(original_ws)) to get the rustc binary, then on line 188 calls gctx.get_sysroot(&rustc).expect(\"able to invoke rustc\"). The invariant is that if load_global_rustc succeeded (found and queried rustc), then get_sysroot (which calls rustc.sysroot()) must also succeed, since it re-invokes the same working rustc.","triggerScenarios":"Running cargo fix when rustc was found and initially queried successfully, but a subsequent call to determine the sysroot fails — e.g., rustc was removed/uninstalled between the two calls, the sysroot path is on a filesystem that became unavailable, or rustc panics when invoked with --print sysroot.","commonSituations":"rustup toolchain being uninstalled or modified during a cargo fix run; a broken rustc wrapper (RUSTC env var) that works for some queries but not others; filesystem issues (NFS disconnect, permissions) on the sysroot path; concurrent cargo processes modifying the toolchain.","solutions":["Verify rustc is functional: run rustc --print sysroot and confirm it outputs a valid path.","Reinstall or repair the Rust toolchain: rustup toolchain install stable.","Check the RUSTC environment variable is not set to a broken wrapper.","Ensure no concurrent rustup operations are modifying the toolchain during the build."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify rustc is functional before running cargo fix\nfn check_rustc() -> Result<(), String> {\n    let output = std::process::Command::new(\"rustc\")\n        .arg(\"--print\")\n        .arg(\"sysroot\")\n        .output()\n        .map_err(|e| format!(\"cannot invoke rustc: {}\", e))?;\n    if !output.status.success() {\n        return Err(\"rustc --print sysroot failed\".into());\n    }\n    let sysroot = String::from_utf8_lossy(&output.stdout);\n    if !std::path::Path::new(sysroot.trim()).is_dir() {\n        return Err(format!(\"sysroot {} does not exist\", sysroot.trim()));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify rustc --print sysroot works before running cargo fix.","Repair the toolchain with rustup if rustc is broken: rustup toolchain install stable.","Check that RUSTC env var is not set to a broken wrapper.","Avoid concurrent rustup operations during builds."],"tags":["rust","cargo","panic","invariant","cargo-fix","rustc","sysroot","toolchain"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}