[diagnostics] Attempting to initialize a private field in a public tuple struct yields confusing error message #75906
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 a constructor counterpart to #75907
Overview
Errors for private fields in public non-tuple structs are pretty good. Given the following code:
The following error is returned:
A hint could be useful here, but overall this is good enough to understand. However when we convert this to a tuple struct the errors get more confusing:
This yields the following error:
The message of
expected function, tuple struct or tuple variant, found struct Bar
is not helpful here. It's a bit confusing what the fix is: how do we make the constructor visible? I had to look up how to declare visibility for inner fields in tuple structs.Proposed solution
The error message could probably use some work. Something closer to the text of non-tuple structs would be clearer:
Or perhaps an even better direction would be:
The main code block seems useful. But we could go even further and provide a hint on how to fix this if the struct is defined inside the same project:
Conclusion
I found a location where our errors aren't as good as they could be, and figured there may be a way we can use that to not just improve the error message -- but actually teach people about visibility modifiers in tuple structs.
I hope this is helpful. Thanks!
The text was updated successfully, but these errors were encountered: