clippy: apply latest fixes

This commit is contained in:
Philipp Schuster
2025-03-23 15:45:52 +01:00
parent b8e1df0f5d
commit 90f24de04d
18 changed files with 49 additions and 49 deletions
+4 -7
View File
@@ -69,13 +69,10 @@ pub fn unsafe_protocol(args: TokenStream, input: TokenStream) -> TokenStream {
quote!(::uefi::guid!(#lit))
}
Expr::Path(ExprPath { path, .. }) => quote!(#path),
_ => {
return err!(
expr,
"macro input must be either a string literal or path to a constant"
)
.into();
}
_ => err!(
expr,
"macro input must be either a string literal or path to a constant"
),
};
let item_struct = parse_macro_input!(input as ItemStruct);
+2 -2
View File
@@ -993,10 +993,10 @@ mod tests {
fn test_unaligned_cstr16() {
let mut buf = [0u16; 6];
let us = unsafe {
let ptr = buf.as_mut_ptr() as *mut u8;
let ptr = buf.as_mut_ptr().cast::<u8>();
// Intentionally create an unaligned u16 pointer. This
// leaves room for five u16 characters.
let ptr = ptr.add(1) as *mut u16;
let ptr = ptr.add(1).cast::<u16>();
// Write out the "test" string.
ptr.add(0).write_unaligned(b't'.into());
ptr.add(1).write_unaligned(b'e'.into());
+1 -1
View File
@@ -112,7 +112,7 @@ mod tests {
#[test]
fn test_allocation_alignment() {
for request_alignment in [1, 2, 4, 8, 16, 32, 64, 128] {
for request_len in [1 as usize, 32, 64, 128, 1024] {
for request_len in [1_usize, 32, 64, 128, 1024] {
let buffer =
AlignedBuffer::from_size_align(request_len, request_alignment).unwrap();
assert_eq!(buffer.ptr() as usize % request_alignment, 0);
+2 -2
View File
@@ -461,13 +461,13 @@ mod tests {
];
/// Returns a copy of [`BASE_MMAP_UNSORTED`] owned on the stack.
fn new_mmap_memory() -> [MemoryDescriptor; 3] {
const fn new_mmap_memory() -> [MemoryDescriptor; 3] {
BASE_MMAP_UNSORTED
}
fn mmap_raw<'a>(memory: &mut [MemoryDescriptor]) -> (&'a mut [u8], MemoryMapMeta) {
let desc_size = size_of::<MemoryDescriptor>();
let len = memory.len() * desc_size;
let len = core::mem::size_of_val(memory);
let ptr = memory.as_mut_ptr().cast::<u8>();
let slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
let meta = MemoryMapMeta {
+1 -1
View File
@@ -110,7 +110,7 @@ mod tests_mmap_artificial {
fn buffer_to_map(buffer: &mut [MemoryDescriptor]) -> MemoryMapRefMut {
let mmap_len = size_of_val(buffer);
let mmap = {
unsafe { core::slice::from_raw_parts_mut(buffer.as_mut_ptr() as *mut u8, mmap_len) }
unsafe { core::slice::from_raw_parts_mut(buffer.as_mut_ptr().cast::<u8>(), mmap_len) }
};
MemoryMapRefMut::new(
+1 -1
View File
@@ -18,7 +18,7 @@ pub const unsafe fn maybe_uninit_slice_assume_init_ref<T>(s: &[MaybeUninit<T>])
/// Polyfill for the unstable `MaybeUninit::slice_as_mut_ptr` function.
///
/// See <https://github.com/rust-lang/rust/issues/63569>.
pub fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T {
pub const fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T {
s.as_mut_ptr().cast::<T>()
}
+2 -2
View File
@@ -294,7 +294,7 @@ impl<'a> AtaResponse<'a> {
/// # Returns
/// A reference to the [`AtaStatusBlock`] containing details about the status of the executed operation.
#[must_use]
pub fn status(&self) -> &'a AtaStatusBlock {
pub const fn status(&self) -> &'a AtaStatusBlock {
unsafe {
self.req
.asb
@@ -310,7 +310,7 @@ impl<'a> AtaResponse<'a> {
/// # Returns
/// `Option<&[u8]>`: A slice of the data read from the device, or `None` if no read buffer was used.
#[must_use]
pub fn read_buffer(&self) -> Option<&'a [u8]> {
pub const fn read_buffer(&self) -> Option<&'a [u8]> {
if self.req.packet.in_data_buffer.is_null() {
return None;
}
+2 -8
View File
@@ -51,14 +51,8 @@ mod tests {
#[test]
fn boot_policy() {
assert_eq!(
BootPolicy::try_from(Boolean::TRUE).unwrap(),
BootPolicy::BootSelection
);
assert_eq!(
BootPolicy::try_from(Boolean::FALSE).unwrap(),
BootPolicy::ExactMatch
);
assert_eq!(BootPolicy::from(Boolean::TRUE), BootPolicy::BootSelection);
assert_eq!(BootPolicy::from(Boolean::FALSE), BootPolicy::ExactMatch);
assert_eq!(Boolean::from(BootPolicy::BootSelection), Boolean::TRUE);
assert_eq!(Boolean::from(BootPolicy::ExactMatch), Boolean::FALSE);
}
+1 -1
View File
@@ -248,7 +248,7 @@ mod tests {
};
use core::slice;
fn path_to_bytes(path: &DevicePath) -> &[u8] {
const fn path_to_bytes(path: &DevicePath) -> &[u8] {
unsafe { slice::from_raw_parts(path.as_ffi_ptr().cast::<u8>(), size_of_val(path)) }
}
+1 -1
View File
@@ -95,7 +95,7 @@ impl LoadedImage {
///
/// [`load_options_as_cstr16`]: `Self::load_options_as_cstr16`
#[must_use]
pub fn load_options_as_bytes(&self) -> Option<&[u8]> {
pub const fn load_options_as_bytes(&self) -> Option<&[u8]> {
if self.0.load_options.is_null() {
None
} else {
+5 -1
View File
@@ -436,7 +436,11 @@ mod tests {
assert_eq!(align_of_val(info), T::alignment());
// Check the hardcoded name slice offset.
assert_eq!(
unsafe { (name.as_ptr() as *const u8).offset_from(info as *const _ as *const u8) },
unsafe {
name.as_ptr()
.cast::<u8>()
.offset_from(core::ptr::from_ref(info).cast::<u8>())
},
T::name_offset() as isize
);
}
+17 -10
View File
@@ -414,7 +414,11 @@ mod tests {
Status::BUFFER_TOO_SMALL
} else {
unsafe {
ptr::copy_nonoverlapping((info as *const FileInfo).cast(), buffer, required_size);
ptr::copy_nonoverlapping(
core::ptr::from_ref::<FileInfo>(info).cast(),
buffer,
required_size,
);
}
unsafe {
*buffer_size = required_size;
@@ -423,7 +427,7 @@ mod tests {
}
}
extern "efiapi" fn stub_open(
const extern "efiapi" fn stub_open(
_this: *mut FileProtocolV1,
_new_handle: *mut *mut FileProtocolV1,
_filename: *const uefi_raw::Char16,
@@ -433,15 +437,15 @@ mod tests {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
const extern "efiapi" fn stub_close(_this: *mut FileProtocolV1) -> Status {
Status::SUCCESS
}
extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
const extern "efiapi" fn stub_delete(_this: *mut FileProtocolV1) -> Status {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_read(
const extern "efiapi" fn stub_read(
_this: *mut FileProtocolV1,
_buffer_size: *mut usize,
_buffer: *mut c_void,
@@ -449,7 +453,7 @@ mod tests {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_write(
const extern "efiapi" fn stub_write(
_this: *mut FileProtocolV1,
_buffer_size: *mut usize,
_buffer: *const c_void,
@@ -457,18 +461,21 @@ mod tests {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_get_position(
const extern "efiapi" fn stub_get_position(
_this: *const FileProtocolV1,
_position: *mut u64,
) -> Status {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_set_position(_this: *mut FileProtocolV1, _position: u64) -> Status {
const extern "efiapi" fn stub_set_position(
_this: *mut FileProtocolV1,
_position: u64,
) -> Status {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_set_info(
const extern "efiapi" fn stub_set_info(
_this: *mut FileProtocolV1,
_information_type: *const Guid,
_buffer_size: usize,
@@ -477,7 +484,7 @@ mod tests {
Status::UNSUPPORTED
}
extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
const extern "efiapi" fn stub_flush(_this: *mut FileProtocolV1) -> Status {
Status::UNSUPPORTED
}
}
+2 -2
View File
@@ -247,7 +247,7 @@ impl<'buffers> NvmeResponse<'buffers> {
/// # Returns
/// `Option<&[u8]>`: A slice of the transfer buffer, or `None` if the request was started without.
#[must_use]
pub fn transfer_buffer(&self) -> Option<&'buffers [u8]> {
pub const fn transfer_buffer(&self) -> Option<&'buffers [u8]> {
if self.req.packet.transfer_buffer.is_null() {
return None;
}
@@ -264,7 +264,7 @@ impl<'buffers> NvmeResponse<'buffers> {
/// # Returns
/// `Option<&[u8]>`: A slice of the metadata buffer, or `None` if the request was started without.
#[must_use]
pub fn metadata_buffer(&self) -> Option<&'buffers [u8]> {
pub const fn metadata_buffer(&self) -> Option<&'buffers [u8]> {
if self.req.packet.meta_data_buffer.is_null() {
return None;
}
+2 -2
View File
@@ -300,7 +300,7 @@ impl<'a> ScsiResponse<'a> {
/// # Safety
/// - If the buffer pointer is `NULL`, the method returns `None` and avoids dereferencing it.
#[must_use]
pub fn read_buffer(&self) -> Option<&'a [u8]> {
pub const fn read_buffer(&self) -> Option<&'a [u8]> {
if self.0.packet.in_data_buffer.is_null() {
return None;
}
@@ -320,7 +320,7 @@ impl<'a> ScsiResponse<'a> {
/// # Safety
/// - If the buffer pointer is `NULL`, the method returns `None` and avoids dereferencing it.
#[must_use]
pub fn sense_data(&self) -> Option<&'a [u8]> {
pub const fn sense_data(&self) -> Option<&'a [u8]> {
if self.0.packet.sense_data.is_null() {
return None;
}
+1 -1
View File
@@ -92,7 +92,7 @@ impl MemoryProtection {
}
/// Convert a byte `Range` to `(base_address, length)`.
fn range_to_base_and_len(r: Range<PhysicalAddress>) -> (PhysicalAddress, PhysicalAddress) {
const fn range_to_base_and_len(r: Range<PhysicalAddress>) -> (PhysicalAddress, PhysicalAddress) {
(r.start, r.end.checked_sub(r.start).unwrap())
}
+3 -6
View File
@@ -178,12 +178,9 @@ mod tests {
with_config_table(|slice| {
for i in slice {
match i.guid {
ConfigTableEntry::ACPI2_GUID => {
acpi2_address = Some(i.address);
break;
}
_ => {}
if i.guid == ConfigTableEntry::ACPI2_GUID {
acpi2_address = Some(i.address);
break;
}
}
});
+1 -1
View File
@@ -4,7 +4,7 @@ use core::ptr::{self, NonNull};
/// Copy the bytes of `val` to `ptr`, then advance pointer to just after the
/// newly-copied bytes.
pub unsafe fn ptr_write_unaligned_and_add<T>(ptr: &mut *mut u8, val: T) {
pub const unsafe fn ptr_write_unaligned_and_add<T>(ptr: &mut *mut u8, val: T) {
unsafe {
ptr.cast::<T>().write_unaligned(val);
*ptr = ptr.add(size_of::<T>());
+1
View File
@@ -139,6 +139,7 @@ impl ToTokens for PackedType {
}
}
#[allow(clippy::large_enum_variant)]
enum BuildType {
None,
Packed,