Repository: rust
Issue: Type inference fails with `adt_const_params` and `const_generic_exprs` for associated types
Labels: C-bug,A-const-generics,F-generic_const_exprs,F-adt_const_params

<!--
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.
-->

Sorry for the long example, but it is the shortest that I could come up with that reproduces the bug:

```rust
#![allow(incomplete_features)]
#![feature(generic_const_exprs, adt_const_params)]

use std::{marker::ConstParamTy, ops::Add};

#[derive(ConstParamTy, PartialEq, Eq)]
pub struct Value(i32);

#[derive(Clone, Copy)]
pub struct MyType<const D: Value>;

impl Value {
    pub const fn add(self, other: Self) -> Self {
        Self(self.0 + other.0)
    }
}

impl<const DL: Value, const DR: Value> std::ops::Add<MyType<DR>> for MyType<DL>
where
    MyType<{ DL.add(DR) }>:,
{
    type Output = MyType<{ DL.add(DR) }>;

    fn add(self, _: MyType<DR>) -> Self::Output {
        MyType
    }
}

pub type One = MyType<{ Value(1) }>;
pub type Two = MyType<{ Value(2) }>;

fn foo(one: One) -> <One as Add<Two>>::Output {
    let two = one + one;
    one + two
}

fn foo_annotated(one: One) -> <One as Add<Two>>::Output {
    let two: Two = one + one;
    one + two
}
```

I expected both `foo` and `foo_annotated` to compile, but only `foo_annotated` compiles. `foo` fails to compile with:
```
error[E0308]: mismatched types
  --> src/main.rs:36:5
   |
36 |     one + two
   |     ^^^^^^^^^ expected `Value(2)`, found `{const expr}`
   |
   = note: expected constant `Value(2)`
              found constant `{const expr}`
```

`foo` compiles correctly if any of the following changes are made:
1. `Value` is replaced by an `i32` everywhere (which removes the dependency on `adt_const_params`)
2. The return type of `foo` is specified directly as `MyType { Value(3) }`
3. A different, simpler expression is used:
```
fn foo(one: One) -> <One as Add<One>>::Output {
    one + one
}
```

I didn't find anything in my search through the issues, so I hope this isn't a duplicate.
Totally not a critical bug but it would be nice if the compiler could infer the type of the expression correctly. Currently, any expression involving more than a few inferred types seems to require an annotation.

### 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.72.0-nightly (dd5d7c729 2023-06-02)
binary: rustc
commit-hash: dd5d7c729d4e8a59708df64002e09dbcbc4005ba
commit-date: 2023-06-02
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.4
```

<!--
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>

```
Compiling comptest v0.1.0 (/home/toni/projects/comptest)
error[E0308]: mismatched types
  --> src/main.rs:36:5
   |
36 |     one + two
   |     ^^^^^^^^^ expected `Value(2)`, found `{const expr}`
   |
   = note: expected constant `Value(2)`
              found constant `{const expr}`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `comptest` (bin "main") due to previous error
```

</p>
</details>