macro
cfg! — Evaluate a compile-time configuration predicate
Evaluate a configuration predicate to a bool during compilation. Unlike the #[cfg] attribute, cfg! does not remove source code; both branches of a surrounding if must still be valid Rust. This example assumes a target with 32-bit or 64-bit pointers. Expression result: bool. Expected result (not executed): stdout: 'Common pointer width: true\n'; no stderr. Common mistake: Placing target-specific unresolved symbols inside an if cfg!(...) branch; use #[cfg] to omit unavailable code.
Formal Syntax & Structure
rust syntaxrust
cfg!(predicate)Working Example
Example Snippetrust
fn main() { let supported = cfg!(any(target_pointer_width = "32", target_pointer_width = "64")); println!("Common pointer width: {supported}");}