Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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 #125866

Open
gendx opened this issue Jun 1, 2024 · 2 comments
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_closures `#![feature(const_closures)]` F-const_mut_refs `#![feature(const_mut_refs)]` F-const_trait_impl `#![feature(const_trait_impl)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gendx
Copy link

gendx commented Jun 1, 2024

I know that const_closures feature is incomplete (#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

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

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
Backtrace

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>

@gendx gendx added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 1, 2024
@jieyouxu jieyouxu added F-const_mut_refs `#![feature(const_mut_refs)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue requires-incomplete-features This issue requires the use of incomplete features. F-effects `#![feature(effects)]` F-const_closures `#![feature(const_closures)]` A-closures Area: Closures (`|…| { … }`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-closures Area: Closures (`|…| { … }`) labels Jun 4, 2024
@GrigorenkoPV
Copy link
Contributor

Looked for the PR introducing the ICE

searched nightlies: from nightly-2022-02-19 to nightly-2024-05-31
regressed nightly: nightly-2024-02-09
searched commit range: 8ace7ea...98aa362
regressed commit: 6894f43 (#120381)

Funnily enough, the ICE disappeared a week ago

searched nightlies: from nightly-2024-05-31 to nightly-2024-06-30
regressed nightly: nightly-2024-06-23
searched commit range: c1b336c...3cb521a
Regression in rust-lang-ci@7ba756a
The PR introducing the regression in this rollup is #126552

@fmease fmease added F-const_trait_impl `#![feature(const_trait_impl)]` and removed F-effects `#![feature(effects)]` labels Nov 15, 2024
@fmease
Copy link
Member

fmease commented Nov 15, 2024

Fixed. Needs test.

@fmease fmease added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_closures `#![feature(const_closures)]` F-const_mut_refs `#![feature(const_mut_refs)]` F-const_trait_impl `#![feature(const_trait_impl)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants