{"id":"4a477110a7574fad","repo":"rust-lang/rust","slug":"failed-to-spawn-rustc","errorCode":null,"errorMessage":"Failed to spawn rustc: {}","messagePattern":"Failed to spawn rustc: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs","lineNumber":54,"sourceCode":"        args.push(OsString::from(sysroot.to_str().unwrap()));\n    }\n    if passed_args.is_empty() {\n        // Don't pass any arguments when the user didn't pass any arguments\n        // either to ensure the help message is shown.\n        args.clear();\n    }\n    args.extend(passed_args);\n\n    let rustc = if let Some(rustc) = option_env!(\"RUSTC\") {\n        rustc\n    } else {\n        // Ensure that the right toolchain is used\n        env::set_var(\"RUSTUP_TOOLCHAIN\", option_env!(\"TOOLCHAIN_NAME\").expect(\"TOOLCHAIN_NAME\"));\n        \"rustc\"\n    };\n\n    #[cfg(unix)]\n    panic!(\"Failed to spawn rustc: {}\", Command::new(rustc).args(args).exec());\n\n    #[cfg(not(unix))]\n    std::process::exit(\n        Command::new(rustc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),\n    );\n}\n","sourceCodeStart":36,"sourceCodeEnd":61,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs#L36-L61","documentation":"Panics in the rustc-clif launcher shim when Command::exec() cannot replace the process with rustc. rustc-clif prepends the cranelift codegen-backend and sysroot flags and then execs the real rustc; the panic fires only when exec itself fails, not when rustc exits non-zero.","triggerScenarios":"Reached at the tail of rustc-clif.rs (unix path) after assembling -Zcodegen-backend=, --sysroot, and panic flags. Exec fails when the rustc binary cannot be started at all.","commonSituations":"rustc not on PATH or RUSTC env var points to a missing/unexecutable binary; the rustup toolchain named by TOOLCHAIN_NAME is not installed or was partially uninstalled; running rustc-clif directly without the rustup-managed sysroot next to it; broken PATH in a nested shell or CI container; the sysroot parent walk (sysroot.parent()) produced an unexpected path because the binary was relocated.","solutions":["Run `rustup toolchain list` and install the expected toolchain.","Run `which rustc` / `$RUSTC --version` in the same environment.","Invoke rustc-clif through the installed toolchain (e.g. `rustup run <toolchain> rustc-clif`) rather than the bare binary, so the sysroot resolves correctly.","Re-run `./y.rs prepare` to (re)install the toolchain and scripts together."],"exampleFix":"// before\n#[cfg(unix)]\npanic!(\"Failed to spawn rustc: {}\", Command::new(rustc).args(args).exec());\n// after\n#[cfg(unix)]\n{\n    eprintln!(\"rustc-clif: exec rustc={:?} sysroot={:?}\", rustc, sysroot);\n    panic!(\"Failed to spawn rustc: {}\", Command::new(rustc).args(args).exec());\n}","handlingStrategy":"validation","validationCode":"fn ensure_tool(name: &str) -> Result<(), String> {\n    if which::which(name).is_err() {\n        return Err(format!(\"{} not found on PATH; run `rustup component add rustc` or fix PATH\", name));\n    }\n    Ok(())\n}\n// call ensure_tool(\"rustc\") before invoking rustc-clif","typeGuard":"fn rustc_available() -> bool {\n    std::process::Command::new(\"rustc\").arg(\"--version\").status().is_ok()\n}","tryCatchPattern":"use std::panic;\nif panic::catch_unwind(|| Command::new(\"rustc\").args(args).status()).is_err() {\n    eprintln!(\"rustc spawn failed; check toolchain / PATH\"); std::process::exit(1);\n}","preventionTips":["Verify `rustc --version` works before invoking rustc-clif.","Pin the toolchain with rustup so rustc-clif resolves to the expected binary.","Make sure RUSTC_WRAPPER / RUSTC env vars are not pointing at a missing binary.","Don't shadow rustc with a script that itself fails to exec."],"tags":["cg-clif","launcher","process-spawn","unix","rustup"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}