Repository navigation
ICE: failed to resolve instance for <fn(FooImpl, ()) as FooFn>::bar #139120
Copy link
Copy link
Closed as duplicate
Closed as duplicate
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
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}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
Activity
compiler-errors commentedon Mar 30, 2025
This is an example of the "type inference + higher-ranked type" problem that should be fixed by the new trait solver. If you search through that tag you may be able to find another instnce of this issue.
pufmat commentedon Mar 30, 2025
Okay, thanks.
lcnr commentedon Oct 6, 2026
closing as a duplicate as we've already got a few tests for this in the ui test suite and the fix for this is very consistent, so having many slightly different tests downstream of the same underlying bug isn't useful
Rollup merge of rust-lang#163806 - lcnr:crashes-migration-cont, r=lqd
Rollup merge of rust-lang#163806 - lcnr:crashes-migration-cont, r=lqd
Rollup merge of rust-lang#163806 - lcnr:crashes-migration-cont, r=lqd
Unrolled build for #163806 in rollup 163957