From b41daddce1f3655ef9774c7c27ceb84512a4ba02 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Fri, 18 Oct 2024 17:28:49 +0800 Subject: [PATCH] misc: Remove manual implementation of is_power_of_two As clippy of rust-toolchain version 1.83.0-beta.1 suggests, remove manual implementation of `is_power_of_two` to improve readability. Signed-off-by: Ruoqing He --- block/src/qcow/qcow_raw_file.rs | 2 +- pci/src/configuration.rs | 4 ++-- vm-virtio/src/queue.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/src/qcow/qcow_raw_file.rs b/block/src/qcow/qcow_raw_file.rs index 4bac118ad9..ba985c1a25 100644 --- a/block/src/qcow/qcow_raw_file.rs +++ b/block/src/qcow/qcow_raw_file.rs @@ -24,7 +24,7 @@ impl QcowRawFile { /// Creates a `QcowRawFile` from the given `File`, `None` is returned if `cluster_size` is not /// a power of two. pub fn from(file: RawFile, cluster_size: u64) -> Option { - if cluster_size.count_ones() != 1 { + if !cluster_size.is_power_of_two() { return None; } Some(QcowRawFile { diff --git a/pci/src/configuration.rs b/pci/src/configuration.rs index 7fb819d215..3e612edb77 100644 --- a/pci/src/configuration.rs +++ b/pci/src/configuration.rs @@ -734,7 +734,7 @@ impl PciConfiguration { return Err(Error::BarInUse(bar_idx)); } - if config.size.count_ones() != 1 { + if !config.size.is_power_of_two() { return Err(Error::BarSizeInvalid(config.size)); } @@ -806,7 +806,7 @@ impl PciConfiguration { return Err(Error::RomBarInUse(bar_idx)); } - if config.size.count_ones() != 1 { + if !config.size.is_power_of_two() { return Err(Error::RomBarSizeInvalid(config.size)); } diff --git a/vm-virtio/src/queue.rs b/vm-virtio/src/queue.rs index 285692af64..4e55cc4b5d 100644 --- a/vm-virtio/src/queue.rs +++ b/vm-virtio/src/queue.rs @@ -178,7 +178,7 @@ pub mod testing { // We try to make sure things are aligned properly :-s pub fn new(start: GuestAddress, mem: &'a GuestMemoryMmap, qsize: u16) -> Self { // power of 2? - assert!(qsize > 0 && qsize & (qsize - 1) == 0); + assert!(qsize.is_power_of_two()); let mut dtable = Vec::with_capacity(qsize as usize);