..
should be suggested when attempting to ignore a private enum variant with _
#135903
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
rustc: you might want to ignore the private value by using `..`
Rationale and extra context
On ignoring a pattern in a match, the reference reads:
Their detailed sections read, in part:
and
All of this makes ignoring a value via
_
and..
seem functionally equivalent, and generally this is true, except for when you are ignoring a value whose type is private. In that case,_
causes an error, while..
is fine.I would have assumed that the compiler was able to entirely ignore your "use" of the private type in either case, but given that it isn't so, it would be nice to have a helpful message pointing in that direction. It seems like
_
sufficiently expresses the intent to ignore the private value such that it would justify suggesting..
as an alternative. This would be a reasonable suggestion for 1-tuple data enums and for N-tuple data enums, where assigning a private type to_
can also be replaced with..
.A real world example of where this would have been useful can be seen here: mlua-rs/mlua#502, where I opened an Issue with the mlua project asking for a workaround to allow exhaustive pattern matching in a public enum that had been updated to contain a private type. The library was updated to make the type public but undocumented, but another commenter later pointed out that
..
would have also been an option.It would also be nice to provide similar hints for structs, for example:
In addition to the current error of:
To add something like: "you might want to ignore the field 'a' entirely by using
..
"Other cases
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: