Repository: rust
Issue: ICE: kcfi: encode_const: unexpected kind `UnevaluatedConst { .. }`
Labels: A-debuginfo,I-ICE,T-compiler,A-sanitizers,C-bug,F-generic_const_exprs,F-generic_arg_infer

<!--
[31mICE[0m: Rustc ./poly-const-unevaluated-ice-106423.rs '-Zsanitizer=kcfi -Cpanic=abort --edition=2018 -ooutputfile -Zdump-mir-dir=dir' 'error: internal compiler error: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:158:13: encode_const: unexpected kind `UnevaluatedConst { def: DefId(0:38 ~ poly_const_unevaluated_ice_106423[90a0]::zpk2tf_st::{constant#1}), args: [(Mul: (4_usize: usize), (2_usize: usize))] }`', 'error: internal compiler error: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:158:13: encode_const: unexpected kind `UnevaluatedConst { def: DefId(0:38 ~ poly_const_unevaluated_ice_106423[90a0]::zpk2tf_st::{constant#1}), args: [(Mul: (4_usize: usize), (2_usize: usize))] }`'
File: /tmp/im/poly-const-unevaluated-ice-106423.rs
-->

auto-reduced (treereduce-rust):
````rust
#![feature(generic_const_exprs, generic_arg_infer)]

use core::mem::MaybeUninit;

pub struct Arr<T, const N: usize> {
    v: [MaybeUninit<T>; N],
}

impl<T, const N: usize> Arr<T, N> {
    const ELEM: MaybeUninit<T> = MaybeUninit::uninit();
    const INIT: [MaybeUninit<T>; N] = [Self::ELEM; N];

    fn new() -> Self {
        Arr { v: Self::INIT }
    }
}

pub struct BaFormatFilter<const N: usize> {}

pub enum DigitalFilter<const N: usize>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    Ba(BaFormatFilter<{ N * 2 + 1 }>),
}

pub fn iirfilter_st_copy<const N: usize, const M: usize>(_: [f32; M]) -> DigitalFilter<N>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    let zpk = zpk2tf_st(&Arr::<f32, { N * 2 }>::new(), &Arr::<f32, { N * 2 }>::new());
    DigitalFilter::Ba(zpk)
}

pub fn zpk2tf_st<const N: usize>(_z: &Arr<f32, N>, _p: &Arr<f32, N>) -> BaFormatFilter<{ N + 1 }> {
    BaFormatFilter {}
}

fn main() {
    iirfilter_st_copy::<4, 2>([10., 50.]);
}


````

<details><summary><strong>original code</strong></summary>
<p>

original:
````rust
// issue: rust-lang/rust#106423
// ICE collection encountered polymorphic constant: UnevaluatedConst {..}
//@ edition:2021
//@ check-pass

#![feature(generic_const_exprs, generic_arg_infer)]
#![allow(incomplete_features)]
#![allow(unused)]

use core::mem::MaybeUninit;

pub struct Arr<T, const N: usize> {
    v: [MaybeUninit<T>; N],
}

impl<T, const N: usize> Arr<T, N> {
    const ELEM: MaybeUninit<T> = MaybeUninit::uninit();
    const INIT: [MaybeUninit<T>; N] = [Self::ELEM; N]; // important for optimization of `new`

    fn new() -> Self {
        Arr { v: Self::INIT }
    }
}

pub struct BaFormatFilter<const N: usize> {}

pub enum DigitalFilter<const N: usize>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    Ba(BaFormatFilter<{ N * 2 + 1 }>),
}

pub fn iirfilter_st_copy<const N: usize, const M: usize>(_: [f32; M]) -> DigitalFilter<N>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    let zpk = zpk2tf_st(&Arr::<f32, { N * 2 }>::new(), &Arr::<f32, { N * 2 }>::new());
    DigitalFilter::Ba(zpk)
}

pub fn zpk2tf_st<const N: usize>(
    _z: &Arr<f32, N>,
    _p: &Arr<f32, N>,
) -> BaFormatFilter<{ N + 1 }>
where
    [(); N + 1]: Sized,
{
    BaFormatFilter {}
}


fn main() {
    iirfilter_st_copy::<4, 2>([10., 50.,]);
}

````
</p>
</details>

Version information
````
rustc 1.81.0-nightly (7bb0ef490 2024-06-09)
binary: rustc
commit-hash: 7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a
commit-date: 2024-06-09
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

````

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc -Zsanitizer=kcfi -Cpanic=abort --edition=2018`

<!--
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>Program output</strong></summary>
<p>

```
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.gDgKBFsvnsak/rustc_testrunner_tmpdir_reporting.MRWKJmBGzCHY/mvce.rs:1:12
  |
