Skip to content

Commit 9a95466

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

File tree

17 files changed

+49
-49
lines changed

17 files changed

+49
-49
lines changed

uefi-macros/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ pub fn unsafe_protocol(args: TokenStream, input: TokenStream) -> TokenStream {
6969
quote!(::uefi::guid!(#lit))
7070
}
7171
Expr::Path(ExprPath { path, .. }) => quote!(#path),
72-
_ => {
73-
return err!(
74-
expr,
75-
"macro input must be either a string literal or path to a constant"
76-
)
77-
.into();
78-
}
72+
_ => err!(
73+
expr,
74+
"macro input must be either a string literal or path to a constant"
75+
)
76+
.into(),
7977
};
8078

8179
let item_struct = parse_macro_input!(input as ItemStruct);

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-8
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,8 @@ mod tests {
5151

5252
#[test]
5353
fn boot_policy() {
54-
assert_eq!(
55-
BootPolicy::try_from(Boolean::TRUE).unwrap(),
56-
BootPolicy::BootSelection
57-
);
58-
assert_eq!(
59-
BootPolicy::try_from(Boolean::FALSE).unwrap(),
60-
BootPolicy::ExactMatch
61-
);
54+
assert_eq!(BootPolicy::from(Boolean::TRUE), BootPolicy::BootSelection);
55+
assert_eq!(BootPolicy::from(Boolean::FALSE), BootPolicy::ExactMatch);
6256
assert_eq!(Boolean::from(BootPolicy::BootSelection), Boolean::TRUE);
6357
assert_eq!(Boolean::from(BootPolicy::ExactMatch), Boolean::FALSE);
6458
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,11 @@ 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 {
440+
name.as_ptr()
441+
.cast::<u8>()
442+
.offset_from(core::ptr::from_ref(info).cast::<u8>())
443+
},
440444
T::name_offset() as isize
441445
);
442446
}

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

+17-10
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ 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(
418+
core::ptr::from_ref::<FileInfo>(info).cast(),
419+
buffer,
420+
required_size,
421+
);
418422
}
419423
unsafe {
420424
*buffer_size = required_size;
@@ -423,7 +427,7 @@ mod tests {
423427
}
424428
}
425429

426-
extern "efiapi" fn stub_open(
430+
const extern "efiapi" fn stub_open(
427431
_this: *mut FileProtocolV1,
428432
_new_handle: *mut *mut FileProtocolV1,
429433
_filename: *const uefi_raw::Char16,
@@ -433,42 +437,45 @@ mod tests {
433437
Status::UNSUPPORTED
434438
}
435439

436-
extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
440+
const extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
437441
Status::SUCCESS
438442
}
439443

440-
extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
444+
const extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
441445
Status::UNSUPPORTED
442446
}
443447

444-
extern "efiapi" fn stub_read(
448+
const extern "efiapi" fn stub_read(
445449
_this: *mut FileProtocolV1,
446450
_buffer_size: *mut usize,
447451
_buffer: *mut c_void,
448452
) -> Status {
449453
Status::UNSUPPORTED
450454
}
451455

452-
extern "efiapi" fn stub_write(
456+
const extern "efiapi" fn stub_write(
453457
_this: *mut FileProtocolV1,
454458
_buffer_size: *mut usize,
455459
_buffer: *const c_void,
456460
) -> Status {
457461
Status::UNSUPPORTED
458462
}
459463

460-
extern "efiapi" fn stub_get_position(
464+
const extern "efiapi" fn stub_get_position(
461465
_this: *const FileProtocolV1,
462466
_position: *mut u64,
463467
) -> Status {
464468
Status::UNSUPPORTED
465469
}
466470

467-
extern "efiapi" fn stub_set_position(_this: *mut FileProtocolV1, _position: u64) -> Status {
471+
const extern "efiapi" fn stub_set_position(
472+
_this: *mut FileProtocolV1,
473+
_position: u64,
474+
) -> Status {
468475
Status::UNSUPPORTED
469476
}
470477

471-
extern "efiapi" fn stub_set_info(
478+
const extern "efiapi" fn stub_set_info(
472479
_this: *mut FileProtocolV1,
473480
_information_type: *const Guid,
474481
_buffer_size: usize,
@@ -477,7 +484,7 @@ mod tests {
477484
Status::UNSUPPORTED
478485
}
479486

480-
extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
487+
const extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
481488
Status::UNSUPPORTED
482489
}
483490
}

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)