From 7e9b4306fcacb339d7b910a54fb93b0e9d4bef18 Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Mon, 29 Jan 2024 19:56:10 +0100 Subject: [PATCH] include only one variant in compiled code (#2438) --- primitives/core/macros/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/primitives/core/macros/src/lib.rs b/primitives/core/macros/src/lib.rs index 9494db3e0c..9f6d16ef6e 100644 --- a/primitives/core/macros/src/lib.rs +++ b/primitives/core/macros/src/lib.rs @@ -17,19 +17,23 @@ #[macro_export] macro_rules! if_production_or { - ($prod_variant:expr, $non_prod_variant:expr) => { - if cfg!(feature = "production") { - $prod_variant - } else { + ($prod_variant:expr, $non_prod_variant:expr) => {{ + #[cfg(not(feature = "production"))] + { $non_prod_variant } - }; + #[cfg(feature = "production")] + { + $prod_variant + } + }}; } #[macro_export] macro_rules! if_not_production { ($expression:expr) => { - if cfg!(not(feature = "production")) { + #[cfg(not(feature = "production"))] + { $expression } };