rust-lang/rust · error · bridge::Error
Failed to resolve ` ` with
Error message
Failed to resolve `{def:?}` with `{args:?}` What it means
Returned by Instance::resolve in rustc_public::mir::mono when the compiler's internal resolve_instance query returns None for the given FnDef and GenericArgs. This means no valid monomorphized instance could be constructed — the generic arguments don't satisfy the function's generic parameter requirements, or the def/args combination is otherwise invalid. rustc_public is the stable IR API for compiler consumers (custom codegen backends, analysis tools, etc.).
Solutions
- Verify that the GenericArgs match the FnDef's generic parameter count and kinds (lifetimes, types, consts).
- Use Instance::args() on a known-good instance to inspect the expected args shape, then compare with what you're passing.
- Prefer using the compiler's own monomorphization queries (e.g., collecting MonoItems from the mono-item collector) rather than constructing instances manually.
- Check that the FnDef was obtained from the same compilation context (same TyCtxt) as the args — cross-context def IDs are invalid.
- Handle the Result::Err gracefully — if you're iterating over potentially-unresolvable defs, filter them rather than failing.
Example fix
// before: manual args construction with wrong arity
let args = GenericArgs::new(&[/* only lifetime, missing type arg */]);
let instance = Instance::resolve(def, &args)?; // fails
// after: obtain args from the def's own generic parameters
let correct_args = with(|cx| cx.instance_args(some_valid_def));
// or iterate mono items instead of constructing instances manually
for item in tcx.collect_mono_items() { /* use pre-resolved instances */ } Defensive patterns
Strategy: try-catch
Validate before calling
// Before calling Instance::resolve, validate that the args match the def's generics.
use rustc_public::mir::mono::Instance;
use rustc_public::ty::{FnDef, GenericArgs};
fn try_resolve_safe(def: FnDef, args: &GenericArgs) -> Option<Instance> {
Instance::resolve(def, args).ok()
// Returns None if resolution fails, instead of propagating the error.
} Try / catch
// Instance::resolve returns Result<Instance, Error>. Handle gracefully:
match Instance::resolve(def, &args) {
Ok(instance) => {
// use instance
}
Err(e) => {
// log and skip — don't treat as fatal unless all instances must resolve
eprintln!("warning: could not resolve instance: {e}");
continue;
}
} Prevention
- Don't construct GenericArgs manually — obtain them from the compiler's queries (e.g., instance_args).
- Ensure FnDef and GenericArgs come from the same TyCtxt / compilation context.
- Always handle the Result::Err case rather than unwrapping.
- Prefer iterating pre-resolved MonoItems from the monomorphization collector.
When it happens
Trigger: A rustc_public consumer calls Instance::resolve(def, args) where def is a FnDef and args is a GenericArgs that doesn't match the function's generic signature — wrong number of type/lifetime/const parameters, args that violate trait bounds, or a def that isn't resolvable in the current context.
Common situations: Custom codegen backend or analysis tool constructing GenericArgs manually with incorrect arity; using a FnDef from one crate with args shaped for another; passing args that include types not meeting the function's where-clauses; stale def_id after incremental recompilation invalidated it.
Related errors
- Item kind ` ` cannot be converted
- Item requires monomorphization
- expected monomorphic const in codegen
- {self:?}
- Const ` ` cannot be encoded as u64
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/71eef5008d4d46ab.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/rustc_public/src/mir/mono.rs:129
/// The plain name does not include type arguments (as `trimmed_name` does),
/// which is more convenient to match with intrinsic symbols.
pub fn intrinsic_name(&self) -> Option<Symbol> {
match self.kind {
InstanceKind::Intrinsic => {
Some(with(|context| context.intrinsic(self.def.def_id()).unwrap().fn_name()))
}
InstanceKind::LlvmIntrinsic
| InstanceKind::Item
| InstanceKind::Virtual { .. }
| InstanceKind::Shim => None,
}
}
/// Resolve an instance starting from a function definition and generic arguments.
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
with(|context| {
context.resolve_instance(def, args).ok_or_else(|| {
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
})
})
}
/// Resolve the drop in place for a given type.
pub fn resolve_drop_in_place(ty: Ty) -> Instance {
with(|cx| cx.resolve_drop_in_place(ty))
}
/// Resolve an instance for a given function pointer.
pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
with(|context| {
context.resolve_for_fn_ptr(def, args).ok_or_else(|| {
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
})
})
}
View on GitHub (pinned to 7088e4b63a)