From 6691f0e1ddf440b210189e883e009f2847fbb977 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Tue, 30 Jul 2024 08:19:01 +0200 Subject: [PATCH 1/3] clippy/uefi: prefer Self where possible --- uefi/src/data_types/chars.rs | 12 +-- uefi/src/data_types/owned_strs.rs | 8 +- uefi/src/data_types/strs.rs | 10 +-- uefi/src/helpers/logger.rs | 4 +- uefi/src/lib.rs | 7 +- uefi/src/mem/memory_map/impl_.rs | 2 +- uefi/src/proto/console/text/input.rs | 6 +- uefi/src/proto/debug/exception.rs | 56 ++++++------- uefi/src/proto/device_path/mod.rs | 116 +++++++++++++-------------- uefi/src/proto/tcg/v1.rs | 2 +- uefi/src/proto/tcg/v2.rs | 6 +- uefi/src/result/error.rs | 2 +- uefi/src/result/mod.rs | 4 +- uefi/src/result/status.rs | 4 +- uefi/src/table/runtime.rs | 4 +- uefi/src/table/system.rs | 2 +- 16 files changed, 124 insertions(+), 121 deletions(-) diff --git a/uefi/src/data_types/chars.rs b/uefi/src/data_types/chars.rs index 60671514b..c2f5bd63f 100644 --- a/uefi/src/data_types/chars.rs +++ b/uefi/src/data_types/chars.rs @@ -35,19 +35,19 @@ impl TryFrom for Char8 { } impl From for char { - fn from(char: Char8) -> char { - char::from(char.0) + fn from(char: Char8) -> Self { + Self::from(char.0) } } impl From for Char8 { fn from(value: u8) -> Self { - Char8(value) + Self(value) } } impl From for u8 { - fn from(char: Char8) -> u8 { + fn from(char: Char8) -> Self { char.0 } } @@ -107,7 +107,7 @@ impl TryFrom for Char16 { } impl From for char { - fn from(char: Char16) -> char { + fn from(char: Char16) -> Self { u32::from(char.0).try_into().unwrap() } } @@ -127,7 +127,7 @@ impl TryFrom for Char16 { } impl From for u16 { - fn from(char: Char16) -> u16 { + fn from(char: Char16) -> Self { char.0 } } diff --git a/uefi/src/data_types/owned_strs.rs b/uefi/src/data_types/owned_strs.rs index cf11f43ae..6fe29a6bd 100644 --- a/uefi/src/data_types/owned_strs.rs +++ b/uefi/src/data_types/owned_strs.rs @@ -113,7 +113,7 @@ impl CString16 { impl Default for CString16 { fn default() -> Self { - CString16::new() + Self::new() } } @@ -141,7 +141,7 @@ impl TryFrom<&str> for CString16 { // Add trailing nul. output.push(NUL_16); - Ok(CString16(output)) + Ok(Self(output)) } } @@ -175,7 +175,7 @@ impl<'a> TryFrom<&UnalignedSlice<'a, u16>> for CString16 { fn try_from(input: &UnalignedSlice) -> Result { let v = input.to_vec(); - CString16::try_from(v) + Self::try_from(v) } } @@ -189,7 +189,7 @@ impl From<&CStr16> for CString16 { impl From<&CString16> for String { fn from(value: &CString16) -> Self { let slice: &CStr16 = value.as_ref(); - String::from(slice) + Self::from(slice) } } diff --git a/uefi/src/data_types/strs.rs b/uefi/src/data_types/strs.rs index 2855e8802..161825200 100644 --- a/uefi/src/data_types/strs.rs +++ b/uefi/src/data_types/strs.rs @@ -457,7 +457,7 @@ impl CStr16 { pub fn from_unaligned_slice<'buf>( src: &UnalignedSlice<'_, u16>, buf: &'buf mut [MaybeUninit], - ) -> Result<&'buf CStr16, UnalignedCStr16Error> { + ) -> Result<&'buf Self, UnalignedCStr16Error> { // The input `buf` might be longer than needed, so get a // subslice of the required length. let buf = buf @@ -469,7 +469,7 @@ impl CStr16 { // Safety: `copy_buf` fully initializes the slice. maybe_uninit_slice_assume_init_ref(buf) }; - CStr16::from_u16_with_nul(buf).map_err(|e| match e { + Self::from_u16_with_nul(buf).map_err(|e| match e { FromSliceWithNulError::InvalidChar(v) => UnalignedCStr16Error::InvalidChar(v), FromSliceWithNulError::InteriorNul(v) => UnalignedCStr16Error::InteriorNul(v), FromSliceWithNulError::NotNulTerminated => UnalignedCStr16Error::NotNulTerminated, @@ -593,7 +593,7 @@ impl From<&CStr16> for alloc::string::String { .map(u16::from) .map(u32::from) .map(|int| char::from_u32(int).expect("Should be encodable as UTF-8")) - .collect::() + .collect::() } } @@ -615,8 +615,8 @@ impl + ?Sized> EqStrUntilNul for CStr16 { } } -impl AsRef for CStr16 { - fn as_ref(&self) -> &CStr16 { +impl AsRef for CStr16 { + fn as_ref(&self) -> &Self { self } } diff --git a/uefi/src/helpers/logger.rs b/uefi/src/helpers/logger.rs index e6fd103f7..cb01a1ae4 100644 --- a/uefi/src/helpers/logger.rs +++ b/uefi/src/helpers/logger.rs @@ -58,7 +58,7 @@ impl core::fmt::Write for DebugconWriter { fn write_str(&mut self, s: &str) -> fmt::Result { for &byte in s.as_bytes() { unsafe { - core::arch::asm!("outb %al, %dx", in("al") byte, in("dx") DebugconWriter::IO_PORT, options(att_syntax)) + core::arch::asm!("outb %al, %dx", in("al") byte, in("dx") Self::IO_PORT, options(att_syntax)) }; } Ok(()) @@ -83,7 +83,7 @@ impl Logger { /// [`set_output`]: Self::set_output #[must_use] pub const fn new() -> Self { - Logger { + Self { writer: AtomicPtr::new(ptr::null_mut()), } } diff --git a/uefi/src/lib.rs b/uefi/src/lib.rs index 4dc526893..fdd9a55c9 100644 --- a/uefi/src/lib.rs +++ b/uefi/src/lib.rs @@ -89,8 +89,11 @@ #![no_std] // Enable some additional warnings and lints. #![warn(clippy::ptr_as_ptr, missing_docs, unused)] -#![deny(clippy::all)] -#![deny(clippy::must_use_candidate)] +#![deny( + clippy::all, + clippy::must_use_candidate, + clippy::use_self +)] #![deny(missing_debug_implementations)] #[cfg(feature = "alloc")] diff --git a/uefi/src/mem/memory_map/impl_.rs b/uefi/src/mem/memory_map/impl_.rs index 1e2ee9890..5fd9d1a90 100644 --- a/uefi/src/mem/memory_map/impl_.rs +++ b/uefi/src/mem/memory_map/impl_.rs @@ -373,7 +373,7 @@ impl MemoryMapOwned { pub(crate) fn from_initialized_mem(buf: MemoryMapBackingMemory, meta: MemoryMapMeta) -> Self { assert!(meta.desc_size >= mem::size_of::()); let len = meta.entry_count(); - MemoryMapOwned { buf, meta, len } + Self { buf, meta, len } } } diff --git a/uefi/src/proto/console/text/input.rs b/uefi/src/proto/console/text/input.rs index 20bb2db83..e681c97cf 100644 --- a/uefi/src/proto/console/text/input.rs +++ b/uefi/src/proto/console/text/input.rs @@ -98,11 +98,11 @@ pub enum Key { } impl From for Key { - fn from(k: InputKey) -> Key { + fn from(k: InputKey) -> Self { if k.scan_code == ScanCode::NULL.0 { - Key::Printable(Char16::try_from(k.unicode_char).unwrap()) + Self::Printable(Char16::try_from(k.unicode_char).unwrap()) } else { - Key::Special(ScanCode(k.scan_code)) + Self::Special(ScanCode(k.scan_code)) } } } diff --git a/uefi/src/proto/debug/exception.rs b/uefi/src/proto/debug/exception.rs index 4298a54b6..b2d453842 100644 --- a/uefi/src/proto/debug/exception.rs +++ b/uefi/src/proto/debug/exception.rs @@ -5,27 +5,27 @@ pub struct ExceptionType(isize); impl ExceptionType { /// Undefined Exception - pub const EXCEPT_EBC_UNDEFINED: ExceptionType = ExceptionType(0); + pub const EXCEPT_EBC_UNDEFINED: Self = Self(0); /// Divide-by-zero Error - pub const EXCEPT_EBC_DIVIDE_ERROR: ExceptionType = ExceptionType(1); + pub const EXCEPT_EBC_DIVIDE_ERROR: Self = Self(1); /// Debug Exception - pub const EXCEPT_EBC_DEBUG: ExceptionType = ExceptionType(2); + pub const EXCEPT_EBC_DEBUG: Self = Self(2); /// Breakpoint - pub const EXCEPT_EBC_BREAKPOINT: ExceptionType = ExceptionType(3); + pub const EXCEPT_EBC_BREAKPOINT: Self = Self(3); /// Overflow - pub const EXCEPT_EBC_OVERFLOW: ExceptionType = ExceptionType(4); + pub const EXCEPT_EBC_OVERFLOW: Self = Self(4); /// Invalid Opcode - pub const EXCEPT_EBC_INVALID_OPCODE: ExceptionType = ExceptionType(5); + pub const EXCEPT_EBC_INVALID_OPCODE: Self = Self(5); /// Stack-Segment Fault - pub const EXCEPT_EBC_STACK_FAULT: ExceptionType = ExceptionType(6); + pub const EXCEPT_EBC_STACK_FAULT: Self = Self(6); /// Alignment Check - pub const EXCEPT_EBC_ALIGNMENT_CHECK: ExceptionType = ExceptionType(7); + pub const EXCEPT_EBC_ALIGNMENT_CHECK: Self = Self(7); /// Instruction Encoding Exception - pub const EXCEPT_EBC_INSTRUCTION_ENCODING: ExceptionType = ExceptionType(8); + pub const EXCEPT_EBC_INSTRUCTION_ENCODING: Self = Self(8); /// Bad Breakpoint Exception - pub const EXCEPT_EBC_BAD_BREAK: ExceptionType = ExceptionType(9); + pub const EXCEPT_EBC_BAD_BREAK: Self = Self(9); /// Single Step Exception - pub const EXCEPT_EBC_SINGLE_STEP: ExceptionType = ExceptionType(10); + pub const EXCEPT_EBC_SINGLE_STEP: Self = Self(10); } #[cfg(target_arch = "x86")] @@ -69,39 +69,39 @@ impl ExceptionType { #[cfg(target_arch = "x86_64")] impl ExceptionType { /// Divide-by-zero Error - pub const EXCEPT_X64_DIVIDE_ERROR: ExceptionType = ExceptionType(0); + pub const EXCEPT_X64_DIVIDE_ERROR: Self = Self(0); /// Debug Exception - pub const EXCEPT_X64_DEBUG: ExceptionType = ExceptionType(1); + pub const EXCEPT_X64_DEBUG: Self = Self(1); /// Non-maskable Interrupt - pub const EXCEPT_X64_NMI: ExceptionType = ExceptionType(2); + pub const EXCEPT_X64_NMI: Self = Self(2); /// Breakpoint - pub const EXCEPT_X64_BREAKPOINT: ExceptionType = ExceptionType(3); + pub const EXCEPT_X64_BREAKPOINT: Self = Self(3); /// Overflow - pub const EXCEPT_X64_OVERFLOW: ExceptionType = ExceptionType(4); + pub const EXCEPT_X64_OVERFLOW: Self = Self(4); /// Bound Range Exceeded - pub const EXCEPT_X64_BOUND: ExceptionType = ExceptionType(5); + pub const EXCEPT_X64_BOUND: Self = Self(5); /// Invalid Opcode - pub const EXCEPT_X64_INVALID_OPCODE: ExceptionType = ExceptionType(6); + pub const EXCEPT_X64_INVALID_OPCODE: Self = Self(6); /// Double Fault - pub const EXCEPT_X64_DOUBLE_FAULT: ExceptionType = ExceptionType(8); + pub const EXCEPT_X64_DOUBLE_FAULT: Self = Self(8); /// Invalid TSS - pub const EXCEPT_X64_INVALID_TSS: ExceptionType = ExceptionType(10); + pub const EXCEPT_X64_INVALID_TSS: Self = Self(10); /// Segment Not Present - pub const EXCEPT_X64_SEG_NOT_PRESENT: ExceptionType = ExceptionType(11); + pub const EXCEPT_X64_SEG_NOT_PRESENT: Self = Self(11); /// Stack-Segment Fault - pub const EXCEPT_X64_STACK_FAULT: ExceptionType = ExceptionType(12); + pub const EXCEPT_X64_STACK_FAULT: Self = Self(12); /// General Protection Fault - pub const EXCEPT_X64_GP_FAULT: ExceptionType = ExceptionType(13); + pub const EXCEPT_X64_GP_FAULT: Self = Self(13); /// Page Fault - pub const EXCEPT_X64_PAGE_FAULT: ExceptionType = ExceptionType(14); + pub const EXCEPT_X64_PAGE_FAULT: Self = Self(14); /// x87 Floating-Point Exception - pub const EXCEPT_X64_FP_ERROR: ExceptionType = ExceptionType(16); + pub const EXCEPT_X64_FP_ERROR: Self = Self(16); /// Alignment Check - pub const EXCEPT_X64_ALIGNMENT_CHECK: ExceptionType = ExceptionType(17); + pub const EXCEPT_X64_ALIGNMENT_CHECK: Self = Self(17); /// Machine Check - pub const EXCEPT_X64_MACHINE_CHECK: ExceptionType = ExceptionType(18); + pub const EXCEPT_X64_MACHINE_CHECK: Self = Self(18); /// SIMD Floating-Point Exception - pub const EXCEPT_X64_SIMD: ExceptionType = ExceptionType(19); + pub const EXCEPT_X64_SIMD: Self = Self(19); } #[cfg(target_arch = "arm")] diff --git a/uefi/src/proto/device_path/mod.rs b/uefi/src/proto/device_path/mod.rs index 185a4e447..2c0553b5c 100644 --- a/uefi/src/proto/device_path/mod.rs +++ b/uefi/src/proto/device_path/mod.rs @@ -171,7 +171,7 @@ impl DevicePathNode { /// remain valid for the lifetime `'a`, and cannot be mutated during /// that lifetime. #[must_use] - pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a DevicePathNode { + pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a Self { let header = *ptr.cast::(); let data_len = usize::from(header.length) - mem::size_of::(); @@ -339,7 +339,7 @@ impl PartialEq for DevicePathInstance { #[cfg(feature = "alloc")] impl ToOwned for DevicePathInstance { - type Owned = Box; + type Owned = Box; fn to_owned(&self) -> Self::Owned { self.to_boxed() @@ -433,7 +433,7 @@ impl DevicePath { /// remain valid for the lifetime `'a`, and cannot be mutated during /// that lifetime. #[must_use] - pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a DevicePath { + pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a Self { &*Self::ptr_from_ffi(ptr.cast::()) } @@ -527,7 +527,7 @@ impl<'a> TryFrom<&[u8]> for &'a DevicePath { #[cfg(feature = "alloc")] impl ToOwned for DevicePath { - type Owned = Box; + type Owned = Box; fn to_owned(&self) -> Self::Owned { self.to_boxed() @@ -678,118 +678,118 @@ pub struct DeviceSubType(pub u8); impl DeviceSubType { /// PCI Device Path. - pub const HARDWARE_PCI: DeviceSubType = DeviceSubType(1); + pub const HARDWARE_PCI: Self = Self(1); /// PCCARD Device Path. - pub const HARDWARE_PCCARD: DeviceSubType = DeviceSubType(2); + pub const HARDWARE_PCCARD: Self = Self(2); /// Memory-mapped Device Path. - pub const HARDWARE_MEMORY_MAPPED: DeviceSubType = DeviceSubType(3); + pub const HARDWARE_MEMORY_MAPPED: Self = Self(3); /// Vendor-Defined Device Path. - pub const HARDWARE_VENDOR: DeviceSubType = DeviceSubType(4); + pub const HARDWARE_VENDOR: Self = Self(4); /// Controller Device Path. - pub const HARDWARE_CONTROLLER: DeviceSubType = DeviceSubType(5); + pub const HARDWARE_CONTROLLER: Self = Self(5); /// BMC Device Path. - pub const HARDWARE_BMC: DeviceSubType = DeviceSubType(6); + pub const HARDWARE_BMC: Self = Self(6); /// ACPI Device Path. - pub const ACPI: DeviceSubType = DeviceSubType(1); + pub const ACPI: Self = Self(1); /// Expanded ACPI Device Path. - pub const ACPI_EXPANDED: DeviceSubType = DeviceSubType(2); + pub const ACPI_EXPANDED: Self = Self(2); /// ACPI _ADR Device Path. - pub const ACPI_ADR: DeviceSubType = DeviceSubType(3); + pub const ACPI_ADR: Self = Self(3); /// NVDIMM Device Path. - pub const ACPI_NVDIMM: DeviceSubType = DeviceSubType(4); + pub const ACPI_NVDIMM: Self = Self(4); /// ATAPI Device Path. - pub const MESSAGING_ATAPI: DeviceSubType = DeviceSubType(1); + pub const MESSAGING_ATAPI: Self = Self(1); /// SCSI Device Path. - pub const MESSAGING_SCSI: DeviceSubType = DeviceSubType(2); + pub const MESSAGING_SCSI: Self = Self(2); /// Fibre Channel Device Path. - pub const MESSAGING_FIBRE_CHANNEL: DeviceSubType = DeviceSubType(3); + pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3); /// 1394 Device Path. - pub const MESSAGING_1394: DeviceSubType = DeviceSubType(4); + pub const MESSAGING_1394: Self = Self(4); /// USB Device Path. - pub const MESSAGING_USB: DeviceSubType = DeviceSubType(5); + pub const MESSAGING_USB: Self = Self(5); /// I2O Device Path. - pub const MESSAGING_I2O: DeviceSubType = DeviceSubType(6); + pub const MESSAGING_I2O: Self = Self(6); /// Infiniband Device Path. - pub const MESSAGING_INFINIBAND: DeviceSubType = DeviceSubType(9); + pub const MESSAGING_INFINIBAND: Self = Self(9); /// Vendor-Defined Device Path. - pub const MESSAGING_VENDOR: DeviceSubType = DeviceSubType(10); + pub const MESSAGING_VENDOR: Self = Self(10); /// MAC Address Device Path. - pub const MESSAGING_MAC_ADDRESS: DeviceSubType = DeviceSubType(11); + pub const MESSAGING_MAC_ADDRESS: Self = Self(11); /// IPV4 Device Path. - pub const MESSAGING_IPV4: DeviceSubType = DeviceSubType(12); + pub const MESSAGING_IPV4: Self = Self(12); /// IPV6 Device Path. - pub const MESSAGING_IPV6: DeviceSubType = DeviceSubType(13); + pub const MESSAGING_IPV6: Self = Self(13); /// UART Device Path. - pub const MESSAGING_UART: DeviceSubType = DeviceSubType(14); + pub const MESSAGING_UART: Self = Self(14); /// USB Class Device Path. - pub const MESSAGING_USB_CLASS: DeviceSubType = DeviceSubType(15); + pub const MESSAGING_USB_CLASS: Self = Self(15); /// USB WWID Device Path. - pub const MESSAGING_USB_WWID: DeviceSubType = DeviceSubType(16); + pub const MESSAGING_USB_WWID: Self = Self(16); /// Device Logical Unit. - pub const MESSAGING_DEVICE_LOGICAL_UNIT: DeviceSubType = DeviceSubType(17); + pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17); /// SATA Device Path. - pub const MESSAGING_SATA: DeviceSubType = DeviceSubType(18); + pub const MESSAGING_SATA: Self = Self(18); /// iSCSI Device Path node (base information). - pub const MESSAGING_ISCSI: DeviceSubType = DeviceSubType(19); + pub const MESSAGING_ISCSI: Self = Self(19); /// VLAN Device Path node. - pub const MESSAGING_VLAN: DeviceSubType = DeviceSubType(20); + pub const MESSAGING_VLAN: Self = Self(20); /// Fibre Channel Ex Device Path. - pub const MESSAGING_FIBRE_CHANNEL_EX: DeviceSubType = DeviceSubType(21); + pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21); /// Serial Attached SCSI (SAS) Ex Device Path. - pub const MESSAGING_SCSI_SAS_EX: DeviceSubType = DeviceSubType(22); + pub const MESSAGING_SCSI_SAS_EX: Self = Self(22); /// NVM Express Namespace Device Path. - pub const MESSAGING_NVME_NAMESPACE: DeviceSubType = DeviceSubType(23); + pub const MESSAGING_NVME_NAMESPACE: Self = Self(23); /// Uniform Resource Identifiers (URI) Device Path. - pub const MESSAGING_URI: DeviceSubType = DeviceSubType(24); + pub const MESSAGING_URI: Self = Self(24); /// UFS Device Path. - pub const MESSAGING_UFS: DeviceSubType = DeviceSubType(25); + pub const MESSAGING_UFS: Self = Self(25); /// SD (Secure Digital) Device Path. - pub const MESSAGING_SD: DeviceSubType = DeviceSubType(26); + pub const MESSAGING_SD: Self = Self(26); /// Bluetooth Device Path. - pub const MESSAGING_BLUETOOTH: DeviceSubType = DeviceSubType(27); + pub const MESSAGING_BLUETOOTH: Self = Self(27); /// Wi-Fi Device Path. - pub const MESSAGING_WIFI: DeviceSubType = DeviceSubType(28); + pub const MESSAGING_WIFI: Self = Self(28); /// eMMC (Embedded Multi-Media Card) Device Path. - pub const MESSAGING_EMMC: DeviceSubType = DeviceSubType(29); + pub const MESSAGING_EMMC: Self = Self(29); /// BluetoothLE Device Path. - pub const MESSAGING_BLUETOOTH_LE: DeviceSubType = DeviceSubType(30); + pub const MESSAGING_BLUETOOTH_LE: Self = Self(30); /// DNS Device Path. - pub const MESSAGING_DNS: DeviceSubType = DeviceSubType(31); + pub const MESSAGING_DNS: Self = Self(31); /// NVDIMM Namespace Device Path. - pub const MESSAGING_NVDIMM_NAMESPACE: DeviceSubType = DeviceSubType(32); + pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32); /// REST Service Device Path. - pub const MESSAGING_REST_SERVICE: DeviceSubType = DeviceSubType(33); + pub const MESSAGING_REST_SERVICE: Self = Self(33); /// NVME over Fabric (NVMe-oF) Namespace Device Path. - pub const MESSAGING_NVME_OF_NAMESPACE: DeviceSubType = DeviceSubType(34); + pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34); /// Hard Drive Media Device Path. - pub const MEDIA_HARD_DRIVE: DeviceSubType = DeviceSubType(1); + pub const MEDIA_HARD_DRIVE: Self = Self(1); /// CD-ROM Media Device Path. - pub const MEDIA_CD_ROM: DeviceSubType = DeviceSubType(2); + pub const MEDIA_CD_ROM: Self = Self(2); /// Vendor-Defined Media Device Path. - pub const MEDIA_VENDOR: DeviceSubType = DeviceSubType(3); + pub const MEDIA_VENDOR: Self = Self(3); /// File Path Media Device Path. - pub const MEDIA_FILE_PATH: DeviceSubType = DeviceSubType(4); + pub const MEDIA_FILE_PATH: Self = Self(4); /// Media Protocol Device Path. - pub const MEDIA_PROTOCOL: DeviceSubType = DeviceSubType(5); + pub const MEDIA_PROTOCOL: Self = Self(5); /// PIWG Firmware File. - pub const MEDIA_PIWG_FIRMWARE_FILE: DeviceSubType = DeviceSubType(6); + pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6); /// PIWG Firmware Volume. - pub const MEDIA_PIWG_FIRMWARE_VOLUME: DeviceSubType = DeviceSubType(7); + pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7); /// Relative Offset Range. - pub const MEDIA_RELATIVE_OFFSET_RANGE: DeviceSubType = DeviceSubType(8); + pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8); /// RAM Disk Device Path. - pub const MEDIA_RAM_DISK: DeviceSubType = DeviceSubType(9); + pub const MEDIA_RAM_DISK: Self = Self(9); /// BIOS Boot Specification Device Path. - pub const BIOS_BOOT_SPECIFICATION: DeviceSubType = DeviceSubType(1); + pub const BIOS_BOOT_SPECIFICATION: Self = Self(1); /// End this instance of a Device Path and start a new one. - pub const END_INSTANCE: DeviceSubType = DeviceSubType(0x01); + pub const END_INSTANCE: Self = Self(0x01); /// End entire Device Path. - pub const END_ENTIRE: DeviceSubType = DeviceSubType(0xff); + pub const END_ENTIRE: Self = Self(0xff); } /// Error returned when attempting to convert from a `&[u8]` to a diff --git a/uefi/src/proto/tcg/v1.rs b/uefi/src/proto/tcg/v1.rs index 0fc55a7da..14cfc86d6 100644 --- a/uefi/src/proto/tcg/v1.rs +++ b/uefi/src/proto/tcg/v1.rs @@ -165,7 +165,7 @@ impl PcrEvent { ptr_write_unaligned_and_add(&mut ptr, event_data_size); ptr::copy(event_data.as_ptr(), ptr, event_data.len()); - let ptr: *mut PcrEvent = + let ptr: *mut Self = ptr_meta::from_raw_parts_mut(buffer.as_mut_ptr().cast(), event_data.len()); Ok(&mut *ptr) } diff --git a/uefi/src/proto/tcg/v2.rs b/uefi/src/proto/tcg/v2.rs index df762f311..aa036bba8 100644 --- a/uefi/src/proto/tcg/v2.rs +++ b/uefi/src/proto/tcg/v2.rs @@ -102,7 +102,7 @@ pub struct BootServiceCapability { impl Default for BootServiceCapability { fn default() -> Self { // OK to unwrap, the size is less than u8. - let struct_size = u8::try_from(mem::size_of::()).unwrap(); + let struct_size = u8::try_from(mem::size_of::()).unwrap(); Self { size: struct_size, @@ -211,7 +211,7 @@ impl PcrEventInputs { ); ptr::copy(event_data.as_ptr(), ptr, event_data.len()); - let ptr: *mut PcrEventInputs = + let ptr: *mut Self = ptr_meta::from_raw_parts_mut(buffer.as_mut_ptr().cast(), event_data.len()); Ok(&mut *ptr) } @@ -261,7 +261,7 @@ impl Debug for PcrEventInputs { // Manual `PartialEq` implementation since it can't be derived for a packed DST. impl PartialEq for PcrEventInputs { - fn eq(&self, other: &PcrEventInputs) -> bool { + fn eq(&self, other: &Self) -> bool { self.size == other.size && self.event_header == other.event_header && self.event == other.event diff --git a/uefi/src/result/error.rs b/uefi/src/result/error.rs index 00b478f7c..dba93e1d7 100644 --- a/uefi/src/result/error.rs +++ b/uefi/src/result/error.rs @@ -44,7 +44,7 @@ impl Error { impl From for Error<()> { fn from(status: Status) -> Self { - Error::new(status, ()) + Self::new(status, ()) } } diff --git a/uefi/src/result/mod.rs b/uefi/src/result/mod.rs index 4826c2f0c..a66fca1a8 100644 --- a/uefi/src/result/mod.rs +++ b/uefi/src/result/mod.rs @@ -80,9 +80,9 @@ impl ResultExt for Result(self, op: O) -> Result + fn handle_warning(self, op: O) -> Self where - O: FnOnce(Error) -> Result, + O: FnOnce(Error) -> Self, { match self { Ok(output) => Ok(output), diff --git a/uefi/src/result/status.rs b/uefi/src/result/status.rs index e42c767a5..808208bb0 100644 --- a/uefi/src/result/status.rs +++ b/uefi/src/result/status.rs @@ -59,7 +59,7 @@ impl StatusExt for Status { #[inline] fn to_result_with_err( self, - err: impl FnOnce(Status) -> ErrData, + err: impl FnOnce(Self) -> ErrData, ) -> Result<(), ErrData> { if self.is_success() { Ok(()) @@ -72,7 +72,7 @@ impl StatusExt for Status { fn to_result_with( self, val: impl FnOnce() -> T, - err: impl FnOnce(Status) -> ErrData, + err: impl FnOnce(Self) -> ErrData, ) -> Result { if self.is_success() { Ok(val()) diff --git a/uefi/src/table/runtime.rs b/uefi/src/table/runtime.rs index aa7584fad..0012206ee 100644 --- a/uefi/src/table/runtime.rs +++ b/uefi/src/table/runtime.rs @@ -605,7 +605,7 @@ impl TryFrom<&[u8]> for Time { type Error = TimeByteConversionError; fn try_from(bytes: &[u8]) -> core::result::Result { - if size_of::