What entities do attributes such as #[cfg(windows)] operate on?
It's possible to put an if, else chain behind a #[cfg(...)], but not a let foo = ...;, but what's the exact rule?
What entities do attributes such as #[cfg(windows)] operate on?
It's possible to put an if, else chain behind a #[cfg(...)], but not a let foo = ...;, but what's the exact rule?
https://doc.rust-lang.org/reference/conditional-compilation.html?highlight=cfg#the-cfg-attribute
The
cfgattribute is allowed anywhere attributes are allowed.
https://doc.rust-lang.org/reference/attributes.html?highlight=attribute#attributes
Attributes may be applied to many things in the language:
- All item declarations accept outer > attributes while external blocks, functions, implementations, and modules accept inner attributes.
- Most statements accept outer attributes (see Expression Attributes for limitations on expression statements).
- Block expressions accept outer and inner attributes, but only when they are the outer expression of an expression statement or the final expression of another block expression.
- Enum variants and struct and union fields accept outer attributes.
- Match expression arms accept outer attributes.
- Generic lifetime or type parameter accept outer attributes.
- Expressions accept outer attributes in limited situations, see Expression Attributes for details.
- Function, closure and function pointer parameters accept outer attributes. This includes attributes on variadic parameters denoted with
...in function pointers and external blocks.