-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference failure leads to incorrect "match arm with an incompatible type" message #57206
Comments
This is because the compiler is trying to unify a type for the entire |
Tweak "incompatible match arms" error - Point at the body expression of the match arm with the type error. - Point at the prior match arms explicitly stating the evaluated type. - Point at the entire match expr in a secondary span, instead of primary. - For type errors in the first match arm, the cause is outside of the match, treat as implicit block error to give a more appropriate error. Fix rust-lang#46776, fix rust-lang#57206. CC rust-lang#24157, rust-lang#38234.
Tweak "incompatible match arms" error - Point at the body expression of the match arm with the type error. - Point at the prior match arms explicitly stating the evaluated type. - Point at the entire match expr in a secondary span, instead of primary. - For type errors in the first match arm, the cause is outside of the match, treat as implicit block error to give a more appropriate error. Fix rust-lang#46776, fix rust-lang#57206. CC rust-lang#24157, rust-lang#38234.
In the code sample below, there are two ultimately identical functions with the same problem, but while the compiler correctly reports the incorrect match block in the first function (
test_func1()
), it fails to do so in the second (test_func2()
):which produces the following correct error for the first function:
but an incorrect error for the second message:
When
test_func2()
is extended with an explicit type hint (that should not be necessary as it can be derived from the existing code), the resulting error message is correct once again:producing
The text was updated successfully, but these errors were encountered: