Improving error messages

I completely agree. This request has appeared multiple times, rightfully so. #21934 keeps track of the discussion around this. I can't promise anything in the short term, but I've been ruminating about how to implement this in such a way that will work with incremental compilation (the internal state of the compiler would allow you to keep a separate per scope mapping for local names, but this would depend on NodeIds which, as I understand it, change on subsequent compilations, so it is not suitable to do this).

This should be possible to do now with little effort. I can't come up with any objection to this, so I will look into writing mentoring instructions for it when I create this ticket.

Currently there's some type elision going on when possible (think Some(3) != Ok(3) => Option<_> != Result<_, _>, but there's plenty of improvement that can be done in this front. Some relevant tickets with plenty of background about some different alternatives: #21025 :closed_book: , #39906 :closed_book: , #43943 :open_book: and #40186 :open_book: .

This is something I've looked into. The compiler would need to start tracking more information than it does now during typeck to keep the span for the first cause of the current type requirement. There is some tracking of this already, but it is lost in some boundaries. Having said that, the compiler should be pointing out with spans something that would read along the lines of expected X, found Y, because x was assigned foo() that returns type argument Z that impls Y but not X (contrived example). #14007 tracks this request.

I have filed #44530 to deal with the first issue you're likely to come across when trying impl Trait. Feel free to add comments and expand on desired output, as well as point out other cases that you would like addressed.

5 Likes