Repository: rust
Issue: associated-types-invalid-trait-ref diagnostics can be misleading
Labels: A-diagnostics,T-compiler

### Code
code from `./ui/associated-types/associated-types-invalid-trait-ref-issue-18865.rs`
```Rust
trait Foo<T> {
    type Bar;
    fn get_bar(&self) -> Self::Bar;
}

fn f<T:Foo<isize>>(t: &T) {
    let u: <T as Foo<usize>>::Bar = t.get_bar();
    //~^ ERROR the trait bound `T: Foo<usize>` is not satisfied
}

fn main() { }
```


The solution to the error is to use `Foo<isize>` for `u` instead of `usize` but rustc totally misses that it looks like:

````
error[E0277]: the trait bound `T: Foo<usize>` is not satisfied
 --> src/lib.rs:7:12
  |
7 |     let u: <T as Foo<usize>>::Bar = t.get_bar();
  |            ^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo<usize>` is not implemented for `T`
  |
help: consider further restricting this bound
  |
6 | fn f<T:Foo<isize> + Foo<usize>>(t: &T) {
  |                   ++++++++++++

For more information about this error, try `rustc --explain E0277`
````
applied:
````rust
trait Foo<T> {
    type Bar;
    fn get_bar(&self) -> Self::Bar;
}

fn f<T:Foo<isize> + Foo<usize>>(t: &T) {
    let u: <T as Foo<usize>>::Bar = t.get_bar();
}

fn main() { }
````
=> new error:

````
error[E0284]: type annotations needed
 --> src/lib.rs:7:39
  |
7 |     let u: <T as Foo<usize>>::Bar = t.get_bar();
  |                                       ^^^^^^^
  |
  = note: cannot satisfy `<T as Foo<_>>::Bar == <T as Foo<usize>>::Bar`
help: try using a fully qualified path to specify the expected types
  |
7 |     let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
  |                                     +++++++++++++++++++++++ ~
````

=> applied

````rust
trait Foo<T> {
    type Bar;
    fn get_bar(&self) -> Self::Bar;
}

fn f<T:Foo<isize> + Foo<usize>>(t: &T) {
    let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
}

fn main() { }
````

=> new error (duplicate?)

````
error[E0277]: the trait bound `T: Foo<T>` is not satisfied
 --> src/lib.rs:7:60
  |
7 |     let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
  |                                     ---------------------- ^ the trait `Foo<T>` is not implemented for `T`
  |                                     |
  |                                     required by a bound introduced by this call
  |
help: consider further restricting this bound
  |
6 | fn f<T:Foo<isize> + Foo<usize> + Foo<T>>(t: &T) {
  |                                ++++++++

error[E0277]: the trait bound `T: Foo<T>` is not satisfied
 --> src/lib.rs:7:37
  |
7 |     let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
  |                                     ^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo<T>` is not implemented for `T`
  |
help: consider further restricting this bound
  |
6 | fn f<T:Foo<isize> + Foo<usize> + Foo<T>>(t: &T) {
  |                                ++++++++

For more information about this error, try `rustc --explain E0277`.
````

suggestion applied:

````rust
trait Foo<T> {
    type Bar;
    fn get_bar(&self) -> Self::Bar;
}

fn f<T:Foo<isize> + Foo<usize> + Foo<T>>(t: &T) {
    let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
}

fn main() { }

````

final error WHICH ACTUALLY HINTS TO THE ACTUAL PROBLEM :D

````
error[E0308]: mismatched types
 --> src/lib.rs:7:37
  |
6 | fn f<T:Foo<isize> + Foo<usize> + Foo<T>>(t: &T) {
  |      - this type parameter
7 |     let u: <T as Foo<usize>>::Bar = <T as Foo<T>>::get_bar(t);
  |            ----------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found type parameter `T`
  |            |
  |            expected due to this
  |
  = note: expected associated type `<T as Foo<usize>>::Bar`
             found associated type `<T as Foo<T>>::Bar`
````