Skip to content

Commit de54d59

Browse files
committed
Add fmt::Debug constraint to BitFlagNum
Otherwise, `T: Debug` isn't enough to imply `BitFlags<T>: Debug`, and this can get in the way of code generated by #[derive(Debug)].
1 parent 6f6d797 commit de54d59

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

enumflags/src/formatting.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{BitFlags, _internal::RawBitFlags};
44
impl<T> fmt::Debug for BitFlags<T>
55
where
66
T: RawBitFlags + fmt::Debug,
7-
T::Type: fmt::Binary + fmt::Debug,
87
{
98
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
109
let name = T::bitflags_type_name();

enumflags/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub mod _internal {
8989

9090
use core::ops::{BitAnd, BitOr, BitXor, Not};
9191
use core::cmp::PartialOrd;
92+
use core::fmt;
9293

9394
pub trait BitFlagNum
9495
: Default
@@ -97,6 +98,8 @@ pub mod _internal {
9798
+ BitXor<Self, Output = Self>
9899
+ Not<Output = Self>
99100
+ PartialOrd<Self>
101+
+ fmt::Debug
102+
+ fmt::Binary
100103
+ Copy
101104
+ Clone {
102105
}

test_suite/tests/formatting.rs

+10
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ fn format() {
7272
"0x0F"
7373
);
7474
}
75+
76+
#[test]
77+
fn debug_generic() {
78+
use enumflags2::{BitFlags, _internal::RawBitFlags};
79+
80+
#[derive(Debug)]
81+
struct Debug<T: RawBitFlags>(BitFlags<T>);
82+
83+
let _ = format!("{:?}", Debug(BitFlags::<Test>::all()));
84+
}

0 commit comments

Comments
 (0)