Repository: rust
Issue: generic_const_exprs: internal compiler error
Labels: I-ICE,T-compiler,C-bug,F-generic_const_exprs,S-has-mcve,S-bug-has-test,requires-incomplete-features,A-monomorphization

<!--
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

https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=658b83919fb776f6e07570c3bec26cb7

Implementation of primitive recursive functions using generic_const_exprs.

Removing lines 102 to 104 makes the code compile successfully.

### Error 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>

```
thread 'rustc' panicked at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/compiler/rustc_middle/src/util/bug.rs:34:50:
Box<dyn Any>
stack backtrace:
   0:     0x7f6197d7daf6 - std::backtrace_rs::backtrace::libunwind::trace::hd6c95564158d2ad1
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f6197d7daf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h1e73453937ee07b8
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6197d7daf6 - std::sys_common::backtrace::_print_fmt::ha4e1fd706ce229f6
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f6197d7daf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h39795cad8f90e005
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f6197dcea7c - core::fmt::rt::Argument::fmt::h3960dd13bbb5335d
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/core/src/fmt/rt.rs:142:9
   5:     0x7f6197dcea7c - core::fmt::write::h2b281d9025b7c47b
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f6197d7242f - std::io::Write::write_fmt::h18044c54acec8470
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/io/mod.rs:1846:15
   7:     0x7f6197d7d8a4 - std::sys_common::backtrace::_print::h7a96956925b1db50
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f6197d7d8a4 - std::sys_common::backtrace::print::h154e885ac7142937
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f6197d805eb - std::panicking::default_hook::{{closure}}::hcfb38eaaff34d735
  10:     0x7f6197d80339 - std::panicking::default_hook::h9d19a71b480c31c0
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/panicking.rs:292:9
  11:     0x7f619ac64eec - std[779ce620e254aa3a]::panicking::update_hook::<alloc[d8bca25f8c4422e2]::boxed::Box<rustc_driver_impl[8762b83a1cb30330]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f6197d80d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc19b64bae054e43a
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/alloc/src/boxed.rs:2030:9
  13:     0x7f6197d80d50 - std::panicking::rust_panic_with_hook::hb2c8227f8d32aff4
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/panicking.rs:786:13
  14:     0x7f619ac91594 - std[779ce620e254aa3a]::panicking::begin_panic::<rustc_errors[6d3bdfbf1892eeff]::ExplicitBug>::{closure#0}
  15:     0x7f619ac8e1e6 - std[779ce620e254aa3a]::sys_common::backtrace::__rust_end_short_backtrace::<std[779ce620e254aa3a]::panicking::begin_panic<rustc_errors[6d3bdfbf1892eeff]::ExplicitBug>::{closure#0}, !>
  16:     0x7f619ac899a6 - std[779ce620e254aa3a]::panicking::begin_panic::<rustc_errors[6d3bdfbf1892eeff]::ExplicitBug>
  17:     0x7f61995fd9a1 - <rustc_errors[6d3bdfbf1892eeff]::diagnostic::BugAbort as rustc_errors[6d3bdfbf1892eeff]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f619b2cec8d - rustc_middle[34d56ef0224e11c8]::util::bug::opt_span_bug_fmt::<rustc_span[c4517cadf0848d66]::span_encoding::Span>::{closure#0}
  19:     0x7f619b2cedea - rustc_middle[34d56ef0224e11c8]::ty::context::tls::with_opt::<rustc_middle[34d56ef0224e11c8]::util::bug::opt_span_bug_fmt<rustc_span[c4517cadf0848d66]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7f619b2ca8d8 - rustc_middle[34d56ef0224e11c8]::ty::context::tls::with_context_opt::<rustc_middle[34d56ef0224e11c8]::ty::context::tls::with_opt<rustc_middle[34d56ef0224e11c8]::util::bug::opt_span_bug_fmt<rustc_span[c4517cadf0848d66]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7f619b2c8354 - rustc_middle[34d56ef0224e11c8]::util::bug::span_bug_fmt::<rustc_span[c4517cadf0848d66]::span_encoding::Span>
  22:     0x7f619c230acd - <rustc_monomorphize[5b7faaf956a6659]::collector::MirUsedCollector as rustc_middle[34d56ef0224e11c8]::mir::visit::Visitor>::visit_operand
  23:     0x7f6199d7b0a9 - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec::{closure#0}
  24:     0x7f619c92db62 - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  25:     0x7f619c92e42d - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  26:     0x7f619c92e42d - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  27:     0x7f619c92e42d - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  28:     0x7f619c92e42d - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  29:     0x7f619c92e42d - rustc_monomorphize[5b7faaf956a6659]::collector::collect_items_rec
  30:     0x7f619c928ef6 - rustc_monomorphize[5b7faaf956a6659]::partitioning::collect_and_partition_mono_items
  31:     0x7f619c928570 - rustc_query_impl[37c0345f91b53f73]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[37c0345f91b53f73]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[34d56ef0224e11c8]::query::erase::Erased<[u8; 24usize]>>
  32:     0x7f619c928555 - <rustc_query_impl[37c0345f91b53f73]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[bdf7c173800a34bb]::ops::function::FnOnce<(rustc_middle[34d56ef0224e11c8]::ty::context::TyCtxt, ())>>::call_once
  33:     0x7f619cf964e2 - rustc_query_system[af6e3207d51907f7]::query::plumbing::try_execute_query::<rustc_query_impl[37c0345f91b53f73]::DynamicConfig<rustc_query_system[af6e3207d51907f7]::query::caches::SingleCache<rustc_middle[34d56ef0224e11c8]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[37c0345f91b53f73]::plumbing::QueryCtxt, false>
  34:     0x7f619cf961d9 - rustc_query_impl[37c0345f91b53f73]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f619cf39196 - rustc_codegen_ssa[8b5438e7ea0b7061]::base::codegen_crate::<rustc_codegen_llvm[31ebdf54597cd9a0]::LlvmCodegenBackend>
  36:     0x7f619cf38e4d - <rustc_codegen_llvm[31ebdf54597cd9a0]::LlvmCodegenBackend as rustc_codegen_ssa[8b5438e7ea0b7061]::traits::backend::CodegenBackend>::codegen_crate
  37:     0x7f619cfcc505 - rustc_interface[55bee3044f76fef8]::passes::start_codegen
  38:     0x7f619cfcbcd5 - <rustc_interface[55bee3044f76fef8]::queries::Queries>::codegen_and_build_linker
  39:     0x7f619ccfccea - rustc_interface[55bee3044f76fef8]::interface::run_compiler::<core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>, rustc_driver_impl[8762b83a1cb30330]::run_compiler::{closure#0}>::{closure#0}
  40:     0x7f619cfada85 - std[779ce620e254aa3a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[55bee3044f76fef8]::util::run_in_thread_with_globals<rustc_interface[55bee3044f76fef8]::util::run_in_thread_pool_with_globals<rustc_interface[55bee3044f76fef8]::interface::run_compiler<core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>, rustc_driver_impl[8762b83a1cb30330]::run_compiler::{closure#0}>::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>
  41:     0x7f619cfad8b2 - <<std[779ce620e254aa3a]::thread::Builder>::spawn_unchecked_<rustc_interface[55bee3044f76fef8]::util::run_in_thread_with_globals<rustc_interface[55bee3044f76fef8]::util::run_in_thread_pool_with_globals<rustc_interface[55bee3044f76fef8]::interface::run_compiler<core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>, rustc_driver_impl[8762b83a1cb30330]::run_compiler::{closure#0}>::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bdf7c173800a34bb]::result::Result<(), rustc_span[c4517cadf0848d66]::ErrorGuaranteed>>::{closure#1} as core[bdf7c173800a34bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f6197d8a725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h87bc13705e796148
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/alloc/src/boxed.rs:2016:9
  43:     0x7f6197d8a725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha41c2c60d398a7ae
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/alloc/src/boxed.rs:2016:9
  44:     0x7f6197d8a725 - std::sys::pal::unix::thread::Thread::new::thread_start::h32fa493a81385954
                               at /rustc/397937d812852f9bbeb671005cb399dbcb357cde/library/std/src/sys/pal/unix/thread.rs:108:17
  45:     0x7f6197c99609 - start_thread
  46:     0x7f6197bbc353 - clone
  47:                0x0 - <unknown>
```

</p>
</details>