rust-lang/rust · error · bridge::Error
{self:?}
Error message
{self:?} What it means
Produced by the `Stable` impl for rustc's `mir::interpret::ErrorHandled` in compiler/rustc_public/src/unstable/convert/stable/mir.rs:921. When a MIR constant failed to evaluate inside the compiler (a `TooGeneric`, `Reported`, or other const-eval error), rustc_public surfaces it as an opaque `Error` whose message is the debug rendering of the original error. This is a pass-through of an internal constant-evaluation failure rather than a rustc_public bug.
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 22057b88b0)
Solutions
- Provide a fully monomorphized typing environment before stabilizing MIR so generic constants can be evaluated.
- Treat `ErrorHandled` as expected for generic/non-mono code and skip or record the item rather than failing.
- Filter out items whose constants are `TooGeneric` before entering the stable conversion path.
Defensive patterns
Strategy: try-catch
Try / catch
// ErrorHandled is opaque by design: it surfaces during const evaluation
// (TooGeneric / Reported / InspectionOverflow) and the Debug string is the
// only payload. Catch, classify heuristically, and degrade gracefully.
fn eval_or_fallback(c: &MirConst) -> Allocation {
match try_eval(c) {
Ok(alloc) => alloc,
Err(e) => {
let msg = e.to_string();
if msg.contains("TooGeneric") {
// provide monomorphized args / a concrete typing env, then retry
return default_allocation(c.ty());
}
if msg.contains("Reported") || msg.contains("Overflow") {
// upstream const-eval reported an error; skip this constant
return default_allocation(c.ty());
}
return default_allocation(c.ty());
}
}
} Prevention
- This error is a propagated compiler-internal `ErrorHandled`; you cannot pre-validate it away. Always handle the `Result` and never `.unwrap()` on const evaluation.
- Ensure the surrounding context is fully monomorphized and that any `GenericArgs` are concrete — `TooGeneric` is the most common trigger.
- Classify by substring on the Debug message (`TooGeneric`, `Reported`, `Overflow`) to choose between retry-with-args and skip; keep a fallback allocation keyed on the const's type.
- Do not surface the raw Debug string to end users; map it to an actionable message in your tool's vocabulary.
When it happens
Trigger: Stabilizing MIR that contains a constant which the compiler could not evaluate under the current typing environment: a `TooGeneric` const, a const that errored and was `Reported` to the user, or an opaque evaluation failure. Walking a function body and converting each `mir::Const`/`ErrorHandled` through the stable layer.
Common situations: Inspecting generic crates where constants depend on unconstrained generic parameters. Reading MIR for items whose const-eval produced errors already reported by rustc. Using a typing environment that is not fully monomorphized, so constants cannot be reduced to a value.
Related errors
- range should be nonempty
- there must be provenance somewhere here
- an interpreter error got improperly discarded; use `discard_
- statics should not have generic parameters
- got a pointer where a ScalarInt was expected
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/7ea0919e4689b84e.json.
Report an issue: GitHub.