Scope of a #[cfg(...)]?

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 cfg attribute 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:

1 Like