in impl A for B
, report trait/impl sig inconsistency before method/body inconsistency
#15657
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
How often have you seen a message like:
when writing an impl, and responded (with some head-scratching): "Nonsense! This trait's method definitely returns an int, not unit!" ... only to then read further down the compiler output and see:
I know it happens to me a lot.
Sample code to illustrate this:
which yields the transcript:
As noted in the program comment, there can be an arbitrary number of type errors before one sees the report of the signature mismatch between the trait and its impl.
In principle there is no "100% right" ordering here between these messages, because there are scenarios where the right response to this message is to revise the trait definition (so that its method signature is changed to match the one in the impl you are writing).
But I believe that in most cases, the trait definition has been worked out long ahead of time (and is often fixed/unchangeable), while the impl itself is under active development, and therefore it would be more helpful to the user if in the final error report, the mismatches between the trait and its impl(s) are reported before the error when attempting to type-check the body of the impl itself.
(I am not super familiar with the code that drives these checks; it could be that fixing this is as simple as reordering a few statements.)
The text was updated successfully, but these errors were encountered: