{"id":"71eef5008d4d46ab","repo":"rust-lang/rust","slug":"failed-to-resolve-def-with-args","errorCode":null,"errorMessage":"Failed to resolve `{def:?}` with `{args:?}`","messagePattern":"Failed to resolve `(.+?)` with `(.+?)`","errorType":"exception","errorClass":"bridge::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_public/src/mir/mono.rs","lineNumber":129,"sourceCode":"    /// The plain name does not include type arguments (as `trimmed_name` does),\n    /// which is more convenient to match with intrinsic symbols.\n    pub fn intrinsic_name(&self) -> Option<Symbol> {\n        match self.kind {\n            InstanceKind::Intrinsic => {\n                Some(with(|context| context.intrinsic(self.def.def_id()).unwrap().fn_name()))\n            }\n            InstanceKind::LlvmIntrinsic\n            | InstanceKind::Item\n            | InstanceKind::Virtual { .. }\n            | InstanceKind::Shim => None,\n        }\n    }\n\n    /// Resolve an instance starting from a function definition and generic arguments.\n    pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {\n        with(|context| {\n            context.resolve_instance(def, args).ok_or_else(|| {\n                bridge::Error::new(format!(\"Failed to resolve `{def:?}` with `{args:?}`\"))\n            })\n        })\n    }\n\n    /// Resolve the drop in place for a given type.\n    pub fn resolve_drop_in_place(ty: Ty) -> Instance {\n        with(|cx| cx.resolve_drop_in_place(ty))\n    }\n\n    /// Resolve an instance for a given function pointer.\n    pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {\n        with(|context| {\n            context.resolve_for_fn_ptr(def, args).ok_or_else(|| {\n                bridge::Error::new(format!(\"Failed to resolve `{def:?}` with `{args:?}`\"))\n            })\n        })\n    }\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_public/src/mir/mono.rs#L111-L147","documentation":"Error returned by `Instance::resolve` in the `rustc_public` stable compiler API when the underlying `resolve_instance` query returns `None` for the given `FnDef` and `GenericArgs`. It means no monomorphized instance could be produced — typically because the supplied generic arguments do not satisfy the function's where-clause/trait bounds, the def is not monomorphizable in this context, or required inference/normalization had not completed.","triggerScenarios":"A tool or driver built on `rustc_public` (e.g. an analyzer, Kani, or a custom compiler driver) calls `Instance::resolve(fn_def, &generic_args)` and the query yields no instance.","commonSituations":"Passing `GenericArgs` whose count/kinds don't match the `FnDef`'s parameters; arguments that violate a trait bound or where-clause; resolving a function whose body is unavailable (extern/FFI declaration); calling resolve before type inference and projection normalization finished.","solutions":["Verify the `GenericArgs` match the `FnDef`'s generic parameter count and kinds (types, lifetimes, const)","Check that every trait/where-clause bound on the function is satisfied by the supplied argument types","Confirm the `FnDef` points to a body-having, non-extern function","If using a custom driver, ensure inference and projection normalization are complete before calling `resolve`"],"exampleFix":"// before: wrong number/type of generic args -> resolve fails\nlet inst = Instance::resolve(fn_def, &generic_args)?;\n// after: build args matching the FnDef's own generics\nlet args = fn_def.args(); // or GenericArgs::new_for(...) matching param kinds\nlet inst = Instance::resolve(fn_def, &args)?;","handlingStrategy":"validation","validationCode":"use rustc_middle::ty::{DefId, GenericArgsRef};\nfn mono_def_is_resolvable(def: DefId, args: GenericArgsRef<'_>, tcx: TyCtxt<'_>) -> bool {\n    let generics = tcx.generics_of(def);\n    args.len() == generics.count() && !tcx.is_foreign_item(def)\n}\nif !mono_def_is_resolvable(def, args, tcx) {\n    return Err(format!(\"unresolvable mono def {:?} args {:?}\", def, args));\n}","typeGuard":"pub fn args_arity_matches(tcx: TyCtxt<'_>, def: DefId, args: GenericArgsRef<'_>) -> bool {\n    tcx.generics_of(def).count() == args.len()\n}","tryCatchPattern":"use std::panic;\nmatch panic::catch_unwind(panic::AssertUnwindSafe(|| mir::mono::resolve(def, args))) {\n    Ok(Some(instance)) => instance,\n    _ => /* resolution failed; skip this mono item */ continue,\n}","preventionTips":["Before resolving a monomorphization instance, confirm the def is a fn/static that participates in mono (not extern/foreign).","Check generic-args arity against tcx.generics_of(def).count() to avoid resolve panics on partial substitution.","Avoid constructing Instance keys manually; go through resolve(), and validate inputs first.","Treat a resolve failure as a recursive/generic-mismatch signal — re-run with fully substituted args."],"tags":["rustc-public","monomorphization","generic-args","compiler-api"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}