Skip to content

Commit 1052376

Browse files
StemClldianpopa
authored andcommitted
Add clippy::cast_lossless warning
Signed-off-by: StemCll lydjotj6f@mozmail.com
1 parent 1644b3c commit 1052376

File tree

31 files changed

+47
-39
lines changed

31 files changed

+47
-39
lines changed

src/api_server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![deny(missing_docs)]
55
#![warn(clippy::ptr_as_ptr)]
66
#![warn(clippy::undocumented_unsafe_blocks)]
7-
7+
#![warn(clippy::cast_lossless)]
88
//! Implements the interface for intercepting API requests, forwarding them to the VMM
99
//! and responding to the user.
1010
//! It is constructed on top of an HTTP Server that uses Unix Domain Sockets and `EPOLL` to

src/arch/src/aarch64/fdt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ fn create_cpu_nodes(fdt: &mut FdtWriter, vcpu_mpidr: &[u64]) -> Result<()> {
146146
fdt.property_u32(cache.type_.of_cache_size(), size as u32)?;
147147
}
148148
if let Some(line_size) = cache.line_size {
149-
fdt.property_u32(cache.type_.of_cache_line_size(), line_size as u32)?;
149+
fdt.property_u32(cache.type_.of_cache_line_size(), u32::from(line_size))?;
150150
}
151151
if let Some(number_of_sets) = cache.number_of_sets {
152-
fdt.property_u32(cache.type_.of_cache_sets(), number_of_sets as u32)?;
152+
fdt.property_u32(cache.type_.of_cache_sets(), u32::from(number_of_sets))?;
153153
}
154154
}
155155

@@ -188,15 +188,15 @@ fn create_cpu_nodes(fdt: &mut FdtWriter, vcpu_mpidr: &[u64]) -> Result<()> {
188188
))?);
189189
fdt.property_u32("phandle", cache_phandle)?;
190190
fdt.property_string("compatible", "cache")?;
191-
fdt.property_u32("cache-level", cache.level as u32)?;
191+
fdt.property_u32("cache-level", u32::from(cache.level))?;
192192
if let Some(size) = cache.size_ {
193193
fdt.property_u32(cache.type_.of_cache_size(), size as u32)?;
194194
}
195195
if let Some(line_size) = cache.line_size {
196-
fdt.property_u32(cache.type_.of_cache_line_size(), line_size as u32)?;
196+
fdt.property_u32(cache.type_.of_cache_line_size(), u32::from(line_size))?;
197197
}
198198
if let Some(number_of_sets) = cache.number_of_sets {
199-
fdt.property_u32(cache.type_.of_cache_sets(), number_of_sets as u32)?;
199+
fdt.property_u32(cache.type_.of_cache_sets(), u32::from(number_of_sets))?;
200200
}
201201
if let Some(cache_type) = cache.type_.of_cache_type() {
202202
fdt.property_null(cache_type)?;

src/arch/src/aarch64/regs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub fn setup_boot_regs(
239239
///
240240
/// * `regid` - The index of the register we are checking.
241241
pub fn is_system_register(regid: u64) -> bool {
242-
if (regid & KVM_REG_ARM_COPROC_MASK as u64) == KVM_REG_ARM_CORE as u64 {
242+
if (regid & u64::from(KVM_REG_ARM_COPROC_MASK)) == u64::from(KVM_REG_ARM_CORE) {
243243
return false;
244244
}
245245

@@ -508,7 +508,7 @@ mod tests {
508508
assert!(!is_system_register(regid));
509509
let regid = KVM_REG_ARM64 as u64
510510
| KVM_REG_SIZE_U64 as u64
511-
| kvm_bindings::KVM_REG_ARM64_SYSREG as u64;
511+
| u64::from(kvm_bindings::KVM_REG_ARM64_SYSREG);
512512
assert!(is_system_register(regid));
513513
}
514514

src/arch/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![deny(missing_docs)]
55
#![warn(clippy::ptr_as_ptr)]
66
#![warn(clippy::undocumented_unsafe_blocks)]
7-
7+
#![warn(clippy::cast_lossless)]
88
//! Implements platform specific functionality.
99
//! Supported platforms: x86_64 and aarch64.
1010
use std::{fmt, result};

src/cpuid/src/bit_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl BitHelper for u32 {
148148
assert!(pos <= MAX_U32_BIT_INDEX, "Invalid pos");
149149

150150
*self &= !(1 << pos);
151-
*self |= (val as u32) << pos;
151+
*self |= (u32::from(val)) << pos;
152152
self
153153
}
154154

src/cpuid/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![deny(missing_docs)]
99
#![warn(clippy::ptr_as_ptr)]
1010
#![warn(clippy::undocumented_unsafe_blocks)]
11-
11+
#![warn(clippy::cast_lossless)]
1212
//! Utility for configuring the CPUID (CPU identification) for the guest microVM.
1313
1414
#![cfg(target_arch = "x86_64")]

src/cpuid/src/transformer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl VmSpec {
3636
cpu_vendor_id,
3737
cpu_index,
3838
cpu_count,
39-
cpu_bits: (cpu_count > 1 && smt) as u8,
39+
cpu_bits: u8::from(cpu_count > 1 && smt),
4040
brand_string: BrandString::from_vendor_id(&cpu_vendor_id),
4141
})
4242
}

src/devices/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#![warn(clippy::ptr_as_ptr)]
99
#![warn(clippy::undocumented_unsafe_blocks)]
10-
10+
#![warn(clippy::cast_lossless)]
1111
//! Emulates virtual and hardware devices.
1212
use std::io;
1313

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl Balloon {
303303
// Remove the page ranges.
304304
for (page_frame_number, range_len) in page_ranges {
305305
let guest_addr =
306-
GuestAddress((page_frame_number as u64) << VIRTIO_BALLOON_PFN_SHIFT);
306+
GuestAddress(u64::from(page_frame_number) << VIRTIO_BALLOON_PFN_SHIFT);
307307

308308
if let Err(err) = remove_range(
309309
mem,
@@ -365,7 +365,7 @@ impl Balloon {
365365
// so we ignore the rest of it.
366366
let addr = head
367367
.addr
368-
.checked_add(index as u64)
368+
.checked_add(u64::from(index))
369369
.ok_or(BalloonError::MalformedDescriptor)?;
370370
let stat = mem
371371
.read_obj::<BalloonStat>(addr)
@@ -445,8 +445,8 @@ impl Balloon {
445445

446446
pub fn update_timer_state(&mut self) {
447447
let timer_state = TimerState::Periodic {
448-
current: Duration::from_secs(self.stats_polling_interval_s as u64),
449-
interval: Duration::from_secs(self.stats_polling_interval_s as u64),
448+
current: Duration::from_secs(u64::from(self.stats_polling_interval_s)),
449+
interval: Duration::from_secs(u64::from(self.stats_polling_interval_s)),
450450
};
451451
self.stats_timer
452452
.set_state(timer_state, SetTimeFlags::Default);
@@ -687,7 +687,7 @@ pub(crate) mod tests {
687687

688688
let features: u64 = (1u64 << VIRTIO_F_VERSION_1)
689689
| ((if *deflate_on_oom { 1 } else { 0 }) << VIRTIO_BALLOON_F_DEFLATE_ON_OOM)
690-
| ((*stats_interval as u64) << VIRTIO_BALLOON_F_STATS_VQ);
690+
| ((u64::from(*stats_interval)) << VIRTIO_BALLOON_F_STATS_VQ);
691691

692692
assert_eq!(balloon.avail_features_by_page(0), features as u32);
693693
assert_eq!(balloon.avail_features_by_page(1), (features >> 32) as u32);

src/devices/src/virtio/balloon/persist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ impl Persist<'_> for Balloon {
145145

146146
// Restart timer if needed.
147147
let timer_state = TimerState::Periodic {
148-
current: Duration::from_secs(state.stats_polling_interval_s as u64),
149-
interval: Duration::from_secs(state.stats_polling_interval_s as u64),
148+
current: Duration::from_secs(u64::from(state.stats_polling_interval_s)),
149+
interval: Duration::from_secs(u64::from(state.stats_polling_interval_s)),
150150
};
151151
balloon
152152
.stats_timer

0 commit comments

Comments
 (0)