Skip to content

Commit acc3253

Browse files
committed
clippy: apply latest fix
1 parent b8e1df0 commit acc3253

File tree

16 files changed

+33
-36
lines changed

16 files changed

+33
-36
lines changed

uefi/src/data_types/strs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,10 @@ mod tests {
993993
fn test_unaligned_cstr16() {
994994
let mut buf = [0u16; 6];
995995
let us = unsafe {
996-
let ptr = buf.as_mut_ptr() as *mut u8;
996+
let ptr = buf.as_mut_ptr().cast::<u8>();
997997
// Intentionally create an unaligned u16 pointer. This
998998
// leaves room for five u16 characters.
999-
let ptr = ptr.add(1) as *mut u16;
999+
let ptr = ptr.add(1).cast::<u16>();
10001000
// Write out the "test" string.
10011001
ptr.add(0).write_unaligned(b't'.into());
10021002
ptr.add(1).write_unaligned(b'e'.into());

uefi/src/mem/aligned_buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod tests {
112112
#[test]
113113
fn test_allocation_alignment() {
114114
for request_alignment in [1, 2, 4, 8, 16, 32, 64, 128] {
115-
for request_len in [1 as usize, 32, 64, 128, 1024] {
115+
for request_len in [1_usize, 32, 64, 128, 1024] {
116116
let buffer =
117117
AlignedBuffer::from_size_align(request_len, request_alignment).unwrap();
118118
assert_eq!(buffer.ptr() as usize % request_alignment, 0);

uefi/src/mem/memory_map/impl_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,13 @@ mod tests {
461461
];
462462

463463
/// Returns a copy of [`BASE_MMAP_UNSORTED`] owned on the stack.
464-
fn new_mmap_memory() -> [MemoryDescriptor; 3] {
464+
const fn new_mmap_memory() -> [MemoryDescriptor; 3] {
465465
BASE_MMAP_UNSORTED
466466
}
467467

468468
fn mmap_raw<'a>(memory: &mut [MemoryDescriptor]) -> (&'a mut [u8], MemoryMapMeta) {
469469
let desc_size = size_of::<MemoryDescriptor>();
470-
let len = memory.len() * desc_size;
470+
let len = core::mem::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

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod tests_mmap_artificial {
110110
fn buffer_to_map(buffer: &mut [MemoryDescriptor]) -> MemoryMapRefMut {
111111
let mmap_len = size_of_val(buffer);
112112
let mmap = {
113-
unsafe { core::slice::from_raw_parts_mut(buffer.as_mut_ptr() as *mut u8, mmap_len) }
113+
unsafe { core::slice::from_raw_parts_mut(buffer.as_mut_ptr().cast::<u8>(), mmap_len) }
114114
};
115115

116116
MemoryMapRefMut::new(

uefi/src/polyfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub const unsafe fn maybe_uninit_slice_assume_init_ref<T>(s: &[MaybeUninit<T>])
1818
/// Polyfill for the unstable `MaybeUninit::slice_as_mut_ptr` function.
1919
///
2020
/// See <https://github.com/rust-lang/rust/issues/63569>.
21-
pub fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T {
21+
pub const fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T {
2222
s.as_mut_ptr().cast::<T>()
2323
}
2424

uefi/src/proto/ata/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<'a> AtaResponse<'a> {
294294
/// # Returns
295295
/// A reference to the [`AtaStatusBlock`] containing details about the status of the executed operation.
296296
#[must_use]
297-
pub fn status(&self) -> &'a AtaStatusBlock {
297+
pub const fn status(&self) -> &'a AtaStatusBlock {
298298
unsafe {
299299
self.req
300300
.asb
@@ -310,7 +310,7 @@ impl<'a> AtaResponse<'a> {
310310
/// # Returns
311311
/// `Option<&[u8]>`: A slice of the data read from the device, or `None` if no read buffer was used.
312312
#[must_use]
313-
pub fn read_buffer(&self) -> Option<&'a [u8]> {
313+
pub const fn read_buffer(&self) -> Option<&'a [u8]> {
314314
if self.req.packet.in_data_buffer.is_null() {
315315
return None;
316316
}

uefi/src/proto/boot_policy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ mod tests {
5252
#[test]
5353
fn boot_policy() {
5454
assert_eq!(
55-
BootPolicy::try_from(Boolean::TRUE).unwrap(),
55+
BootPolicy::from(Boolean::TRUE),
5656
BootPolicy::BootSelection
5757
);
5858
assert_eq!(
59-
BootPolicy::try_from(Boolean::FALSE).unwrap(),
59+
BootPolicy::from(Boolean::FALSE),
6060
BootPolicy::ExactMatch
6161
);
6262
assert_eq!(Boolean::from(BootPolicy::BootSelection), Boolean::TRUE);

uefi/src/proto/device_path/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ mod tests {
248248
};
249249
use core::slice;
250250

251-
fn path_to_bytes(path: &DevicePath) -> &[u8] {
251+
const fn path_to_bytes(path: &DevicePath) -> &[u8] {
252252
unsafe { slice::from_raw_parts(path.as_ffi_ptr().cast::<u8>(), size_of_val(path)) }
253253
}
254254

uefi/src/proto/loaded_image.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl LoadedImage {
9595
///
9696
/// [`load_options_as_cstr16`]: `Self::load_options_as_cstr16`
9797
#[must_use]
98-
pub fn load_options_as_bytes(&self) -> Option<&[u8]> {
98+
pub const fn load_options_as_bytes(&self) -> Option<&[u8]> {
9999
if self.0.load_options.is_null() {
100100
None
101101
} else {

uefi/src/proto/media/file/info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ mod tests {
436436
assert_eq!(align_of_val(info), T::alignment());
437437
// Check the hardcoded name slice offset.
438438
assert_eq!(
439-
unsafe { (name.as_ptr() as *const u8).offset_from(info as *const _ as *const u8) },
439+
unsafe { name.as_ptr().cast::<u8>().offset_from(core::ptr::from_ref(info).cast::<u8>()) },
440440
T::name_offset() as isize
441441
);
442442
}

uefi/src/proto/media/file/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ mod tests {
414414
Status::BUFFER_TOO_SMALL
415415
} else {
416416
unsafe {
417-
ptr::copy_nonoverlapping((info as *const FileInfo).cast(), buffer, required_size);
417+
ptr::copy_nonoverlapping(core::ptr::from_ref::<FileInfo>(info).cast(), buffer, required_size);
418418
}
419419
unsafe {
420420
*buffer_size = required_size;
@@ -423,7 +423,7 @@ mod tests {
423423
}
424424
}
425425

426-
extern "efiapi" fn stub_open(
426+
const extern "efiapi" fn stub_open(
427427
_this: *mut FileProtocolV1,
428428
_new_handle: *mut *mut FileProtocolV1,
429429
_filename: *const uefi_raw::Char16,
@@ -433,42 +433,42 @@ mod tests {
433433
Status::UNSUPPORTED
434434
}
435435

436-
extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
436+
const extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
437437
Status::SUCCESS
438438
}
439439

440-
extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
440+
const extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
441441
Status::UNSUPPORTED
442442
}
443443

444-
extern "efiapi" fn stub_read(
444+
const extern "efiapi" fn stub_read(
445445
_this: *mut FileProtocolV1,
446446
_buffer_size: *mut usize,
447447
_buffer: *mut c_void,
448448
) -> Status {
449449
Status::UNSUPPORTED
450450
}
451451

452-
extern "efiapi" fn stub_write(
452+
const extern "efiapi" fn stub_write(
453453
_this: *mut FileProtocolV1,
454454
_buffer_size: *mut usize,
455455
_buffer: *const c_void,
456456
) -> Status {
457457
Status::UNSUPPORTED
458458
}
459459

460-
extern "efiapi" fn stub_get_position(
460+
const extern "efiapi" fn stub_get_position(
461461
_this: *const FileProtocolV1,
462462
_position: *mut u64,
463463
) -> Status {
464464
Status::UNSUPPORTED
465465
}
466466

467-
extern "efiapi" fn stub_set_position(_this: *mut FileProtocolV1, _position: u64) -> Status {
467+
const extern "efiapi" fn stub_set_position(_this: *mut FileProtocolV1, _position: u64) -> Status {
468468
Status::UNSUPPORTED
469469
}
470470

471-
extern "efiapi" fn stub_set_info(
471+
const extern "efiapi" fn stub_set_info(
472472
_this: *mut FileProtocolV1,
473473
_information_type: *const Guid,
474474
_buffer_size: usize,
@@ -477,7 +477,7 @@ mod tests {
477477
Status::UNSUPPORTED
478478
}
479479

480-
extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
480+
const extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
481481
Status::UNSUPPORTED
482482
}
483483
}

uefi/src/proto/nvme/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'buffers> NvmeResponse<'buffers> {
247247
/// # Returns
248248
/// `Option<&[u8]>`: A slice of the transfer buffer, or `None` if the request was started without.
249249
#[must_use]
250-
pub fn transfer_buffer(&self) -> Option<&'buffers [u8]> {
250+
pub const fn transfer_buffer(&self) -> Option<&'buffers [u8]> {
251251
if self.req.packet.transfer_buffer.is_null() {
252252
return None;
253253
}
@@ -264,7 +264,7 @@ impl<'buffers> NvmeResponse<'buffers> {
264264
/// # Returns
265265
/// `Option<&[u8]>`: A slice of the metadata buffer, or `None` if the request was started without.
266266
#[must_use]
267-
pub fn metadata_buffer(&self) -> Option<&'buffers [u8]> {
267+
pub const fn metadata_buffer(&self) -> Option<&'buffers [u8]> {
268268
if self.req.packet.meta_data_buffer.is_null() {
269269
return None;
270270
}

uefi/src/proto/scsi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a> ScsiResponse<'a> {
300300
/// # Safety
301301
/// - If the buffer pointer is `NULL`, the method returns `None` and avoids dereferencing it.
302302
#[must_use]
303-
pub fn read_buffer(&self) -> Option<&'a [u8]> {
303+
pub const fn read_buffer(&self) -> Option<&'a [u8]> {
304304
if self.0.packet.in_data_buffer.is_null() {
305305
return None;
306306
}
@@ -320,7 +320,7 @@ impl<'a> ScsiResponse<'a> {
320320
/// # Safety
321321
/// - If the buffer pointer is `NULL`, the method returns `None` and avoids dereferencing it.
322322
#[must_use]
323-
pub fn sense_data(&self) -> Option<&'a [u8]> {
323+
pub const fn sense_data(&self) -> Option<&'a [u8]> {
324324
if self.0.packet.sense_data.is_null() {
325325
return None;
326326
}

uefi/src/proto/security/memory_protection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl MemoryProtection {
9292
}
9393

9494
/// Convert a byte `Range` to `(base_address, length)`.
95-
fn range_to_base_and_len(r: Range<PhysicalAddress>) -> (PhysicalAddress, PhysicalAddress) {
95+
const fn range_to_base_and_len(r: Range<PhysicalAddress>) -> (PhysicalAddress, PhysicalAddress) {
9696
(r.start, r.end.checked_sub(r.start).unwrap())
9797
}
9898

uefi/src/system.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,9 @@ mod tests {
178178

179179
with_config_table(|slice| {
180180
for i in slice {
181-
match i.guid {
182-
ConfigTableEntry::ACPI2_GUID => {
183-
acpi2_address = Some(i.address);
184-
break;
185-
}
186-
_ => {}
181+
if i.guid == ConfigTableEntry::ACPI2_GUID {
182+
acpi2_address = Some(i.address);
183+
break;
187184
}
188185
}
189186
});

uefi/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::ptr::{self, NonNull};
44

55
/// Copy the bytes of `val` to `ptr`, then advance pointer to just after the
66
/// newly-copied bytes.
7-
pub unsafe fn ptr_write_unaligned_and_add<T>(ptr: &mut *mut u8, val: T) {
7+
pub const unsafe fn ptr_write_unaligned_and_add<T>(ptr: &mut *mut u8, val: T) {
88
unsafe {
99
ptr.cast::<T>().write_unaligned(val);
1010
*ptr = ptr.add(size_of::<T>());

0 commit comments

Comments
 (0)