Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Debug implementation #268

Merged
merged 1 commit into from Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
}