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:
Henry Hrvoje Tonkovac
2026-06-24 21:18:18 +02:00
committed by Bo Chen
parent f56fa3a865
commit f720e619c1
49 changed files with 158 additions and 228 deletions

View File

@@ -6,7 +6,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier};
use std::time::{Duration, Instant};
use std::{io, mem, thread};
use std::{io, thread};
use acpi_tables::{Aml, AmlSink, aml};
use log::{error, info, warn};
@@ -250,7 +250,7 @@ impl Default for AcpiPmTimerDevice {
impl BusDevice for AcpiPmTimerDevice {
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
if data.len() != mem::size_of::<u32>() {
if data.len() != size_of::<u32>() {
warn!("Invalid sized read of PM timer: {}", data.len());
return;
}

View File

@@ -9,8 +9,8 @@
// Implementation of an intel 82093AA Input/Output Advanced Programmable Interrupt Controller
// See https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf for a specification.
use std::result;
use std::sync::{Arc, Barrier};
use std::{mem, result};
use byteorder::{ByteOrder, LittleEndian};
use log::{debug, error, trace, warn};
@@ -147,7 +147,7 @@ pub struct IoapicState {
impl BusDevice for Ioapic {
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
if data.len() != mem::size_of::<u32>() {
if data.len() != size_of::<u32>() {
warn!("Invalid read size on IOAPIC: {}", data.len());
return;
}
@@ -167,7 +167,7 @@ impl BusDevice for Ioapic {
}
fn write(&mut self, _base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
if data.len() != mem::size_of::<u32>() {
if data.len() != size_of::<u32>() {
warn!("Invalid write size on IOAPIC: {}", data.len());
return None;
}

View File

@@ -452,7 +452,7 @@ mod unit_tests {
),
];
let type_size = std::mem::size_of::<$data_type>();
let type_size = size_of::<$data_type>();
for (test_val, v_arr) in &test_cases {
let v = *test_val as $data_type;
let cmp_iter: Box<dyn Iterator<Item = _>> = if $is_be {

View File

@@ -48,7 +48,7 @@ bitflags! {
macro_rules! generate_read_fn {
($fn_name: ident, $data_type: ty, $byte_type: ty, $type_size: expr, $endian_type: ident) => {
pub fn $fn_name(input: &[$byte_type]) -> $data_type {
assert!($type_size == std::mem::size_of::<$data_type>());
assert!($type_size == size_of::<$data_type>());
let mut array = [0u8; $type_size];
for (byte, read) in array.iter_mut().zip(input.iter().cloned()) {
*byte = read as u8;

View File

@@ -108,8 +108,8 @@ struct PvmemcontrolTransport {
command: PvmemcontrolTransportCommand,
}
const PVMEMCONTROL_DEVICE_MMIO_SIZE: u64 = mem::size_of::<PvmemcontrolTransport>() as u64;
const PVMEMCONTROL_DEVICE_MMIO_ALIGN: u64 = mem::align_of::<PvmemcontrolTransport>() as u64;
const PVMEMCONTROL_DEVICE_MMIO_SIZE: u64 = size_of::<PvmemcontrolTransport>() as u64;
const PVMEMCONTROL_DEVICE_MMIO_ALIGN: u64 = align_of::<PvmemcontrolTransport>() as u64;
impl PvmemcontrolTransport {
fn ack() -> Self {
@@ -293,7 +293,7 @@ impl PvmemcontrolDevice {
let buf_phys_addr = GuestAddress(buf_phys_addr.into());
if !guest_memory.memory().check_range(
buf_phys_addr,
mem::size_of::<PvmemcontrolResp>().max(mem::size_of::<PvmemcontrolReq>()),
size_of::<PvmemcontrolResp>().max(size_of::<PvmemcontrolReq>()),
) {
warn!("guest sent invalid phys addr {:#x}", buf_phys_addr.0);
return PvmemcontrolDevice::new(