Skip to content

Private enum variants #32770

Closed
Closed
@SimonSapin

Description

@SimonSapin

https://stackoverflow.com/questions/36440021/whats-purpose-of-errorkind-nonexhaustive explains why the std::io::ErrorKind enum has this variant:

    #[unstable(feature = "io_error_internals",
               reason = "better expressed through extensible enums that this \
                         enum cannot be exhaustively matched against",
               issue = "0")]
    #[doc(hidden)]
    __Nonexhaustive,

It is to force users to have a catch-all _ arm when matching on an ErrorKind value, 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, ErrorKind abuses 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 pub or priv keywords, like we do for struct fields. Given the above, should this be reconsidered?

CC @aturon & lang team

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-visibilityArea: Visibility / privacy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions