Repository: rust
Issue: [const_closures, const_mut_refs, effects] thread 'rustc' panicked at rustc_middle/src/ty/util.rs:945:22: ConstContext::Maybe must have host effect param
Labels: I-ICE,E-needs-test,T-compiler,C-bug,F-const_mut_refs,F-const_trait_impl,S-has-mcve,requires-incomplete-features,F-const_closures

I know that `const_closures` feature is incomplete (https://github.com/rust-lang/rust/issues/106003). This is to report that I managed to use it with simple const closures such as `const |i| 2 * i as u32`, but slightly more complex expressions like `const |i| 2 * i as u32 + 1` cause an ICE.

### Code

```Rust
#![feature(const_closures, const_trait_impl)]

const fn create_array<const N: usize>(mut f: impl FnMut(usize) -> u32 + Copy) -> [u32; N] {
    let mut array = [0; N];
    let mut i = 0;
    loop {
        array[i] = f(i);
        i += 1;
        if i == N {
            break;
        }
    }
    array
}

fn main() {
    // This works fine.
    let x = create_array(const |i| 2 * i as u32);
    assert_eq!(x, [0, 2, 4, 6, 8]);

    // This closure causes an ICE.
    let y = create_array(const |i| 2 * i as u32 + 1);
    assert_eq!(y, [1, 3, 5, 7, 9]);
}
```


### 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`:

I'm using the Rust Playground today:
```
1.80.0-nightly (2024-05-31 ada5e2c7b5427a591e30)
```

### Error output

```
warning: the feature `const_closures` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(const_closures, const_mut_refs, effects)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
  = note: `#[warn(incomplete_features)]` on by default

thread 'rustc' panicked at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/compiler/rustc_middle/src/ty/util.rs:945:22:
ConstContext::Maybe must have host effect param
```

```
query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` (bin "playground"); 1 warning emitted
```

<!--
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>

```
stack backtrace:
   0:     0x7f26fb2fecc5 - std::backtrace_rs::backtrace::libunwind::trace::h0bda62405550d460
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f26fb2fecc5 - std::backtrace_rs::backtrace::trace_unsynchronized::hc2c3ea3cf2f5c7f0
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f26fb2fecc5 - std::sys_common::backtrace::_print_fmt::h8de6a59eaee45226
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f26fb2fecc5 - <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:     0x7f26fb34f6bb - core::fmt::rt::Argument::fmt::h1ed1f880d19ca3e5
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/fmt/rt.rs:165:63
   5:     0x7f26fb34f6bb - core::fmt::write::h7e2d247389cb3e97
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/fmt/mod.rs:1168:21
   6:     0x7f26fb2f399f - std::io::Write::write_fmt::ha7add8792955e794
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/io/mod.rs:1835:15
   7:     0x7f26fb2fea9e - std::sys_common::backtrace::_print::ha9e91abfc6e8d12d
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f26fb2fea9e - std::sys_common::backtrace::print::ha4520664df90140c
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f26fb3014d9 - std::panicking::default_hook::{{closure}}::h04aa22b6205d98a5
  10:     0x7f26fb30127a - std::panicking::default_hook::hf52ae4d8be29501c
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:298:9
  11:     0x7f26fe4a79af - std[a75323165fe08653]::panicking::update_hook::<alloc[2577b08d1a5511d8]::boxed::Box<rustc_driver_impl[9be41471faca984]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f26fb301c0b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3a2a9442c441a378
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2077:9
  13:     0x7f26fb301c0b - std::panicking::rust_panic_with_hook::he3c87e486ff05d6b
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:799:13
  14:     0x7f26fb301984 - std::panicking::begin_panic_handler::{{closure}}::h01ce2bfd91e16fe0
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:664:13
  15:     0x7f26fb2ff189 - std::sys_common::backtrace::__rust_end_short_backtrace::ha36f641af1493052
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f26fb3016b7 - rust_begin_unwind
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:652:5
  17:     0x7f26fb34bc53 - core::panicking::panic_fmt::h8cbe41bd36f1ccd3
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:72:14
  18:     0x7f26fb34b9fb - core::panicking::panic_display::ha747c5534e5ad54b
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:262:5
  19:     0x7f26fb34b9fb - core::option::expect_failed::hbb084febe087c246
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/option.rs:1997:5
  20:     0x7f270033c110 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::write_method_call_and_enforce_effects
  21:     0x7f26ff9bc9b4 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_overloaded_binop
  22:     0x7f270035111b - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7f26fff47f4c - rustc_hir_typeck[6b466a1699c07763]::check::check_fn
  24:     0x7f270013dabd - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_closure
  25:     0x7f27003538ee - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7f26fcc57fdd - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::confirm_builtin_call
  27:     0x7f270034f762 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7f2700349251 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_decl
  29:     0x7f270034bf47 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_block_with_expected
  30:     0x7f2700350122 - <rustc_hir_typeck[6b466a1699c07763]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7f26fff47f4c - rustc_hir_typeck[6b466a1699c07763]::check::check_fn
  32:     0x7f26fff3d66c - rustc_hir_typeck[6b466a1699c07763]::typeck
  33:     0x7f26fff3d0d1 - 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]>>
  34:     0x7f26ffffa8ae - 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>
  35:     0x7f26ffff93d5 - rustc_query_impl[9b16a2dee6878131]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f26ffff900b - <rustc_middle[353648fe55f979cd]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[2361776b1da3ecb6]::check_crate::{closure#4}>::{closure#0}
  37:     0x7f26ffff7ac7 - rustc_hir_analysis[2361776b1da3ecb6]::check_crate
  38:     0x7f270001087e - rustc_interface[cb0c5c0af19cf814]::passes::analysis
  39:     0x7f27000103db - 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]>>
  40:     0x7f27007604a5 - 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>
  41:     0x7f270076020f - rustc_query_impl[9b16a2dee6878131]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7f27005eb19c - rustc_interface[cb0c5c0af19cf814]::interface::run_compiler::<core[bd782e33ccb6b408]::result::Result<(), rustc_span[5e338462bab9c833]::ErrorGuaranteed>, rustc_driver_impl[9be41471faca984]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7f27005b50c9 - 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>>
  44:     0x7f27005b4e80 - <<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}
  45:     0x7f26fb30bbfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h149a8f3bd2b6d616
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  46:     0x7f26fb30bbfb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc8ac52b5c9166594
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9
  47:     0x7f26fb30bbfb - std::sys::pal::unix::thread::Thread::new::thread_start::h4464ec80ffa1747a
                               at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys/pal/unix/thread.rs:108:17
  48:     0x7f26fb219609 - start_thread
  49:     0x7f26fb13c353 - clone
  50:                0x0 - <unknown>
```

</p>
</details>