rust-lang/rust · error · bridge::Error

{self:?}

Error message

{self:?}

What it means

Produced by the `Stable` impl for `mir::interpret::ErrorHandled` (mir.rs:921), which converts rustc's internal constant-evaluation error type into a stable `Error` by formatting it with Debug. `ErrorHandled` represents any error surfaced during const evaluation — either `TooGeneric` (the constant depends on parameters that are not yet known) or `Reported` (a concrete evaluation error already emitted as a diagnostic).

Solutions

  1. Inspect the formatted message: `TooGeneric` means you must monomorphize/instantiate before evaluating; `Reported(...)` means look at the upstream rustc diagnostic for the root cause.
  2. Guard evaluation behind a check that the relevant item is fully monomorphized.
  3. Fix the source of the const-eval error (e.g. forbidden operation in a const context) shown in the compiler diagnostic.
Defensive patterns

Strategy: try-catch

Try / catch

// ErrorHandled is a propagated error; handle at the query boundary.
let alloc = match static_def.eval_initializer() {
    Ok(a) => a,
    Err(e) => {
        // e is "{self:?}" of ErrorHandled; check for TooGeneric vs Reported
        if e.to_string().contains("TooGeneric") {
            // needs full monomorphization before eval
        }
        return Err(e);
    }
};

Prevention

When it happens

Trigger: Any rustc_public query that triggers constant evaluation — e.g. `try_const_eval`, `eval_initializer` on a static, or reading an evaluated const in MIR — when rustc records an `ErrorHandled` rather than a value.

Common situations: Reading the initializer of a static that fails const evaluation; evaluating an intrinsic that cannot be const-folded; encountering a constant that depends on generic parameters still in scope (TooGeneric) inside a query that expected a monomorphized value.

Related errors


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

Appendix: source

Thrown at compiler/rustc_public/src/unstable/convert/stable/mir.rs:921

                let ty = ty.stable(tables, cx);
                MirConst::new(ConstantKind::ZeroSized, ty, id)
            }
            mir::Const::Val(val, ty) => {
                let ty = cx.lift(ty);
                let val = cx.lift(val);
                let kind = ConstantKind::Allocated(alloc::new_allocation(ty, val, tables, cx));
                let ty = ty.stable(tables, cx);
                MirConst::new(kind, ty, id)
            }
        }
    }
}

impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled {
    type T = Error;

    fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
        bridge::Error::new(format!("{self:?}"))
    }
}

impl<'tcx> Stable<'tcx> for MonoItem<'tcx> {
    type T = crate::mir::mono::MonoItem;

    fn stable<'cx>(
        &self,
        tables: &mut Tables<'cx, BridgeTys>,
        cx: &CompilerCtxt<'cx, BridgeTys>,
    ) -> Self::T {
        use crate::mir::mono::MonoItem as StableMonoItem;
        match self {
            MonoItem::Fn(instance) => StableMonoItem::Fn(instance.stable(tables, cx)),
            MonoItem::Static(def_id) => StableMonoItem::Static(tables.static_def(*def_id)),
            MonoItem::GlobalAsm(item_id) => StableMonoItem::GlobalAsm(opaque(item_id)),
        }
    }

View on GitHub (pinned to 7088e4b63a)