Skip to content

visibility modifiers are accepted for enum variants #28433

Closed
@matklad

Description

@matklad

The following code compiles without warnings:

#[allow(dead_code)]
enum Foo {
    pub Spam,
    Eggs
}

fn main() {

}

I guess that this should be forbidden, because enum vairants inherit visibility of the enum itself. At minimum, this should produce a warning.

This is the relevant line from parser: https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs#L5203

This is the discussion on Rust forum: https://users.rust-lang.org/t/confused-about-enum-variants-visibility/2873

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions