{"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/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_public_bridge/src/context/mod.rs#L27-L63","documentation":"Emitted by CompilerCtxt::handle_fn_abi_err (compiler/rustc_public_bridge/src/context/mod.rs:45), the FnAbiOfHelpers impl for CompilerCtxt. It wraps the ty::layout::FnAbiError returned by rustc's fn_abi_of_instance / fn_abi_of_fn_ptr queries into a Bridge::Error so that consumers of the stable rustc_public API receive a recoverable Result::Err instead of an internal compiler panic. Note that FnAbiError currently has a single variant, Layout(LayoutError), so every ABI failure is ultimately rooted in a layout failure of some type participating in the function signature.","triggerScenarios":"Calling CompilerCtxt::instance_abi(instance) (impls.rs:625) or fn_ptr_abi(sig) (impls.rs:633) when one of the types in the signature yields a LayoutError; an Instance that is not fully monomorphized (still has type parameters) passed to fn_abi_of_instance under TypingEnv::fully_monomorphized(); a function whose signature references an opaque/impl Trait type that cannot normalize after type revelation; SIMD or unsized tail types that violate layout rules; shim/intrinsic instances whose ABI legitimately cannot be computed.","commonSituations":"Static analyzers, codegen tools, ABI extractors, and rustdoc-json consumers built on the unstable rustc_public crate iterating over all DefIds and requesting ABIs indiscriminately; analyzing a crate that did not itself type-check cleanly (rustc cannot produce layouts for error-tainted types); version skew between the rustc_public consumer pinned by a tool and the rustc_public_bridge shipped in the nightly toolchain; processing FFI items with exotic calling conventions or vtable shims (Virtual/Intrinsic InstanceKind).","solutions":["Before calling instance_abi/fn_ptr_abi, verify the instance is fully monomorphized: gate on !instance.has_non_region_param() (see the assert already in instance_ty at impls.rs:615).","Inspect the inner LayoutError variant to act specifically: Unknown/TooGeneric -> skip the item; SizeOverflow/InvalidSimd -> reject the input as malformed; NormalizationFailure -> the crate needs clean type-checking first; ReferencesError -> a prior compile error must be fixed.","Skip ABI requests for InstanceKinds that cannot have a meaningful ABI (Virtual, Intrinsic that must_be_overridden) by checking instance_has_body / item_has_body first.","Pin the exact nightly toolchain whose rustc_public_bridge matches your rustc_public consumer crate version; the API is explicitly unstable and signature shape changes between versions.","Ensure the crate under analysis type-checks with zero errors before driving ABI/layout queries; run cargo check first and stop on errors."],"exampleFix":"// before\nlet abi = ctxt.instance_abi(instance)?;\n\n// after: only request ABI for fully monomorphized, body-having instances\nif !instance.has_non_region_param() && ctxt.has_body(instance.def_id()) {\n    let abi = ctxt.instance_abi(instance)?;\n    // ...use abi\n} else {\n    // skip generic or shim/intrinsic instances\n}","handlingStrategy":"try-catch","validationCode":"// Before instance_abi(): reject Instances that still carry generic params or error types.\n// The bridge queries under TypingEnv::fully_monomorphized(), so any leftover param fails normalization.\nif instance.has_non_region_param() {\n    return Err(MyError::NotMonomorphized(format!(\"{instance:?} still has generic parameters\")));\n}\nif instance\n    .ty(tcx, rustc_middle::ty::TypingEnv::fully_monomorphized())\n    .references_error()\n{\n    return Err(MyError::TypeError(format!(\"{instance:?} contains Ty::Error\")));\n}\n// For fn_ptr_abi(): a PolyFnSig must have no escaping bound variables.\nif sig.escape_depth() != 0 {\n    return Err(MyError::BoundVars(format!(\"{sig:?} has escaping bound vars\")));\n}","typeGuard":"/// True iff `inst` is safe to pass to `CompilerCtxt::instance_abi` (fully monomorphized, no error types).\nfn instance_abi_safe<'tcx>(tcx: rustc_middle::ty::TyCtxt<'tcx>, inst: rustc_middle::ty::Instance<'tcx>) -> bool {\n    !inst.has_non_region_param()\n        && !inst\n            .ty(tcx, rustc_middle::ty::TypingEnv::fully_monomorphized())\n            .references_error()\n}","tryCatchPattern":"// instance_abi() / fn_ptr_abi() return Result<&FnAbi, B::Error>; this is an expected,\n// type-system-dependent runtime condition, not a bug. Propagate or degrade, never .unwrap().\nmatch ctxt.instance_abi(instance) {\n    Ok(fn_abi) => { /* use fn_abi */ }\n    Err(e) => {\n        // ABI not computable for this fn: log with the failing FnAbiRequest and skip it.\n        log::warn!(\"skipping {instance:?}: {e}\");\n    }\n}","preventionTips":["Monomorphize every Instance before querying its ABI: the bridge runs under TypingEnv::fully_monomorphized(), so any leftover generic parameter (gate on instance.has_non_region_param()) fails normalization and surfaces error 350.","Never call fn_ptr_abi on a PolyFnSig with escaping bound variables; substitute/erase them first (sig.escape_depth() == 0).","Filter out functions whose signature references Ty::Error (ty.references_error()) early in your analysis pipeline — their ABI cannot be computed.","Treat ABI computation as advisory, not mandatory: wrap every instance_abi / fn_ptr_abi call in Result handling and degrade by skipping the function rather than aborting the tool.","Cache successful FnAbi results by InstanceDef so a single malformed function does not force re-computation across passes."],"tags":["rustc","rustc-public","abi","layout","compiler-internals"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}