Skip to content

Commit

Permalink
Merge pull request #388 from GnomedDev/packed-internal
Browse files Browse the repository at this point in the history
Add support for impl mode structs to be repr(packed)
  • Loading branch information
KodrAus committed Dec 30, 2023
2 parents 1687ebd + 843cc04 commit 586d819
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/public.rs
Expand Up @@ -321,7 +321,8 @@ macro_rules! __impl_public_bitflags_ops {
&self,
f: &mut $crate::__private::core::fmt::Formatter,
) -> $crate::__private::core::fmt::Result {
$crate::__private::core::fmt::Binary::fmt(&self.0, f)
let inner = self.0;
$crate::__private::core::fmt::Binary::fmt(&inner, f)
}
}

Expand All @@ -330,7 +331,8 @@ macro_rules! __impl_public_bitflags_ops {
&self,
f: &mut $crate::__private::core::fmt::Formatter,
) -> $crate::__private::core::fmt::Result {
$crate::__private::core::fmt::Octal::fmt(&self.0, f)
let inner = self.0;
$crate::__private::core::fmt::Octal::fmt(&inner, f)
}
}

Expand All @@ -339,7 +341,8 @@ macro_rules! __impl_public_bitflags_ops {
&self,
f: &mut $crate::__private::core::fmt::Formatter,
) -> $crate::__private::core::fmt::Result {
$crate::__private::core::fmt::LowerHex::fmt(&self.0, f)
let inner = self.0;
$crate::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}

Expand All @@ -348,7 +351,8 @@ macro_rules! __impl_public_bitflags_ops {
&self,
f: &mut $crate::__private::core::fmt::Formatter,
) -> $crate::__private::core::fmt::Result {
$crate::__private::core::fmt::UpperHex::fmt(&self.0, f)
let inner = self.0;
$crate::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/compile-pass/bitflags_impl_repr_packed.rs
@@ -0,0 +1,13 @@
extern crate bitflags;

#[repr(packed)]
struct Example(u64);

bitflags::bitflags! {
impl Example: u64 {
const FLAG_1 = 0b01;
const FLAG_2 = 0b10;
}
}

fn main() {}

0 comments on commit 586d819

Please sign in to comment.