Skip to content

Make documentation clear about conditional compilation use #15494

Closed
@Qantas94Heavy

Description

@Qantas94Heavy

From what I read of the documentation, only whole items/modules/crates can be processed through conditional compilation.

Static entities in Rust — crates, modules and items — may have attributes applied to them.

Though this is not in the documentation, this seems to work:

fn main() {
    println!("{}", Blue as int);
    println!("{}", Green as int);
}

enum Color {
  Red = 0xff0000,
  #[cfg(windows)]
  Green = 0x00ff00,
  Blue = 0x0000ff
}

As expected, the compiler throws an error (on Linux):

<anon>:3:20: 3:25 error: unresolved name Green.

However, it's not clear in the documentation what is the scope of the attribute in this instance. Have I got my idea of what is an item wrong, or is this merely an oversight in the documentation?

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