Repository: rust
Issue: Incomplete/confusing description of unsatisfied trait bounds on function (plotters)
Labels: A-diagnostics,T-compiler

When building a small script using the [plotters](https://github.com/38/plotters) library, I got several trait bound errors that took me a long time to actually diagnose. I've provided an [MCVE](https://github.com/cr1901/plotters-error) and perhaps additional error output that would've made the problem clearer.

## Actual Error Output
Given the the linked [repository](https://github.com/cr1901/plotters-error) built with `cargo build`, the current error output is:

```
William@DESKTOP-H0PMN4M MINGW64 ~/Projects/MCVE/plotters-error
$ cargo build
   Compiling plotters-error v0.1.0 (C:\msys64\home\William\Projects\MCVE\plotters-error)
error[E0277]: the trait bound `(): Ranged` is not satisfied
  --> src\main.rs:44:45
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                                             ^^^^^^^^^^^^^^^^^^ the trait `Ranged` is not implemented for `()`
   |
note: required by a bound in `Cartesian2d`
  --> C:\Users\William\.cargo\registry\src\github.com-1ecc6299db9ec823\plotters-0.3.1\src\coord\ranged2d\cartesian.rs:20:27
   |
20 | pub struct Cartesian2d<X: Ranged, Y: Ranged> {
   |                           ^^^^^^ required by this bound in `Cartesian2d`

error[E0277]: the trait bound `Cartesian2d<(), RangedCoordu32>: CoordTranslate` is not satisfied
  --> src\main.rs:44:21
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CoordTranslate` is not implemented for `Cartesian2d<(), RangedCoordu32>`
   |
   = help: the following implementations were found:
             <Cartesian2d<X, Y> as CoordTranslate>
note: required by a bound in `ChartContext`
  --> C:\Users\William\.cargo\registry\src\github.com-1ecc6299db9ec823\plotters-0.3.1\src\chart\context.rs:28:53
   |
28 | pub struct ChartContext<'a, DB: DrawingBackend, CT: CoordTranslate> {
   |                                                     ^^^^^^^^^^^^^^ required by this bound in `ChartContext`

error[E0277]: the trait bound `(): Ranged` is not satisfied
  --> src\main.rs:44:21
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Ranged` is not implemented for `()`
   |
note: required by a bound in `Cartesian2d`
  --> C:\Users\William\.cargo\registry\src\github.com-1ecc6299db9ec823\plotters-0.3.1\src\coord\ranged2d\cartesian.rs:20:27
   |
20 | pub struct Cartesian2d<X: Ranged, Y: Ranged> {
   |                           ^^^^^^ required by this bound in `Cartesian2d`

error[E0277]: the trait bound `Cartesian2d<(), RangedCoordu32>: CoordTranslate` is not satisfied
  --> src\main.rs:44:21
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CoordTranslate` is not implemented for `Cartesian2d<(), RangedCoordu32>`
   |
   = help: the following implementations were found:
             <Cartesian2d<X, Y> as CoordTranslate>
note: required by a bound in `ChartContext`
  --> C:\Users\William\.cargo\registry\src\github.com-1ecc6299db9ec823\plotters-0.3.1\src\chart\context.rs:28:53
   |
28 | pub struct ChartContext<'a, DB: DrawingBackend, CT: CoordTranslate> {
   |                                                     ^^^^^^^^^^^^^^ required by this bound in `ChartContext`

error[E0277]: the trait bound `(): Ranged` is not satisfied
  --> src\main.rs:44:21
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Ranged` is not implemented for `()`
   |
note: required by a bound in `Cartesian2d`
  --> C:\Users\William\.cargo\registry\src\github.com-1ecc6299db9ec823\plotters-0.3.1\src\coord\ranged2d\cartesian.rs:20:27
   |
20 | pub struct Cartesian2d<X: Ranged, Y: Ranged> {
   |                           ^^^^^^ required by this bound in `Cartesian2d`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `plotters-error` due to 5 previous errors
```

## Desired Error Output

### `AsRangedCoord`
Ideally the output should _include_ something like (please note my formatting of the arrows is not perfect):

```
error[E0277]: the trait bound `(): Ranged` is not satisfied for `build_cartesian_2d`
  --> src\main.rs:44:45
   |
44 |     let mut chart = ChartBuilder::on(&root).build_cartesian_2d((), 0u32..500u32)?;
   |                                                                       ^^^^^^^^^^^^^^^^^^
   |
note: required by this bound in `build_cartesian_2d`
  --> C:\path\to\plotters\chart\builder.rs
   |
179 | pub fn build_cartesian_2d<X: AsRangedCoord, Y: AsRangedCoord>(
   |                                                ^^^^^^ required by this bound in `build_cartesian_2d`
```

### `CoordTranslate`
Additionally, I do not find the help for "`CoordTranslate` is not implemented" helpful. The current help text:

```
= help: the following implementations were found:
             <Cartesian2d<X, Y> as CoordTranslate>
```

loses information about _why_ the found trait implementations _cannot_ be used, although the reason _why_ the found trait impl can't be used is implied in an earlier error:

```
20 | pub struct Cartesian2d<X: Ranged, Y: Ranged> {
   |                           ^^^^^^ required by this bound in `Cartesian2d`
```

Perhaps some extra context _in the error I'm currently focusing on_ would help?

```
= help: the following implementations were found:
             <Cartesian2d<X: Ranged, Y: Ranged> as CoordTranslate>
```

## Reasoning
The errors reported are correct, but took me a long time to figure out that _all_ the errors boil down to "`Ranged` isn't satisfied for ()", including an error not reported for `AsRangedCoord`. I think what would've helped me most is reporting that `AsRangedCoord` requirements not being satisfied. The errors already report that _other_ trait bounds can't be satisfied because `Ranged` isn't satisfied (`Cartesian2d`).

The function signature for `build_cartesian_2d` in the [docs](https://docs.rs/plotters/0.3.1/plotters/chart/struct.ChartBuilder.html#method.build_cartesian_2d) looks like this:

```
pub fn build_cartesian_2d<X: AsRangedCoord, Y: AsRangedCoord>(
    &mut self,
    x_spec: X,
    y_spec: Y
) -> Result<ChartContext<'a, DB, Cartesian2d<X::CoordDescType, Y::CoordDescType>>, DrawingAreaErrorKind<DB::ErrorType>>
```

### `AsRangedCoord`/`Cartesian2d`
Because `AsRangedCoord` is the first bounds you see when opening the crate docs, it seems reasonable that "the inputs don't implement `AsRangedCoord`" should be shown as part of the diagnostic, and why (because one of it's associated types is bound by `Ranged`) . The `Ranged` trait doesn't even directly appear in build_cartesian_2d's signature.  

The "`Cartesian2d` does not implement `Ranged`" error is fine as-is, but since my eyes errors starting at inputs first, it wasn't clear to me why `Cartesian2d` was reporting errors on a `Ranged` trait not even in the type signature while the similarly-named `AsRangedCoord` was unaffected. Until I understood how `Ranged` and `AsRangedCoord` are related- clear in retrospect, but not clear when looking at multiple errors at once- I thought this might mean I had to focus on two potential error sources instead of one.

### `CoordTranslate`
At this point, I had to spend more time looking at the function outputs, cross-referencing the documentation of those types' trait bounds back to the function signature of `build_cartesian_2d`.  I got further confused by the `help` for "`Cartesian2d<X, Y>` doesn't implement `CoordTranslate`", whose help message claims that the trait `CoordTranslate` _is_ implemented for `Cartesian2d<X,Y>`.

I can scroll up to the previous error to find more context why this implementation for `Cartesian2d<X,Y>` is unusable (I can't actually _make_ a `Cartesian2d<(), RangedCoordu32>`, so it can't possibly satisfy the trait bound `CoordTranslate`). But my eyes tend to focus on one error at a time. _Not understanding the help message immediately was another reason I was looking for hints with `AsRangedCoord` rather than the reported errors._

## Additional Context
I tried this MCVE with two Rust compilers and got the same error output (besides paths):

```
rustc 1.56.0-nightly (d3e2578c3 2021-08-21)
binary: rustc
commit-hash: d3e2578c31688619ddc0a10ddf8543bf4ebcba5b
commit-date: 2021-08-21
host: x86_64-pc-windows-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0
```

```
rustc 1.57.0-nightly (4e89811b4 2021-10-16)
binary: rustc
commit-hash: 4e89811b46323f432544f9c4006e40d5e5d7663f
commit-date: 2021-10-16
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0
```

I also tried duplicating this message in the [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9a1400f1796cbaeace2d3a6f26dd3360), but concluded that I needed to re-implement too much of the crate to trigger the error. @estebank [told me](https://twitter.com/ekuber/status/1447484249146380289) about the `-Z everybody_loops` option that I haven't tried yet, however. So perhaps I can minimize this further.