Skip to content

Confusing "type mismatch" error report: the types might differ while pretty-printer prints them in exactly the same way #23252

Closed
@golddranks

Description

@golddranks

I just encountered this error: (newlines added to hightlight the sameness of the pretty-printer result)

error: type mismatch:
the type `fn(&mut iron::request::Request<'_>) -> core::result::Result<iron::response::Response, iron::error::IronError> {frontpage}` implements the trait
`for<'r,'r> core::ops::Fn<(&'r mut iron::request::Request<'r>,)>`, but the trait
`for<'r,'r> core::ops::Fn<(&'r mut iron::request::Request<'r>,)>` is required (expected struct
`iron::request::Request`, found a different struct 
`iron::request::Request`) [E0281]

This happened to me, because I had my own debugging version of Iron linked in my Cargo.toml. However, I also had the vanilla straight-from-cargo version of Iron extension, Router, linked. Thus, my own code referenced different "iron" crate than the Router code. This made the error report confusing: it looks like the type is the exactly same, although it's from different crate.

I think there's a very simple fix: just check if the traits pretty-prints are exactly the same, and if they are, provide additional information why they are different: i.e. print the paths of the crates they are from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions