rust-lang/rust · error

TOOLCHAIN_NAME

Error message

TOOLCHAIN_NAME

What it means

This panic fires in the `rustdoc-clif` wrapper script for the Cranelift codegen backend. Identical in cause to [266] and [267]: `option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME")` at line 49. The script wraps `rustdoc` with the Cranelift backend and needs the toolchain name to pin the correct rustup toolchain via `RUSTUP_TOOLCHAIN`. If the build-time env var was absent, it panics on launch.

Source

Thrown at compiler/rustc_codegen_cranelift/scripts/rustdoc-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 rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
        rustdoc
    } else {
        // Ensure that the right toolchain is used
        env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
        "rustdoc"
    };

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

    #[cfg(not(unix))]
    std::process::exit(
        Command::new(rustdoc).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 injects `TOOLCHAIN_NAME` at compile time.
  2. Set `TOOLCHAIN_NAME` manually before building: `TOOLCHAIN_NAME=stage2 cargo build --manifest-path scripts/Cargo.toml`.
  3. Set the `RUSTDOC` environment variable to your rustdoc binary; the script will use it directly and skip the toolchain lookup.
  4. Reinstall following the cg_clif README build instructions.

Example fix

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

# after (set RUSTDOC to bypass)
RUSTDOC=$(rustup which rustdoc) rustdoc-clif --version
# or rebuild:
TOOLCHAIN_NAME=nightly cargo build --manifest-path scripts/Cargo.toml
Defensive patterns

Strategy: validation

Validate before calling

// Same as [266]/[267]: ensure TOOLCHAIN_NAME is set at build time
// Or set RUSTDOC to bypass:
// export RUSTDOC=$(rustup which rustdoc)

Prevention

When it happens

Trigger: Running `rustdoc-clif` when the binary was compiled without `TOOLCHAIN_NAME` in the environment. Happens when built outside the official cg_clif build system.

Common situations: Manually building cg_clif scripts or installing a pre-built `rustdoc-clif` that wasn't compiled with the build system's environment. Needed when generating documentation with the Cranelift codegen backend active.

Related errors


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