Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: failed to resolve instance for <fn() -> impl ...> #123145

Closed
tBuLi12 opened this issue Mar 27, 2024 · 2 comments · Fixed by #123579
Closed

ICE: failed to resolve instance for <fn() -> impl ...> #123145

tBuLi12 opened this issue Mar 27, 2024 · 2 comments · Fixed by #123579
Labels
A-traits Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tBuLi12
Copy link

tBuLi12 commented Mar 27, 2024

Code

trait Handler {
    fn handle(&self) {}
}

impl<H: Handler, F: Fn() -> H> Handler for F {}

impl<L: Handler> Handler for (L,) {}

fn one() -> impl Handler {
    (one,)
}

fn main() {
    one.handle();
}

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6

Error output

error: internal compiler error: compiler\rustc_middle\src\ty\instance.rs:414:25: failed to resolve instance for <fn() -> impl Handler {one} as Handler>::handle: Ok(
                                    None,
                                )
Backtrace

thread 'rustc' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce\compiler\rustc_errors\src\lib.rs:1119:75:
Box<dyn Any>
stack backtrace:
   0:     0x7ffe056a22c2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7851e041f2b8bcc2
   1:     0x7ffe056d4cdd - core::fmt::write::h1642dfca37b49735
   2:     0x7ffe05698ca1 - <std::io::IoSlice as core::fmt::Debug>::fmt::h7801514a6fc13a4a
   3:     0x7ffe056a20ea - std::sys_common::backtrace::lock::h8caaa69a6cc2258b
   4:     0x7ffe056a5529 - std::panicking::default_hook::h67f6260a0bf37eca
   5:     0x7ffe056a51e5 - std::panicking::default_hook::h67f6260a0bf37eca
   6:     0x7ffe09f2fb03 - <tracing_subscriber[b129777695c18cc]::fmt::format::Writer>::write_fmt
   7:     0x7ffe056a5b43 - std::panicking::rust_panic_with_hook::h870983d929e74e12
   8:     0x7ffe0b3b7438 - <rustc_span[64dbdf40f18d9543]::symbol::MacroRulesNormalizedIdent as rustc_errors[9e3a9f6acb1d6850]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
   9:     0x7ffe0b3b6d59 - <rustc_span[64dbdf40f18d9543]::symbol::MacroRulesNormalizedIdent as rustc_errors[9e3a9f6acb1d6850]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
  10:     0x7ffe0b3afb39 - <std[9ab95dd99822253f]::io::error::Error as rustc_errors[9e3a9f6acb1d6850]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
  11:     0x7ffe0b39747c - <rustc_errors[9e3a9f6acb1d6850]::diagnostic_builder::Bug as rustc_errors[9e3a9f6acb1d6850]::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
  12:     0x7ffe0b23f3b7 - rustc_middle[29ac2ae09cb008db]::ty::context::tls::TLV::__getit::destroy
  13:     0x7ffe0b23d3b3 - rustc_middle[29ac2ae09cb008db]::util::bug::bug_fmt
  14:     0x7ffe0b23d21d - <rustc_middle[29ac2ae09cb008db]::traits::util::Elaborator as core[d8a3f01ca499b8ab]::iter::traits::iterator::Iterator>::next
  15:     0x7ffe0b23d1ea - <rustc_middle[29ac2ae09cb008db]::traits::util::Elaborator as core[d8a3f01ca499b8ab]::iter::traits::iterator::Iterator>::next
  16:     0x7ffe0b23d2c2 - rustc_middle[29ac2ae09cb008db]::util::bug::bug_fmt
  17:     0x7ffe09de7917 - <rustc_middle[29ac2ae09cb008db]::ty::instance::Instance>::expect_resolve
  18:     0x7ffe091dbf2b - <rustc_monomorphize[5b0405cbcca7e001]::collector::MirUsedCollector as rustc_middle[29ac2ae09cb008db]::mir::visit::Visitor>::visit_constant
  19:     0x7ffe091d8c8b - <rustc_monomorphize[5b0405cbcca7e001]::collector::MirUsedCollector as rustc_middle[29ac2ae09cb008db]::mir::visit::Visitor>::visit_operand
  20:     0x7ffe088a6645 - <rustc_hir_analysis[2ba85467cc3c2e66]::check::wfcheck::check_where_clauses::{closure#2}::CountParams as rustc_type_ir[fb309861c70c8016]::visit::TypeVisitor<rustc_middle[29ac2ae09cb008db]::ty::context::TyCtxt>>::visit_const
  21:     0x7ffe088abe52 - <rustc_hir_analysis[2ba85467cc3c2e66]::check::wfcheck::check_where_clauses::{closure#2}::CountParams as rustc_type_ir[fb309861c70c8016]::visit::TypeVisitor<rustc_middle[29ac2ae09cb008db]::ty::context::TyCtxt>>::visit_const
  22:     0x7ffe088a8518 - <rustc_hir_analysis[2ba85467cc3c2e66]::check::wfcheck::check_where_clauses::{closure#2}::CountParams as rustc_type_ir[fb309861c70c8016]::visit::TypeVisitor<rustc_middle[29ac2ae09cb008db]::ty::context::TyCtxt>>::visit_const
  23:     0x7ffe091d14bd - rustc_monomorphize[5b0405cbcca7e001]::partitioning::collect_and_partition_mono_items
  24:     0x7ffe08ad038a - rustc_query_impl[1b1c3ff2f5873f4d]::profiling_support::alloc_self_profile_query_strings
  25:     0x7ffe08a9b22d - rustc_traits[39dfbaf382113380]::type_op::type_op_normalize_fn_sig
  26:     0x7ffe08b493fc - rustc_query_impl[1b1c3ff2f5873f4d]::profiling_support::alloc_self_profile_query_strings
  27:     0x7ffe08aee434 - rustc_query_impl[1b1c3ff2f5873f4d]::profiling_support::alloc_self_profile_query_strings
  28:     0x7ffe08afaf7e - rustc_query_impl[1b1c3ff2f5873f4d]::profiling_support::alloc_self_profile_query_strings
  29:     0x7ffe0ab43c44 - <rustc_query_impl[1b1c3ff2f5873f4d]::plumbing::QueryCtxt as rustc_query_system[79eaec2bcc989eb1]::query::QueryContext>::depth_limit_error
  30:     0x7ffe06100464 - <rustc_codegen_llvm[8a535c964cfc05c8]::back::lto::ModuleBuffer as core[d8a3f01ca499b8ab]::ops::drop::Drop>::drop
  31:     0x7ffe060e2cff - <rustc_codegen_llvm[8a535c964cfc05c8]::LlvmCodegenBackend as rustc_codegen_ssa[1dc4bfd57c326e00]::traits::backend::CodegenBackend>::codegen_crate
  32:     0x7ffe060a9439 - rustc_interface[9ef98228d448de4b]::interface::parse_check_cfg
  33:     0x7ffe06090b37 - rustc_interface[9ef98228d448de4b]::passes::start_codegen
  34:     0x7ffe060a27e2 - rustc_interface[9ef98228d448de4b]::interface::parse_check_cfg
  35:     0x7ffe06081b0f - <rustc_interface[9ef98228d448de4b]::queries::Queries>::codegen_and_build_linker
  36:     0x7ffe06040ee1 - rustc_driver_impl[5ff3db5439d2e5e5]::args::arg_expand_all
  37:     0x7ffe06058809 - <rustc_middle[29ac2ae09cb008db]::ty::SymbolName as core[d8a3f01ca499b8ab]::fmt::Debug>::fmt
  38:     0x7ffe0605770f - <rustc_middle[29ac2ae09cb008db]::ty::SymbolName as core[d8a3f01ca499b8ab]::fmt::Debug>::fmt
  39:     0x7ffe06061068 - <rustc_middle[29ac2ae09cb008db]::ty::SymbolName as core[d8a3f01ca499b8ab]::fmt::Debug>::fmt
  40:     0x7ffe056b7ebc - std::sys::windows::thread::Thread::new::h827e23232df84eef
  41:     0x7fff00ab257d - BaseThreadInitThunk
  42:     0x7fff0196aa58 - RtlUserThreadStart

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.76.0 (07dca489a 2024-02-04) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@tBuLi12 tBuLi12 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 27, 2024
@compiler-errors
Copy link
Member

This is correctly reported as an overflow in the new trait solver:

error[E0275]: overflow evaluating the requirement `impl Handler == (fn() -> impl Handler {one},)`
  --> <source>:10:5
   |
10 |     (one,)
   |     ^^^^^^

error[E0275]: overflow evaluating the requirement `(fn() -> impl Handler {one},) <: impl Handler`
  --> <source>:9:26
   |
9  |   fn one() -> impl Handler {
   |  __________________________^
10 | |     (one,)
11 | | }
   | |_^

error: aborting due to 2 previous errors

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Mar 28, 2024
@GrigorenkoPV
Copy link
Contributor

On 1.34 and before that, the compiler SIGSEGVs with stack overflow.

On 1.35-1.40 it works just fine, surprisingly.

On 1.41-1.47 it ICEs with thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9.

On 1.48-1.61 it ICEs with "no errors encountered even though delay_span_bug issued".

On 1.62-1.67 it ICEs with "called Option::unwrap() on a None value', compiler/rustc_monomorphize/src/collector.rs:934:13".

Starting with 1.68 it ICEs with the same message as in the issue.

@jieyouxu jieyouxu added A-traits Area: Trait system S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 7, 2024
@bors bors closed this as completed in 7c43bc0 Apr 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2024
Rollup merge of rust-lang#123579 - matthiaskrgr:I_Love_Tests, r=jieyouxu

add some more tests

Fixes rust-lang#115806
Fixes rust-lang#116710
Fixes rust-lang#123145
Fixes rust-lang#105488
Fixes rust-lang#122488
Fixes rust-lang#123078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants