Type mismatch when pattern matching to a unit struct could really use some better diagnostics #48062
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
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.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-diagnostics
Working group: Diagnostics
I've answered a question like this every day for the past 3 days... https://users.rust-lang.org/t/how-to-create-a-new-option-serde-json-value-value/15466
The problem is with code like this:
Typically the let binding and the struct definition are much more separated, and the struct definition comes from a glob import. The error received is:
This error isn't wrong, and I'm not even proposing that we remove it. However, in the specific case where the match is on a unit struct, I do think it would be incredibly helpful to add a
help
diagnostic pointing at the span wherefoo
was brought into scope, stating that a struct with zero fields namedfoo
was imported. E.g.I have purposely biased this error message towards
use
vs definition, because I think the overwhelmingly common case is going to be fromuse
not definition (though the error is still reasonable when pointing at the definition).I'd be happy to implement this if it'd be accepted, though I think I'll probably need a bit of help.
The text was updated successfully, but these errors were encountered: