Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPrivate enum variants #32770
Comments
This comment has been minimized.
This comment has been minimized.
|
AFAIR, private variants/variant fields/trait items were considered rarely necessary and nobody wanted to make them private by default, and at the same time nobody wanted to revive |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin This is indeed a There are a couple ways we might go about this:
Given that we've already accepted the new privacy mechanism, I suspect that'll be the way to go here. (Of course, it still needs to be implemented!) |
This comment has been minimized.
This comment has been minimized.
|
@aturon RFC 1422 didn't address enums. Is |
This comment has been minimized.
This comment has been minimized.
|
@durka Ah! You're right, the RFC's detailed design only covers an expansion of the grammar for places that currently permit I had always assumed that this RFC would also introduce new locations for Paging @rust-lang/lang! |
This comment has been minimized.
This comment has been minimized.
|
@aturon I am in favor of permitting |
This comment has been minimized.
This comment has been minimized.
|
Another possibility for a dedicated mechanism is an attribute on the enum to control whether or not exhaustive matches are allowed, e.g. |
This comment has been minimized.
This comment has been minimized.
|
I’m not a fan of |
This comment has been minimized.
This comment has been minimized.
|
For compareason with other languages, OCaml has a lint that a lot of people use that warns (or errors, depending on the flags passed to the compiler) about There is also another (newer) feature: open variants. type my_variant = ..
my_variant += Foo(int)
my_variant += Bar(string)New variants can be added anywhere, even in other modules. The OCaml also has variants with |
petrochenkov
referenced this issue
Feb 1, 2017
Closed
Tracking issue for `pub(restricted)` privacy (RFC #1422) #32409
petrochenkov
self-assigned this
Feb 19, 2017
petrochenkov
added
A-resolve
A-visibility
labels
Feb 19, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm going to close this in favor of rust-lang/rfcs#943. |
SimonSapin commentedApr 6, 2016
https://stackoverflow.com/questions/36440021/whats-purpose-of-errorkind-nonexhaustive explains why the
std::io::ErrorKindenum has this variant:It is to force users to have a catch-all
_arm when matching on anErrorKindvalue, so that more variants can be added in the future.Clearly this is a future-proofing mechanism that is useful. There is no reason it wouldn’t be as useful in external libraries on crates.io than in the standard library. But to achieve it,
ErrorKindabuses the stability mechanism with#[unstable], which can only be used in the standard library.I’m sure this was discussed before, but a quick search did not show why we don’t allow variants of the same enum to have different privacy/visibility with
puborprivkeywords, like we do for struct fields. Given the above, should this be reconsidered?CC @aturon & lang team