Repository: rust
Issue: ICE “unexpected bound ty in binder” involving type binder, `Fn`-family trait and closure
Labels: I-ICE,T-compiler,C-bug,glacier,S-bug-has-test,F-non_lifetime_binders

```rs
#![feature(non_lifetime_binders)]

fn take(_: impl for<T> FnOnce(T) -> T) {}

fn main() {
    take(|x| x)
}
```

### Error output

```
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> take_id.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/ac4379fea9e83465d814bb05005689f49bd2141e/compiler/rustc_middle/src/ty/fold.rs:297:33: unexpected bound ty in binder: BoundTy { var: 0, kind: Anon(0) }

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/compiler/rustc_errors/src/lib.rs:1644:9
```

<details><summary><strong>Backtrace</strong></summary>
<p>

```
stack backtrace:
   0:     0x7f1e8f56653a - std::backtrace_rs::backtrace::libunwind::trace::ha7277b97837a680e
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1e8f56653a - std::backtrace_rs::backtrace::trace_unsynchronized::h2eae6446df1fb3c7
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1e8f56653a - std::sys_common::backtrace::_print_fmt::hcce758637ada6e5e
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f1e8f56653a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h048020a39b1c8541
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1e8f5c9cee - core::fmt::write::h8cb0e60463f917ed
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f1e8f5593e5 - std::io::Write::write_fmt::h6a4bf43ae33fb5c2
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/io/mod.rs:1684:15
   6:     0x7f1e8f566305 - std::sys_common::backtrace::_print::h01686671a8f910e8
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f1e8f566305 - std::sys_common::backtrace::print::hb036d568178720fa
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f1e8f56907f - std::panicking::default_hook::{{closure}}::hac5f47cee0e06043
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:271:22
   9:     0x7f1e8f568dbb - std::panicking::default_hook::hc30c65fb62dafbb3
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:290:9
  10:     0x7f1e927e25c5 - rustc_driver_impl[1bafdf3e8b0cbe0c]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f1e8f5698bd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hec34b5992590fa06
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:2001:9
  12:     0x7f1e8f5698bd - std::panicking::rust_panic_with_hook::h44e2196c38854f66
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/panicking.rs:696:13
  13:     0x7f1e92d3e671 - std[f869becc71c6b456]::panicking::begin_panic::<rustc_errors[d0ebe06311983455]::ExplicitBug>::{closure#0}
  14:     0x7f1e92d36fe6 - std[f869becc71c6b456]::sys_common::backtrace::__rust_end_short_backtrace::<std[f869becc71c6b456]::panicking::begin_panic<rustc_errors[d0ebe06311983455]::ExplicitBug>::{closure#0}, !>
  15:     0x7f1e92daba26 - std[f869becc71c6b456]::panicking::begin_panic::<rustc_errors[d0ebe06311983455]::ExplicitBug>
  16:     0x7f1e92d8a1a6 - std[f869becc71c6b456]::panic::panic_any::<rustc_errors[d0ebe06311983455]::ExplicitBug>
  17:     0x7f1e92d85ba6 - <rustc_errors[d0ebe06311983455]::HandlerInner>::bug::<&alloc[56a1e614eb299497]::string::String>
  18:     0x7f1e92d85870 - <rustc_errors[d0ebe06311983455]::Handler>::bug::<&alloc[56a1e614eb299497]::string::String>
  19:     0x7f1e92d7cb7b - rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt::<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}
  20:     0x7f1e92d7b4ca - rustc_middle[6b96750649b9b523]::ty::context::tls::with_opt::<rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f1e92d7b496 - rustc_middle[6b96750649b9b523]::ty::context::tls::with_context_opt::<rustc_middle[6b96750649b9b523]::ty::context::tls::with_opt<rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt<rustc_span[481fe46353bf1cdc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f1e92d7cac6 - rustc_middle[6b96750649b9b523]::util::bug::opt_span_bug_fmt::<rustc_span[481fe46353bf1cdc]::span_encoding::Span>
  23:     0x7f1e90eeec13 - rustc_middle[6b96750649b9b523]::util::bug::bug_fmt
  24:     0x7f1e92a4230c - <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::replace_late_bound_regions_uncached::<rustc_middle[6b96750649b9b523]::ty::sty::FnSig, <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::replace_late_bound_regions<rustc_middle[6b96750649b9b523]::ty::sty::FnSig, <rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>::erase_late_bound_regions<rustc_middle[6b96750649b9b523]::ty::sty::FnSig>::{closure#0}>::{closure#0}>::{closure#0}
  25:     0x7f1e90e228fd - <&rustc_middle[6b96750649b9b523]::ty::list::List<rustc_middle[6b96750649b9b523]::ty::Ty> as rustc_type_ir[52d4fefb1527696e]::fold::TypeFoldable<rustc_middle[6b96750649b9b523]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[6b96750649b9b523]::ty::fold::BoundVarReplacer<rustc_middle[6b96750649b9b523]::ty::fold::FnMutDelegate>>
  26:     0x7f1e90c1236b - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::closure_sigs
  27:     0x7f1e90c10183 - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_closure
  28:     0x7f1e90b9f3fc - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7f1e90e86ebd - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_argument_types
  30:     0x7f1e90b6d7bb - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_call
  31:     0x7f1e90b9b6ad - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f1e90bcacbe - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_block_with_expected
  33:     0x7f1e90b9bbdf - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  34:     0x7f1e9166f7d4 - <rustc_hir_typeck[b98449f9e1a7a434]::fn_ctxt::FnCtxt>::check_return_expr
  35:     0x7f1e91667bc7 - rustc_hir_typeck[b98449f9e1a7a434]::check::check_fn
  36:     0x7f1e91651c37 - rustc_hir_typeck[b98449f9e1a7a434]::typeck
  37:     0x7f1e90a2052c - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::typeck, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  38:     0x7f1e91faf34f - rustc_data_structures[afc619c2eff4eef5]::sync::par_for_each_in::<&[rustc_span[481fe46353bf1cdc]::def_id::LocalDefId], <rustc_middle[6b96750649b9b523]::hir::map::Map>::par_body_owners<rustc_hir_typeck[b98449f9e1a7a434]::typeck_item_bodies::{closure#0}>::{closure#0}>
  39:     0x7f1e91faf10f - rustc_hir_typeck[b98449f9e1a7a434]::typeck_item_bodies
  40:     0x7f1e91e2c55d - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::typeck_item_bodies, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  41:     0x7f1e91e2c24b - <rustc_query_impl[1c38571c4f3dd9ba]::Queries as rustc_middle[6b96750649b9b523]::ty::query::QueryEngine>::typeck_item_bodies
  42:     0x7f1e90b68493 - <rustc_session[d491f4b0c10bdfb9]::session::Session>::time::<(), rustc_hir_analysis[717970e329447c82]::check_crate::{closure#7}>
  43:     0x7f1e90b64f4d - rustc_hir_analysis[717970e329447c82]::check_crate
  44:     0x7f1e90b5b072 - rustc_interface[841154c2f5280d71]::passes::analysis
  45:     0x7f1e92033d9d - rustc_query_system[5157c2c547c7c596]::query::plumbing::try_execute_query::<rustc_query_impl[1c38571c4f3dd9ba]::queries::analysis, rustc_query_impl[1c38571c4f3dd9ba]::plumbing::QueryCtxt>
  46:     0x7f1e92033a9f - <rustc_query_impl[1c38571c4f3dd9ba]::Queries as rustc_middle[6b96750649b9b523]::ty::query::QueryEngine>::analysis
  47:     0x7f1e91e63616 - <rustc_middle[6b96750649b9b523]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>
  48:     0x7f1e91a47f48 - rustc_span[481fe46353bf1cdc]::with_source_map::<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  49:     0x7f1e91a3f4dc - std[f869becc71c6b456]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[841154c2f5280d71]::util::run_in_thread_pool_with_globals<rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>
  50:     0x7f1e91a3ef0a - <<std[f869becc71c6b456]::thread::Builder>::spawn_unchecked_<rustc_interface[841154c2f5280d71]::util::run_in_thread_pool_with_globals<rustc_interface[841154c2f5280d71]::interface::run_compiler<core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>, rustc_driver_impl[1bafdf3e8b0cbe0c]::run_compiler::{closure#1}>::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c7837a1117e32cc5]::result::Result<(), rustc_span[481fe46353bf1cdc]::ErrorGuaranteed>>::{closure#1} as core[c7837a1117e32cc5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f1e8f5737b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc371c06232f0c824
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:1987:9
  52:     0x7f1e8f5737b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7dc3758286df85d1
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/alloc/src/boxed.rs:1987:9
  53:     0x7f1e8f5737b3 - std::sys::unix::thread::Thread::new::thread_start::h64782255c7c71ccd
                               at /rustc/ac4379fea9e83465d814bb05005689f49bd2141e/library/std/src/sys/unix/thread.rs:108:17
  54:     0x7f1e8f3068fd - <unknown>
  55:     0x7f1e8f388a60 - <unknown>
  56:                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: rustc 1.70.0-nightly (ac4379fea 2023-03-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted
```

</p>
</details>

### Meta

Latest **master** (ac4379fea9e83465d814bb05005689f49bd2141e).

`rustc -Vv`:

```
rustc 1.70.0-nightly (ac4379fea 2023-03-06)
binary: rustc
commit-hash: ac4379fea9e83465d814bb05005689f49bd2141e
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
```


@rustbot label F-non_lifetime_binders