Text of rust.docs.kernel.org › core › macro.cfg.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

cfg in core - Rust

Skip to main content cfg core Macro cfg 1.6.0 · Source macro_rules! cfg { ($($cfg:tt)*) => { ... }; } Expand description Evaluates boolean combinations of configuration flags at compile-time. In addition to the #[cfg] attribute, this macro is provided to allow boolean expression evaluation of configuration flags. This frequently leads to less duplicated code. The syntax given to this macro is the same syntax as the cfg attribute. cfg! , unlike #[cfg] , does not remove any code and only evaluates to true or false.

For example, all blocks in an if/else expression need to be valid when cfg! is used for the condition, regardless of what cfg! is evaluating. § Examples let my_directory = if cfg! (windows) { "windows-specific-directory" } else { "unix-directory" };