Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upType mismatch error should have spans if it's too long #21025
Comments
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
I think there may already be an issue on this (@wycats, do you remember?), but I think another approach here is to change the formatting so that the expected/found types are on separate lines, aligned horizontally, with diffs (identified textually) highlighted in red. This would be fantastic to implement but probably requires a richer alternative to |
This comment has been minimized.
This comment has been minimized.
|
Something like |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Big +1. This would be a killer feature and one that every beginner would soon be aware of :) |
kmcallister
added
the
A-diagnostics
label
Jan 12, 2015
This comment has been minimized.
This comment has been minimized.
|
We frequently run into problems like these. Thankfully we have already seen some significant improvements, primarily that errors like this are now split up into several lines, and that Rust actually tries (with varying success) to point out where it happened. For example, the error mentioned by @Manishearth now looks like this:
Which is already much better. For us, it would be immensely helpful, if a lot of the superfluous stuff was removed from the "found" part of the error message. The "expected" part is nicely trimmed, with underscores replacing irrelevant type parameters. Ideally, the error message would look something like:
(With or without the |
This comment has been minimized.
This comment has been minimized.
|
Or, to put it more simply, consider the following code struct Foo<T, U> ( u8 );
fn bar(x: Foo<u8, i8>) {
}
fn main() {
let x: Foo<u8, u8> = Foo(42);
bar(x);
}We get the following error message: foo.rs:9:7: 9:8 error: mismatched types:
expected `Foo<u8, i8>`,
found `Foo<u8, i64>`
(expected i8,
found i64)
foo.rs:9 bar(x);
^
error: aborting due to previous errorIdeally, Rust could replace |
This comment has been minimized.
This comment has been minimized.
|
Another case:
would be much easier to read if (a) it factored out the common type and (b) suggested a fix:
|
This comment has been minimized.
This comment has been minimized.
|
Triage; still lots of room for improvement here. |
This comment has been minimized.
This comment has been minimized.
|
I can see five possible cases:
For the 1st case, I like @dhardy's proposal:
For the 2nd case, I can't think of a nice way to present it over what we already have: the types are simply wrong. For the 3rd case it currently would look a bit like this, which I don't think is too bad:
but could be changed to look this way to look consistent with the 1st case's (this example is for the 4th case, but it'd look practically the same for the 3rd case):
Supporting this case could get hairy quickly. For example, how many type parameters before you are noisier than the current message? The 5th case is the same as the 1st one, only reversed:
The way I see it, there's nothing that could be done for the 2nd case, supporting the 4th could be tricky to get right, and the 3rd case is already somewhat clean. That leaves case 1 and 5 as the most highly actionable messages to work on (finding if there're sub matches on type inequality), with the possibility to clean up the 3rd case slightly as asked by @Munksgaard (replace types parameters that are are equal with underscore on message). Does that look right? |
Manishearth commentedJan 12, 2015
It would be useful if there was a note as to where the
()andStringfrom(expected (), found struct collections::string::String)were for large types.An additional note that's shown when the error report is above x (300?) characters which highlights the mismatched types (using something like our
^~~~~~for code spans) would be useful.