Closed seanmonstar closed 1 year ago
cc @jonathandturner
Related to #21025 (& closed PR #39906).
I was searching around for this issue, writing down some keywords so I hopefully can find it easier in the future:
Current output:
error[E0271]: type mismatch resolving `<std::result::Result<std::result::Result<(), std::result::Result<std::result::Result<(), std::result::Result<std::result::Result<(), std::option::Option<{integer}>>, ()>>, ()>>, ()> as Future>::Error == Foo`
--> src/main.rs:16:5
|
16 | / Box::new(
17 | | Ok::<_, ()>(
18 | | Err::<(), _>(
19 | | Ok::<_, ()>(
... |
28 | | )
29 | | )
| |_____^ expected (), found struct `Foo`
|
= note: expected type `()`
found type `Foo`
= note: required for the cast to the object type `dyn Future<Error = Foo>`
Triage: few changes
error[[E0271]](https://doc.rust-lang.org/nightly/error-index.html#E0271): type mismatch resolving `<Result<Result<(), Result<Result<(), Result<Result<(), Option<{integer}>>, ()>>, ()>>, ()> as Future>::Error == Foo`
--> src/main.rs:16:5
|
16 | / Box::new(
17 | | Ok::<_, ()>(
18 | | Err::<(), _>(
19 | | Ok::<_, ()>(
... |
28 | | )
29 | | )
| |_____^ type mismatch resolving `<Result<Result<(), Result<Result<(), Result<Result<(), Option<{integer}>>, ()>>, ()>>, ()> as Future>::Error == Foo`
|
note: expected this to be `Foo`
--> src/main.rs:6:18
|
6 | type Error = E;
| ^
= note: required for the cast from `Result<Result<(), Result<Result<(), Result<Result<(), Option<{integer}>>, ()>>, ()>>, ()>` to the object type `dyn Future<Error = Foo>`
This error is encountered often with futures and tokio, where a returned future has an associated type that doesn't match the expected return type.
An example of current behavior:
And a playpen of a the current behavior (though the error is much smaller): https://is.gd/iigJ2p
A message like this pushes the actionable information down several lines. It may help to instead, output something like this:
Additionally, it might be even clearer to omit some of the type parameters (leaving enough to differentiate) in the 'expected' and 'found' notes, leaving the full type for the bottom note.
cc @eddyb