Skip to content

Commit

Permalink
Merge pull request #330 from KodrAus/fix/missing-docs
Browse files Browse the repository at this point in the history
Fix up missing docs for consts within consts
  • Loading branch information
KodrAus committed Apr 3, 2023
2 parents 83359a6 + 7eb912a commit 98b85d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/example_generated.rs
Expand Up @@ -28,7 +28,11 @@ __impl_internal_bitflags! {
}

__impl_public_bitflags! {
Flags: u32, Field0, Iter, IterRaw {
Flags: u32, Field0, Iter, IterRaw;
}

__impl_public_bitflags_consts! {
Flags {
A = 0b00000001;
B = 0b00000010;
C = 0b00000100;
Expand Down
23 changes: 17 additions & 6 deletions src/lib.rs
Expand Up @@ -544,6 +544,22 @@ macro_rules! bitflags {
$vis struct $BitFlags;
}

// Workaround for: https://github.com/bitflags/bitflags/issues/320
__impl_public_bitflags_consts! {
$BitFlags {
$(
$(#[$inner $($args)*])*
#[allow(
dead_code,
deprecated,
unused_attributes,
non_upper_case_globals
)]
$Flag = $value;
)*
}
}

#[allow(
dead_code,
deprecated,
Expand Down Expand Up @@ -582,12 +598,7 @@ macro_rules! bitflags {
}

__impl_public_bitflags! {
$BitFlags: $T, InternalBitFlags, Iter, IterRaw {
$(
$(#[$inner $($args)*])*
$Flag = $value;
)*
}
$BitFlags: $T, InternalBitFlags, Iter, IterRaw;
}
};

Expand Down
33 changes: 22 additions & 11 deletions src/public.rs
Expand Up @@ -26,12 +26,7 @@ macro_rules! __declare_public_bitflags {
#[doc(hidden)]
macro_rules! __impl_public_bitflags {
(
$PublicBitFlags:ident: $T:ty, $InternalBitFlags:ident, $Iter:ident, $IterNames:ident {
$(
$(#[$attr:ident $($args:tt)*])*
$Flag:ident = $value:expr;
)*
}
$PublicBitFlags:ident: $T:ty, $InternalBitFlags:ident, $Iter:ident, $IterNames:ident;
) => {
impl $crate::__private::core::fmt::Binary for $PublicBitFlags {
fn fmt(&self, f: &mut $crate::__private::core::fmt::Formatter) -> $crate::__private::core::fmt::Result {
Expand All @@ -58,11 +53,6 @@ macro_rules! __impl_public_bitflags {
}

impl $PublicBitFlags {
$(
$(#[$attr $($args)*])*
pub const $Flag: Self = Self::from_bits_retain($value);
)*

/// Returns an empty set of flags.
#[inline]
pub const fn empty() -> Self {
Expand Down Expand Up @@ -454,3 +444,24 @@ macro_rules! __impl_public_bitflags {
impl $crate::__private::ImplementedByBitFlagsMacro for $PublicBitFlags {}
};
}

/// Implement constants on the public (user-facing) bitflags type.
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! __impl_public_bitflags_consts {
(
$PublicBitFlags:ident {
$(
$(#[$attr:ident $($args:tt)*])*
$Flag:ident = $value:expr;
)*
}
) => {
impl $PublicBitFlags {
$(
$(#[$attr $($args)*])*
pub const $Flag: Self = Self::from_bits_retain($value);
)*
}
};
}

0 comments on commit 98b85d5

Please sign in to comment.