rust-lang/rust · error

not implemented

Error message

not implemented

What it means

`handle_native` (gcc_util.rs:118-131) resolves the `native` target CPU: if the requested `name` is not the special `NATIVE_CPU` token it maps via `arch_to_gcc`. When `name == NATIVE_CPU` (i.e. `-C target-cpu=native`), detecting the actual host CPU requires the libgccjit `master` feature — `context.get_target_info().arch()` (gcc_util.rs:126-127). Without `feature="master"` the fallback is `unimplemented!()` at line 130. So building/running rustc_codegen_gcc without the `master` feature and requesting native CPU detection is unsupported.

Source

Thrown at compiler/rustc_codegen_gcc/src/gcc_util.rs:130

        "M68000" => "68000",
        "M68020" => "68020",
        _ => name,
    }
}

fn handle_native(name: &str) -> &str {
    if name != NATIVE_CPU {
        return arch_to_gcc(name);
    }

    #[cfg(feature = "master")]
    {
        // Get the native arch.
        let context = Context::default();
        context.get_target_info().arch().unwrap().to_str().unwrap()
    }
    #[cfg(not(feature = "master"))]
    unimplemented!();
}

pub fn target_cpu(sess: &Session) -> &str {
    match sess.opts.cg.target_cpu {
        Some(ref name) => handle_native(name),
        None => handle_native(sess.target.cpu.as_ref()),
    }
}

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Enable the `master` feature when building rustc_codegen_gcc (`--cfg feature="master"` / build with the project's prescribed libgccjit-master toolchain) so `get_target_info().arch()` is available.
  2. Stop passing `-Ctarget-cpu=native`; use an explicit CPU name (e.g. `-Ctarget-cpu=x86-64`) which takes the `arch_to_gcc` path and does not require the feature.
  3. If you must support native detection without the master feature, implement a fallback (e.g. read the host CPU via another mechanism) instead of `unimplemented!()`.
  4. Check that your libgccjit is built from master and that the gccjit crate exposes `get_target_info`; a released libgccjit lacks this API.

Example fix

// before (invocation triggering gcc_util.rs:130)
// RUSTFLAGS='-Ctarget-cpu=native' cargo build   (master feature OFF)

// after
// either enable master, or pin the cpu:
// 1) build backend with:   --cfg feature="master"
// 2) or pass explicit cpu: RUSTFLAGS='-Ctarget-cpu=x86-64' cargo build
Defensive patterns

Strategy: fallback

Validate before calling

// gcc_util.rs:130 -> unimplemented!() under #[cfg(not(feature = "master"))]
// for native arch detection. Enable the master libgccjit feature, or bypass
// native_arch() by passing target_cpu explicitly.
#[cfg(feature = "master")]
fn native_arch() -> String { /* implemented path */ }
#[cfg(not(feature = "master"))]
fn native_arch() -> String {
    // fallback: do not query libgccjit; use a static/hardcoded value
    String::from("native")
}

Prevention

When it happens

Trigger: Compiling with `--cfg feature="master"` disabled (the default for a plain `cargo build` of the backend) AND the codegen session requests `target-cpu=native` or the target spec's `cpu` field equals `NATIVE_CPU`. `target_cpu(sess)` (gcc_util.rs:133-138) calls `handle_native` which hits the `#[cfg(not(feature = "master"))]` arm.

Common situations: Running the backend without the `master` libgccjit feature but passing `-Ctarget-cpu=native` (common when users copy LLVM-oriented RUSTFLAGS). Also when the target spec itself defaults `cpu` to `native`. The `master` feature corresponds to building libgccjit from its Git master branch rather than a released version.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/4a6740ec4efe5dbd.json. Report an issue: GitHub.