Repository: rust
Issue: ICE: Awfully specific error on nightly when mixing recursive structs and associated constants used in a `generic_const_exprs` bound for a blanket impl, with an implementation for the struct that recurses into its child
Labels: I-ICE,T-compiler,C-bug,requires-nightly,glacier,F-generic_const_exprs,S-bug-has-test,requires-incomplete-features

Let me start by saying I have no idea what this code breaks or how, but this is the smallest I could get it.
It appears that making the impl recursively call the struct's child is important to trigger it.
[Error reproducible in playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5b92b9f2523c8061c98a291867e3972f)


### Code

```Rust
#![feature(generic_const_exprs)]

// Main function seems irrelevant
fn main() {}

// Constant must be provided via an associated constant in a trait
pub trait ConstTrait {
	const ASSOC_CONST: usize;
}

// For some reason I find it's necessary to have an implementation of this trait that recurses
pub trait OtherTrait
{
	fn comm(self);
}

// There must be a blanket impl here
impl<T> OtherTrait for T where
    T: ConstTrait,
    [();T::ASSOC_CONST]: Sized,
{
    fn comm(self) {
        todo!()
    }
}

// The struct must be recursive
pub struct RecursiveStruct(Box<RecursiveStruct>);

// This implementation must exist, and it must recurse into its child
impl OtherTrait for RecursiveStruct {
    fn comm(self) {
        (self.0).comm();
    }
}
```


### Meta

`rustc --version --verbose`:
```
rustc 1.63.0-nightly (dc80ca78b 2022-06-21)
binary: rustc
commit-hash: dc80ca78b6ec2b6bba02560470347433bcd0bb3c
commit-date: 2022-06-21
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5
```

### Error output

```
   Compiling weird-bug v0.1.0 (/home/adriano/Documents/Personal/codeProjects/rustc-bug-minimize)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

warning: function cannot return without recursing
  --> src/main.rs:32:5
   |
32 |     fn comm(self) {
   |     ^^^^^^^^^^^^^ cannot return without recursing
33 |         (self.0).comm();
   |         --------------- recursive call site
   |
   = note: `#[warn(unconditional_recursion)]` on by default
   = help: a `loop` may express intention better if this is on purpose

