{"record":{"id":"39009b5c16e1c3e3","repo":"rust-lang/rust","slug":"failed-to-get-abi-for-fn-abi-request-err","errorCode":null,"errorMessage":"Failed to get ABI for `{fn_abi_request:?}`: {err:?}","messagePattern":"Failed to get ABI for `(.+?)`: (.+?)","errorType":"exception","errorClass":"B::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_public_bridge/src/context/mod.rs","lineNumber":45,"sourceCode":"\nimpl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> {\n    pub fn new(tcx: TyCtxt<'tcx>) -> Self {\n        Self { tcx, _marker: Default::default() }\n    }\n}\n\n/// Implement error handling for extracting function ABI information.\nimpl<'tcx, B: Bridge> FnAbiOfHelpers<'tcx> for CompilerCtxt<'tcx, B> {\n    type FnAbiOfResult = Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, B::Error>;\n\n    #[inline]\n    fn handle_fn_abi_err(\n        &self,\n        err: ty::layout::FnAbiError<'tcx>,\n        _span: rustc_span::Span,\n        fn_abi_request: ty::layout::FnAbiRequest<'tcx>,\n    ) -> B::Error {\n        B::Error::new(format!(\"Failed to get ABI for `{fn_abi_request:?}`: {err:?}\"))\n    }\n}\n\nimpl<'tcx, B: Bridge> LayoutOfHelpers<'tcx> for CompilerCtxt<'tcx, B> {\n    type LayoutOfResult = Result<ty::layout::TyAndLayout<'tcx>, B::Error>;\n\n    #[inline]\n    fn handle_layout_err(\n        &self,\n        err: ty::layout::LayoutError<'tcx>,\n        _span: rustc_span::Span,\n        ty: Ty<'tcx>,\n    ) -> B::Error {\n        B::Error::new(format!(\"Failed to get layout for `{ty}`: {err}\"))\n    }\n}\n\nimpl<'tcx, B: Bridge> HasTypingEnv<'tcx> for CompilerCtxt<'tcx, B> {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_public_bridge/src/context/mod.rs#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure every argument and return type in the signature has a computable, sized layout before requesting the ABI.","Catch the error at the call site and skip the function (log its name) rather than aborting.","Fix the offending signature (e.g. replace `dyn Trait` by-sized with a concrete type or pointer)."],"exampleFix":"// before\nlet abi = instance.fn_abi()?;\n\n// after\nlet abi = instance.fn_abi().map_err(|e| {\n    log::warn!(\"no ABI for {}: {e}\", instance.name());\n    e\n})?;","handlingStrategy":"try-catch","validationCode":"// Best-effort: confirm all sig arg/ret types have layouts before asking for the ABI.\n// (Layout failures are the usual root cause of FnAbiError.)\nlet sig_ok = sig.inputs().all(|t| tcx.layout_of(env.as_query_input(*t)).is_ok())\n    && tcx.layout_of(env.as_query_input(sig.output())).is_ok();\nif !sig_ok {\n    return Err(\"function signature has uncomputable layout\");\n}","typeGuard":"fn has_computable_fn_abi<'tcx>(sig: &PolyFnSig<'tcx>, tcx: TyCtxt<'tcx>, env: TypingEnv<'tcx>) -> bool {\n    let s = sig.skip_binder();\n    s.inputs().iter().all(|t| tcx.layout_of(env.as_query_input(**t)).is_ok())\n        && tcx.layout_of(env.as_query_input(s.output())).is_ok()\n}","tryCatchPattern":"let abi = match instance.fn_abi() {\n    Ok(abi) => abi,\n    Err(e) => {\n        // signature not ABI-computable; skip this instance\n        log::warn!(\"skipping {}: {e}\", instance.name());\n        continue;\n    }\n};","preventionTips":["Validate function signatures are well-formed before ABI queries.","Treat FnAbiError as usually rooted in a layout problem on an arg/return type."],"tags":["rustc-public-bridge","abi","layout","fn-sig"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}