1 | #![feature(generic_const_exprs, generic_arg_infer)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: field `v` is never read
 --> /tmp/icemaker_global_tempdir.gDgKBFsvnsak/rustc_testrunner_tmpdir_reporting.MRWKJmBGzCHY/mvce.rs:6:5
  |
5 | pub struct Arr<T, const N: usize> {
  |            --- field in this struct
6 |     v: [MaybeUninit<T>; N],
  |     ^
  |
  = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:158:13: encode_const: unexpected kind `UnevaluatedConst { def: DefId(0:37 ~ mvce[64a8]::zpk2tf_st::{constant#0}), args: [(Mul: (4_usize: usize), (2_usize: usize))] }`

thread 'rustc' panicked at compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:158:13:
Box<dyn Any>
stack backtrace:
   0:     0x78e6f81a5f15 - std::backtrace_rs::backtrace::libunwind::trace::heabb972c4bf30194
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x78e6f81a5f15 - std::backtrace_rs::backtrace::trace_unsynchronized::h4ba1442eaca1bb10
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x78e6f81a5f15 - std::sys_common::backtrace::_print_fmt::h4d12f471d77196b5
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x78e6f81a5f15 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdafa2e62094a2544
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x78e6f81f6c5b - core::fmt::rt::Argument::fmt::h3bdee6e081605bf4
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/core/src/fmt/rt.rs:165:63
   5:     0x78e6f81f6c5b - core::fmt::write::h3a87f6a731d66d11
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/core/src/fmt/mod.rs:1168:21
   6:     0x78e6f819abef - std::io::Write::write_fmt::h639f79d09cf27b23
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/io/mod.rs:1835:15
   7:     0x78e6f81a5cee - std::sys_common::backtrace::_print::h8440f387a509d641
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x78e6f81a5cee - std::sys_common::backtrace::print::haf9fb54157ed196a
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x78e6f81a8729 - std::panicking::default_hook::{{closure}}::ha531e390acdea902
  10:     0x78e6f81a84ca - std::panicking::default_hook::h47e5185002a51d52
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/panicking.rs:298:9
  11:     0x78e6f49d673f - std[3073bd340ab08955]::panicking::update_hook::<alloc[4ecaa96cdf69b562]::boxed::Box<rustc_driver_impl[4e6b8414dae3c1cf]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x78e6f81a8e5b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h32e30fee99996214
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/alloc/src/boxed.rs:2077:9
  13:     0x78e6f81a8e5b - std::panicking::rust_panic_with_hook::h73cccfbddee60476
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/panicking.rs:799:13
  14:     0x78e6f4a06f84 - std[3073bd340ab08955]::panicking::begin_panic::<rustc_errors[d1d8d20dbd2ccc21]::ExplicitBug>::{closure#0}
  15:     0x78e6f4a03a66 - std[3073bd340ab08955]::sys_common::backtrace::__rust_end_short_backtrace::<std[3073bd340ab08955]::panicking::begin_panic<rustc_errors[d1d8d20dbd2ccc21]::ExplicitBug>::{closure#0}, !>
  16:     0x78e6f49fee46 - std[3073bd340ab08955]::panicking::begin_panic::<rustc_errors[d1d8d20dbd2ccc21]::ExplicitBug>
  17:     0x78e6f4a105a1 - <rustc_errors[d1d8d20dbd2ccc21]::diagnostic::BugAbort as rustc_errors[d1d8d20dbd2ccc21]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x78e6f4ef9b3c - rustc_middle[a5a7a5d95a79c83]::util::bug::opt_span_bug_fmt::<rustc_span[fa5d72863ffc22f0]::span_encoding::Span>::{closure#0}
  19:     0x78e6f4ee2c6a - rustc_middle[a5a7a5d95a79c83]::ty::context::tls::with_opt::<rustc_middle[a5a7a5d95a79c83]::util::bug::opt_span_bug_fmt<rustc_span[fa5d72863ffc22f0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x78e6f4ee2b0b - rustc_middle[a5a7a5d95a79c83]::ty::context::tls::with_context_opt::<rustc_middle[a5a7a5d95a79c83]::ty::context::tls::with_opt<rustc_middle[a5a7a5d95a79c83]::util::bug::opt_span_bug_fmt<rustc_span[fa5d72863ffc22f0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x78e6f33fcc50 - rustc_middle[a5a7a5d95a79c83]::util::bug::bug_fmt
  22:     0x78e6f538582a - rustc_sanitizers[9a055dd07b406515]::cfi::typeid::itanium_cxx_abi::encode::encode_const
  23:     0x78e6f5385228 - rustc_sanitizers[9a055dd07b406515]::cfi::typeid::itanium_cxx_abi::encode::encode_args
  24:     0x78e6f5387f5c - rustc_sanitizers[9a055dd07b406515]::cfi::typeid::itanium_cxx_abi::encode::encode_ty
  25:     0x78e6f538dcf7 - rustc_sanitizers[9a055dd07b406515]::cfi::typeid::itanium_cxx_abi::typeid_for_fnabi
  26:     0x78e6f538e546 - rustc_sanitizers[9a055dd07b406515]::cfi::typeid::itanium_cxx_abi::typeid_for_instance
  27:     0x78e6f5386b2c - rustc_sanitizers[9a055dd07b406515]::kcfi::typeid::typeid_for_instance
  28:     0x78e6f330dd15 - <rustc_codegen_llvm[90f7dfbc3b8799f7]::context::CodegenCx as rustc_codegen_ssa[60af8791d0b2af86]::traits::declare::PreDefineMethods>::predefine_fn
  29:     0x78e6f6b2f861 - rustc_codegen_llvm[90f7dfbc3b8799f7]::base::compile_codegen_unit::module_codegen
  30:     0x78e6f6b2bbbc - <rustc_codegen_llvm[90f7dfbc3b8799f7]::LlvmCodegenBackend as rustc_codegen_ssa[60af8791d0b2af86]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  31:     0x78e6f6df87c1 - rustc_codegen_ssa[60af8791d0b2af86]::base::codegen_crate::<rustc_codegen_llvm[90f7dfbc3b8799f7]::LlvmCodegenBackend>
  32:     0x78e6f6c437ce - <rustc_codegen_llvm[90f7dfbc3b8799f7]::LlvmCodegenBackend as rustc_codegen_ssa[60af8791d0b2af86]::traits::backend::CodegenBackend>::codegen_crate
  33:     0x78e6f6c4315f - rustc_interface[b48fbfbbfca56691]::passes::start_codegen
  34:     0x78e6f6c427da - <rustc_interface[b48fbfbbfca56691]::queries::Queries>::codegen_and_build_linker
  35:     0x78e6f6a7cd32 - rustc_interface[b48fbfbbfca56691]::interface::run_compiler::<core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>, rustc_driver_impl[4e6b8414dae3c1cf]::run_compiler::{closure#0}>::{closure#1}
  36:     0x78e6f6a43a89 - std[3073bd340ab08955]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b48fbfbbfca56691]::util::run_in_thread_with_globals<rustc_interface[b48fbfbbfca56691]::util::run_in_thread_pool_with_globals<rustc_interface[b48fbfbbfca56691]::interface::run_compiler<core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>, rustc_driver_impl[4e6b8414dae3c1cf]::run_compiler::{closure#0}>::{closure#1}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>::{closure#0}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>
  37:     0x78e6f6a43836 - <<std[3073bd340ab08955]::thread::Builder>::spawn_unchecked_<rustc_interface[b48fbfbbfca56691]::util::run_in_thread_with_globals<rustc_interface[b48fbfbbfca56691]::util::run_in_thread_pool_with_globals<rustc_interface[b48fbfbbfca56691]::interface::run_compiler<core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>, rustc_driver_impl[4e6b8414dae3c1cf]::run_compiler::{closure#0}>::{closure#1}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>::{closure#0}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[be135d473bf2241c]::result::Result<(), rustc_span[fa5d72863ffc22f0]::ErrorGuaranteed>>::{closure#2} as core[be135d473bf2241c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x78e6f81b2e4b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h19ba87d856808e00
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/alloc/src/boxed.rs:2063:9
  39:     0x78e6f81b2e4b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc37c884ba84dd5ac
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/alloc/src/boxed.rs:2063:9
  40:     0x78e6f81b2e4b - std::sys::pal::unix::thread::Thread::new::thread_start::h713e9186dc9dedf7
                               at /rustc/7bb0ef4902e43f338aa73c3ff728bea3cb9ecf6a/library/std/src/sys/pal/unix/thread.rs:108:17
  41:     0x78e6f16a6ded - <unknown>
  42:     0x78e6f172a0dc - <unknown>
  43:                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: rustc 1.81.0-nightly (7bb0ef490 2024-06-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z sanitizer=kcfi -C panic=abort -Z dump-mir-dir=dir

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


```

</p>
</details>

<!--
query stack:
error: internal compiler error: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:158:13: encode_const: unexpected kind `UnevaluatedConst { def: DefId(0:37 ~ mvce[64a8]::zpk2tf_st::{constant#0}), args: [(Mul: (4_usize: usize), (2_usize: usize))] }`

-->
@rustbot label +F-generic_const_exprs +F-generic_arg_infer