rust-lang/cargo · error

able to invoke rustc

Error message

able to invoke rustc

What it means

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.

Source

Thrown at src/ops/cargo_fix/mod.rs:188

    let mut wrapper = ProcessBuilder::new(env::current_exe()?);
    wrapper.env(FIX_ENV_INTERNAL, lock_server.addr().to_string());
    let _started = lock_server.start()?;

    opts.compile_opts.build_config.force_rebuild = true;

    if opts.broken_code {
        wrapper.env(BROKEN_CODE_ENV_INTERNAL, "1");
    }

    if let Some(mode) = &opts.edition {
        wrapper.env(EDITION_ENV_INTERNAL, mode.to_string());
    }
    if opts.idioms {
        wrapper.env(IDIOMS_ENV_INTERNAL, "1");
    }

    let rustc = gctx.load_global_rustc(Some(original_ws))?;
    let sysroot = gctx.get_sysroot(&rustc).expect("able to invoke rustc");
    if sysroot.is_dir() {
        wrapper.env(SYSROOT_INTERNAL, sysroot);
    }

    *opts
        .compile_opts
        .build_config
        .rustfix_diagnostic_server
        .borrow_mut() = Some(RustfixDiagnosticServer::new()?);

    if let Some(server) = opts
        .compile_opts
        .build_config
        .rustfix_diagnostic_server
        .borrow()
        .as_ref()
    {
        server.configure(&mut wrapper);

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Verify rustc is functional: run rustc --print sysroot and confirm it outputs a valid path.
  2. Reinstall or repair the Rust toolchain: rustup toolchain install stable.
  3. Check the RUSTC environment variable is not set to a broken wrapper.
  4. Ensure no concurrent rustup operations are modifying the toolchain during the build.
Defensive patterns

Strategy: validation

Validate before calling

// Verify rustc is functional before running cargo fix
fn check_rustc() -> Result<(), String> {
    let output = std::process::Command::new("rustc")
        .arg("--print")
        .arg("sysroot")
        .output()
        .map_err(|e| format!("cannot invoke rustc: {}", e))?;
    if !output.status.success() {
        return Err("rustc --print sysroot failed".into());
    }
    let sysroot = String::from_utf8_lossy(&output.stdout);
    if !std::path::Path::new(sysroot.trim()).is_dir() {
        return Err(format!("sysroot {} does not exist", sysroot.trim()));
    }
    Ok(())
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/47f138803cdbd57f.json. Report an issue: GitHub.