Description
TL;DR: Iterator<Item=...>
type mismatches are described wrong.
In some cases -- I've reproduced consistently with associated types, but haven't explored further -- type mismatches are reported incorrectly, with the expected type being reported as "found" and the actual type being reported as "expected".
For example, let _: &Iterator<Item=i8> = &vec![1u32].iter()
produces an error where it "expected type &u32
; found type i8
". That's... not right, though, obviously, since the right-hand side matches Iterator<Item=u32>
, and the left side requires Iterator<Item=i8>
-- so it should be expecting i8
and finding u32
. For a MCVE (playground):
trait F {
type T;
}
struct Fi<A>(A);
impl<A> F for Fi<A> {
type T = A;
}
fn main() {
let _: &dyn F<T=i8> = &Fi(1u32);
}
This is a relatively small bug, but it makes debugging extremely difficult when you don't know what's happening, and just see that it's expecting exactly the type you're providing it.
It does not occur with generics, or plain wrong types -- e.g. let _: Fi<i8> = Fi(1u32);
and let _: i8 = 1u32
both fail with correct error messages.
I think this might be the same as #57226, but I wanted to bump the issue (since that one hasn't had any attention and I think this is important) as well as provide a somewhat clearer, more minimal example.
Occurs with rustc 1.38.0-nightly as well as beta and stable.