Skip to content

Unclear error message when using Result instead of Ok #43871

Closed
@joepie91

Description

@joepie91

I made the mistake of trying to do if let Result(foo) = bar instead of if let Ok(foo) = bar, and got a confusing error like the following:

error[E0532]: expected tuple struct/variant, found enum `Result`
  --> src/service/prime.rs:18:16
   |
18 |         if let Result(parsed_number) = request.parse::<u64>() {
   |                ^^^^^^ not a tuple struct/variant

It took me a while to figure out what was wrong here; the error index entry for this error code was not very helpful either. Part of the problem is that the error tells me what it isn't, but not how what it is relates to that. To a beginner, the relationship between an Enum and one of its variants won't be intuitively obvious.

Perhaps the compiler feedback could also be improved here by suggesting Ok/Err (for Result) and Some/None (for Option), as these are common cases where this might occur. A more generic approach would be to simply list expected/valid variants for the specified Enum.

(As an aside, the contributing guidelines claimed that there would be an issue template, but there doesn't seem to be. I'm not sure whether that is intentional or not.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions