-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
"try expression alternatives have incompatible types" is confusing wording #71309
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-try_blocks`#![feature(try_blocks)]``#![feature(try_blocks)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-try_blocks`#![feature(try_blocks)]``#![feature(try_blocks)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Simple example:
Compilation result (
rust version 1.44.0-nightly (52fa23add 2020-04-18)):Parts of this diagnostic are great, showing the mismatched types (
u32andi32) 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
matchblock 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
returnrather than producing a value? Did type inference infer the error branch as having typeu32due 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=hiroutput and try to compile that:...oddly enough, I don't get a "match arms have incompatible types" error, but a more helpful one instead: