From d689c709ea6e942de1687d918eaee541610aa86d Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Mon, 21 Oct 2019 15:35:54 +0200 Subject: [PATCH] improve readability of is_power_of_two --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 82c1943b7d05..e14c886aec39 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3750,7 +3750,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub const fn is_power_of_two(self) -> bool { - ((self.wrapping_sub(1)) & self == 0) & !(self == 0) + self.count_ones() == 1 } }