[diagnostics] Attempting to destructure a private field in a public tuple struct yields confusing error message #75907
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-visibility
Area: Visibility / privacy.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
This is the destructure counterpart of #75906
Overview
Attempting to destructure a private field in a public tuple struct yields a confusing error message. Given the following code:
The following error is generated:
This seems quite helpful: some field is private, so we can infer we probably should make it public instead. However when we convert the code to a tuple struct things become more confusing:
The following error is generated:
The error message itself doesn't point us to the problem (
expected tuple struct or tuple variant, found struct Bar
), and mentioning a constructor in the code block isn't helpful either. After all we're not trying to construct anything; we're trying to destruct.Proposed solution
When accessing a private field in a tuple struct rustc already generates pretty good errors:
When destructuring tuple structs these errors would be accurate as well:
We could take it even further and suggest a fix for this as well:
Conclusion
In this issue I've shown an incorrect error message that occurs when attempting to destructure a private field in a tuple-struct, and made suggestions on how we can improve this.
I hope this is helpful. Thanks!
The text was updated successfully, but these errors were encountered: