rust-lang/rust · error

not implemented

Error message

not implemented

What it means

In codegen_static (consts.rs:96), the backend checks whether the static's value type is i1 (a single boolean bit, the LLVM representation of bool SSA values). If so it calls unimplemented!() because the GCC path for storing a boolean SSA value into a static's storage slot is not finished — the FIXME comment above notes that i1 values must be widened to i8 for some LLVM optimization passes, but the GCC backend has not implemented that widening for statics.

Solutions

  1. Switch the affected crate to the LLVM backend.
  2. Change the static's type from bool to a type that lowers to i8/u8 (e.g. static FLAG: u8 = 1;) and convert at use sites.
  3. If you control a fork, widen the i1 value to i8 before storage in codegen_static, mirroring the LLVM backend.
  4. Avoid static bools in code compiled with rustc_codegen_gcc until the gap is closed upstream.

Example fix

// before: static bool (panics in gcc backend at consts.rs:96)
static ENABLED: bool = true;

// after: store as u8, convert at use sites
static ENABLED: u8 = 1;
// at use site:
let enabled = ENABLED != 0;
Defensive patterns

Strategy: validation

Validate before calling

# Reject static bools in code meant for the gcc backend.
if grep -rnE '^\s*static\s+[A-Z_]+\s*:\s*bool' src/; then
  echo 'static bool is unsupported by rustc_codegen_gcc (consts.rs:96); use u8 or compile with LLVM.'
  exit 1
fi

Type guard

// Represent boolean globals as u8 to avoid the i1 static codegen path.
struct Flag(const u8);
impl Flag {
    const TRUE: u8 = 1;
    const FALSE: u8 = 0;
}
static ENABLED: u8 = Flag::TRUE; // caller checks != 0

Try / catch

if ! RUSTFLAGS="-Zcodegen-backend=gcc" cargo build 2>err.log; then
  grep -q 'not implemented' err.log && { echo 'static bool gap; using LLVM'; cargo build; }
fi

Prevention

When it happens

Trigger: Defining a static whose initializer value lowers to an i1 type — e.g. static BOOL: bool = true; or any static of type bool where the codegen value is the i1 representation rather than i8. Compiling such a crate with the GCC backend reaches consts.rs:96 and panics.

Common situations: Defining static bools or statics of types whose initializer is reduced to an i1 constant; common in config flags, feature flags, or FFI bool globals compiled under the GCC backend.

Related errors


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

Appendix: source

Thrown at compiler/rustc_codegen_gcc/src/consts.rs:96

            .global_set_readonly();
        self.const_globals.borrow_mut().insert(cv, global_value);
        global_value
    }

    fn codegen_static(&mut self, def_id: DefId) {
        let attrs = self.tcx.codegen_fn_attrs(def_id);

        let Ok((value, alloc)) = codegen_static_initializer(self, def_id) else {
            // Error has already been reported
            return;
        };
        let alloc = alloc.inner();

        // boolean SSA values are i1, but they have to be stored in i8 slots,
        // otherwise some LLVM optimization passes don't work as expected
        let val_llty = self.val_ty(value);
        if val_llty == self.type_i1() {
            unimplemented!();
        };

        let is_thread_local = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
        let global = self.get_static_inner(def_id, val_llty);

        #[cfg(feature = "master")]
        if global.to_rvalue().get_type() != val_llty {
            global.to_rvalue().set_type(val_llty);
        }

        // NOTE: Alignment from attributes has already been applied to the allocation.
        set_global_alignment(self, global, alloc.align);

        global.global_set_initializer_rvalue(value);

        // As an optimization, all shared statics which do not have interior
        // mutability are placed into read-only memory.
        if alloc.mutability.is_not() {

View on GitHub (pinned to 7088e4b63a)