Repository: rust
Issue: ICE with generic_const_exprs (and std::simd)
Labels: I-ICE,T-compiler,C-bug,F-generic_const_exprs,S-bug-has-test,requires-incomplete-features

I tried this code (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d0cf160632f8eed6e09099624d1cd545):

```rust
#![feature(portable_simd)]
#![feature(generic_const_exprs)]

use core::simd::num::SimdUint;
use core::mem;
use core::simd::*;

pub unsafe fn better_transmute<T, U>(x: T) -> U {
  assert!(mem::size_of::<T>() == mem::size_of::<U>());
  mem::transmute_copy::<mem::ManuallyDrop<T>, U>(&mem::ManuallyDrop::new(x))
}


pub fn double_up_u8<const N: usize>(x: Simd<u8, N>) -> Simd<u8, { N * 2 }>
where
  LaneCount<N>: SupportedLaneCount,
  LaneCount<{ N * 2 }>: SupportedLaneCount,
{
  unsafe { better_transmute(x.cast::<u16>() | (x.cast::<u16>() << 8)) }
}

pub fn quadruple_up_u8<const N: usize>(
  x: Simd<u8, N>,
) -> Simd<u8, { N * 2 * 2 }>
where
  LaneCount<N>: SupportedLaneCount,
  LaneCount<{ N * 2 }>: SupportedLaneCount,
  LaneCount<{ N * 2 * 2 }>: SupportedLaneCount,
{
  let x = double_up_u8(x);
  double_up_u8(x)
}

pub fn quadruple_up_u8_concrete_16(x: Simd<u8, 16>) -> Simd<u8, 64> {
  quadruple_up_u8(x)
}
```

