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

Failed to get ABI for

Error message

Failed to get ABI for `{fn_abi_request:?}`: {err:?}

What it means

Produced by `FnAbiOfHelpers::handle_fn_abi_err` (mod.rs:45), invoked by rustc when computing a function ABI fails. The underlying `FnAbiError` is usually a wrapped `Layout(LayoutError)` — the ABI cannot be computed because one of the function's argument or return types has no valid layout.

Solutions

  1. Ensure every argument and return type in the signature has a computable, sized layout before requesting the ABI.
  2. Catch the error at the call site and skip the function (log its name) rather than aborting.
  3. Fix the offending signature (e.g. replace `dyn Trait` by-sized with a concrete type or pointer).

Example fix

// before
let abi = instance.fn_abi()?;

// after
let abi = instance.fn_abi().map_err(|e| {
    log::warn!("no ABI for {}: {e}", instance.name());
    e
})?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Best-effort: confirm all sig arg/ret types have layouts before asking for the ABI.
// (Layout failures are the usual root cause of FnAbiError.)
let sig_ok = sig.inputs().all(|t| tcx.layout_of(env.as_query_input(*t)).is_ok())
    && tcx.layout_of(env.as_query_input(sig.output())).is_ok();
if !sig_ok {
    return Err("function signature has uncomputable layout");
}

Type guard

fn has_computable_fn_abi<'tcx>(sig: &PolyFnSig<'tcx>, tcx: TyCtxt<'tcx>, env: TypingEnv<'tcx>) -> bool {
    let s = sig.skip_binder();
    s.inputs().iter().all(|t| tcx.layout_of(env.as_query_input(**t)).is_ok())
        && tcx.layout_of(env.as_query_input(s.output())).is_ok()
}

Try / catch

let abi = match instance.fn_abi() {
    Ok(abi) => abi,
    Err(e) => {
        // signature not ABI-computable; skip this instance
        log::warn!("skipping {}: {e}", instance.name());
        continue;
    }
};

Prevention

When it happens

Trigger: Calling `instance.fn_abi()` or `fn_ptr_abi(sig)` on a function whose signature contains a type with an unknown/unsized/overflowing layout, so `fn_abi_of_instance`/`fn_abi_of_fn_ptr` triggers the helper error.

Common situations: Requesting the ABI of an extern/intrinsic function with opaque args; a function pointer built from an inferred signature that includes an unsized type; ABI computation after a type-definitions change.

Related errors


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

Appendix: source

Thrown at compiler/rustc_public_bridge/src/context/mod.rs:45

impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> {
    pub fn new(tcx: TyCtxt<'tcx>) -> Self {
        Self { tcx, _marker: Default::default() }
    }
}

/// Implement error handling for extracting function ABI information.
impl<'tcx, B: Bridge> FnAbiOfHelpers<'tcx> for CompilerCtxt<'tcx, B> {
    type FnAbiOfResult = Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, B::Error>;

    #[inline]
    fn handle_fn_abi_err(
        &self,
        err: ty::layout::FnAbiError<'tcx>,
        _span: rustc_span::Span,
        fn_abi_request: ty::layout::FnAbiRequest<'tcx>,
    ) -> B::Error {
        B::Error::new(format!("Failed to get ABI for `{fn_abi_request:?}`: {err:?}"))
    }
}

impl<'tcx, B: Bridge> LayoutOfHelpers<'tcx> for CompilerCtxt<'tcx, B> {
    type LayoutOfResult = Result<ty::layout::TyAndLayout<'tcx>, B::Error>;

    #[inline]
    fn handle_layout_err(
        &self,
        err: ty::layout::LayoutError<'tcx>,
        _span: rustc_span::Span,
        ty: Ty<'tcx>,
    ) -> B::Error {
        B::Error::new(format!("Failed to get layout for `{ty}`: {err}"))
    }
}

impl<'tcx, B: Bridge> HasTypingEnv<'tcx> for CompilerCtxt<'tcx, B> {

View on GitHub (pinned to 7088e4b63a)