Skip to content

ICE: relating different kinds #126416

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait Output<'a, T: 'a> {
    type Type;
}

struct Wrapper;

impl Wrapper {
    fn do_something_wrapper<O, F>(&mut self, _: F)
    where
        F: for<'a> FnOnce(<F as Output<i32>>::Type),
    {
    }
}

fn main() {
    let mut wrapper = Wrapper;
    wrapper.do_something_wrapper(|value| ());
}

original:

//! This test used to ICE: #121134
//@ pretty-expanded FIXME #23616//! no bound for the projection's trait, and the projection has the wrong
//~^ ERROR lifetime may not live long enough//! instantiate the bounds with inference vars would ICE.
//! instantiate the bounds with inference vars would ICE.
#![feature(unboxed_closures)]

trait Output<'a, T: 'a> {
    type Type;
}

struct Wrapper;

impl Wrapper {
    fn do_something_wrapper<O, F>(&mut self, _: F)
    where
        F: for<'a> FnOnce(<F as Output<i32>>::Type),
        //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied
    {
    }
}

fn main() {
    let mut wrapper = Wrapper;
    wrapper.do_something_wrapper(|value| ());
}

Version information

rustc 1.81.0-nightly (9fdbfe144 2024-06-13)
binary: rustc
commit-hash: 9fdbfe1441a82e96e3f99ae199ff5348d8d948ae
commit-date: 2024-06-13
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0277]: the trait bound `for<'a> F: Output<'a, i32>` is not satisfied
  --> /tmp/icemaker_global_tempdir.V2SoPHdzetdg/rustc_testrunner_tmpdir_reporting.8xjszJFoJpuf/mvce.rs:8:5
   |
8  | /     fn do_something_wrapper<O, F>(&mut self, _: F)
9  | |     where
10 | |         F: for<'a> FnOnce(<F as Output<i32>>::Type),
   | |____________________________________________________^ the trait `for<'a> Output<'a, i32>` is not implemented for `F`
   |
help: consider further restricting this bound
   |
10 |         F: for<'a> FnOnce(<F as Output<i32>>::Type) + for<'a> Output<'a, i32>,
   |                                                     +++++++++++++++++++++++++

error[E0277]: the trait bound `for<'a> F: Output<'a, i32>` is not satisfied
 --> /tmp/icemaker_global_tempdir.V2SoPHdzetdg/rustc_testrunner_tmpdir_reporting.8xjszJFoJpuf/mvce.rs:8:8
  |
8 |     fn do_something_wrapper<O, F>(&mut self, _: F)
  |        ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Output<'a, i32>` is not implemented for `F`
  |
help: consider further restricting this bound
  |
10|         F: for<'a> FnOnce(<F as Output<i32>>::Type) + for<'a> Output<'a, i32>,
  |                                                     +++++++++++++++++++++++++

error[E0277]: the trait bound `F: Output<'_, i32>` is not satisfied
  --> /tmp/icemaker_global_tempdir.V2SoPHdzetdg/rustc_testrunner_tmpdir_reporting.8xjszJFoJpuf/mvce.rs:10:12
   |
10 |         F: for<'a> FnOnce(<F as Output<i32>>::Type),
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_, i32>` is not implemented for `F`
   |
help: consider further restricting this bound
   |
10 |         F: for<'a> FnOnce(<F as Output<i32>>::Type) + Output<'_, i32>,
   |                                                     +++++++++++++++++

error[E0277]: the trait bound `F: Output<'_, i32>` is not satisfied
  --> /tmp/icemaker_global_tempdir.V2SoPHdzetdg/rustc_testrunner_tmpdir_reporting.8xjszJFoJpuf/mvce.rs:10:20
   |
