Skip to content

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

Open
@mqudsi

Description

@mqudsi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions