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

@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
use std::any::Any;
use std::{mem, result};
use std::result;
use serde::de::Error as SerdeError;
use serde::{Deserialize, Serialize};
@@ -67,7 +67,7 @@ impl<'de> Deserialize<'de> for GicState {
}
const {
assert!(mem::size_of::<GicStateDefaultDeserialize>() == mem::size_of::<GicState>());
assert!(size_of::<GicStateDefaultDeserialize>() == size_of::<GicState>());
};
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;

View File

@@ -54,12 +54,12 @@ macro_rules! cmp_rm_r {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let op0_value = get_op(&insn, 0, std::mem::size_of::<$bound>(), state, platform)
let op0_value = get_op(&insn, 0, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let op1_value = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let op1_value = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let cpazso = calc_rflags_cpazso(op0_value, op1_value, std::mem::size_of::<$bound>());
let cpazso = calc_rflags_cpazso(op0_value, op1_value, size_of::<$bound>());
state.set_flags((state.flags() & !FLAGS_MASK) | cpazso);
@@ -76,12 +76,12 @@ macro_rules! cmp_r_rm {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let op0_value = get_op(&insn, 0, std::mem::size_of::<$bound>(), state, platform)
let op0_value = get_op(&insn, 0, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let op1_value = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let op1_value = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let cpazso = calc_rflags_cpazso(op0_value, op1_value, std::mem::size_of::<$bound>());
let cpazso = calc_rflags_cpazso(op0_value, op1_value, size_of::<$bound>());
state.set_flags((state.flags() & !FLAGS_MASK) | cpazso);
@@ -98,12 +98,12 @@ macro_rules! cmp_rm_imm {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let op0_value = get_op(&insn, 0, std::mem::size_of::<$bound>(), state, platform)
let op0_value = get_op(&insn, 0, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let op1_value = get_op(&insn, 1, std::mem::size_of::<$imm>(), state, platform)
let op1_value = get_op(&insn, 1, size_of::<$imm>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let cpazso = calc_rflags_cpazso(op0_value, op1_value, std::mem::size_of::<$bound>());
let cpazso = calc_rflags_cpazso(op0_value, op1_value, size_of::<$bound>());
state.set_flags((state.flags() & !FLAGS_MASK) | cpazso);

View File

@@ -22,13 +22,13 @@ macro_rules! mov_rm_r {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let src_reg_value = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let src_reg_value = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(
&insn,
0,
std::mem::size_of::<$bound>(),
size_of::<$bound>(),
state,
platform,
src_reg_value,
@@ -48,18 +48,11 @@ macro_rules! mov_rm_imm {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let imm = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let imm = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(
&insn,
0,
std::mem::size_of::<$bound>(),
state,
platform,
imm,
)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(&insn, 0, size_of::<$bound>(), state, platform, imm)
.map_err(EmulationError::PlatformEmulationError)?;
Ok(())
}
@@ -74,19 +67,13 @@ macro_rules! movzx {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let src_value = get_op(
&insn,
1,
std::mem::size_of::<$src_op_size>(),
state,
platform,
)
.map_err(EmulationError::PlatformEmulationError)?;
let src_value = get_op(&insn, 1, size_of::<$src_op_size>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(
&insn,
0,
std::mem::size_of::<$dest_op_size>(),
size_of::<$dest_op_size>(),
state,
platform,
src_value,
@@ -113,18 +100,11 @@ macro_rules! mov_r_imm {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let imm = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let imm = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(
&insn,
0,
std::mem::size_of::<$bound>(),
state,
platform,
imm,
)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(&insn, 0, size_of::<$bound>(), state, platform, imm)
.map_err(EmulationError::PlatformEmulationError)?;
Ok(())
}

View File

@@ -39,7 +39,7 @@ macro_rules! movs {
.map_err(|e| EmulationError::InvalidOperand(anyhow!(e)))?;
let backwards = string_op_backwards(state.flags());
let len = std::mem::size_of::<$bound>();
let len = size_of::<$bound>();
while count > 0 {
let mut memory: [u8; 8] = [0; 8];

View File

@@ -20,23 +20,16 @@ macro_rules! or_rm_r {
state: &mut T,
platform: &mut dyn PlatformEmulator<CpuState = T>,
) -> Result<(), EmulationError<Exception>> {
let src_reg_value = get_op(&insn, 1, std::mem::size_of::<$bound>(), state, platform)
let src_reg_value = get_op(&insn, 1, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let dst_value = get_op(&insn, 0, std::mem::size_of::<$bound>(), state, platform)
let dst_value = get_op(&insn, 0, size_of::<$bound>(), state, platform)
.map_err(EmulationError::PlatformEmulationError)?;
let result = src_reg_value | dst_value;
set_op(
&insn,
0,
std::mem::size_of::<$bound>(),
state,
platform,
result,
)
.map_err(EmulationError::PlatformEmulationError)?;
set_op(&insn, 0, size_of::<$bound>(), state, platform, result)
.map_err(EmulationError::PlatformEmulationError)?;
Ok(())
}

View File

@@ -40,7 +40,7 @@ macro_rules! stos {
.map_err(|e| EmulationError::InvalidOperand(anyhow!(e)))?;
let backwards = string_op_backwards(state.flags());
let len = std::mem::size_of::<$bound>();
let len = size_of::<$bound>();
let rax_bytes = rax.to_le_bytes();
while count > 0 {