-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Type mismatch when pattern matching to a unit struct could really use some better diagnostics #48062
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
helpdiagnostic pointing at the span wherefoowas brought into scope, stating that a struct with zero fields namedfoowas imported. E.g.I have purposely biased this error message towards
usevs definition, because I think the overwhelmingly common case is going to be fromusenot 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.