Repository: rust
Issue: ICE: type_of_opaque: `unexpected bound ty in binder: 0`
Labels: I-ICE,T-compiler,C-bug,S-bug-has-test,F-non_lifetime_binders

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
#![feature(non_lifetime_binders)]
fn take(id: impl for<T> Fn(T) -> T) {
    id(0);
    id("");
}

fn take2() -> impl for<T> Fn(T) -> T {
    |x| x
}

fn main() {
    take(|x| take2)
}

```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.80.0-nightly (ada5e2c7b 2024-05-31)
binary: rustc
commit-hash: ada5e2c7b5427a591e30baeeee2698a5eb6db0bd
commit-date: 2024-05-31
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6
```

### Error output

```
<output>
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> lif.rs:1:12
  |
1 | #![feature(non_lifetime_binders)]
  |            ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/compiler/rustc_middle/src/ty/fold.rs:284:33: unexpected bound ty in binder: 0

thread 'rustc' panicked at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/compiler/rustc_middle/src/ty/fold.rs:284:33:
Box<dyn Any>
stack backtrace:
   0:     0x7bc0c7bcdcc5 - std::backtrace_rs::backtrace::libunwind::trace::h0bda62405550d460
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7bc0c7bcdcc5 - std::backtrace_rs::backtrace::trace_unsynchronized::hc2c3ea3cf2f5c7f0
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7bc0c7bcdcc5 - std::sys_common::backtrace::_print_fmt::h8de6a59eaee45226
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7bc0c7bcdcc5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd6ffc154782334f4
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7bc0c7c1e6bb - core::fmt::rt::Argument::fmt::h1ed1f880d19ca3e5
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/fmt/rt.rs:165:63
   5:     0x7bc0c7c1e6bb - core::fmt::write::h7e2d247389cb3e97
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/fmt/mod.rs:1168:21
   6:     0x7bc0c7bc299f - std::io::Write::write_fmt::ha7add8792955e794
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/io/mod.rs:1835:15
   7:     0x7bc0c7bcda9e - std::sys_common::backtrace::_print::ha9e91abfc6e8d12d
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7bc0c7bcda9e - std::sys_common::backtrace::print::ha4520664df90140c
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7bc0c7bd04d9 - std::panicking::default_hook::{{closure}}::h04aa22b6205d98a5
  10:     0x7bc0c7bd027a - std::panicking::default_hook::hf52ae4d8be29501c
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:298:9
  11:     0x7bc0c43339af - std[a75323165fe08653]::panicking::update_hook::<alloc[2577b08d1a5511d8]::boxed::Box<rustc_driver_impl[9be41471faca984]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7bc0c7bd0c0b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3a2a9442c441a378
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2077:9
  13:     0x7bc0c7bd0c0b - std::panicking::rust_panic_with_hook::he3c87e486ff05d6b
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:799:13
  14:     0x7bc0c4364304 - std[a75323165fe08653]::panicking::begin_panic::<rustc_errors[258af463c632d5aa]::ExplicitBug>::{closure#0}
  15:     0x7bc0c4360c36 - std[a75323165fe08653]::sys_common::backtrace::__rust_end_short_backtrace::<std[a75323165fe08653]::panicking::begin_panic<rustc_errors[258af463c632d5aa]::ExplicitBug>::{closure#0}, !>
  16:     0x7bc0c435bf86 - std[a75323165fe08653]::panicking::begin_panic::<rustc_errors[258af463c632d5aa]::ExplicitBug>
  17:     0x7bc0c436d781 - <rustc_errors[258af463c632d5aa]::diagnostic::BugAbort as rustc_errors[258af463c632d5aa]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7bc0c485bdbc - rustc_middle[353648fe55f979cd]::util::bug::opt_span_bug_fmt::<rustc_span[5e338462bab9c833]::span_encoding::Span>::{closure#0}
  19:     0x7bc0c483e82a - rustc_middle[353648fe55f979cd]::ty::context::tls::with_opt::<rustc_middle[353648fe55f979cd]::util::bug::opt_span_bug_fmt<rustc_span[5e338462bab9c833]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7bc0c483e6ab - rustc_middle[353648fe55f979cd]::ty::context::tls::with_context_opt::<rustc_middle[353648fe55f979cd]::ty::context::tls::with_opt<rustc_middle[353648fe55f979cd]::util::bug::opt_span_bug_fmt<rustc_span[5e338462bab9c833]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7bc0c2b2a100 - rustc_middle[353648fe55f979cd]::util::bug::bug_fmt
  22:     0x7bc0c44f611c - <rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>::instantiate_bound_regions_uncached::<rustc_type_ir[c27970b0cda7b0ad]::ty_kind::FnSig<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>, <rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>::instantiate_bound_regions<rustc_type_ir[c27970b0cda7b0ad]::ty_kind::FnSig<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>, <rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>::instantiate_bound_regions_with_erased<rustc_type_ir[c27970b0cda7b0ad]::ty_kind::FnSig<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>>::{closure#0}>::{closure#0}>::{closure#0}
  23:     0x7bc0c5c11a8a - <rustc_middle[353648fe55f979cd]::ty::fold::BoundVarReplacer<rustc_middle[353648fe55f979cd]::ty::fold::FnMutDelegate> as rustc_type_ir[c27970b0cda7b0ad]::fold::TypeFolder<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>>::fold_ty
  24:     0x7bc0c5c10cd0 - <&rustc_middle[353648fe55f979cd]::ty::list::RawList<(), rustc_middle[353648fe55f979cd]::ty::Ty> as rustc_type_ir[c27970b0cda7b0ad]::fold::TypeFoldable<rustc_middle[353648fe55f979cd]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[353648fe55f979cd]::ty::fold::BoundVarReplacer<rustc_middle[353648fe55f979cd]::ty::fold::FnMutDelegate>>
  25:     0x7bc0c5858a0c - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::closure_sigs
  26:     0x7bc0c5fc919b - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_closure
  27:     0x7bc0c61df8ee - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7bc0c61d70ce - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:     0x7bc0c61dc122 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7bc0c5dd3f4c - rustc_hir_typeck[6b466a1699c07763]::check::check_fn
  31:     0x7bc0c5dc966c - rustc_hir_typeck[6b466a1699c07763]::typeck
  32:     0x7bc0c5dc90d1 - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7bc0c5e868ae - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::VecCache<rustc_span[5e338462bab9c833]::def_id::LocalDefId, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  34:     0x7bc0c5e853d5 - rustc_query_impl[9b16a2dee6878131]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7bc0c5f420fc - rustc_middle[353648fe55f979cd]::query::plumbing::query_get_at::<rustc_query_system[965e295a0f1b428c]::query::caches::VecCache<rustc_span[5e338462bab9c833]::def_id::LocalDefId, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>>
  36:     0x7bc0c662c46b - rustc_hir_analysis[2361776b1da3ecb6]::collect::type_of::type_of_opaque
  37:     0x7bc0c662c3a7 - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7bc0c5a38227 - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::DefIdCache<rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  39:     0x7bc0c6830df6 - rustc_query_impl[9b16a2dee6878131]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7bc0c5f3ca7c - rustc_middle[353648fe55f979cd]::query::plumbing::query_get_at::<rustc_query_system[965e295a0f1b428c]::query::caches::DefIdCache<rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>>
  41:     0x7bc0c34ad273 - rustc_hir_analysis[2361776b1da3ecb6]::collect::type_of::type_of
  42:     0x7bc0c5a3962a - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7bc0c5a38227 - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::DefIdCache<rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  44:     0x7bc0c5a37de7 - rustc_query_impl[9b16a2dee6878131]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7bc0c5f3ca7c - rustc_middle[353648fe55f979cd]::query::plumbing::query_get_at::<rustc_query_system[965e295a0f1b428c]::query::caches::DefIdCache<rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 8usize]>>>
  46:     0x7bc0c63e7671 - rustc_hir_analysis[2361776b1da3ecb6]::check::check::check_item_type
  47:     0x7bc0c63ceb35 - rustc_hir_analysis[2361776b1da3ecb6]::check::wfcheck::check_well_formed
  48:     0x7bc0c63cd3c7 - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>
  49:     0x7bc0c63ccb66 - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::VecCache<rustc_hir[de6e03571ff16fe3]::hir_id::OwnerId, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  50:     0x7bc0c63cc8e4 - rustc_query_impl[9b16a2dee6878131]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7bc0c63ca7b7 - rustc_hir_analysis[2361776b1da3ecb6]::check::wfcheck::check_mod_type_wf
  52:     0x7bc0c63ca5e1 - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>
  53:     0x7bc0c62a4870 - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::DefaultCache<rustc_span[5e338462bab9c833]::def_id::LocalModDefId, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  54:     0x7bc0c62a4619 - rustc_query_impl[9b16a2dee6878131]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7bc0c5e834cc - rustc_hir_analysis[2361776b1da3ecb6]::check_crate
  56:     0x7bc0c5e9c87e - rustc_interface[cb0c5c0af19cf814]::passes::analysis
  57:     0x7bc0c5e9c3db - rustc_query_impl[9b16a2dee6878131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b16a2dee6878131]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>
  58:     0x7bc0c65ec4a5 - rustc_query_system[965e295a0f1b428c]::query::plumbing::try_execute_query::<rustc_query_impl[9b16a2dee6878131]::DynamicConfig<rustc_query_system[965e295a0f1b428c]::query::caches::SingleCache<rustc_middle[353648fe55f979cd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9b16a2dee6878131]::plumbing::QueryCtxt, false>
  59:     0x7bc0c65ec20f - rustc_query_impl[9b16a2dee6878131]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  60:     0x7bc0c647719c - rustc_interface[cb0c5c0af19cf814]::interface::run_compiler::<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}
  61:     0x7bc0c64410c9 - std[a75323165fe08653]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_with_globals<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_pool_with_globals<rustc_interface[cb0c5c0af19cf814]::interface::run_compiler<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>
  62:     0x7bc0c6440e80 - <<std[a75323165fe08653]::thread::Builder>::spawn_unchecked_<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_with_globals<rustc_interface[cb0c5c0af19cf814]::util::run_in_thread_pool_with_globals<rustc_interface[cb0c5c0af19cf814]::interface::run_compiler<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>>::{closure#2} as core[bd782e33ccb6b408]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  63:     0x7bc0c7bdabfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h149a8f3bd2b6d616
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  64:     0x7bc0c7bdabfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc8ac52b5c9166594
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  65:     0x7bc0c7bdabfb - std::sys::pal::unix::thread::Thread::new::thread_start::h4464ec80ffa1747a
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys/pal/unix/thread.rs:108:17
  66:     0x7bc0c10aa1cf - <unknown>
  67:     0x7bc0c112b6ec - <unknown>
  68:                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: please attach the file at `/tmp/l/rustc-ice-2024-06-01T05_10_51-509304.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `take2`
#1 [type_of_opaque] computing type of opaque `take2::{opaque#0}`
end of query stack
error: aborting due to 1 previous error; 1 warning emitted
```

</p>
</details>