Skip to content

Commit

Permalink
Merge pull request #268 from konsumlamm/fix-debug
Browse files Browse the repository at this point in the history
Fix bug in `Debug` implementation
  • Loading branch information
KodrAus committed Jan 8, 2022
2 parents 54b1b86 + 263c7ff commit 7a9d7c7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Expand Up @@ -494,8 +494,7 @@ macro_rules! __impl_bitflags {
f.write_str(" | ")?;
}
first = false;
f.write_str("0x")?;
$crate::_core::fmt::LowerHex::fmt(&extra_bits, f)?;
$crate::_core::write!(f, "{:#x}", extra_bits)?;
}
if first {
f.write_str("(empty)")?;
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/trait/custom_impl.rs
Expand Up @@ -62,4 +62,4 @@ impl BitFlags for BootlegFlags {
}
}

fn main() { }
fn main() {}
4 changes: 1 addition & 3 deletions tests/compile-pass/impls/convert.rs
Expand Up @@ -12,6 +12,4 @@ impl From<u32> for Flags {
}
}

fn main() {

}
fn main() {}
14 changes: 14 additions & 0 deletions tests/compile-pass/impls/fmt.rs
@@ -0,0 +1,14 @@
use bitflags::bitflags;

bitflags! {
struct Flags: u8 {
const TWO = 0x2;
}
}

fn main() {
// bug #267 (https://github.com/bitflags/bitflags/issues/267)
let flags = unsafe { Flags::from_bits_unchecked(0b11) };
assert_eq!(format!("{:?}", flags), "TWO | 0x1");
assert_eq!(format!("{:#?}", flags), "TWO | 0x1");
}
Expand Up @@ -7,13 +7,18 @@ macro_rules! stringify {
($($t:tt)*) => { "..." };
}

#[allow(unused_macros)]
macro_rules! write {
($($t:tt)*) => { "..." };
}

bitflags! {
struct Test: u8 {
const A = 1;
}
}

fn main() {
// Just make sure we don't call the redefined `stringify` macro
assert_eq!(format!("{:?}", Test::A), "A");
// Just make sure we don't call the redefined `stringify` or `write` macro
assert_eq!(format!("{:?}", unsafe { Test::from_bits_unchecked(0b11) }), "A | 0x2");
}

0 comments on commit 7a9d7c7

Please sign in to comment.