Repository: rust
Issue: Rustc crashes at compiler/rustc_middle/src/ty/instance.rs, caused by assertion `left matches right` failed
Labels: I-ICE,T-compiler,C-bug,needs-triage

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

Note that if we remove the first line `#![feature(min_generic_const_args)]`, the panic disappeares.

```Rust
#![feature(min_generic_const_args)]
struct U;
struct S<const N: U>()
where
    S<{ U }>:;
fn main() {}
```


### 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`:
```
rustc 1.86.0-nightly (f85c6de55 2025-01-26)
binary: rustc
commit-hash: f85c6de55206dbee5ffedfd821df1503a7b92346
commit-date: 2025-01-26
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
```

### Error output

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


thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:531:9:
assertion `left matches right` failed: `Instance::try_resolve` should only be used to resolve instances of functions, statics, and consts; to resolve associated types, use `try_normalize_erasing_regions`.
  left: Ctor(Struct, Const)
 right: DefKind::Fn | DefKind::AssocFn | DefKind::Const | DefKind::AssocConst |
DefKind::AnonConst | DefKind::InlineConst | DefKind::Static { .. } |
DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure |
DefKind::SyntheticCoroutineBody
stack backtrace:
   0:     0x7fa280d3c210 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hec9bc6463e252640
   1:     0x7fa2815acee6 - core::fmt::write::h962cad0079919c7e
   2:     0x7fa2824aac51 - std::io::Write::write_fmt::h081e59591f35f868
   3:     0x7fa280d3c072 - std::sys::backtrace::BacktraceLock::print::he0deffbd85e9a2c5
   4:     0x7fa280d3e4f2 - std::panicking::default_hook::{{closure}}::h99776b3a5456e866
   5:     0x7fa280d3e37a - std::panicking::default_hook::hcad38b9ed4b5517d
   6:     0x7fa27fef3279 - std[cc940dec3ff43b12]::panicking::update_hook::<alloc[5f7a888829935c2b]::boxed::Box<rustc_driver_impl[af2bdb3744899392]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7fa280d3f073 - std::panicking::rust_panic_with_hook::hbfeeff1ab3569ba1
   8:     0x7fa280d3ed6a - std::panicking::begin_panic_handler::{{closure}}::h32c93c4f5d28ab99
   9:     0x7fa280d3c6e9 - std::sys::backtrace::__rust_end_short_backtrace::h1884c239824d44f7
  10:     0x7fa280d3ea2d - rust_begin_unwind
  11:     0x7fa27d9d1bd0 - core::panicking::panic_fmt::he58927c3c03479ba
  12:     0x7fa27f915586 - core::panicking::assert_failed_inner::hfb3c935e17727acd
  13:     0x7fa28049b942 - core[c1de5c9ad145c0db]::panicking::assert_matches_failed::<rustc_hir[2d8a80fbfdaaf69c]::def::DefKind>
  14:     0x7fa2817a1f93 - <rustc_middle[ea35cf57050946b4]::ty::instance::Instance>::try_resolve
  15:     0x7fa282284cf1 - <rustc_middle[ea35cf57050946b4]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  16:     0x7fa282284a77 - rustc_trait_selection[9f2c8c71993b8584]::traits::try_evaluate_const
  17:     0x7fa282284513 - <rustc_trait_selection[9f2c8c71993b8584]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[de1b3d84f3386c16]::fold::TypeFolder<rustc_middle[ea35cf57050946b4]::ty::context::TyCtxt>>::fold_const
  18:     0x7fa281dd0361 - <rustc_trait_selection[9f2c8c71993b8584]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[de1b3d84f3386c16]::fold::FallibleTypeFolder<rustc_middle[ea35cf57050946b4]::ty::context::TyCtxt>>::try_fold_binder::<rustc_type_ir[de1b3d84f3386c16]::predicate_kind::PredicateKind<rustc_middle[ea35cf57050946b4]::ty::context::TyCtxt>>
  19:     0x7fa2819bcdb8 - rustc_trait_selection[9f2c8c71993b8584]::traits::normalize::normalize_with_depth_to::<rustc_middle[ea35cf57050946b4]::ty::predicate::Predicate>
  20:     0x7fa2819bbb57 - rustc_trait_selection[9f2c8c71993b8584]::traits::wf::clause_obligations
  21:     0x7fa2819c0388 - rustc_hir_analysis[ce12ae6d63b57b8a]::check::wfcheck::check_where_clauses
  22:     0x7fa281bd5e00 - rustc_hir_analysis[ce12ae6d63b57b8a]::check::wfcheck::check_type_defn
  23:     0x7fa281bcf821 - rustc_hir_analysis[ce12ae6d63b57b8a]::check::wfcheck::check_well_formed
  24:     0x7fa281bce247 - rustc_query_impl[52b9445d4dcf70be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[52b9445d4dcf70be]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 1usize]>>
  25:     0x7fa281bcdce9 - rustc_query_system[b5c6449b7ccd2566]::query::plumbing::try_execute_query::<rustc_query_impl[52b9445d4dcf70be]::DynamicConfig<rustc_data_structures[aef26e4d10f0fc6d]::vec_cache::VecCache<rustc_span[d5a27b28009c9e0]::def_id::LocalDefId, rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[b5c6449b7ccd2566]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[52b9445d4dcf70be]::plumbing::QueryCtxt, false>
  26:     0x7fa281bcd746 - rustc_query_impl[52b9445d4dcf70be]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7fa281bcb36c - rustc_hir_analysis[ce12ae6d63b57b8a]::check::wfcheck::check_mod_type_wf
  28:     0x7fa281bcb18b - rustc_query_impl[52b9445d4dcf70be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[52b9445d4dcf70be]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 1usize]>>
  29:     0x7fa2824b2ac8 - rustc_query_system[b5c6449b7ccd2566]::query::plumbing::try_execute_query::<rustc_query_impl[52b9445d4dcf70be]::DynamicConfig<rustc_query_system[b5c6449b7ccd2566]::query::caches::DefaultCache<rustc_span[d5a27b28009c9e0]::def_id::LocalModDefId, rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[52b9445d4dcf70be]::plumbing::QueryCtxt, false>
  30:     0x7fa2824b2870 - rustc_query_impl[52b9445d4dcf70be]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7fa2819371e6 - rustc_hir_analysis[ce12ae6d63b57b8a]::check_crate
  32:     0x7fa281933aa2 - rustc_interface[d0d5d02e7a56d74f]::passes::run_required_analyses
  33:     0x7fa2824a635e - rustc_interface[d0d5d02e7a56d74f]::passes::analysis
  34:     0x7fa2824a632f - rustc_query_impl[52b9445d4dcf70be]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[52b9445d4dcf70be]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 0usize]>>
  35:     0x7fa282493315 - rustc_query_system[b5c6449b7ccd2566]::query::plumbing::try_execute_query::<rustc_query_impl[52b9445d4dcf70be]::DynamicConfig<rustc_query_system[b5c6449b7ccd2566]::query::caches::SingleCache<rustc_middle[ea35cf57050946b4]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[52b9445d4dcf70be]::plumbing::QueryCtxt, false>
  36:     0x7fa28249304e - rustc_query_impl[52b9445d4dcf70be]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7fa2824b9429 - rustc_interface[d0d5d02e7a56d74f]::passes::create_and_enter_global_ctxt::<core[c1de5c9ad145c0db]::option::Option<rustc_interface[d0d5d02e7a56d74f]::queries::Linker>, rustc_driver_impl[af2bdb3744899392]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  38:     0x7fa282504213 - rustc_interface[d0d5d02e7a56d74f]::interface::run_compiler::<(), rustc_driver_impl[af2bdb3744899392]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7fa282400eb5 - std[cc940dec3ff43b12]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d0d5d02e7a56d74f]::util::run_in_thread_with_globals<rustc_interface[d0d5d02e7a56d74f]::util::run_in_thread_pool_with_globals<rustc_interface[d0d5d02e7a56d74f]::interface::run_compiler<(), rustc_driver_impl[af2bdb3744899392]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40:     0x7fa282400b99 - <<std[cc940dec3ff43b12]::thread::Builder>::spawn_unchecked_<rustc_interface[d0d5d02e7a56d74f]::util::run_in_thread_with_globals<rustc_interface[d0d5d02e7a56d74f]::util::run_in_thread_pool_with_globals<rustc_interface[d0d5d02e7a56d74f]::interface::run_compiler<(), rustc_driver_impl[af2bdb3744899392]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c1de5c9ad145c0db]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7fa28240032b - std::sys::pal::unix::thread::Thread::new::thread_start::hb22e947f5885a296
  42:     0x7fa27c756609 - start_thread
                               at /build/glibc-LcI20x/glibc-2.31/nptl/pthread_create.c:477:8
  43:     0x7fa27c67b353 - clone
                               at /build/glibc-LcI20x/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95:0
  44:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.
```

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

```
<backtrace>
```

</p>
</details>