Repository: rust
Issue: Compiler Hangs When Compiling Code with `generic_const_exprs`
Labels: T-compiler,C-bug,I-hang,F-generic_const_exprs

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
#![feature(generic_const_exprs)]
trait MyFn<Args> {
    type Output;
    fn call(self, args: Args) -> Self::Output;
}
struct Bubble<T, const N: u8> {
    t: std::marker::PhantomData<T>,
}
impl<T> MyFn<T> for Bubble<T, 1> {
    type Output = [T; 1];
    fn call(self, args: T) -> [T; 1] {
        [args]
    }
}
impl<T, const N: u8> MyFn<T> for Bubble<T, N>
where
    [(); { N - 1 }]:,
    Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
{
    type Output = [T; N];
    fn call(self, args: T) -> [T; N] {
        let f = Bubble::<[T; N], { N - 1 }> {
            t: std::marker::PhantomData,
        };
        f.call([args])
    }
}
impl<T, const N: u8> MyFn<T> for Bubble<T, N>
where
    [(); { N - 1 }]:,
    Bubble<[T; N], { N - 1 }>: MyFn<[T; N]>,
{
    type Output = [T; 1];
    fn call(self, args: T) -> [T; 1] {
        let f = Bubble::<[T; 1], { N - 1 }> {
            t: std::marker::PhantomData,
        };
        f.call([args])
    }
}
fn main() {}
```

I expected to see this happen: *The compiler compiles successfully or outputs an error message.*

Instead, this happened: *The code, as provided below, appears to encounter a hang*

Interestingly, when I remove `#![feature(generic_const_exprs)]` , this piece of code quickly compiles and produces error messages.

### 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.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
```
The same problem is reproduced on the nightly version(1.75.0-nightly `aa1a71e9e 2023-10-26`)
what's more, to get more information,I also tried '-Z time-passes' (using nighly version):
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Output</summary>
<p>

```
time:   0.000; rss:   29MB ->   31MB (   +2MB)	parse_crate
time:   0.003; rss:   35MB ->   49MB (  +14MB)	expand_crate
time:   0.003; rss:   35MB ->   49MB (  +14MB)	macro_expand_crate
time:   0.001; rss:   49MB ->   52MB (   +3MB)	late_resolve_crate
time:   0.001; rss:   49MB ->   52MB (   +3MB)	resolve_crate
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> code.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unnecessary braces around const expression
  --> code.rs:17:10
   |
17 |     [(); { N - 1 }]:,
   |          ^^     ^^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
17 -     [(); { N - 1 }]:,
17 +     [(); N - 1]:,
   |

warning: unnecessary braces around const expression
  --> code.rs:30:10
   |
30 |     [(); { N - 1 }]:,
   |          ^^     ^^
   |
help: remove these braces
   |
30 -     [(); { N - 1 }]:,
30 +     [(); N - 1]:,
   |

time:   0.007; rss:   52MB ->   58MB (   +6MB)	looking_for_entry_point
time:   0.007; rss:   52MB ->   58MB (   +6MB)	misc_checking_1
time:   0.001; rss:   58MB ->   61MB (   +3MB)	type_collecting
error[E0080]: evaluation of `<Bubble<[!0; 1], { N - 1 }> as MyFn<[!0; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!1; 1], 0> as MyFn<[!1; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!2; 1], 0> as MyFn<[!2; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!3; 1], 0> as MyFn<[!3; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!4; 1], 0> as MyFn<[!4; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!5; 1], 0> as MyFn<[!5; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!6; 1], 0> as MyFn<[!6; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!7; 1], 0> as MyFn<[!7; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!8; 1], 0> as MyFn<[!8; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!9; 1], 0> as MyFn<[!9; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!10; 1], 0> as MyFn<[!10; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!11; 1], 0> as MyFn<[!11; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!12; 1], 0> as MyFn<[!12; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!13; 1], 0> as MyFn<[!13; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!14; 1], 0> as MyFn<[!14; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!15; 1], 0> as MyFn<[!15; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!16; 1], 0> as MyFn<[!16; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

error[E0080]: evaluation of `<Bubble<[!17; 1], 0> as MyFn<[!17; 1]>>::{constant#2}` failed
  --> code.rs:18:22
   |
18 |     Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
   |                      ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow

……
```

</p>
</details>