mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: use prelude size_of
size_of is part of std::prelude as of Rust 1.80 (with size_of_val, align_of, align_of_val), and the workspace MSRV is 1.89, so qualifying it (mem::size_of, std::mem::size_of, core::mem::size_of) is unnecessary. Convert every qualified size_of call-site to the bare prelude form and drop the now-redundant `use std::mem::size_of;` imports, keeping `use std::mem;` where it still serves non-prelude items (transmute, swap, replace, take, zeroed, MaybeUninit, offset_of). size_of is the only one of the four currently used in the tree. Pure refactor, no behavioural change. Follow-up to the clippy::absolute_paths cleanup (#7670), as discussed in #8444. Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com> Assisted-by: Claude:Opus-4.8
This commit is contained in:
committed by
Bo Chen
parent
f56fa3a865
commit
f720e619c1
@@ -53,7 +53,7 @@ macro_rules! arm64_core_reg_id {
|
||||
KVM_REG_ARM64 as u64
|
||||
| u64::from(KVM_REG_ARM_CORE)
|
||||
| $size
|
||||
| (($offset / mem::size_of::<u32>()) as u64)
|
||||
| (($offset / size_of::<u32>()) as u64)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, RwLock};
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{fs, io, mem, result};
|
||||
use std::{fs, io, result};
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use anyhow::Context;
|
||||
@@ -1108,7 +1108,7 @@ impl vm::Vm for KvmVm {
|
||||
flags |= KVM_MEM_LOG_DIRTY_PAGES;
|
||||
}
|
||||
|
||||
const _: () = assert!(mem::size_of::<usize>() <= mem::size_of::<u64>());
|
||||
const _: () = assert!(size_of::<usize>() <= size_of::<u64>());
|
||||
|
||||
// Create a per-region guest_memfd when supported.
|
||||
// Each region gets its own fd sized exactly to memory_size
|
||||
@@ -1222,7 +1222,7 @@ impl vm::Vm for KvmVm {
|
||||
flags |= KVM_MEM_LOG_DIRTY_PAGES;
|
||||
}
|
||||
|
||||
const _: () = assert!(mem::size_of::<usize>() <= mem::size_of::<u64>());
|
||||
const _: () = assert!(size_of::<usize>() <= size_of::<u64>());
|
||||
|
||||
let mut region = kvm_userspace_memory_region2 {
|
||||
slot,
|
||||
@@ -2022,7 +2022,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||
.map_err(|e| cpu::HypervisorCpuError::GetAarchCoreRegister(e.into()))?;
|
||||
state.regs.regs[i] = u64::from_le_bytes(bytes);
|
||||
off += mem::size_of::<u64>();
|
||||
off += size_of::<u64>();
|
||||
}
|
||||
|
||||
// We are now entering the "Other register" section of the ARMv8-a architecture.
|
||||
@@ -2075,7 +2075,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||
.map_err(|e| cpu::HypervisorCpuError::GetAarchCoreRegister(e.into()))?;
|
||||
state.spsr[i] = u64::from_le_bytes(bytes);
|
||||
off += mem::size_of::<u64>();
|
||||
off += size_of::<u64>();
|
||||
}
|
||||
|
||||
Ok(state.into())
|
||||
@@ -2177,7 +2177,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
&kvm_regs_state.regs.regs[i].to_le_bytes(),
|
||||
)
|
||||
.map_err(|e| cpu::HypervisorCpuError::SetAarchCoreRegister(e.into()))?;
|
||||
off += mem::size_of::<u64>();
|
||||
off += size_of::<u64>();
|
||||
}
|
||||
|
||||
let off = offset_of!(user_pt_regs, sp);
|
||||
@@ -2228,7 +2228,7 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
&kvm_regs_state.spsr[i].to_le_bytes(),
|
||||
)
|
||||
.map_err(|e| cpu::HypervisorCpuError::SetAarchCoreRegister(e.into()))?;
|
||||
off += mem::size_of::<u64>();
|
||||
off += size_of::<u64>();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -3723,7 +3723,7 @@ impl KvmVcpu {
|
||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U128, off), &mut bytes)
|
||||
.map_err(|e| cpu::HypervisorCpuError::GetAarchCoreRegister(e.into()))?;
|
||||
regs.fp_regs.vregs[i] = u128::from_le_bytes(bytes);
|
||||
off += mem::size_of::<u128>();
|
||||
off += size_of::<u128>();
|
||||
}
|
||||
|
||||
// Floating-point Status Register
|
||||
@@ -3756,7 +3756,7 @@ impl KvmVcpu {
|
||||
®s.fp_regs.vregs[i].to_le_bytes(),
|
||||
)
|
||||
.map_err(|e| cpu::HypervisorCpuError::SetAarchCoreRegister(e.into()))?;
|
||||
off += mem::size_of::<u128>();
|
||||
off += size_of::<u128>();
|
||||
}
|
||||
|
||||
// Floating-point Status Register
|
||||
|
||||
@@ -74,7 +74,7 @@ macro_rules! riscv64_reg_id {
|
||||
kvm_bindings::KVM_REG_RISCV as u64
|
||||
| u64::from($reg_type)
|
||||
| u64::from(kvm_bindings::KVM_REG_SIZE_U64)
|
||||
| (($offset / std::mem::size_of::<u64>()) as u64)
|
||||
| (($offset / size_of::<u64>()) as u64)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,6 @@ impl SevFd {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::mem::size_of;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user