10 |         F: for<'a> FnOnce(<F as Output<i32>>::Type),
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_, i32>` is not implemented for `F`
   |
help: consider further restricting this bound
   |
10 |         F: for<'a> FnOnce(<F as Output<i32>>::Type) + Output<'_, i32>,
   |                                                     +++++++++++++++++

error: internal compiler error: compiler/rustc_infer/src/infer/at.rs:368:21: relating different kinds: (Alias(Projection, AliasTy { args: [?3t, !10_1.Named(DefId(0:16 ~ mvce[9b0e]::{impl#0}::do_something_wrapper::'_), "'_"), i32], def_id: DefId(0:6 ~ mvce[9b0e]::Output::Type), _use_alias_ty_new_instead: () }),) !7_1.Named(DefId(0:16 ~ mvce[9b0e]::{impl#0}::do_something_wrapper::'_), "'_")

thread 'rustc' panicked at compiler/rustc_infer/src/infer/at.rs:368:21:
Box<dyn Any>
stack backtrace:
   0:     0x7ba12fe46ae5 - std::backtrace_rs::backtrace::libunwind::trace::ha3ab76cb43bb1368
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7ba12fe46ae5 - std::backtrace_rs::backtrace::trace_unsynchronized::hb5cc2b59767e67ec
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ba12fe46ae5 - std::sys_common::backtrace::_print_fmt::h95a3a9c53c66bf04
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ba12fe46ae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8cfda73c2a92feb2
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ba12fe9777b - core::fmt::rt::Argument::fmt::hf4ecd87cd25c64f9
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/core/src/fmt/rt.rs:165:63
   5:     0x7ba12fe9777b - core::fmt::write::haa80a9c534e31eab
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/core/src/fmt/mod.rs:1168:21
   6:     0x7ba12fe3b76f - std::io::Write::write_fmt::hc1cd1cf89e04171f
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/io/mod.rs:1835:15
   7:     0x7ba12fe468be - std::sys_common::backtrace::_print::hc54672ee9616fdc2
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ba12fe468be - std::sys_common::backtrace::print::hb162d5121355a056
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ba12fe492f9 - std::panicking::default_hook::{{closure}}::h304b290f864ea3b5
  10:     0x7ba12fe4909c - std::panicking::default_hook::hef815e37252f6fb2
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/panicking.rs:292:9
  11:     0x7ba12c6acf30 - std[b8312f6d1c472845]::panicking::update_hook::<alloc[8901845baeab31]::boxed::Box<rustc_driver_impl[9b7a6d874770339f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ba12fe49bff - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h64eafb31c66a3499
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/alloc/src/boxed.rs:2076:9
  13:     0x7ba12fe49bff - std::panicking::rust_panic_with_hook::h9b91adbd155bccf5
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/panicking.rs:801:13
  14:     0x7ba12c6ddaa1 - std[b8312f6d1c472845]::panicking::begin_panic::<rustc_errors[7d6d08bf2206b20]::ExplicitBug>::{closure#0}
  15:     0x7ba12c6da6a6 - std[b8312f6d1c472845]::sys_common::backtrace::__rust_end_short_backtrace::<std[b8312f6d1c472845]::panicking::begin_panic<rustc_errors[7d6d08bf2206b20]::ExplicitBug>::{closure#0}, !>
  16:     0x7ba12c6da386 - std[b8312f6d1c472845]::panicking::begin_panic::<rustc_errors[7d6d08bf2206b20]::ExplicitBug>
  17:     0x7ba12c6e6e31 - <rustc_errors[7d6d08bf2206b20]::diagnostic::BugAbort as rustc_errors[7d6d08bf2206b20]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7ba12cbe0e4c - rustc_middle[378d6b6a215ba68]::util::bug::opt_span_bug_fmt::<rustc_span[22f8cecf10eb8678]::span_encoding::Span>::{closure#0}
  19:     0x7ba12cbc9eca - rustc_middle[378d6b6a215ba68]::ty::context::tls::with_opt::<rustc_middle[378d6b6a215ba68]::util::bug::opt_span_bug_fmt<rustc_span[22f8cecf10eb8678]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7ba12cbc9d6b - rustc_middle[378d6b6a215ba68]::ty::context::tls::with_context_opt::<rustc_middle[378d6b6a215ba68]::ty::context::tls::with_opt<rustc_middle[378d6b6a215ba68]::util::bug::opt_span_bug_fmt<rustc_span[22f8cecf10eb8678]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7ba12a551770 - rustc_middle[378d6b6a215ba68]::util::bug::bug_fmt
  22:     0x7ba12e31d86a - <rustc_middle[378d6b6a215ba68]::ty::generic_args::GenericArg as rustc_infer[18d7b06ccebc4a49]::infer::at::ToTrace>::to_trace
  23:     0x7ba12d1519fd - <rustc_infer[18d7b06ccebc4a49]::infer::at::At>::eq::<rustc_middle[378d6b6a215ba68]::ty::generic_args::GenericArg>
  24:     0x7ba12d145585 - <rustc_infer[18d7b06ccebc4a49]::infer::InferCtxt>::enter_forall::<rustc_type_ir[d4be8c3a1ba1e26]::predicate::TraitPredicate<rustc_middle[378d6b6a215ba68]::ty::context::TyCtxt>, (), <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_function_argument_obligation<rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>::{closure#1}>
  25:     0x7ba12d230251 - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_function_argument_obligation::<rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>
  26:     0x7ba12d228fce - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_obligation_cause_code::<rustc_span[22f8cecf10eb8678]::ErrorGuaranteed, rustc_middle[378d6b6a215ba68]::ty::predicate::Predicate>
  27:     0x7ba12d24a91c - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::note_obligation_cause
  28:     0x7ba12d23c2d7 - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_selection_error
  29:     0x7ba12d24f817 - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
  30:     0x7ba12d239755 - <rustc_infer[18d7b06ccebc4a49]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[4c82f2a92a28516c]::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
  31:     0x7ba12e487975 - <rustc_hir_typeck[46e3eb670cb77fcc]::fn_ctxt::FnCtxt>::type_inference_fallback
  32:     0x7ba12dbdd98f - rustc_hir_typeck[46e3eb670cb77fcc]::typeck
  33:     0x7ba12dbdd3fb - rustc_query_impl[b42533e2e2de3919]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b42533e2e2de3919]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[378d6b6a215ba68]::query::erase::Erased<[u8; 8usize]>>
  34:     0x7ba12dd0066e - rustc_query_system[8978f5aeec6db06a]::query::plumbing::try_execute_query::<rustc_query_impl[b42533e2e2de3919]::DynamicConfig<rustc_query_system[8978f5aeec6db06a]::query::caches::VecCache<rustc_span[22f8cecf10eb8678]::def_id::LocalDefId, rustc_middle[378d6b6a215ba68]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b42533e2e2de3919]::plumbing::QueryCtxt, false>
  35:     0x7ba12dcff155 - rustc_query_impl[b42533e2e2de3919]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7ba12dcfed8b - <rustc_middle[378d6b6a215ba68]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[3833ea85fef40b2c]::check_crate::{closure#4}>::{closure#0}
  37:     0x7ba12dcfd847 - rustc_hir_analysis[3833ea85fef40b2c]::check_crate
  38:     0x7ba12e442687 - rustc_interface[f64d9339fe208e7b]::passes::analysis
  39:     0x7ba12e4421c7 - rustc_query_impl[b42533e2e2de3919]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b42533e2e2de3919]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[378d6b6a215ba68]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7ba12e832be5 - rustc_query_system[8978f5aeec6db06a]::query::plumbing::try_execute_query::<rustc_query_impl[b42533e2e2de3919]::DynamicConfig<rustc_query_system[8978f5aeec6db06a]::query::caches::SingleCache<rustc_middle[378d6b6a215ba68]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b42533e2e2de3919]::plumbing::QueryCtxt, false>
  41:     0x7ba12e83294f - rustc_query_impl[b42533e2e2de3919]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7ba12e6cbc52 - rustc_interface[f64d9339fe208e7b]::interface::run_compiler::<core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>, rustc_driver_impl[9b7a6d874770339f]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7ba12e6ef5e7 - std[b8312f6d1c472845]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f64d9339fe208e7b]::util::run_in_thread_with_globals<rustc_interface[f64d9339fe208e7b]::util::run_in_thread_pool_with_globals<rustc_interface[f64d9339fe208e7b]::interface::run_compiler<core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>, rustc_driver_impl[9b7a6d874770339f]::run_compiler::{closure#0}>::{closure#1}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>::{closure#0}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>
  44:     0x7ba12e6ef3aa - <<std[b8312f6d1c472845]::thread::Builder>::spawn_unchecked_<rustc_interface[f64d9339fe208e7b]::util::run_in_thread_with_globals<rustc_interface[f64d9339fe208e7b]::util::run_in_thread_pool_with_globals<rustc_interface[f64d9339fe208e7b]::interface::run_compiler<core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>, rustc_driver_impl[9b7a6d874770339f]::run_compiler::{closure#0}>::{closure#1}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>::{closure#0}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a215b071cb710c88]::result::Result<(), rustc_span[22f8cecf10eb8678]::ErrorGuaranteed>>::{closure#2} as core[a215b071cb710c88]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7ba12fe53a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h38d1450b33cb88dc
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/alloc/src/boxed.rs:2062:9
  46:     0x7ba12fe53a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h03abae454ea5f513
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/alloc/src/boxed.rs:2062:9
  47:     0x7ba12fe53a7b - std::sys::pal::unix::thread::Thread::new::thread_start::hf41d3eaffac37908
                               at /rustc/9fdbfe1441a82e96e3f99ae199ff5348d8d948ae/library/std/src/sys/pal/unix/thread.rs:108:17
  48:     0x7ba1292a6ded - <unknown>
  49:     0x7ba12932a0dc - <unknown>
  50:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.81.0-nightly (9fdbfe144 2024-06-13) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0277`.

@rustbot label +F-unboxed_closures

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-unboxed_closures`#![feature(unboxed_closures)]`I-ICEIssue: 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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions