Repository: rust
Issue: ICE when implementing a generic trait + generic supertrait (and default values)
Labels: I-ICE,T-compiler,C-bug,requires-nightly,F-generic_const_exprs,F-adt_const_params,S-bug-has-test

### Summary

The ICE occurs if

- generic trait has a generic supertrait
- trait and supertrait share the same generic
- trait's and supertrait's generic defines a default value for the generic (can differ between trait and supertrait)
- generic's default value is only defined in the trait definition, not in the implementation
- "generic_const_expr" gate is enabled (even though it's functionality not used)

The ICE occurs as the trait is implemented for a type. The targeted type doesn't have to be the same as the generic one.

```rust
#![feature(adt_const_params)]
#![feature(generic_const_exprs)]

use core::marker::ConstParamTy;

// #[derive(ConstParamTy, PartialEq, Eq)]
// struct StructOrEnum;

#[derive(ConstParamTy, PartialEq, Eq)]
enum StructOrEnum {
    A,
}

trait TraitParent<const SMTH: StructOrEnum = { StructOrEnum::A }> {}

trait TraitChild<const SMTH: StructOrEnum = { StructOrEnum::A }>: TraitParent<SMTH> {}

impl TraitParent for StructOrEnum {}

// ICE occurs
impl TraitChild for StructOrEnum {}

// ICE does not occur
// impl TraitChild<{ StructOrEnum::A }> for StructOrEnum {}
```

### Version

```text
rustc 1.82.0-nightly (f167efad2 2024-08-24)
binary: rustc
commit-hash: f167efad2f51088d86180ee89177b3d7c9e7c2f5
commit-date: 2024-08-24
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
```


### Error output

<details><summary>Backtrace</summary>
  <p>

  ```
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::const_param_out_of_range
   3: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const.llvm.11519418143500691559.cold
   4: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
   5: <rustc_trait_selection::traits::wf::WfPredicates>::nominal_obligations
   6: <rustc_trait_selection::traits::wf::WfPredicates as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_const
   7: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
   8: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
   9: <rustc_trait_selection::traits::engine::ObligationCtxt<rustc_trait_selection::traits::FulfillmentError>>::assumed_wf_types_and_report_errors
  10: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  11: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  12: rustc_hir_analysis::check_crate
  13: rustc_interface::passes::run_required_analyses
  14: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  15: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  ```

  </p>
</details>
<details><summary>ICE</summary>
  <p>

  ```
thread 'rustc' panicked at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/compiler/rustc_type_ir/src/binder.rs:739:9:
const parameter `SMTH/#1` (SMTH/#1/1) out of range when instantiating args=[StructOrEnum]
stack backtrace:
   0:     0x7044d54c4ea5 - std::backtrace::Backtrace::create::h60f0872d50b7947d
   1:     0x7044d39d1ec5 - std::backtrace::Backtrace::force_capture::h5f5782d9f084b444
   2:     0x7044d2b602ae - std[6e15924ca43b8509]::panicking::update_hook::<alloc[74339d1d9b201e21]::boxed::Box<rustc_driver_impl[d6b1c5b97f2d776c]::install_ice_hook::{closure#0}>>::{closure#0}
   3:     0x7044d39e9d37 - std::panicking::rust_panic_with_hook::h48ec1454fab3e9d6
   4:     0x7044d39e99f7 - std::panicking::begin_panic_handler::{{closure}}::hdfdc79a140009172
   5:     0x7044d39e71f9 - std::sys::backtrace::__rust_end_short_backtrace::h5e9ef3624d34a08c
   6:     0x7044d39e96c4 - rust_begin_unwind
   7:     0x7044d0b9f263 - core::panicking::panic_fmt::h5c7dda2686e962d9
   8:     0x7044d30f2bb9 - <rustc_type_ir[a178b1c04a843a22]::binder::ArgFolder<rustc_middle[715031de33b6a9f]::ty::context::TyCtxt>>::const_param_out_of_range
   9:     0x7044d55da828 - <rustc_type_ir[a178b1c04a843a22]::binder::ArgFolder<rustc_middle[715031de33b6a9f]::ty::context::TyCtxt> as rustc_type_ir[a178b1c04a843a22]::fold::TypeFolder<rustc_middle[715031de33b6a9f]::ty::context::TyCtxt>>::fold_const.llvm.11519418143500691559.cold
  10:     0x7044d423268c - <rustc_middle[715031de33b6a9f]::ty::generics::GenericPredicates>::instantiate_into
  11:     0x7044d422f5a3 - <rustc_trait_selection[76948cd8c7a47ffa]::traits::wf::WfPredicates>::nominal_obligations
  12:     0x7044d4c88362 - <rustc_trait_selection[76948cd8c7a47ffa]::traits::wf::WfPredicates as rustc_type_ir[a178b1c04a843a22]::visit::TypeVisitor<rustc_middle[715031de33b6a9f]::ty::context::TyCtxt>>::visit_const
  13:     0x7044d08b4bdf - <rustc_trait_selection[76948cd8c7a47ffa]::traits::fulfill::FulfillProcessor as rustc_data_structures[34dac5edc44e011b]::obligation_forest::ObligationProcessor>::process_obligation
  14:     0x7044d44178c1 - <rustc_data_structures[34dac5edc44e011b]::obligation_forest::ObligationForest<rustc_trait_selection[76948cd8c7a47ffa]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[76948cd8c7a47ffa]::traits::fulfill::FulfillProcessor>
  15:     0x7044d440a8c3 - <rustc_trait_selection[76948cd8c7a47ffa]::traits::engine::ObligationCtxt<rustc_trait_selection[76948cd8c7a47ffa]::traits::FulfillmentError>>::assumed_wf_types_and_report_errors
  16:     0x7044d17183ca - rustc_hir_analysis[2f099064b091af30]::check::wfcheck::check_well_formed
  17:     0x7044d45a6d27 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7a841671113bb270]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>
  18:     0x7044d45aa4ea - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::<rustc_query_impl[7a841671113bb270]::DynamicConfig<rustc_query_system[77a41dfa2d87d677]::query::caches::VecCache<rustc_hir[9a201f138b4d1b5]::hir_id::OwnerId, rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true>
  19:     0x7044d45a9ef8 - rustc_query_impl[7a841671113bb270]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  20:     0x7044d45a7acb - rustc_hir_analysis[2f099064b091af30]::check::wfcheck::check_mod_type_wf
  21:     0x7044d45a7909 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7a841671113bb270]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>
  22:     0x7044d508fbcc - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::<rustc_query_impl[7a841671113bb270]::DynamicConfig<rustc_query_system[77a41dfa2d87d677]::query::caches::DefaultCache<rustc_span[641b1e127128c80]::def_id::LocalModDefId, rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true>
  23:     0x7044d509089b - rustc_query_impl[7a841671113bb270]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  24:     0x7044d473c34d - rustc_hir_analysis[2f099064b091af30]::check_crate
  25:     0x7044d4739abf - rustc_interface[eb6eb7ed9ab023cb]::passes::run_required_analyses
  26:     0x7044d4d59c9e - rustc_interface[eb6eb7ed9ab023cb]::passes::analysis
  27:     0x7044d4d59c71 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7a841671113bb270]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>
  28:     0x7044d520d90d - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::<rustc_query_impl[7a841671113bb270]::DynamicConfig<rustc_query_system[77a41dfa2d87d677]::query::caches::SingleCache<rustc_middle[715031de33b6a9f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true>
  29:     0x7044d520d5ba - rustc_query_impl[7a841671113bb270]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  30:     0x7044d4ff43aa - rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler::<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7044d506f390 - std[6e15924ca43b8509]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_with_globals<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_pool_with_globals<rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>
  32:     0x7044d506f9fa - <<std[6e15924ca43b8509]::thread::Builder>::spawn_unchecked_<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_with_globals<rustc_interface[eb6eb7ed9ab023cb]::util::run_in_thread_pool_with_globals<rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler<core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#1} as core[f2f627d3c87d2691]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7044d506fd6b - std::sys::pal::unix::thread::Thread::new::thread_start::h5ac727470998e7f2
  34:     0x7044d680d39d - <unknown>
  35:     0x7044d689249c - <unknown>
  36:                0x0 - <unknown>


rustc version: 1.82.0-nightly (f167efad2 2024-08-24)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:21:1: 21:33>` is well-formed
rust-lang/rust-clippy#1 [check_mod_type_wf] checking that types are well-formed in top-level module
rust-lang/rust-clippy#2 [analysis] running analysis passes on this crate
end of query stack
  ```

  </p>
</details>