From 8af45d24ce10af123f59e66c0c235c698ac67d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 8 Jul 2024 16:02:48 +0200 Subject: [PATCH] sp-core: Improve docs generated by `generate_feature_enabled_macro` (#4968) Now: ![image](https://github.com/paritytech/polkadot-sdk/assets/5718007/01545872-e21b-48b9-9913-4b940ff3f361) Before: ![image](https://github.com/paritytech/polkadot-sdk/assets/5718007/09ae9fa4-eca8-43f7-a083-a4555e392610) We sadly can not remove the `_macro_name`, but this way we at least show the correct macro plus docs. --- substrate/primitives/core/src/lib.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/substrate/primitives/core/src/lib.rs b/substrate/primitives/core/src/lib.rs index 098bd135bfeb..78ec92e4be98 100644 --- a/substrate/primitives/core/src/lib.rs +++ b/substrate/primitives/core/src/lib.rs @@ -430,16 +430,7 @@ pub const MAX_POSSIBLE_ALLOCATION: u32 = 33554432; // 2^25 bytes, 32 MiB macro_rules! generate_feature_enabled_macro { ( $macro_name:ident, $feature_name:meta, $d:tt ) => { $crate::paste::paste!{ - /// Enable/disable the given code depending on - #[doc = concat!("`", stringify!($feature_name), "`")] - /// being enabled for the crate or not. - /// - /// # Example /// - /// ```nocompile - /// // Will add the code depending on the feature being enabled or not. - #[doc = concat!(stringify!($macro_name), "!( println!(\"Hello\") )")] - /// ``` #[cfg($feature_name)] #[macro_export] macro_rules! [<_ $macro_name>] { @@ -448,6 +439,13 @@ macro_rules! generate_feature_enabled_macro { } } + /// + #[cfg(not($feature_name))] + #[macro_export] + macro_rules! [<_ $macro_name>] { + ( $d ( $d input:tt )* ) => {}; + } + /// Enable/disable the given code depending on #[doc = concat!("`", stringify!($feature_name), "`")] /// being enabled for the crate or not. @@ -458,15 +456,8 @@ macro_rules! generate_feature_enabled_macro { /// // Will add the code depending on the feature being enabled or not. #[doc = concat!(stringify!($macro_name), "!( println!(\"Hello\") )")] /// ``` - #[cfg(not($feature_name))] - #[macro_export] - macro_rules! [<_ $macro_name>] { - ( $d ( $d input:tt )* ) => {}; - } - - // Work around for: - #[doc(hidden)] - pub use [<_ $macro_name>] as $macro_name; + // https://github.com/rust-lang/rust/pull/52234 + pub use [<_ $macro_name>] as $macro_name; } }; }