Repository: rust
Issue: Associated type resolution fails with blanket impl for supertrait
Labels: A-trait-system,T-compiler,C-discussion

<!--
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
trait General {
    type Associated;

    fn get(&self) -> Self::Associated;
}

trait Specialized: General {}

impl<T: Specialized> General for T {
    type Associated = i32;

    fn get(&self) -> i32 {
        todo!()
    }
}
```

I expected to see this happen: The code compiles without issue

Instead, this happened: It fails to compile with this error:

```
error[E0053]: method `get` has an incompatible type for trait
  --> src/lib.rs:12:22
   |
10 |     type Associated = i32;
   |     ---------------------- expected this associated type
11 |
12 |     fn get(&self) -> i32 {
   |                      ^^^
   |                      |
   |                      expected associated type, found `i32`
   |                      help: change the output type to match the trait: `<T as General>::Associated`
   |
note: type in trait
  --> src/lib.rs:4:22
   |
4  |     fn get(&self) -> Self::Associated;
   |                      ^^^^^^^^^^^^^^^^
   = note: expected fn pointer `fn(&T) -> <T as General>::Associated`
              found fn pointer `fn(&T) -> i32`
```

I've confirmed that all of the elements in this reproduction are necessary, and the bug appears to be an interaction between the supertrait (`trait Specialized: General`) and the constrained blanket impl (`impl<T: Specialized> General for T`). Removing either the constraint or the supertrait makes the problem disappear.

Additionally, it's possible to fix the issue by using `Self::Associated` in the return type position of `fn get` in the `impl` block. However, in this case, it's impossible to actually *implement* the function; the same type resolution failure reappears when you try to return a value:

```rust
    fn get(&self) -> Self::Associated {
        10
    }
```

```
error[E0308]: mismatched types
  --> src/lib.rs:13:9
   |
12 |     fn get(&self) -> Self::Associated {
   |                      ---------------- expected `<T as General>::Associated` because of return type
13 |         10
   |         ^^ expected associated type, found integer
   |
   = note: expected associated type `<T as General>::Associated`
                         found type `{integer}`
   = help: consider constraining the associated type `<T as General>::Associated` to `{integer}` or calling a method that returns `<T as General>::Associated`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

For more information about this error, try `rustc --explain E0308`.
```

### 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.
-->

The bug appears on all current versions of Rust. Tested with:

Stable: 1.64.0
Beta: 1.65.0-beta.2 (2022-09-24 e5da98475e88b52384ba)
Nightly: 1.66.0-nightly (2022-09-29 9c56d9d6fec6262bbb15)