Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve output of E0271 #40186

Closed
seanmonstar opened this issue Mar 1, 2017 · 6 comments · Fixed by #106596
Closed

Improve output of E0271 #40186

seanmonstar opened this issue Mar 1, 2017 · 6 comments · Fixed by #106596
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@seanmonstar
Copy link
Contributor

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:

error[E0271]: type mismatch resolving `<futures::AndThen<futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@src/consumer/pinger.rs:100:41: 107:18 uri:_, request_type:_, correlation_id:_, tx:_, event:_]>, [closure@src/consumer/pinger.rs:107:35: 110:18], futures::FutureResult<std::vec::Vec<u8>, futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>>, std::vec::Vec<u8>>, futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>, [closure@src/consumer/pinger.rs:110:29: 127:18 timer:_, status_code:_, response_status:_, uri:_, tx:_, event:_, headers:_, request_type:_, correlation_id:_]> as futures::IntoFuture>::Error == futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>`
   |
16 |     Box::new(
   |     ^ expected futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>, found struct `io::Error`
   |
   = note: expected type `futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>`
   = note:    found type `io::Error`
   = note: required for the cast to the object type `Future<Error=futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>> + 'static`

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:

error[E0271]: type mismatch resolving `<futures::AndThen<...>::Error`
   |
16 |     Box::new(
   |     ^ expected futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>, found struct `io::Error`
   |
   = note: expected type `futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>`
   = note:    found type `io::Error`
   = note: required for the cast to the object type `Future<Error=futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>> + 'static`
   = note: full type is `<futures::AndThen<futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@src/consumer/pinger.rs:100:41: 107:18 uri:_, request_type:_, correlation_id:_, tx:_, event:_]>, [closure@src/consumer/pinger.rs:107:35: 110:18], futures::FutureResult<std::vec::Vec<u8>, futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>>, std::vec::Vec<u8>>, futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>, [closure@src/consumer/pinger.rs:110:29: 127:18 timer:_, status_code:_, response_status:_, uri:_, tx:_, event:_, headers:_, request_type:_, correlation_id:_]> as futures::IntoFuture>::Error == futures::sink::Send<futures::sync::mpsc::Sender<(events::http_request_event::HttpRequestEvent, std::result::Result<consumer::pinger::HttpResult, consumer::pinger::HttpResult>)>>`

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.

error[E0271]: type mismatch resolving `<futures::AndThen<...>::Error`
   |
16 |     Box::new(
   |     ^ expected futures::sink::Send<...>, found struct `io::Error`
   |
   = note: expected type `futures::sink::Send<...>`
   = note:    found type `io::Error`

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Mar 1, 2017

cc @jonathandturner

@estebank
Copy link
Contributor

estebank commented Mar 7, 2017

Related to #21025 (& closed PR #39906).

@alexcrichton alexcrichton added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 10, 2017
@alexcrichton
Copy link
Member

I was searching around for this issue, writing down some keywords so I hopefully can find it easier in the future:

  • future
  • too long error message
  • message too long

TimNN added a commit to TimNN/rust that referenced this issue Apr 12, 2017
…, r=nikomatsakis

Highlight and simplify mismatched types

Shorten mismatched types errors by replacing subtypes that are not
different with `_`, and highlighting only the subtypes that are
different.

Given a file

```rust
struct X<T1, T2> {
    x: T1,
    y: T2,
}

fn foo() -> X<X<String, String>, String> {
    X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
}

fn bar() -> Option<String> {
    "".to_string()
}
```

provide the following output

```rust
error[E0308]: mismatched types
  --> file.rs:6:5
   |
 6 |     X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found {integer}
   |
   = note: expected type `X<X<_, std::string::String>, _>`
                                 ^^^^^^^^^^^^^^^^^^^   // < highlighted
              found type `X<X<_, {integer}>, _>`
                                 ^^^^^^^^^             // < highlighted

error[E0308]: mismatched types
  --> file.rs:6:5
   |
10 |     "".to_string()
   |     ^^^^^^^^^^^^^^ expected struct `std::option::Option`, found `std::string::String`
   |
   = note: expected type `Option<std::string::String>`
                          ^^^^^^^                   ^  // < highlighted
              found type `std::string::String`
```

Fix rust-lang#21025. Re: rust-lang#40186. Follow up to rust-lang#39906.

I'm looking to change how this output is accomplished so that it doesn't create list of strings to pass around, but rather add an elided `Ty` placeholder, and use the same string formatting for normal types. I'll be doing that soonish.

r? @nikomatsakis
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank
Copy link
Contributor

Re #43354

@estebank
Copy link
Contributor

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>`

@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
@estebank
Copy link
Contributor

estebank commented Jan 8, 2023

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>`

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 12, 2023
@bors bors closed this as completed in f1ffe82 Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants