Skip to content

#[cfg] does not filter struct fields or enum variants #11085

@huonw

Description

@huonw
struct Foo {
    #[cfg(foo)]
    a: int,
    #[cfg(not(foo))]
    a: uint
}

/*
enum Bar {
    #[cfg(bar)]
    Baz(int),
    #[cfg(not(bar))]
    Baz(uint)
}
*/

fn main() {}
$ rustc cfg-variant-fields.rs
cfg-variant-fields.rs:5:4: 5:11 error: field `a` is already declared
cfg-variant-fields.rs:5     a: uint
                            ^~~~~~~
cfg-variant-fields.rs:3:4: 3:10 note: Previously declared here
cfg-variant-fields.rs:3     a: int,
                            ^~~~~~

Uncommenting the enum gives a similar error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions