Skip to content

Commit f93c22b

Browse files
committed
chore(rust): fix clippy warnings
Fix new clippy warnings Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 551eff6 commit f93c22b

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

src/cpu-template-helper/src/utils/x86_64.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ mod tests {
194194
use vmm::cpu_config::x86_64::custom_cpu_template::CpuidRegisterModifier;
195195

196196
use super::*;
197-
use crate::utils::x86_64::{cpuid_leaf_modifier, cpuid_reg_modifier, msr_modifier};
198197

199198
macro_rules! cpuid_modifier_map {
200199
($leaf:expr, $subleaf:expr, $flags:expr, $register:expr, $value:expr) => {

src/firecracker/src/api_server/parsed_request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ pub mod tests {
406406
"{} {} HTTP/1.1\r\nContent-Type: application/json\r\n",
407407
request_type, endpoint
408408
);
409-
if body.is_some() {
409+
if let Some(body) = body {
410410
return format!(
411411
"{}Content-Length: {}\r\n\r\n{}",
412412
req_no_body,
413-
body.unwrap().len(),
414-
body.unwrap()
413+
body.len(),
414+
body
415415
);
416416
}
417417
format!("{}\r\n", req_no_body,)

src/vmm/src/arch/x86_64/interrupts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111

112112
v.iter_mut()
113113
.for_each(|x| *x = set_apic_delivery_mode(*x, 2));
114-
let after: Vec<u32> = v.iter().map(|x| ((*x & !0x700) | ((2) << 8))).collect();
114+
let after: Vec<u32> = v.iter().map(|x| (*x & !0x700) | ((2) << 8)).collect();
115115
assert_eq!(v, after);
116116
}
117117

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl Balloon {
393393
let max_len = MAX_PAGES_IN_DESC * SIZE_OF_U32;
394394
valid_descs_found = true;
395395

396-
if !head.is_write_only() && len % SIZE_OF_U32 == 0 {
396+
if !head.is_write_only() && len.is_multiple_of(SIZE_OF_U32) {
397397
// Check descriptor pfn count.
398398
if len > max_len {
399399
error!(

src/vmm/src/devices/virtio/block/vhost_user/device.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,20 @@ impl TryFrom<&BlockDeviceConfig> for VhostUserBlockConfig {
6969
type Error = VhostUserBlockError;
7070

7171
fn try_from(value: &BlockDeviceConfig) -> Result<Self, Self::Error> {
72-
if value.socket.is_some()
73-
&& value.is_read_only.is_none()
74-
&& value.path_on_host.is_none()
75-
&& value.rate_limiter.is_none()
76-
&& value.file_engine_type.is_none()
77-
{
72+
if let (Some(socket), None, None, None, None) = (
73+
&value.socket,
74+
&value.is_read_only,
75+
&value.path_on_host,
76+
&value.rate_limiter,
77+
&value.file_engine_type,
78+
) {
7879
Ok(Self {
7980
drive_id: value.drive_id.clone(),
8081
partuuid: value.partuuid.clone(),
8182
is_root_device: value.is_root_device,
8283
cache_type: value.cache_type,
8384

84-
socket: value.socket.as_ref().unwrap().clone(),
85+
socket: socket.clone(),
8586
})
8687
} else {
8788
Err(VhostUserBlockError::Config)

src/vmm/src/devices/virtio/block/virtio/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ impl TryFrom<&BlockDeviceConfig> for VirtioBlockConfig {
204204
type Error = VirtioBlockError;
205205

206206
fn try_from(value: &BlockDeviceConfig) -> Result<Self, Self::Error> {
207-
if value.path_on_host.is_some() && value.socket.is_none() {
207+
if let (Some(path_on_host), None) = (&value.path_on_host, &value.socket) {
208208
Ok(Self {
209209
drive_id: value.drive_id.clone(),
210210
partuuid: value.partuuid.clone(),
211211
is_root_device: value.is_root_device,
212212
cache_type: value.cache_type,
213213

214214
is_read_only: value.is_read_only.unwrap_or(false),
215-
path_on_host: value.path_on_host.as_ref().unwrap().clone(),
215+
path_on_host: path_on_host.clone(),
216216
rate_limiter: value.rate_limiter,
217217
file_engine_type: value.file_engine_type.unwrap_or_default(),
218218
})

src/vmm/src/devices/virtio/block/virtio/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl Request {
297297
RequestType::In | RequestType::Out => {
298298
// Check that the data length is a multiple of 512 as specified in the virtio
299299
// standard.
300-
if req.data_len % SECTOR_SIZE != 0 {
300+
if !req.data_len.is_multiple_of(SECTOR_SIZE) {
301301
return Err(VirtioBlockError::InvalidDataLength);
302302
}
303303
let top_sector = req

src/vmm/src/devices/virtio/mem/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl VirtioMem {
570570
return Err(VirtioMemError::DeviceNotActive);
571571
}
572572

573-
if requested_size % self.config.block_size != 0 {
573+
if !requested_size.is_multiple_of(self.config.block_size) {
574574
return Err(VirtioMemError::InvalidSize(requested_size));
575575
}
576576
if requested_size > self.config.region_size {

src/vmm/src/dumbo/pdu/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn compute_checksum<T: NetworkBytes + Debug>(
9696
sum += usize::from(bytes.ntohs_unchecked(i * 2));
9797
}
9898

99-
if len % 2 != 0 {
99+
if !len.is_multiple_of(2) {
100100
sum += usize::from(bytes[len - 1]) << 8;
101101
}
102102

src/vmm/src/rate_limiter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl TokenBucket {
152152
// we would allow some fraction of a nano second to be used twice, allowing
153153
// for the generation of one extra token in extreme circumstances).
154154
let mut time_adjustment = tokens * processed_refill_time / processed_capacity;
155-
if tokens * processed_refill_time % processed_capacity != 0 {
155+
if !(tokens * processed_refill_time).is_multiple_of(processed_capacity) {
156156
time_adjustment += 1;
157157
}
158158

0 commit comments

Comments
 (0)