Repository: rust
Issue: ICE: `called 'Result::unwrap_err()' on an 'Ok' value: MethodCallee `
Labels: I-ICE,P-low,T-compiler,C-bug,S-bug-has-test

<!--
ICE: Rustc ./BB46933371FE1A9056B1FE9FA982D37C278851295F07AEE8A85D56116A733DD5.rs '' 'thread 'rustc' panicked at compiler/rustc_hir_typeck/src/op.rs:593:30: 'called `Result::unwrap_err()` on an `Ok` value: MethodCallee { def_id: DefId(2:3465 ~ core[c9a4]::ops::arith::Add::add), args: [&'?1 N/#0, N/#0], sig: fn(&'?1 N/#0, N/#0) -> ?4t }'', 'thread 'rustc' panicked at compiler/rustc_hir_typeck/src/op.rs:593:30: 'called `Result::unwrap_err()` on an `Ok` value: MethodCallee { def_id: DefId(2:3465 ~ core[c9a4]::ops::arith::Add::add), args: [&'?1 N/#0, N/#0], sig: fn(&'?1 N/#0, N/#0) -> ?4t }''
File: /home/gh-matthiaskrgr/im/BB46933371FE1A9056B1FE9FA982D37C278851295F07AEE8A85D56116A733DD5.rs
-->

auto-reduced (treereduce-rust):
````rust
use std::ops::Add;

pub trait Numoid
where
    Self: Sized,
    for<N: Numoid> &'a Self: Add<Self>,
{
}

pub fn compute<N: Numoid>(a: N, b: N) -> N {
    &a + b
}

````

original:
````rust
use std::ops::Add;

pub trait Numoid where
  Self: Sized,
  for<N: Numoid> &'a Self: Add<Self, Output = Self>
{}

impl<N> Numoid for N where
  for<'a> &'a N: Add<N, Output = N>
{}

pub fn compute<N: Numoid>(a: N, b: N) -> N
    // where for<'a> &'a N: Add<N, Output = N> // redundant bound is required
{ &a + b }
````

Version information
````
rustc 1.84.0-nightly (c22887b4d 2024-11-10)
binary: rustc
commit-hash: c22887b4d97400e8e024e19fb5f724eda65ad58d
commit-date: 2024-11-10
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/c22887b4d97400e8e024e19fb5f724eda65ad58d/compiler/rustc_hir_typeck/src/op.rs#L587-L599

Command:
`/home/gh-matthiaskrgr/.rustup/toolchains/master/bin/rustc `

<details><summary><strong>Program output</strong></summary>
<p>

```
error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.8MhAhK5jiuLv/rustc_testrunner_tmpdir_reporting.CRfxbVTvebpq/mvce.rs:6:21
  |
6 |     for<N: Numoid> &'a Self: Add<Self>,
  |                     ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
6 |     for<'a, N: Numoid> &'a Self: Add<Self>,
  |         +++
help: consider introducing lifetime `'a` here
  |
3 | pub trait Numoid<'a>
  |                 ++++

error[E0658]: only lifetime parameters can be used in this context
 --> /tmp/icemaker_global_tempdir.8MhAhK5jiuLv/rustc_testrunner_tmpdir_reporting.CRfxbVTvebpq/mvce.rs:6:9
  |
6 |     for<N: Numoid> &'a Self: Add<Self>,
  |         ^
  |
  = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
  = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-10; consider upgrading it if it is out of date

error: bounds cannot be used in this context
 --> /tmp/icemaker_global_tempdir.8MhAhK5jiuLv/rustc_testrunner_tmpdir_reporting.CRfxbVTvebpq/mvce.rs:6:12
  |
6 |     for<N: Numoid> &'a Self: Add<Self>,
  |            ^^^^^^

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.8MhAhK5jiuLv/rustc_testrunner_tmpdir_reporting.CRfxbVTvebpq/mvce.rs:12:2
   |
12 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.8MhAhK5jiuLv/rustc_testrunner_tmpdir_reporting.CRfxbVTvebpq/mvce.rs`

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/op.rs:593:30:
called `Result::unwrap_err()` on an `Ok` value: MethodCallee { def_id: DefId(2:3465 ~ core[c9a4]::ops::arith::Add::add), args: [&'?1 N/#0, N/#0], sig: fn(&'?1 N/#0, N/#0) -> ?4t }
stack backtrace:
   0:     0x71bc56a6ea2a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h83ad5e2a379fc4af
   1:     0x71bc57204126 - core::fmt::write::hd8ade6666fd2c40a
   2:     0x71bc5820c551 - std::io::Write::write_fmt::h7d2b379dca789286
   3:     0x71bc56a6e882 - std::sys::backtrace::BacktraceLock::print::h59e64fca617eeec6
   4:     0x71bc56a70d86 - std::panicking::default_hook::{{closure}}::h16156878543f93cc
   5:     0x71bc56a70bd0 - std::panicking::default_hook::hbaee2e322f8f0f8f
   6:     0x71bc55ae8e89 - std[248d60aad2b34f5b]::panicking::update_hook::<alloc[51073ec307549381]::boxed::Box<rustc_driver_impl[85a2628807024745]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x71bc56a71498 - std::panicking::rust_panic_with_hook::h1585e6a773a078df
   8:     0x71bc56a7126a - std::panicking::begin_panic_handler::{{closure}}::h3c7880b1e47691e7
   9:     0x71bc56a6eed9 - std::sys::backtrace::__rust_end_short_backtrace::hfac10c8ba5512bd0
  10:     0x71bc56a70f2c - rust_begin_unwind
  11:     0x71bc534d2650 - core::panicking::panic_fmt::h8ce9768a1a123ba1
  12:     0x71bc53986e46 - core::result::unwrap_failed::h51824eae6f4049d1
  13:     0x71bc573eb52a - <rustc_hir_typeck[d66e89de08caab9]::fn_ctxt::FnCtxt>::check_overloaded_binop
  14:     0x71bc57fe139e - <rustc_hir_typeck[d66e89de08caab9]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  15:     0x71bc57fd9659 - <rustc_hir_typeck[d66e89de08caab9]::fn_ctxt::FnCtxt>::check_block_with_expected
  16:     0x71bc57fdf9e4 - <rustc_hir_typeck[d66e89de08caab9]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17:     0x71bc5741085b - rustc_hir_typeck[d66e89de08caab9]::check::check_fn
  18:     0x71bc5740632c - rustc_hir_typeck[d66e89de08caab9]::typeck
  19:     0x71bc57405cd3 - rustc_query_impl[edd1d74896ea38c9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[edd1d74896ea38c9]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dc17d8c02b0af06a]::query::erase::Erased<[u8; 8usize]>>
  20:     0x71bc578b6681 - rustc_query_system[16014b61255515c2]::query::plumbing::try_execute_query::<rustc_query_impl[edd1d74896ea38c9]::DynamicConfig<rustc_query_system[16014b61255515c2]::query::caches::VecCache<rustc_span[966ebffeac22211b]::def_id::LocalDefId, rustc_middle[dc17d8c02b0af06a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[edd1d74896ea38c9]::plumbing::QueryCtxt, false>
  21:     0x71bc578b4d8d - rustc_query_impl[edd1d74896ea38c9]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  22:     0x71bc578b4a07 - <rustc_middle[dc17d8c02b0af06a]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[aca35e167d413358]::check_crate::{closure#4}>::{closure#0}
  23:     0x71bc578b29cf - rustc_hir_analysis[aca35e167d413358]::check_crate
  24:     0x71bc578a310a - rustc_interface[1e17fd868ff3e64c]::passes::run_required_analyses
  25:     0x71bc5800141e - rustc_interface[1e17fd868ff3e64c]::passes::analysis
  26:     0x71bc580013ef - rustc_query_impl[edd1d74896ea38c9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[edd1d74896ea38c9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dc17d8c02b0af06a]::query::erase::Erased<[u8; 1usize]>>
  27:     0x71bc581d5d2e - rustc_query_system[16014b61255515c2]::query::plumbing::try_execute_query::<rustc_query_impl[edd1d74896ea38c9]::DynamicConfig<rustc_query_system[16014b61255515c2]::query::caches::SingleCache<rustc_middle[dc17d8c02b0af06a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[edd1d74896ea38c9]::plumbing::QueryCtxt, false>
  28:     0x71bc581d5a0e - rustc_query_impl[edd1d74896ea38c9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x71bc580cc93a - rustc_interface[1e17fd868ff3e64c]::interface::run_compiler::<core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>, rustc_driver_impl[85a2628807024745]::run_compiler::{closure#0}>::{closure#1}
  30:     0x71bc58183410 - std[248d60aad2b34f5b]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1e17fd868ff3e64c]::util::run_in_thread_with_globals<rustc_interface[1e17fd868ff3e64c]::util::run_in_thread_pool_with_globals<rustc_interface[1e17fd868ff3e64c]::interface::run_compiler<core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>, rustc_driver_impl[85a2628807024745]::run_compiler::{closure#0}>::{closure#1}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>::{closure#0}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>
  31:     0x71bc5818382b - <<std[248d60aad2b34f5b]::thread::Builder>::spawn_unchecked_<rustc_interface[1e17fd868ff3e64c]::util::run_in_thread_with_globals<rustc_interface[1e17fd868ff3e64c]::util::run_in_thread_pool_with_globals<rustc_interface[1e17fd868ff3e64c]::interface::run_compiler<core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>, rustc_driver_impl[85a2628807024745]::run_compiler::{closure#0}>::{closure#1}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>::{closure#0}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c9a4dec56b015974]::result::Result<(), rustc_span[966ebffeac22211b]::ErrorGuaranteed>>::{closure#1} as core[c9a4dec56b015974]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x71bc581842f9 - std::sys::pal::unix::thread::Thread::new::thread_start::hd6ed3da90976b7d6
  33:     0x71bc5209ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  34:     0x71bc52129c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  35:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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.84.0-nightly (c22887b4d 2024-11-10) running on x86_64-unknown-linux-gnu

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

Some errors have detailed explanations: E0261, E0601, E0658.
For more information about an error, try `rustc --explain E0261`.

```

</p>
</details>

<!--
query stack:
#0 [typeck] type-checking `compute`
#1 [analysis] running analysis passes on this crate

-->