Associated types cause "expected" and "found" to be reversed in error messages #63211
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-type-system
Area: Type system
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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 typei8
". That's... not right, though, obviously, since the right-hand side matchesIterator<Item=u32>
, and the left side requiresIterator<Item=i8>
-- so it should be expectingi8
and findingu32
. For a MCVE (playground):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);
andlet _: 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.
The text was updated successfully, but these errors were encountered: