Skip to content

Commit

Permalink
sp-core: Improve docs generated by generate_feature_enabled_macro (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored and TomaszWaszczyk committed Jul 13, 2024
1 parent bd66f24 commit 83f8c38
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions substrate/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>] {
Expand All @@ -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.
Expand All @@ -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: <https://github.com/rust-lang/rust/pull/52234>
#[doc(hidden)]
pub use [<_ $macro_name>] as $macro_name;
// https://github.com/rust-lang/rust/pull/52234
pub use [<_ $macro_name>] as $macro_name;
}
};
}
Expand Down

0 comments on commit 83f8c38

Please sign in to comment.