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

Type mismatch with generic parameter returns less than helpful errors #43943

Open
mqudsi opened this Issue Aug 17, 2017 · 0 comments

Comments

Projects
None yet
3 participants
@mqudsi
Copy link

mqudsi commented Aug 17, 2017

When a type does not match a generic parameter (I'm not sure if it's treated differently if it's because a generic constraint failed or because a previous usage dictated a particular variant of that generic), the resulting error message is not helpful because it seems to indicate that everything is OK.

As an example:

error[E0308]: mismatched types
  --> src/main.rs:80:23
   |
80 |             return Ok(response);
   |                       ^^^^^^^^ expected type parameter, found struct `std::io::Cursor`
   |
   = note: expected type `tiny_http::Response<R>`
              found type `tiny_http::Response<std::io::Cursor<std::vec::Vec<u8>>>`
   = help: here are some functions which might fulfill your needs:
           - .with_data(...)
           - .with_header(...)
           - .with_status_code(...)

the method in question was declared as

fn send_email<R>(req: &mut Request) -> Result<Response<R>, String>
    where R: std::io::Read

I believe the compiler message should at least indicate the constraints on R, because as it currently reads, tiny_http::Response<std::io::Cursor<std::vec::Vec<u8>>> is a valid form of tiny_http::Response<R> for R=std::io::Cursor<std::vec::Vec<u8>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.