warning: Error finalizing incremental compilation session directory `/home/adriano/Documents/Personal/codeProjects/rustc-bug-minimize/target/debug/incremental/weird_bug-qoicnetgtthv/s-gayz2hndkv-18rp3za-working`: No such file or directory (os error 2)

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: unexpected `TooGeneric` for Unevaluated { def: WithOptConstParam { did: DefId(0:10 ~ weird_bug[30bc]::{impl#0}::{constant#0}), const_param_did: None }, substs: [std::boxed::Box<RecursiveStruct>], promoted: () }
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:102:22

error: internal compiler error: unexpected `TooGeneric` for Unevaluated { def: WithOptConstParam { did: DefId(0:10 ~ weird_bug[30bc]::{impl#0}::{constant#0}), const_param_did: None }, substs: [&std::boxed::Box<RecursiveStruct>], promoted: () }
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:102:22

error: internal compiler error: unexpected `TooGeneric` for Unevaluated { def: WithOptConstParam { did: DefId(0:10 ~ weird_bug[30bc]::{impl#0}::{constant#0}), const_param_did: None }, substs: [&mut std::boxed::Box<RecursiveStruct>], promoted: () }
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:102:22

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1425:13
stack backtrace:
   0:     0x7f9e2389e02d - std::backtrace_rs::backtrace::libunwind::trace::h66824bd979b46652
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f9e2389e02d - std::backtrace_rs::backtrace::trace_unsynchronized::h0caf895dc6521160
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9e2389e02d - std::sys_common::backtrace::_print_fmt::h8ee19c74892f96ef
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f9e2389e02d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f38873b172b3ee3
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f9e238f9dec - core::fmt::write::h95bc5c1a2dab38ae
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/core/src/fmt/mod.rs:1197:17
   5:     0x7f9e2388f741 - std::io::Write::write_fmt::hcbe645da27d05687
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/io/mod.rs:1672:15
   6:     0x7f9e238a0cf5 - std::sys_common::backtrace::_print::h491b32351e64ba40
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f9e238a0cf5 - std::sys_common::backtrace::print::h95813b9263ac2531
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f9e238a0cf5 - std::panicking::default_hook::{{closure}}::h97b51a053e0a66a6
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:295:22
   9:     0x7f9e238a0a16 - std::panicking::default_hook::h4e7a054eecf2a40c
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:314:9
  10:     0x7f9e240fd3c4 - rustc_driver[90499e6357860faf]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f9e238a13ca - std::panicking::rust_panic_with_hook::hc34128de9b2f1619
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:702:17
  12:     0x7f9e252aa121 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}
  13:     0x7f9e252a75e6 - std[b701561e8274a90e]::sys_common::backtrace::__rust_end_short_backtrace::<std[b701561e8274a90e]::panicking::begin_panic<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}, !>
  14:     0x7f9e252b6336 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  15:     0x7f9e252b3556 - std[b701561e8274a90e]::panic::panic_any::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  16:     0x7f9e26b9a3cc - <rustc_errors[66b38508c80fa53]::HandlerInner as core[61a96b067728b167]::ops::drop::Drop>::drop
  17:     0x7f9e262c3ed8 - core[61a96b067728b167]::ptr::drop_in_place::<rustc_session[4ced65ff44b6b5e6]::parse::ParseSess>
  18:     0x7f9e262c7003 - <alloc[2bc16101ff7e918e]::rc::Rc<rustc_session[4ced65ff44b6b5e6]::session::Session> as core[61a96b067728b167]::ops::drop::Drop>::drop
  19:     0x7f9e262ed5cd - core[61a96b067728b167]::ptr::drop_in_place::<rustc_interface[fff95432a826ec6b]::interface::Compiler>
  20:     0x7f9e262ecf04 - rustc_span[a21f0b15de3a4c22]::with_source_map::<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_interface[fff95432a826ec6b]::interface::create_compiler_and_run<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#1}>
  21:     0x7f9e262c96e2 - <scoped_tls[fd6fb1272a57f899]::ScopedKey<rustc_span[a21f0b15de3a4c22]::SessionGlobals>>::set::<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  22:     0x7f9e262decdf - std[b701561e8274a90e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  23:     0x7f9e262dee19 - <<std[b701561e8274a90e]::thread::Builder>::spawn_unchecked_<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#1} as core[61a96b067728b167]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  24:     0x7f9e238ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hed39a37500816679
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  25:     0x7f9e238ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf70a23328098c6ee
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  26:     0x7f9e238ab303 - std::sys::unix::thread::Thread::new::thread_start::h4e2fce376f42517a
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys/unix/thread.rs:108:17
  27:     0x7f9e2348c54d - <unknown>
  28:     0x7f9e23511874 - clone
  29:                0x0 - <unknown>

note: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.63.0-nightly (dc80ca78b 2022-06-21) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `weird-bug` (bin "weird-bug") generated 3 warnings
error: could not compile `weird-bug`; 3 warnings emitted
```
<details><summary><strong>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1425:13
stack backtrace:
   0:     0x7f9e2389e02d - std::backtrace_rs::backtrace::libunwind::trace::h66824bd979b46652
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f9e2389e02d - std::backtrace_rs::backtrace::trace_unsynchronized::h0caf895dc6521160
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9e2389e02d - std::sys_common::backtrace::_print_fmt::h8ee19c74892f96ef
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f9e2389e02d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f38873b172b3ee3
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f9e238f9dec - core::fmt::write::h95bc5c1a2dab38ae
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/core/src/fmt/mod.rs:1197:17
   5:     0x7f9e2388f741 - std::io::Write::write_fmt::hcbe645da27d05687
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/io/mod.rs:1672:15
   6:     0x7f9e238a0cf5 - std::sys_common::backtrace::_print::h491b32351e64ba40
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f9e238a0cf5 - std::sys_common::backtrace::print::h95813b9263ac2531
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f9e238a0cf5 - std::panicking::default_hook::{{closure}}::h97b51a053e0a66a6
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:295:22
   9:     0x7f9e238a0a16 - std::panicking::default_hook::h4e7a054eecf2a40c
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:314:9
  10:     0x7f9e240fd3c4 - rustc_driver[90499e6357860faf]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f9e238a13ca - std::panicking::rust_panic_with_hook::hc34128de9b2f1619
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:702:17
  12:     0x7f9e252aa121 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}
  13:     0x7f9e252a75e6 - std[b701561e8274a90e]::sys_common::backtrace::__rust_end_short_backtrace::<std[b701561e8274a90e]::panicking::begin_panic<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}, !>
  14:     0x7f9e252b6336 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  15:     0x7f9e252b3556 - std[b701561e8274a90e]::panic::panic_any::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  16:     0x7f9e26b9a3cc - <rustc_errors[66b38508c80fa53]::HandlerInner as core[61a96b067728b167]::ops::drop::Drop>::drop
  17:     0x7f9e262c3ed8 - core[61a96b067728b167]::ptr::drop_in_place::<rustc_session[4ced65ff44b6b5e6]::parse::ParseSess>
  18:     0x7f9e262c7003 - <alloc[2bc16101ff7e918e]::rc::Rc<rustc_session[4ced65ff44b6b5e6]::session::Session> as core[61a96b067728b167]::ops::drop::Drop>::drop
  19:     0x7f9e262ed5cd - core[61a96b067728b167]::ptr::drop_in_place::<rustc_interface[fff95432a826ec6b]::interface::Compiler>
  20:     0x7f9e262ecf04 - rustc_span[a21f0b15de3a4c22]::with_source_map::<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_interface[fff95432a826ec6b]::interface::create_compiler_and_run<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#1}>
  21:     0x7f9e262c96e2 - <scoped_tls[fd6fb1272a57f899]::ScopedKey<rustc_span[a21f0b15de3a4c22]::SessionGlobals>>::set::<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  22:     0x7f9e262decdf - std[b701561e8274a90e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  23:     0x7f9e262dee19 - <<std[b701561e8274a90e]::thread::Builder>::spawn_unchecked_<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#1} as core[61a96b067728b167]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  24:     0x7f9e238ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hed39a37500816679
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  25:     0x7f9e238ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf70a23328098c6ee
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  26:     0x7f9e238ab303 - std::sys::unix::thread::Thread::new::thread_start::h4e2fce376f42517a
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys/unix/thread.rs:108:17
  27:     0x7f9e2348c54d - <unknown>
  28:     0x7f9e23511874 - clone
  29:                0x0 - <unknown>
```

</p>
</details>

EDIT: Realized I was running an old version of nightly. Logs are updated to show errors at `rustc 1.63.0-nightly (dc80ca78b 2022-06-21) running on x86_64-unknown-linux-gnu`. Also showing the full backtrace.
EDIT 2: Simplified trait names and added comments.
EDIT 3: Clarified a sentence
EDIT 4: Updated playground link