Repository: rust
Issue: Generic Constants Nightly breaks with Rust 1.68
Labels: T-compiler,C-bug,A-const-generics,requires-nightly,F-generic_const_exprs,requires-incomplete-features

<!--
Thank you for filing a regression report! 🐛 A regression is something that changed between versions of Rust but was not supposed to.

Please provide a short summary of the regression, along with any information you feel is relevant to replicate it.
--> 

The following code compiles on Rust 1.67 (nightly) but not on Rust 1.68 (nightly)

### Code

```rust
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

fn main() {
    println!("Hello, world!");
}

// FUNCTION THAT IS NOW BROKEN
fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]:  {
    let _ = T::do_something_super().to_bytes();
}

// Trait I implement for a few subtypes of my main type "SuperTrait"
trait MySerde {
    const LEN: usize;

    fn to_bytes(&self) -> [u8; Self::LEN];
    fn from_bytes(bytes: [u8; Self::LEN]) -> Self;
}

// each subtrait would have its own requirements
trait SubTrait: MySerde {
    // stuff
}

// We need a subtrait for constants or we get a cycle when defining SUPER_ARR
trait ConstantsForSuper {
    const SUPER_SIZE: usize;
}

// in my actual example SuperTrait has several types implementing differeent subtraits
// (all of which require serde)
trait SuperTrait: ConstantsForSuper where [(); Self::SUPER_SIZE]: {
    type MyType: SubTrait;

    const SUPER_ARR: [Self::MyType; Self::SUPER_SIZE];

    fn do_something_super() -> Self::MyType;
}
```

### Version it worked on

<!--
Provide the most recent version this worked on, for example:

It most recently worked on: Rust 1.47
-->

It most recently worked on: 1.67

### Version with regression


`rustc --version --verbose`:
```
rustc 1.68.0-nightly (4781233a7 2023-01-16)
binary: rustc
commit-hash: 4781233a77e879e49cb5ce3c98d2abba6a6ade7a
commit-date: 2023-01-16
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
```

<!--
Did the compiler crash? If so, please provide a backtrace.
-->

### Backtrace
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
/~/project$ RUST_BACKTRACE=1 cargo build
   Compiling minimal_breakage v0.1.0 (/~/project)
error[E0391]: cycle detected when building an abstract representation for `do_something::{constant#0}`
 --> src/main.rs:9:45
  |
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]:  {
  |                                             ^^^^^^^^^^^^^^
  |
note: ...which requires building THIR for `do_something::{constant#0}`...
 --> src/main.rs:9:45
  |
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]:  {
  |                                             ^^^^^^^^^^^^^^
note: ...which requires type-checking `do_something::{constant#0}`...
 --> src/main.rs:9:45
  |
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]:  {
  |                                             ^^^^^^^^^^^^^^
  = note: ...which again requires building an abstract representation for `do_something::{constant#0}`, completing the cycle
note: cycle used when checking that `do_something` is well-formed
 --> src/main.rs:9:1
  |
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]:  {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0391`.
error: could not compile `minimal_breakage` due to previous error
```

</p>
</details>

<!--
If you know when this regression occurred, please add a line like below, replacing `{channel}` with one of stable, beta, or nightly.

@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged
-->