rust-lang/rust · error

TOOLCHAIN_NAME

Error message

TOOLCHAIN_NAME

What it means

This panic fires in the `rustc-clif` wrapper script for the Cranelift codegen backend. Identical in cause to [266]: `option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME")` at line 49. The script sets `RUSTUP_TOOLCHAIN` to the value of `TOOLCHAIN_NAME` to ensure the right toolchain is used when invoking `rustc`. If the variable wasn't set at script-compile time, the script panics on launch.

Source

Thrown at compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs:49

    if !passed_args
        .iter()
        .any(|arg| arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot=")))
    {
        args.push(OsString::from("--sysroot"));
        args.push(OsString::from(sysroot.to_str().unwrap()));
    }
    if passed_args.is_empty() {
        // Don't pass any arguments when the user didn't pass any arguments
        // either to ensure the help message is shown.
        args.clear();
    }
    args.extend(passed_args);

    let rustc = if let Some(rustc) = option_env!("RUSTC") {
        rustc
    } else {
        // Ensure that the right toolchain is used
        env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
        "rustc"
    };

    #[cfg(unix)]
    panic!("Failed to spawn rustc: {}", Command::new(rustc).args(args).exec());

    #[cfg(not(unix))]
    std::process::exit(
        Command::new(rustc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
    );
}

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Use the official `y.rs` build system which sets `TOOLCHAIN_NAME` during compilation.
  2. Set `TOOLCHAIN_NAME` manually: `TOOLCHAIN_NAME=stage2 cargo build --manifest-path scripts/Cargo.toml`.
  3. Set the `RUSTC` environment variable to your rustc binary; the script will use it directly and bypass the `TOOLCHAIN_NAME` path.
  4. Reinstall cg_clif following the README's exact build instructions.

Example fix

# before (rustc-clif built without TOOLCHAIN_NAME → panic)
rustc-clif --version

# after (set RUSTC env to bypass toolchain lookup)
RUSTC=$(rustup which rustc) rustc-clif --version
# or rebuild properly:
TOOLCHAIN_NAME=nightly cargo build --manifest-path scripts/Cargo.toml
Defensive patterns

Strategy: validation

Validate before calling

// Same as [266]: ensure TOOLCHAIN_NAME is set at build time
// test -n "$TOOLCHAIN_NAME" || export TOOLCHAIN_NAME=$(rustc --version)
// Or set RUSTC to bypass:
// export RUSTC=$(rustup which rustc)

Prevention

When it happens

Trigger: Running `rustc-clif` (the Cranelift backend's rustc wrapper) when the binary was compiled without `TOOLCHAIN_NAME` in the build environment. Occurs when the wrapper was built outside the cg_clif build system.

Common situations: Manually building the cg_clif scripts without the build system, or installing a pre-built binary that was compiled without proper environment setup. The `rustc-clif` wrapper is what actually invokes rustc with `-Zcodegen-backend=<cranelift dylib>`, so it's needed for every cg_clif compilation.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/000315b84817814c. Report an issue: GitHub.