```

error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:510:25: failed to resolve instance for <std::simd::Simd<u8, 16 * 2> as SimdUint>::cast::<u16>: Ok(
                                    None,
                                )

thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:510:25:
Box<dyn Any>
stack backtrace:
   0:     0x7faef43c4ae5 - std::backtrace_rs::backtrace::libunwind::trace::h5ef2cc16e9a7415a
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7faef43c4ae5 - std::backtrace_rs::backtrace::trace_unsynchronized::h9b5e016e9075f714
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7faef43c4ae5 - std::sys_common::backtrace::_print_fmt::h2f62c7f9ff224e93
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7faef43c4ae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbe51682735731910
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7faef441577b - core::fmt::rt::Argument::fmt::h1994ab2b310d665e
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/core/src/fmt/rt.rs:165:63
   5:     0x7faef441577b - core::fmt::write::hade58a36d63468d7
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/core/src/fmt/mod.rs:1168:21
   6:     0x7faef43b96bf - std::io::Write::write_fmt::h16145587d801a9ab
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/io/mod.rs:1835:15
   7:     0x7faef43c48be - std::sys_common::backtrace::_print::ha8082e56201dadb4
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7faef43c48be - std::sys_common::backtrace::print::he30f96b4e7f6cbfd
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7faef43c72f9 - std::panicking::default_hook::{{closure}}::hf0801f6b18a968d3
  10:     0x7faef43c709c - std::panicking::default_hook::hd2defec7eda5aeb0
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/panicking.rs:292:9
  11:     0x7faef76ec050 - std[a8a14b0e6646fad5]::panicking::update_hook::<alloc[798fb67bec780804]::boxed::Box<rustc_driver_impl[fb29927f0a07f39d]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7faef43c7bff - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hcab2bb72e8fd3275
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/alloc/src/boxed.rs:2076:9
  13:     0x7faef43c7bff - std::panicking::rust_panic_with_hook::hde93283600065c53
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/panicking.rs:801:13
  14:     0x7faef771ca11 - std[a8a14b0e6646fad5]::panicking::begin_panic::<rustc_errors[707d6179d593b007]::ExplicitBug>::{closure#0}
  15:     0x7faef77194f6 - std[a8a14b0e6646fad5]::sys_common::backtrace::__rust_end_short_backtrace::<std[a8a14b0e6646fad5]::panicking::begin_panic<rustc_errors[707d6179d593b007]::ExplicitBug>::{closure#0}, !>
  16:     0x7faef77148d6 - std[a8a14b0e6646fad5]::panicking::begin_panic::<rustc_errors[707d6179d593b007]::ExplicitBug>
  17:     0x7faef7725f61 - <rustc_errors[707d6179d593b007]::diagnostic::BugAbort as rustc_errors[707d6179d593b007]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7faef7c23c2c - rustc_middle[a6772a91e67f1048]::util::bug::opt_span_bug_fmt::<rustc_span[e3a1e1b56e6f88d8]::span_encoding::Span>::{closure#0}
  19:     0x7faef7c0ccaa - rustc_middle[a6772a91e67f1048]::ty::context::tls::with_opt::<rustc_middle[a6772a91e67f1048]::util::bug::opt_span_bug_fmt<rustc_span[e3a1e1b56e6f88d8]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7faef7c0cb4b - rustc_middle[a6772a91e67f1048]::ty::context::tls::with_context_opt::<rustc_middle[a6772a91e67f1048]::ty::context::tls::with_opt<rustc_middle[a6772a91e67f1048]::util::bug::opt_span_bug_fmt<rustc_span[e3a1e1b56e6f88d8]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7faef56095f0 - rustc_middle[a6772a91e67f1048]::util::bug::bug_fmt
  22:     0x7faef8ee99c8 - <rustc_middle[a6772a91e67f1048]::ty::instance::Instance>::expect_resolve
  23:     0x7faef98a2da6 - rustc_monomorphize[b25ec8e9515cda93]::collector::collect_items_rec::{closure#0}
  24:     0x7faef8ad93bf - rustc_monomorphize[b25ec8e9515cda93]::collector::collect_items_rec
  25:     0x7faef8ad9b36 - rustc_monomorphize[b25ec8e9515cda93]::collector::collect_items_rec
  26:     0x7faef8ad9b36 - rustc_monomorphize[b25ec8e9515cda93]::collector::collect_items_rec
  27:     0x7faef8ec42f9 - rustc_monomorphize[b25ec8e9515cda93]::partitioning::collect_and_partition_mono_items
  28:     0x7faef9af6ee4 - rustc_query_impl[1babe9a7768fd14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1babe9a7768fd14]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a6772a91e67f1048]::query::erase::Erased<[u8; 24usize]>>
  29:     0x7faef9af6ec9 - <rustc_query_impl[1babe9a7768fd14]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[df0bc3c4e892894f]::ops::function::FnOnce<(rustc_middle[a6772a91e67f1048]::ty::context::TyCtxt, ())>>::call_once
  30:     0x7faef9af6a88 - rustc_query_system[f0d53dba093567b9]::query::plumbing::try_execute_query::<rustc_query_impl[1babe9a7768fd14]::DynamicConfig<rustc_query_system[f0d53dba093567b9]::query::caches::SingleCache<rustc_middle[a6772a91e67f1048]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[1babe9a7768fd14]::plumbing::QueryCtxt, false>
  31:     0x7faef9af67a1 - rustc_query_impl[1babe9a7768fd14]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7faef9544c09 - rustc_codegen_ssa[1546aa7d1fe842a3]::back::symbol_export::exported_symbols_provider_local
  33:     0x7faef8bcf7a5 - rustc_query_impl[1babe9a7768fd14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1babe9a7768fd14]::query_impl::exported_symbols::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a6772a91e67f1048]::query::erase::Erased<[u8; 16usize]>>
  34:     0x7faef8bcf76d - <rustc_query_impl[1babe9a7768fd14]::query_impl::exported_symbols::dynamic_query::{closure#2} as core[df0bc3c4e892894f]::ops::function::FnOnce<(rustc_middle[a6772a91e67f1048]::ty::context::TyCtxt, rustc_span[e3a1e1b56e6f88d8]::def_id::CrateNum)>>::call_once
  35:     0x7faef97aafa6 - rustc_query_system[f0d53dba093567b9]::query::plumbing::try_execute_query::<rustc_query_impl[1babe9a7768fd14]::DynamicConfig<rustc_query_system[f0d53dba093567b9]::query::caches::VecCache<rustc_span[e3a1e1b56e6f88d8]::def_id::CrateNum, rustc_middle[a6772a91e67f1048]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[1babe9a7768fd14]::plumbing::QueryCtxt, false>
  36:     0x7faef97aabab - rustc_query_impl[1babe9a7768fd14]::query_impl::exported_symbols::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7faef97aa8ec - rustc_middle[a6772a91e67f1048]::query::plumbing::query_get_at::<rustc_query_system[f0d53dba093567b9]::query::caches::VecCache<rustc_span[e3a1e1b56e6f88d8]::def_id::CrateNum, rustc_middle[a6772a91e67f1048]::query::erase::Erased<[u8; 16usize]>>>
  38:     0x7faef922eb4a - <rustc_metadata[b6ccef206159871f]::rmeta::encoder::EncodeContext>::encode_crate_root
  39:     0x7faef99746d8 - rustc_metadata[b6ccef206159871f]::rmeta::encoder::encode_metadata
  40:     0x7faef996f8b2 - rustc_metadata[b6ccef206159871f]::fs::encode_and_write_metadata
  41:     0x7faef996e340 - rustc_interface[eafdc2161e58eccb]::passes::start_codegen
  42:     0x7faef996da9a - <rustc_interface[eafdc2161e58eccb]::queries::Queries>::codegen_and_build_linker
  43:     0x7faef9724732 - rustc_interface[eafdc2161e58eccb]::interface::run_compiler::<core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>, rustc_driver_impl[fb29927f0a07f39d]::run_compiler::{closure#0}>::{closure#1}
  44:     0x7faef9746827 - std[a8a14b0e6646fad5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[eafdc2161e58eccb]::util::run_in_thread_with_globals<rustc_interface[eafdc2161e58eccb]::util::run_in_thread_pool_with_globals<rustc_interface[eafdc2161e58eccb]::interface::run_compiler<core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>, rustc_driver_impl[fb29927f0a07f39d]::run_compiler::{closure#0}>::{closure#1}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>::{closure#0}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>
  45:     0x7faef97465ea - <<std[a8a14b0e6646fad5]::thread::Builder>::spawn_unchecked_<rustc_interface[eafdc2161e58eccb]::util::run_in_thread_with_globals<rustc_interface[eafdc2161e58eccb]::util::run_in_thread_pool_with_globals<rustc_interface[eafdc2161e58eccb]::interface::run_compiler<core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>, rustc_driver_impl[fb29927f0a07f39d]::run_compiler::{closure#0}>::{closure#1}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>::{closure#0}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[df0bc3c4e892894f]::result::Result<(), rustc_span[e3a1e1b56e6f88d8]::ErrorGuaranteed>>::{closure#2} as core[df0bc3c4e892894f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x7faef43d1a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9777b4cca5324078
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/alloc/src/boxed.rs:2062:9
  47:     0x7faef43d1a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8c468acad9ff28af
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/alloc/src/boxed.rs:2062:9
  48:     0x7faef43d1a7b - std::sys::pal::unix::thread::Thread::new::thread_start::hc013dcac52817fe6
                               at /rustc/8337ba9189de188e2ed417018af2bf17a57d51ac/library/std/src/sys/pal/unix/thread.rs:108:17
  49:     0x7faef42df609 - start_thread
  50:     0x7faef4202353 - clone
  51:                0x0 - <unknown>
```

</p>
</details>