From 3f0b2e58c73ec3dc6bffb38c90d4c701f7e94a4f Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Tue, 4 Feb 2020 11:47:06 +0100 Subject: [PATCH] Let is_all() ignore extra bits (fixes #208) --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 55daa5e..c92fe5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -664,7 +664,7 @@ macro_rules! __impl_bitflags { /// Returns `true` if all flags are currently set. #[inline] pub const fn is_all(&self) -> bool { - self.bits == $BitFlags::all().bits + $BitFlags::all().bits | self.bits == self.bits } } @@ -1048,6 +1048,11 @@ mod tests { assert!(!Flags::A.is_all()); assert!(Flags::ABC.is_all()); + let extra = unsafe { Flags::from_bits_unchecked(0b1000) }; + assert!(!extra.is_all()); + assert!(!(Flags::A | extra).is_all()); + assert!((Flags::ABC | extra).is_all()); + assert!(AnotherSetOfFlags::ANOTHER_FLAG.is_all()); }