Repository: rust
Issue: generic_const_exprs: cycle detected where it is not expected
Labels: T-compiler,C-bug,A-const-generics,requires-nightly,F-generic_const_exprs,requires-incomplete-features,I-cycle

<!--
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 hit this while checking whether the [fixed crate](https://crates.io/crates/fixed) can be ported from typenum to nightly with `generic_const_exprs`. The code below contains two parts which seem to be independent, but they are causing a cycle to be detected. Commenting out either part 1 or part 2 will remove the compilation error.

```rust
#![feature(generic_const_exprs)]

pub struct If<const CONDITION: bool>;
pub trait True {}
impl True for If<true> {}

// Part 1
pub struct FixedI8<const FRAC: u32> {
    pub bits: i8,
}

impl<const FRAC: u32> PartialEq<FixedI8<FRAC>> for i8
where
    If<{ FRAC <= 8 }>: True,
{
    fn eq(&self, _rhs: &FixedI8<FRAC>) -> bool {
        unimplemented!()
    }
}

// Part 2
pub struct FixedU64<const FRAC: u32> {
    pub bits: u64,
}

impl<const FRAC_DST: u32> From<u8> for FixedU64<FRAC_DST>
where
    If<{ 8 <= 64 - FRAC_DST }>: True,
{
    fn from(_src: u8) -> Self {
        unimplemented!()
    }
}

```

This error message is shown:
```
cargo +nightly check
    Checking fcg2 v0.1.0 (/home/trevor/try/fcg2)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.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

error[E0391]: cycle detected when type-checking the const argument `<impl at src/lib.rs:26:1: 33:2>::{constant#0}`
  --> src/lib.rs:28:8
   |
28 |     If<{ 8 <= 64 - FRAC_DST }>: True,
   |        ^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires trying to unify the generic constants <impl at src/lib.rs:12:1: 19:2>::{constant#0} and <impl at src/lib.rs:26:1: 33:2>::{constant#0}...
  --> src/lib.rs:14:8
   |
14 |     If<{ FRAC <= 8 }>: True,
   |        ^^^^^^^^^^^^^
note: ...which requires building an abstract representation for the const argument <impl at src/lib.rs:26:1: 33:2>::{constant#0}...
  --> src/lib.rs:28:8
   |
28 |     If<{ 8 <= 64 - FRAC_DST }>: True,
   |        ^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires building THIR for `<impl at src/lib.rs:26:1: 33:2>::{constant#0}`...
  --> src/lib.rs:28:8
   |
28 |     If<{ 8 <= 64 - FRAC_DST }>: True,
   |        ^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which again requires type-checking the const argument `<impl at src/lib.rs:26:1: 33:2>::{constant#0}`, completing the cycle
note: cycle used when building MIR for `<impl at src/lib.rs:26:1: 33:2>::{constant#0}`
  --> src/lib.rs:28:8
   |
28 |     If<{ 8 <= 64 - FRAC_DST }>: True,
   |        ^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0391`.
warning: `fcg2` (lib) generated 1 warning
error: could not compile `fcg2` due to previous error; 1 warning emitted
```

### 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 +nightly --version --verbose`:
```
rustc 1.61.0-nightly (68369a041 2022-02-22)
binary: rustc
commit-hash: 68369a041cea809a87e5bd80701da90e0e0a4799
commit-date: 2022-02-22
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
```