"try expression alternatives have incompatible types" is confusing wording #71309
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-incorrect
Diagnostics: A diagnostic that is giving misleading or incorrect information.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
F-try_blocks
`#![feature(try_blocks)]`
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Simple example:
Compilation result (
rust version 1.44.0-nightly (52fa23add 2020-04-18)
):Parts of this diagnostic are great, showing the mismatched types (
u32
andi32
) and even suggesting a valid possible fix. But the wording of the error itself is confusing. What "try expression alternatives"? I don't see any alternatives.Taking a glance at the compiler implementation, it's referring to the arms of the
match
block that?
desugars into. But it's confusing to talk about those, because:They're not visible to the user.
Why would there be a type mismatch between the arms in the first place, if there are only two arms and one of them always ends in a
return
rather than producing a value? Did type inference infer the error branch as having typeu32
due to the context?If so, the message is technically accurate, but unhelpful: from the user's point of view, the 'real' issue is a mismatch between the expected type of
x?
(namelyi32
) and the context. As far as I can imagine, this is the only possible cause of a type mismatch between the arms of a desugared?
. So it seems like it would be fine to just change the error message to not mention the arms.As a sidenote, if I take the
-Zunpretty=hir
output and try to compile that:...oddly enough, I don't get a "match arms have incompatible types" error, but a more helpful one instead:
The text was updated successfully, but these errors were encountered: