Confused about enum variants visibility


#1

To my surprise, rust accepts visibility modifiers for enum variants. For example, the following code is valid:

enum Foo {
    pub Bar,
    Quux
}

What is the semantics of variants visibility? Why would I want to mark only some of enum’s variants as public?


#2

At one point, long ago, fields of structs were public by default, and could be made private with the priv keyword. Like struct fields, enum variants could also be private. RFC #1 changed this behavior to make fields private by default and removed the ability for variants to be private. It looks like the parser was never properly updated to forbid visibility modifiers on enum variants.


#3

FYI, this is now fixed: https://github.com/rust-lang/rust/pull/28442