Repository: rust
Issue: Unable to satisfy associated type equality constraints (E0284) past a certain depth with multiple supertraits sharing a common supertrait
Labels: T-compiler,A-inference,C-bug

I have a hierarchy of traits, where the super-most trait has some associated type that the sub-traits in the hierarchy apply additional trait constraints to. In lieu of using associated type bounds (or any unstable features), I'm declaring an associated type in each sub-trait with the appropriate trait constraints and applying an equality constraint between each supertrait associated type and the sub-trait's associated type, e.g.:

```rust
trait BaseTrait {
    type AssocBase;
}

trait Foo {}
trait SubTrait: BaseTrait<AssocBase = Self::AssocSub> {
    type AssocSub: Foo;
}
```

This has worked fine under most circumstances where a sub-trait only has one supertrait from the hierarchy, but fails to compile when a sub-trait has multiple supertraits that share a common base, where that base in turn has yet another parent in the hierarchy.

I tried [this code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f2156eee8cb56e4f8fe2e193f23092ad) (minimal repro I could construct, with associated type trait constraints omitted as they don't seem to affect the results):

```rust
pub trait BaseTrait {
    type AssocBase;
}

pub trait MiddleTrait: BaseTrait<AssocBase = Self::AssocMiddle> {
    type AssocMiddle;
}

pub trait SubTraitA: MiddleTrait<AssocMiddle = Self::AssocSubA> {
    type AssocSubA;
}

pub trait SubTraitB: MiddleTrait<AssocMiddle = Self::AssocSubB> {
    type AssocSubB;
}

pub trait CombinedTrait:
    SubTraitA<AssocSubA = Self::AssocCombined> + SubTraitB<AssocSubB = Self::AssocCombined>
{
    type AssocCombined;
}
```

I expected to see this happen: Successful compilation.

Instead, this happened:

```
Compiling playground v0.0.1 (/playground)
error[[E0284]](https://doc.rust-lang.org/nightly/error_codes/E0284.html): type annotations needed
  --> src/lib.rs:17:1
   |
17 | / pub trait CombinedTrait:
18 | |     SubTraitA<AssocSubA = Self::AssocCombined> + SubTraitB<AssocSubB = Self::AssocCombined>
   | |___________________________________________________________________________________________^ cannot infer type
   |
   = note: cannot satisfy `<Self as MiddleTrait>::AssocMiddle == _`

error[[E0284]](https://doc.rust-lang.org/nightly/error_codes/E0284.html): type annotations needed: cannot satisfy `<Self as MiddleTrait>::AssocMiddle == <Self as CombinedTrait>::AssocCombined`
  --> src/lib.rs:18:5
   |
18 |     SubTraitA<AssocSubA = Self::AssocCombined> + SubTraitB<AssocSubB = Self::AssocCombined>
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Self as MiddleTrait>::AssocMiddle == <Self as CombinedTrait>::AssocCombined`
   |
note: required by a bound in `SubTraitA`
  --> src/lib.rs:9:34
   |
9  | pub trait SubTraitA: MiddleTrait<AssocMiddle = Self::AssocSubA> {
   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SubTraitA`

error[[E0284]](https://doc.rust-lang.org/nightly/error_codes/E0284.html): type annotations needed
  --> src/lib.rs:20:5
   |
20 |     type AssocCombined;
   |     ^^^^^^^^^^^^^^^^^^ cannot infer type
   |
   = note: cannot satisfy `<Self as MiddleTrait>::AssocMiddle == _`

For more information about this error, try `rustc --explain E0284`.
error: could not compile `playground` (lib) due to 3 previous errors
```

Adding [explicit equality constraints on `AssocBase` and `AssocMiddle`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=3e179e3074e902824bb37c30ed15b4ec) to all applicable traits does not resolve the issue, but [removing `BaseTrait` from the hierarchy](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=26ae392036d3754a8c1c28790d972618) does compile successfully.

### Meta

`rustc --version --verbose`:
```
rustc 1.70.0-nightly (8be3c2bda 2023-03-24)
binary: rustc
commit-hash: 8be3c2bda6b683f87b24714ba595e8b04faef54c
commit-date: 2023-03-24
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
```
(Also tested with 1.68.1 stable.)