ICE: `failed to resolve instance for <fn(FooImpl, ()) as FooFn>::bar`
Open
Nobody has claimed this yet.
C-bug
fixed-by-next-solver
I-ICE
S-bug-has-test
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
pub trait Foo {
type Bar<'a>;
}
pub struct FooImpl {}
impl Foo for FooImpl {
type Bar<'a> = ();
}
pub trait FooFn {
fn bar(&self);
}
impl<T: Foo> FooFn for fn(T, T::Bar<'_>) {
fn bar(&self) {}
}
fn foo<T: Foo>(f: fn(T, T::Bar<'_>)) {
let _: &dyn FooFn = &f;
}
fn main() {
foo(|_: FooImpl, _| {});
}
Meta
rustc --version --verbose:
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7
Error output
error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:585:21: failed to resolve instance for <fn(FooImpl, ()) as FooFn>::bar
--> src/main.rs:12:5
|
12 | fn bar(&self);
| ^^^^^^^^^^^^^^
thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:585:21:
Box<dyn Any>
Backtrace
stack backtrace:
0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
7: <rustc_middle::ty::instance::Instance>::expect_resolve
8: <rustc_middle::ty::instance::Instance>::expect_resolve_for_vtable
9: rustc_trait_selection::traits::vtable::vtable_entries::{closure#0}
10: rustc_trait_selection::traits::vtable::vtable_entries
[... omitted 3 frames ...]
11: rustc_monomorphize::collector::create_mono_items_for_vtable_methods
12: rustc_monomorphize::collector::items_of_instance
[... omitted 1 frame ...]
13: rustc_monomorphize::collector::collect_items_rec::{closure#0}
14: rustc_monomorphize::collector::collect_items_rec
15: rustc_monomorphize::collector::collect_items_rec
16: rustc_monomorphize::partitioning::collect_and_partition_mono_items
[... omitted 2 frames ...]
17: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
18: <rustc_interface::queries::Linker>::codegen_and_build_linker
19: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
20: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal example from the issue and confirm the ICE. Read compiler/rustc_middle/src/ty/instance.rs at the reported line, then follow the vtable path through rustc_trait_selection and rustc_monomorphize. Done means the example no longer triggers an internal compiler error and has a regression test covering the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100