Skip to content

ICE: relating different kinds: ?2t '?2 #127745

Closed
@Naserume

Description

@Naserume

Code

#![feature(fn_traits, unboxed_closures)]

trait Lt<'a> {
    type T;
}
impl<'f> Lt<'a> for () {
    type T;
}

struct Foo<T>(T);

impl<T: Copy> Fn<()> for Foo<T> {
    fn call(&self, _: ()) -> T {
        match *self {
            Foo(t) => t,
        }
    }
}

impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}

impl<T: Copy> FnOnce<H> for Foo<T> {
    type Output = T;

    fn call_once(self, _: ()) -> T {
        self.call(())
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (fcaa6fdfb 2024-07-13)
binary: rustc
commit-hash: fcaa6fdfbee1316184e7ad98c53241d52cd30a5f
commit-date: 2024-07-13
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error: associated type in `impl` without body
 --> ./B8BC8.rs:7:5
  |
7 |     type T;
  |     ^^^^^^-
  |           |
  |           help: provide a definition for the type: `= <type>;`

error[E0261]: use of undeclared lifetime name `'a`
 --> ./B8BC8.rs:6:13
  |
6 | impl<'f> Lt<'a> for () {
  |      -      ^^ undeclared lifetime
  |      |
  |      help: consider introducing lifetime `'a` here: `'a,`

error[E0412]: cannot find type `H` in this scope
  --> ./B8BC8.rs:22:22
   |
22 | impl<T: Copy> FnOnce<H> for Foo<T> {
   |      -               ^
   |      |
   |      similarly named type parameter `T` defined here
   |
help: a type parameter with a similar name exists
   |
22 | impl<T: Copy> FnOnce<T> for Foo<T> {
   |                      ~
help: you might be missing a type parameter
   |
22 | impl<T: Copy, H> FnOnce<H> for Foo<T> {
   |             +++

error[E0277]: expected a `FnOnce()` closure, found `Foo<T>`
  --> ./B8BC8.rs:12:26
   |
12 | impl<T: Copy> Fn<()> for Foo<T> {
   |                          ^^^^^^ expected an `FnOnce()` closure, found `Foo<T>`
   |
   = help: the trait `FnOnce()` is not implemented for `Foo<T>`, which is required by `Foo<T>: FnMut()`
   = note: wrap the `Foo<T>` in a closure with no arguments: `|| { /* code */ }`
   = note: required for `Foo<T>` to implement `FnMut()`
note: required by a bound in `Fn`
  --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:76:28
   |
76 | pub trait Fn<Args: Tuple>: FnMut<Args> {
   |                            ^^^^^^^^^^^ required by this bound in `Fn`

error[E0277]: the trait bound `(): Lt<'_>` is not satisfied
  --> ./B8BC8.rs:12:26
   |
12 | impl<T: Copy> Fn<()> for Foo<T> {
   |                          ^^^^^^ the trait `Lt<'_>` is not implemented for `()`, which is required by `Foo<T>: FnMut()`
   |
note: required by a bound in `Fn`
  --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:76:28
   |
76 | pub trait Fn<Args: Tuple>: FnMut<Args> {
   |                            ^^^^^^^^^^^ required by this bound in `Fn`

error[E0053]: method `call` has an incompatible type for trait
  --> ./B8BC8.rs:13:5
   |
13 |     fn call(&self, _: ()) -> T {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn
   |
   = note: expected signature `extern "rust-call" fn(&Foo<_>, ()) -> _`
              found signature `fn(&Foo<_>, ()) -> T`

error[E0277]: the trait bound `(): Lt<'_>` is not satisfied
  --> ./B8BC8.rs:20:15
   |
20 | impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}
   |               ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Lt<'_>` is not implemented for `()`

error[E0277]: expected a `FnOnce<_>` closure, found `Foo<T>`
   --> ./B8BC8.rs:20:44
    |
20  | impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}
    |                                            ^^^^^^ expected an `FnOnce<_>` closure, found `Foo<T>`
    |
    = help: the trait `FnOnce<_>` is not implemented for `Foo<T>`
note: required by a bound in `FnMut`
   --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:163:31
    |
163 | pub trait FnMut<Args: Tuple>: FnOnce<Args> {
    |                               ^^^^^^^^^^^^ required by this bound in `FnMut`

error[E0277]: the trait bound `(): Lt<'_>` is not satisfied
  --> ./B8BC8.rs:20:44
   |
20 | impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}
   |                                            ^^^^^^ the trait `Lt<'_>` is not implemented for `()`, which is required by `Foo<T>: FnMut<_>`

error[E0277]: the trait bound `(): Lt<'_>` is not satisfied
  --> ./B8BC8.rs:20:21
   |
20 | impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}
   |                     ^^^^^^^^^^^^^^^^^ the trait `Lt<'_>` is not implemented for `()`

error[E0046]: not all trait items implemented, missing: `call_mut`
  --> ./B8BC8.rs:20:1
   |
20 | impl<T: Copy> FnMut<<() as Lt<'_>>::T> for Foo<T> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `call_mut` in implementation
   |
   = help: implement the missing item: `fn call_mut(&mut self, _: <() as Lt<'_>>::T) -> <Self as FnOnce<<() as Lt<'_>>::T>>::Output { todo!() }`

error[E0277]: expected a `FnOnce()` closure, found `Foo<T>`
  --> ./B8BC8.rs:26:14
   |
26 |         self.call(())
   |              ^^^^ expected an `FnOnce()` closure, found `Foo<T>`
   |
   = help: the trait `FnOnce()` is not implemented for `Foo<T>`
   = note: wrap the `Foo<T>` in a closure with no arguments: `|| { /* code */ }`

error: internal compiler error: compiler/rustc_infer/src/infer/at.rs:415:21: relating different kinds: ?2t '?2
Backtrace

thread 'rustc' panicked at compiler/rustc_infer/src/infer/at.rs:415:21:
Box<dyn Any>
stack backtrace:
   0:        0x109af6373 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h605d51fc858e32d3
   1:        0x109b412fb - core::fmt::write::he70b1f5b242a09e4
   2:        0x109aec0be - std::io::Write::write_fmt::hbfde528b9dfff91a
   3:        0x109af8c1a - std::panicking::default_hook::{{closure}}::hfdc91bfcaaf40c09
   4:        0x109af88ca - std::panicking::default_hook::h8673ceadddb8316e
   5:        0x112e7d8dc - std[8bfe66706d3bd117]::panicking::update_hook::<alloc[ea04c33bd6f71985]::boxed::Box<rustc_driver_impl[d8a49a9463f03e6]::install_ice_hook::{closure#0}>>::{closure#0}
   6:        0x109af9a09 - std::panicking::rust_panic_with_hook::h206b639ed4704bb1
   7:        0x112ef0bb7 - std[8bfe66706d3bd117]::panicking::begin_panic::<rustc_errors[7f155011d809a3bf]::ExplicitBug>::{closure#0}
   8:        0x112edc9f9 - std[8bfe66706d3bd117]::sys::backtrace::__rust_end_short_backtrace::<std[8bfe66706d3bd117]::panicking::begin_panic<rustc_errors[7f155011d809a3bf]::ExplicitBug>::{closure#0}, !>
   9:        0x117957469 - std[8bfe66706d3bd117]::panicking::begin_panic::<rustc_errors[7f155011d809a3bf]::ExplicitBug>
  10:        0x112f02c06 - <rustc_errors[7f155011d809a3bf]::diagnostic::BugAbort as rustc_errors[7f155011d809a3bf]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:        0x113bc8b45 - rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt::<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}
  12:        0x113b7f0b7 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_opt::<rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:        0x113b7ebf5 - rustc_middle[66eaac359ba8a608]::ty::context::tls::with_context_opt::<rustc_middle[66eaac359ba8a608]::ty::context::tls::with_opt<rustc_middle[66eaac359ba8a608]::util::bug::opt_span_bug_fmt<rustc_span[9df13b32b3ae4eb2]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:        0x117a1ff9b - rustc_middle[66eaac359ba8a608]::util::bug::bug_fmt
  15:        0x11366776e - <rustc_middle[66eaac359ba8a608]::ty::generic_args::GenericArg as rustc_infer[3da7f7f7e3fca22e]::infer::at::ToTrace>::to_trace
  16:        0x1149f5ace - <rustc_infer[3da7f7f7e3fca22e]::infer::at::At>::eq::<rustc_middle[66eaac359ba8a608]::ty::generic_args::GenericArg>
  17:        0x114ba8079 - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::suggestions::TypeErrCtxtExt>::note_function_argument_obligation::<rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>
  18:        0x114b9f41d - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::suggestions::TypeErrCtxtExt>::note_obligation_cause_code::<rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed, rustc_middle[66eaac359ba8a608]::ty::predicate::Predicate>
  19:        0x114b75162 - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::fulfillment_errors::InferCtxtPrivExt>::note_obligation_cause
  20:        0x114b66703 - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::fulfillment_errors::TypeErrCtxtSelectionErrExt>::report_selection_error
  21:        0x114bb3a45 - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::TypeErrCtxtExt>::report_fulfillment_error
  22:        0x114bb29a6 - <rustc_infer[3da7f7f7e3fca22e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bf739c384407ce51]::error_reporting::traits::TypeErrCtxtExt>::report_fulfillment_errors
  23:        0x11352a915 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  24:        0x11352c91e - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::expected_inputs_for_expected_output
  25:        0x113471658 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_method_argument_types
  26:        0x1135272f0 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_expr_kind
  27:        0x11343ea9e - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:        0x113480da6 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:        0x11343ea9e - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:        0x113440c74 - <rustc_hir_typeck[a7633e0d641b9efc]::fn_ctxt::FnCtxt>::check_return_expr
  31:        0x113501e36 - rustc_hir_typeck[a7633e0d641b9efc]::check::check_fn
  32:        0x1134fd551 - rustc_hir_typeck[a7633e0d641b9efc]::typeck
  33:        0x11456666c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>
  34:        0x1143e3fae - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::VecCache<rustc_span[9df13b32b3ae4eb2]::def_id::LocalDefId, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  35:        0x114589dab - rustc_query_impl[ab99e8e391ad42b2]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:        0x113100df6 - <rustc_middle[66eaac359ba8a608]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[c06ca58d4f3a4935]::check_crate::{closure#4}>::{closure#0}
  37:        0x11324f94c - rustc_hir_analysis[c06ca58d4f3a4935]::check_crate
  38:        0x11380ce37 - rustc_interface[f3798eed8f7e14ff]::passes::run_required_analyses
  39:        0x11380f2d3 - rustc_interface[f3798eed8f7e14ff]::passes::analysis
  40:        0x11456671c - rustc_query_impl[ab99e8e391ad42b2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab99e8e391ad42b2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>
  41:        0x11433ebfe - rustc_query_system[55587a8be6cb95b6]::query::plumbing::try_execute_query::<rustc_query_impl[ab99e8e391ad42b2]::DynamicConfig<rustc_query_system[55587a8be6cb95b6]::query::caches::SingleCache<rustc_middle[66eaac359ba8a608]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ab99e8e391ad42b2]::plumbing::QueryCtxt, false>
  42:        0x114570c77 - rustc_query_impl[ab99e8e391ad42b2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:        0x112e23537 - <rustc_interface[f3798eed8f7e14ff]::queries::QueryResult<&rustc_middle[66eaac359ba8a608]::ty::context::GlobalCtxt>>::enter::<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
  44:        0x112e84c1b - rustc_interface[f3798eed8f7e14ff]::interface::run_compiler::<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}
  45:        0x112e6ffc1 - std[8bfe66706d3bd117]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_with_globals<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_pool_with_globals<rustc_interface[f3798eed8f7e14ff]::interface::run_compiler<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>
  46:        0x112e8b5e6 - <<std[8bfe66706d3bd117]::thread::Builder>::spawn_unchecked_<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_with_globals<rustc_interface[f3798eed8f7e14ff]::util::run_in_thread_pool_with_globals<rustc_interface[f3798eed8f7e14ff]::interface::run_compiler<core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>, rustc_driver_impl[d8a49a9463f03e6]::run_compiler::{closure#0}>::{closure#1}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[84f3396b7379d157]::result::Result<(), rustc_span[9df13b32b3ae4eb2]::ErrorGuaranteed>>::{closure#2} as core[84f3396b7379d157]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:        0x109b029bb - std::sys::pal::unix::thread::Thread::new::thread_start::hff8a09cc296b9c2d
  48:     0x7ff801f5318b - __pthread_start

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: please attach the file at `/Users/sal/Documents/240714/rustc-ice-2024-07-15T01_37_11-61737.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `<impl at ./B8BC8.rs:22:1: 22:35>::call_once`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 13 previous errors

Some errors have detailed explanations: E0046, E0053, E0261, E0277, E0412.
For more information about an error, try `rustc --explain E0046`.

Note

ICE location

impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: match (a.unpack(), b.unpack()) {
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b))
}
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
}
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
}
(
GenericArgKind::Lifetime(_),
GenericArgKind::Type(_) | GenericArgKind::Const(_),
)
| (
GenericArgKind::Type(_),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_),
)
| (
GenericArgKind::Const(_),
GenericArgKind::Lifetime(_) | GenericArgKind::Type(_),
) => {
bug!("relating different kinds: {a:?} {b:?}")
}
},
}
}
}

@rustbot label +F-unboxed_closures

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions