Skip to content

Commit 6a18a9d

Browse files
authored
Merge pull request #1734 from rust-osdev/bishop-prelude-cleaner
Use size_of/align_of from prelude
2 parents d30f3c3 + 7e0b8b3 commit 6a18a9d

File tree

11 files changed

+10
-20
lines changed

11 files changed

+10
-20
lines changed

uefi-raw/src/protocol/device_path.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,12 @@ impl DevicePathUtilitiesProtocol {
304304
#[cfg(test)]
305305
mod tests {
306306
use super::*;
307-
use core::mem;
308307

309308
/// Test that ensures the struct is packed. Thus, we don't need to
310309
/// explicitly specify `packed`.
311310
#[test]
312311
fn abi() {
313-
assert_eq!(mem::size_of::<DevicePathProtocol>(), 4);
314-
assert_eq!(mem::align_of::<DevicePathProtocol>(), 1);
312+
assert_eq!(size_of::<DevicePathProtocol>(), 4);
313+
assert_eq!(align_of::<DevicePathProtocol>(), 1);
315314
}
316315
}

uefi-raw/src/table/system.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::table::boot::BootServices;
66
use crate::table::configuration::ConfigurationTable;
77
use crate::table::runtime::RuntimeServices;
88
use crate::{Char16, Handle};
9-
use core::mem::size_of;
109
use core::ptr;
1110

1211
#[derive(Clone, Debug, Eq, PartialEq)]

uefi-test-runner/src/proto/pci/root_bridge.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

3-
use core::mem;
43
use uefi::Handle;
54
use uefi::boot::{OpenProtocolAttributes, OpenProtocolParams, ScopedProtocol, image_handle};
65
use uefi::proto::ProtocolPointer;
@@ -11,7 +10,7 @@ const RED_HAT_PCI_VENDOR_ID: u16 = 0x1AF4;
1110
const MASS_STORAGE_CTRL_CLASS_CODE: u8 = 0x1;
1211
const SATA_CTRL_SUBCLASS_CODE: u8 = 0x6;
1312

14-
const REG_SIZE: u8 = mem::size_of::<u32>() as u8;
13+
const REG_SIZE: u8 = size_of::<u32>() as u8;
1514

1615
pub fn test() {
1716
let pci_handles = uefi::boot::find_handles::<PciRootBridgeIo>().unwrap();

uefi-test-runner/src/proto/usb/io.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

3-
use core::mem;
43
use uefi::proto::usb::DeviceDescriptor;
54
use uefi::proto::usb::io::{ControlTransfer, UsbIo};
65
use uefi::{Status, boot};
@@ -61,14 +60,14 @@ pub fn test() {
6160
result.expect("failed to acquire string descriptor");
6261
}
6362

64-
let mut buffer = [0u8; mem::size_of::<DeviceDescriptor>()];
63+
let mut buffer = [0u8; size_of::<DeviceDescriptor>()];
6564

6665
io.control_transfer(
6766
DEVICE_TO_HOST | STANDARD_REQUEST | DEVICE_RECIPIENT,
6867
GET_DESCRIPTOR_REQUEST,
6968
u16::from(DEVICE_DESCRIPTOR) << 8,
7069
0,
71-
ControlTransfer::DataIn(&mut buffer[..mem::size_of::<DeviceDescriptor>()]),
70+
ControlTransfer::DataIn(&mut buffer[..size_of::<DeviceDescriptor>()]),
7271
0,
7372
)
7473
.expect("failed control transfer");

uefi/src/mem/memory_map/impl_.rs

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

468468
fn mmap_raw<'a>(memory: &mut [MemoryDescriptor]) -> (&'a mut [u8], MemoryMapMeta) {
469469
let desc_size = size_of::<MemoryDescriptor>();
470-
let len = core::mem::size_of_val(memory);
470+
let len = size_of_val(memory);
471471
let ptr = memory.as_mut_ptr().cast::<u8>();
472472
let slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
473473
let meta = MemoryMapMeta {

uefi/src/mem/memory_map/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ impl MemoryMapMeta {
105105
#[cfg(test)]
106106
mod tests_mmap_artificial {
107107
use super::*;
108-
use core::mem::{size_of, size_of_val};
109108

110109
fn buffer_to_map(buffer: &mut [MemoryDescriptor]) -> MemoryMapRefMut<'_> {
111110
let mmap_len = size_of_val(buffer);

uefi/src/mem/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ mod tests {
120120
use crate::{ResultExt, StatusExt};
121121
#[cfg(feature = "unstable")]
122122
use alloc::alloc::Global;
123-
use core::mem::{align_of, size_of};
124123

125124
/// Some simple dummy type to test [`make_boxed`].
126125
#[derive(Debug)]

uefi/src/proto/device_path/device_path_gen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::proto::device_path::{
1717
use crate::proto::network::IpAddress;
1818
use crate::{Guid, guid};
1919
use bitflags::bitflags;
20-
use core::mem::{size_of, size_of_val};
2120
use core::ptr::addr_of;
2221
use core::{fmt, slice};
2322
use ptr_meta::Pointee;
@@ -3650,7 +3649,7 @@ pub mod build {
36503649
use crate::CStr16;
36513650
use crate::proto::device_path::build::{BuildError, BuildNode};
36523651
use crate::proto::device_path::{DeviceSubType, DeviceType};
3653-
use core::mem::{MaybeUninit, size_of_val};
3652+
use core::mem::MaybeUninit;
36543653
/// Device path build nodes for [`DeviceType::END`].
36553654
pub mod end {
36563655
use super::*;

uefi/src/proto/device_path/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,6 @@ fn open_utility_protocol() -> Result<ScopedProtocol<DevicePathUtilities>, Device
921921
mod tests {
922922
use super::*;
923923
use alloc::vec::Vec;
924-
use core::mem::{size_of, size_of_val};
925924

926925
/// Create a node to `path` from raw data.
927926
fn add_node(path: &mut Vec<u8>, device_type: u8, sub_type: u8, node_data: &[u8]) {

uefi/src/proto/pci/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ enum PciIoMode {
106106
}
107107

108108
fn encode_io_mode_and_unit<U: PciIoUnit>(mode: PciIoMode) -> PciRootBridgeIoProtocolWidth {
109-
match (mode, core::mem::size_of::<U>()) {
109+
match (mode, size_of::<U>()) {
110110
(PciIoMode::Normal, 1) => PciRootBridgeIoProtocolWidth::UINT8,
111111
(PciIoMode::Normal, 2) => PciRootBridgeIoProtocolWidth::UINT16,
112112
(PciIoMode::Normal, 4) => PciRootBridgeIoProtocolWidth::UINT32,
@@ -129,11 +129,10 @@ fn encode_io_mode_and_unit<U: PciIoUnit>(mode: PciIoMode) -> PciRootBridgeIoProt
129129
#[cfg(test)]
130130
mod tests {
131131
use super::PciIoAddress;
132-
use core::mem;
133132

134133
#[test]
135134
fn test_pci_ioaddr_raw_conversion() {
136-
assert_eq!(mem::size_of::<u64>(), mem::size_of::<PciIoAddress>());
135+
assert_eq!(size_of::<u64>(), size_of::<PciIoAddress>());
137136
let srcaddr = PciIoAddress {
138137
reg: 0x11,
139138
fun: 0x33,

0 commit comments

Comments
 (0)