Repository: rust
Issue: ICE: `failed to resolve instance for <Self as EnvFuture>::g`
Labels: I-ICE,T-compiler,C-bug,requires-nightly,S-has-mcve,S-bug-has-test,F-explicit_tail_calls

<!--
[31mICE[0m: Rustc ./a.rs '' 'error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:585:21: failed to resolve instance for <Self as EnvFuture>::g', 'error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:585:21: failed to resolve instance for <Self as EnvFuture>::g'
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
pub trait EnvFuture {
    type Item;

    fn g(a: String, b: &str) -> String {
        become a + b;
    }
}

````

original:
````rust
// Make sure that the mono-item collector does not crash when trying to
// instantiate a default impl of a method with lifetime parameters.
// See https://github.com/rust-lang/rust/issues/47309

//@ compile-flags:-Clink-dead-code
//@ build-pass

#![crate_type="rlib"]

pub trait EnvFuture {
    type Item;

    fn g(a: String, b: &str) -> String {
    become a + b; //~ error: `become` does not support operators
}
}

struct Foo;

impl<'a> EnvFuture for &'a Foo {
    type Item = ();
}

````

Version information
````
rustc 1.85.0-nightly (4790a435c 2024-12-15)
binary: rustc
commit-hash: 4790a435cbcb55c94ccdef51bf7a9b2e55824528
commit-date: 2024-12-15
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/4790a435cbcb55c94ccdef51bf7a9b2e55824528/compiler/rustc_middle/src/ty/instance.rs#L579-L591

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

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

```
error[E0658]: `become` expression is experimental
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:5:9
  |
5 |         become a + b;
  |         ^^^^^^^^^^^^
  |
  = note: see issue #112788 <https://github.com/rust-lang/rust/issues/112788> for more information
  = help: add `#![feature(explicit_tail_calls)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-15; consider upgrading it if it is out of date

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

error: `become` does not support operators
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:5:16
  |
5 |         become a + b;
  |                ^^^^^
  |
help: try using the method directly
  |
5 |         become (a).add(b);
  |                + ~~~~~~ +

error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:585:21: failed to resolve instance for <Self as EnvFuture>::g
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:4:5
  |
4 |     fn g(a: String, b: &str) -> String {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:585:21:
Box<dyn Any>
stack backtrace:
   0:     0x7fa93f3a4c5a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::heb202b000efba683
   1:     0x7fa93fc13d66 - core::fmt::write::h4529572b8b32da24
   2:     0x7fa940c1db51 - std::io::Write::write_fmt::h1a906436cb206037
   3:     0x7fa93f3a4ab2 - std::sys::backtrace::BacktraceLock::print::h934abc86fa2dd260
   4:     0x7fa93f3a6faa - std::panicking::default_hook::{{closure}}::hfd4bbe50128406cd
   5:     0x7fa93f3a6df3 - std::panicking::default_hook::h25fd19fcd22c2e04
   6:     0x7fa93e4f9a68 - std[70002648da4681c1]::panicking::update_hook::<alloc[334d4c3039138aa]::boxed::Box<rustc_driver_impl[2cc745b14baadf]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7fa93f3a7768 - std::panicking::rust_panic_with_hook::h3f6d3ded85336e6b
   8:     0x7fa93e52f911 - std[70002648da4681c1]::panicking::begin_panic::<rustc_errors[196465616da871a4]::ExplicitBug>::{closure#0}
   9:     0x7fa93e524ab6 - std[70002648da4681c1]::sys::backtrace::__rust_end_short_backtrace::<std[70002648da4681c1]::panicking::begin_panic<rustc_errors[196465616da871a4]::ExplicitBug>::{closure#0}, !>
  10:     0x7fa93e52486f - std[70002648da4681c1]::panicking::begin_panic::<rustc_errors[196465616da871a4]::ExplicitBug>
  11:     0x7fa93e5398d1 - <rustc_errors[196465616da871a4]::diagnostic::BugAbort as rustc_errors[196465616da871a4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7fa93ea9971c - <rustc_errors[196465616da871a4]::DiagCtxtHandle>::span_bug::<rustc_span[5501a71f8d28de35]::span_encoding::Span, alloc[334d4c3039138aa]::string::String>
  13:     0x7fa93eb30657 - rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt::<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}
  14:     0x7fa93eb1600a - rustc_middle[4552a92c16cacd81]::ty::context::tls::with_opt::<rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7fa93eb15e9b - rustc_middle[4552a92c16cacd81]::ty::context::tls::with_context_opt::<rustc_middle[4552a92c16cacd81]::ty::context::tls::with_opt<rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7fa93cfa5f07 - rustc_middle[4552a92c16cacd81]::util::bug::span_bug_fmt::<rustc_span[5501a71f8d28de35]::span_encoding::Span>
  17:     0x7fa9402d2284 - <rustc_middle[4552a92c16cacd81]::ty::instance::Instance>::expect_resolve
  18:     0x7fa93eb97fe8 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor>::needs_location
  19:     0x7fa94058cd42 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  20:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  21:     0x7fa94058ae91 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_block
  22:     0x7fa94058b0df - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  23:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  24:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  25:     0x7fa94058a3f6 - rustc_mir_build[377f342b43331edb]::check_tail_calls::check_tail_calls
  26:     0x7fa94058a0af - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::check_tail_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7fa94059b5c7 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  28:     0x7fa94059b1c1 - rustc_query_impl[98026ab69133ca5a]::query_impl::check_tail_calls::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7fa94059fd39 - rustc_mir_build[377f342b43331edb]::build::mir_build
  30:     0x7fa93fc077d4 - rustc_mir_transform[f55849332dfb7241]::mir_built
  31:     0x7fa93fc07797 - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7fa93fe75711 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  33:     0x7fa93fe752cd - rustc_query_impl[98026ab69133ca5a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fa93cc1e8e5 - rustc_mir_build[377f342b43331edb]::check_unsafety::check_unsafety
  35:     0x7fa9404f50e7 - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>
  36:     0x7fa9404f53a9 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  37:     0x7fa9404f5011 - rustc_query_impl[98026ab69133ca5a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7fa940053bb2 - rustc_interface[cf66c2394d3c8572]::passes::run_required_analyses
  39:     0x7fa940c0c91e - rustc_interface[cf66c2394d3c8572]::passes::analysis
  40:     0x7fa940c0c8ef - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>
  41:     0x7fa940c41015 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_query_system[c5a9321c1b201b0d]::query::caches::SingleCache<rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  42:     0x7fa940c40d4e - rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7fa940cb61b4 - rustc_interface[cf66c2394d3c8572]::interface::run_compiler::<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}
  44:     0x7fa940b685db - std[70002648da4681c1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  45:     0x7fa940b68a90 - <<std[70002648da4681c1]::thread::Builder>::spawn_unchecked_<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[3b8d2fc2756ea0bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x7fa940b6a06f - std::sys::pal::unix::thread::Thread::new::thread_start::hdeaa41b2ac9b4ad7
  47:     0x7fa93aca339d - <unknown>
  48:     0x7fa93ad2849c - <unknown>
  49:                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.85.0-nightly (4790a435c 2024-12-15) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_tail_calls] tail-call-checking `EnvFuture::g`
#1 [mir_built] building MIR for `EnvFuture::g`
end of query stack
error: aborting due to 4 previous errors

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

```

</p>
</details>

<!--
query stack:
#0 [check_tail_calls] tail-call-checking `EnvFuture::g`
#1 [mir_built] building MIR for `EnvFuture::g`

-->