Skip to content

Commit 438269e

Browse files
committed
clippy: prefer Self where possible
1 parent 0358496 commit 438269e

File tree

14 files changed

+113
-111
lines changed

14 files changed

+113
-111
lines changed

uefi/src/data_types/chars.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ impl TryFrom<char> for Char8 {
3535
}
3636

3737
impl From<Char8> for char {
38-
fn from(char: Char8) -> char {
39-
char::from(char.0)
38+
fn from(char: Char8) -> Self {
39+
Self::from(char.0)
4040
}
4141
}
4242

4343
impl From<u8> for Char8 {
4444
fn from(value: u8) -> Self {
45-
Char8(value)
45+
Self(value)
4646
}
4747
}
4848

4949
impl From<Char8> for u8 {
50-
fn from(char: Char8) -> u8 {
50+
fn from(char: Char8) -> Self {
5151
char.0
5252
}
5353
}
@@ -107,7 +107,7 @@ impl TryFrom<char> for Char16 {
107107
}
108108

109109
impl From<Char16> for char {
110-
fn from(char: Char16) -> char {
110+
fn from(char: Char16) -> Self {
111111
u32::from(char.0).try_into().unwrap()
112112
}
113113
}
@@ -127,7 +127,7 @@ impl TryFrom<u16> for Char16 {
127127
}
128128

129129
impl From<Char16> for u16 {
130-
fn from(char: Char16) -> u16 {
130+
fn from(char: Char16) -> Self {
131131
char.0
132132
}
133133
}

uefi/src/data_types/strs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl CStr16 {
457457
pub fn from_unaligned_slice<'buf>(
458458
src: &UnalignedSlice<'_, u16>,
459459
buf: &'buf mut [MaybeUninit<u16>],
460-
) -> Result<&'buf CStr16, UnalignedCStr16Error> {
460+
) -> Result<&'buf Self, UnalignedCStr16Error> {
461461
// The input `buf` might be longer than needed, so get a
462462
// subslice of the required length.
463463
let buf = buf
@@ -469,7 +469,7 @@ impl CStr16 {
469469
// Safety: `copy_buf` fully initializes the slice.
470470
maybe_uninit_slice_assume_init_ref(buf)
471471
};
472-
CStr16::from_u16_with_nul(buf).map_err(|e| match e {
472+
Self::from_u16_with_nul(buf).map_err(|e| match e {
473473
FromSliceWithNulError::InvalidChar(v) => UnalignedCStr16Error::InvalidChar(v),
474474
FromSliceWithNulError::InteriorNul(v) => UnalignedCStr16Error::InteriorNul(v),
475475
FromSliceWithNulError::NotNulTerminated => UnalignedCStr16Error::NotNulTerminated,
@@ -615,8 +615,8 @@ impl<StrType: AsRef<str> + ?Sized> EqStrUntilNul<StrType> for CStr16 {
615615
}
616616
}
617617

618-
impl AsRef<CStr16> for CStr16 {
619-
fn as_ref(&self) -> &CStr16 {
618+
impl AsRef<Self> for CStr16 {
619+
fn as_ref(&self) -> &Self {
620620
self
621621
}
622622
}

uefi/src/helpers/logger.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl core::fmt::Write for DebugconWriter {
5858
fn write_str(&mut self, s: &str) -> fmt::Result {
5959
for &byte in s.as_bytes() {
6060
unsafe {
61-
core::arch::asm!("outb %al, %dx", in("al") byte, in("dx") DebugconWriter::IO_PORT, options(att_syntax))
61+
core::arch::asm!("outb %al, %dx", in("al") byte, in("dx") Self::IO_PORT, options(att_syntax))
6262
};
6363
}
6464
Ok(())
@@ -83,7 +83,7 @@ impl Logger {
8383
/// [`set_output`]: Self::set_output
8484
#[must_use]
8585
pub const fn new() -> Self {
86-
Logger {
86+
Self {
8787
writer: AtomicPtr::new(ptr::null_mut()),
8888
}
8989
}

uefi/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@
8989
#![no_std]
9090
// Enable some additional warnings and lints.
9191
#![warn(clippy::ptr_as_ptr, missing_docs, unused)]
92-
#![deny(clippy::all)]
93-
#![deny(clippy::must_use_candidate)]
92+
#![deny(
93+
clippy::must_use_candidate,
94+
clippy::use_self,
95+
)]
9496
#![deny(missing_debug_implementations)]
9597

9698
#[cfg(feature = "alloc")]

uefi/src/proto/console/text/input.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ pub enum Key {
9898
}
9999

100100
impl From<InputKey> for Key {
101-
fn from(k: InputKey) -> Key {
101+
fn from(k: InputKey) -> Self {
102102
if k.scan_code == ScanCode::NULL.0 {
103-
Key::Printable(Char16::try_from(k.unicode_char).unwrap())
103+
Self::Printable(Char16::try_from(k.unicode_char).unwrap())
104104
} else {
105-
Key::Special(ScanCode(k.scan_code))
105+
Self::Special(ScanCode(k.scan_code))
106106
}
107107
}
108108
}

uefi/src/proto/debug/exception.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ pub struct ExceptionType(isize);
55

66
impl ExceptionType {
77
/// Undefined Exception
8-
pub const EXCEPT_EBC_UNDEFINED: ExceptionType = ExceptionType(0);
8+
pub const EXCEPT_EBC_UNDEFINED: Self = Self(0);
99
/// Divide-by-zero Error
10-
pub const EXCEPT_EBC_DIVIDE_ERROR: ExceptionType = ExceptionType(1);
10+
pub const EXCEPT_EBC_DIVIDE_ERROR: Self = Self(1);
1111
/// Debug Exception
12-
pub const EXCEPT_EBC_DEBUG: ExceptionType = ExceptionType(2);
12+
pub const EXCEPT_EBC_DEBUG: Self = Self(2);
1313
/// Breakpoint
14-
pub const EXCEPT_EBC_BREAKPOINT: ExceptionType = ExceptionType(3);
14+
pub const EXCEPT_EBC_BREAKPOINT: Self = Self(3);
1515
/// Overflow
16-
pub const EXCEPT_EBC_OVERFLOW: ExceptionType = ExceptionType(4);
16+
pub const EXCEPT_EBC_OVERFLOW: Self = Self(4);
1717
/// Invalid Opcode
18-
pub const EXCEPT_EBC_INVALID_OPCODE: ExceptionType = ExceptionType(5);
18+
pub const EXCEPT_EBC_INVALID_OPCODE: Self = Self(5);
1919
/// Stack-Segment Fault
20-
pub const EXCEPT_EBC_STACK_FAULT: ExceptionType = ExceptionType(6);
20+
pub const EXCEPT_EBC_STACK_FAULT: Self = Self(6);
2121
/// Alignment Check
22-
pub const EXCEPT_EBC_ALIGNMENT_CHECK: ExceptionType = ExceptionType(7);
22+
pub const EXCEPT_EBC_ALIGNMENT_CHECK: Self = Self(7);
2323
/// Instruction Encoding Exception
24-
pub const EXCEPT_EBC_INSTRUCTION_ENCODING: ExceptionType = ExceptionType(8);
24+
pub const EXCEPT_EBC_INSTRUCTION_ENCODING: Self = Self(8);
2525
/// Bad Breakpoint Exception
26-
pub const EXCEPT_EBC_BAD_BREAK: ExceptionType = ExceptionType(9);
26+
pub const EXCEPT_EBC_BAD_BREAK: Self = Self(9);
2727
/// Single Step Exception
28-
pub const EXCEPT_EBC_SINGLE_STEP: ExceptionType = ExceptionType(10);
28+
pub const EXCEPT_EBC_SINGLE_STEP: Self = Self(10);
2929
}
3030

3131
#[cfg(target_arch = "x86")]
@@ -69,39 +69,39 @@ impl ExceptionType {
6969
#[cfg(target_arch = "x86_64")]
7070
impl ExceptionType {
7171
/// Divide-by-zero Error
72-
pub const EXCEPT_X64_DIVIDE_ERROR: ExceptionType = ExceptionType(0);
72+
pub const EXCEPT_X64_DIVIDE_ERROR: Self = Self(0);
7373
/// Debug Exception
74-
pub const EXCEPT_X64_DEBUG: ExceptionType = ExceptionType(1);
74+
pub const EXCEPT_X64_DEBUG: Self = Self(1);
7575
/// Non-maskable Interrupt
76-
pub const EXCEPT_X64_NMI: ExceptionType = ExceptionType(2);
76+
pub const EXCEPT_X64_NMI: Self = Self(2);
7777
/// Breakpoint
78-
pub const EXCEPT_X64_BREAKPOINT: ExceptionType = ExceptionType(3);
78+
pub const EXCEPT_X64_BREAKPOINT: Self = Self(3);
7979
/// Overflow
80-
pub const EXCEPT_X64_OVERFLOW: ExceptionType = ExceptionType(4);
80+
pub const EXCEPT_X64_OVERFLOW: Self = Self(4);
8181
/// Bound Range Exceeded
82-
pub const EXCEPT_X64_BOUND: ExceptionType = ExceptionType(5);
82+
pub const EXCEPT_X64_BOUND: Self = Self(5);
8383
/// Invalid Opcode
84-
pub const EXCEPT_X64_INVALID_OPCODE: ExceptionType = ExceptionType(6);
84+
pub const EXCEPT_X64_INVALID_OPCODE: Self = Self(6);
8585
/// Double Fault
86-
pub const EXCEPT_X64_DOUBLE_FAULT: ExceptionType = ExceptionType(8);
86+
pub const EXCEPT_X64_DOUBLE_FAULT: Self = Self(8);
8787
/// Invalid TSS
88-
pub const EXCEPT_X64_INVALID_TSS: ExceptionType = ExceptionType(10);
88+
pub const EXCEPT_X64_INVALID_TSS: Self = Self(10);
8989
/// Segment Not Present
90-
pub const EXCEPT_X64_SEG_NOT_PRESENT: ExceptionType = ExceptionType(11);
90+
pub const EXCEPT_X64_SEG_NOT_PRESENT: Self = Self(11);
9191
/// Stack-Segment Fault
92-
pub const EXCEPT_X64_STACK_FAULT: ExceptionType = ExceptionType(12);
92+
pub const EXCEPT_X64_STACK_FAULT: Self = Self(12);
9393
/// General Protection Fault
94-
pub const EXCEPT_X64_GP_FAULT: ExceptionType = ExceptionType(13);
94+
pub const EXCEPT_X64_GP_FAULT: Self = Self(13);
9595
/// Page Fault
96-
pub const EXCEPT_X64_PAGE_FAULT: ExceptionType = ExceptionType(14);
96+
pub const EXCEPT_X64_PAGE_FAULT: Self = Self(14);
9797
/// x87 Floating-Point Exception
98-
pub const EXCEPT_X64_FP_ERROR: ExceptionType = ExceptionType(16);
98+
pub const EXCEPT_X64_FP_ERROR: Self = Self(16);
9999
/// Alignment Check
100-
pub const EXCEPT_X64_ALIGNMENT_CHECK: ExceptionType = ExceptionType(17);
100+
pub const EXCEPT_X64_ALIGNMENT_CHECK: Self = Self(17);
101101
/// Machine Check
102-
pub const EXCEPT_X64_MACHINE_CHECK: ExceptionType = ExceptionType(18);
102+
pub const EXCEPT_X64_MACHINE_CHECK: Self = Self(18);
103103
/// SIMD Floating-Point Exception
104-
pub const EXCEPT_X64_SIMD: ExceptionType = ExceptionType(19);
104+
pub const EXCEPT_X64_SIMD: Self = Self(19);
105105
}
106106

107107
#[cfg(target_arch = "arm")]

uefi/src/proto/device_path/mod.rs

+54-54
Original file line numberDiff line numberDiff line change
@@ -678,118 +678,118 @@ pub struct DeviceSubType(pub u8);
678678

679679
impl DeviceSubType {
680680
/// PCI Device Path.
681-
pub const HARDWARE_PCI: DeviceSubType = DeviceSubType(1);
681+
pub const HARDWARE_PCI: Self = Self(1);
682682
/// PCCARD Device Path.
683-
pub const HARDWARE_PCCARD: DeviceSubType = DeviceSubType(2);
683+
pub const HARDWARE_PCCARD: Self = Self(2);
684684
/// Memory-mapped Device Path.
685-
pub const HARDWARE_MEMORY_MAPPED: DeviceSubType = DeviceSubType(3);
685+
pub const HARDWARE_MEMORY_MAPPED: Self = Self(3);
686686
/// Vendor-Defined Device Path.
687-
pub const HARDWARE_VENDOR: DeviceSubType = DeviceSubType(4);
687+
pub const HARDWARE_VENDOR: Self = Self(4);
688688
/// Controller Device Path.
689-
pub const HARDWARE_CONTROLLER: DeviceSubType = DeviceSubType(5);
689+
pub const HARDWARE_CONTROLLER: Self = Self(5);
690690
/// BMC Device Path.
691-
pub const HARDWARE_BMC: DeviceSubType = DeviceSubType(6);
691+
pub const HARDWARE_BMC: Self = Self(6);
692692

693693
/// ACPI Device Path.
694-
pub const ACPI: DeviceSubType = DeviceSubType(1);
694+
pub const ACPI: Self = Self(1);
695695
/// Expanded ACPI Device Path.
696-
pub const ACPI_EXPANDED: DeviceSubType = DeviceSubType(2);
696+
pub const ACPI_EXPANDED: Self = Self(2);
697697
/// ACPI _ADR Device Path.
698-
pub const ACPI_ADR: DeviceSubType = DeviceSubType(3);
698+
pub const ACPI_ADR: Self = Self(3);
699699
/// NVDIMM Device Path.
700-
pub const ACPI_NVDIMM: DeviceSubType = DeviceSubType(4);
700+
pub const ACPI_NVDIMM: Self = Self(4);
701701

702702
/// ATAPI Device Path.
703-
pub const MESSAGING_ATAPI: DeviceSubType = DeviceSubType(1);
703+
pub const MESSAGING_ATAPI: Self = Self(1);
704704
/// SCSI Device Path.
705-
pub const MESSAGING_SCSI: DeviceSubType = DeviceSubType(2);
705+
pub const MESSAGING_SCSI: Self = Self(2);
706706
/// Fibre Channel Device Path.
707-
pub const MESSAGING_FIBRE_CHANNEL: DeviceSubType = DeviceSubType(3);
707+
pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3);
708708
/// 1394 Device Path.
709-
pub const MESSAGING_1394: DeviceSubType = DeviceSubType(4);
709+
pub const MESSAGING_1394: Self = Self(4);
710710
/// USB Device Path.
711-
pub const MESSAGING_USB: DeviceSubType = DeviceSubType(5);
711+
pub const MESSAGING_USB: Self = Self(5);
712712
/// I2O Device Path.
713-
pub const MESSAGING_I2O: DeviceSubType = DeviceSubType(6);
713+
pub const MESSAGING_I2O: Self = Self(6);
714714
/// Infiniband Device Path.
715-
pub const MESSAGING_INFINIBAND: DeviceSubType = DeviceSubType(9);
715+
pub const MESSAGING_INFINIBAND: Self = Self(9);
716716
/// Vendor-Defined Device Path.
717-
pub const MESSAGING_VENDOR: DeviceSubType = DeviceSubType(10);
717+
pub const MESSAGING_VENDOR: Self = Self(10);
718718
/// MAC Address Device Path.
719-
pub const MESSAGING_MAC_ADDRESS: DeviceSubType = DeviceSubType(11);
719+
pub const MESSAGING_MAC_ADDRESS: Self = Self(11);
720720
/// IPV4 Device Path.
721-
pub const MESSAGING_IPV4: DeviceSubType = DeviceSubType(12);
721+
pub const MESSAGING_IPV4: Self = Self(12);
722722
/// IPV6 Device Path.
723-
pub const MESSAGING_IPV6: DeviceSubType = DeviceSubType(13);
723+
pub const MESSAGING_IPV6: Self = Self(13);
724724
/// UART Device Path.
725-
pub const MESSAGING_UART: DeviceSubType = DeviceSubType(14);
725+
pub const MESSAGING_UART: Self = Self(14);
726726
/// USB Class Device Path.
727-
pub const MESSAGING_USB_CLASS: DeviceSubType = DeviceSubType(15);
727+
pub const MESSAGING_USB_CLASS: Self = Self(15);
728728
/// USB WWID Device Path.
729-
pub const MESSAGING_USB_WWID: DeviceSubType = DeviceSubType(16);
729+
pub const MESSAGING_USB_WWID: Self = Self(16);
730730
/// Device Logical Unit.
731-
pub const MESSAGING_DEVICE_LOGICAL_UNIT: DeviceSubType = DeviceSubType(17);
731+
pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17);
732732
/// SATA Device Path.
733-
pub const MESSAGING_SATA: DeviceSubType = DeviceSubType(18);
733+
pub const MESSAGING_SATA: Self = Self(18);
734734
/// iSCSI Device Path node (base information).
735-
pub const MESSAGING_ISCSI: DeviceSubType = DeviceSubType(19);
735+
pub const MESSAGING_ISCSI: Self = Self(19);
736736
/// VLAN Device Path node.
737-
pub const MESSAGING_VLAN: DeviceSubType = DeviceSubType(20);
737+
pub const MESSAGING_VLAN: Self = Self(20);
738738
/// Fibre Channel Ex Device Path.
739-
pub const MESSAGING_FIBRE_CHANNEL_EX: DeviceSubType = DeviceSubType(21);
739+
pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21);
740740
/// Serial Attached SCSI (SAS) Ex Device Path.
741-
pub const MESSAGING_SCSI_SAS_EX: DeviceSubType = DeviceSubType(22);
741+
pub const MESSAGING_SCSI_SAS_EX: Self = Self(22);
742742
/// NVM Express Namespace Device Path.
743-
pub const MESSAGING_NVME_NAMESPACE: DeviceSubType = DeviceSubType(23);
743+
pub const MESSAGING_NVME_NAMESPACE: Self = Self(23);
744744
/// Uniform Resource Identifiers (URI) Device Path.
745-
pub const MESSAGING_URI: DeviceSubType = DeviceSubType(24);
745+
pub const MESSAGING_URI: Self = Self(24);
746746
/// UFS Device Path.
747-
pub const MESSAGING_UFS: DeviceSubType = DeviceSubType(25);
747+
pub const MESSAGING_UFS: Self = Self(25);
748748
/// SD (Secure Digital) Device Path.
749-
pub const MESSAGING_SD: DeviceSubType = DeviceSubType(26);
749+
pub const MESSAGING_SD: Self = Self(26);
750750
/// Bluetooth Device Path.
751-
pub const MESSAGING_BLUETOOTH: DeviceSubType = DeviceSubType(27);
751+
pub const MESSAGING_BLUETOOTH: Self = Self(27);
752752
/// Wi-Fi Device Path.
753-
pub const MESSAGING_WIFI: DeviceSubType = DeviceSubType(28);
753+
pub const MESSAGING_WIFI: Self = Self(28);
754754
/// eMMC (Embedded Multi-Media Card) Device Path.
755-
pub const MESSAGING_EMMC: DeviceSubType = DeviceSubType(29);
755+
pub const MESSAGING_EMMC: Self = Self(29);
756756
/// BluetoothLE Device Path.
757-
pub const MESSAGING_BLUETOOTH_LE: DeviceSubType = DeviceSubType(30);
757+
pub const MESSAGING_BLUETOOTH_LE: Self = Self(30);
758758
/// DNS Device Path.
759-
pub const MESSAGING_DNS: DeviceSubType = DeviceSubType(31);
759+
pub const MESSAGING_DNS: Self = Self(31);
760760
/// NVDIMM Namespace Device Path.
761-
pub const MESSAGING_NVDIMM_NAMESPACE: DeviceSubType = DeviceSubType(32);
761+
pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32);
762762
/// REST Service Device Path.
763-
pub const MESSAGING_REST_SERVICE: DeviceSubType = DeviceSubType(33);
763+
pub const MESSAGING_REST_SERVICE: Self = Self(33);
764764
/// NVME over Fabric (NVMe-oF) Namespace Device Path.
765-
pub const MESSAGING_NVME_OF_NAMESPACE: DeviceSubType = DeviceSubType(34);
765+
pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34);
766766

767767
/// Hard Drive Media Device Path.
768-
pub const MEDIA_HARD_DRIVE: DeviceSubType = DeviceSubType(1);
768+
pub const MEDIA_HARD_DRIVE: Self = Self(1);
769769
/// CD-ROM Media Device Path.
770-
pub const MEDIA_CD_ROM: DeviceSubType = DeviceSubType(2);
770+
pub const MEDIA_CD_ROM: Self = Self(2);
771771
/// Vendor-Defined Media Device Path.
772-
pub const MEDIA_VENDOR: DeviceSubType = DeviceSubType(3);
772+
pub const MEDIA_VENDOR: Self = Self(3);
773773
/// File Path Media Device Path.
774-
pub const MEDIA_FILE_PATH: DeviceSubType = DeviceSubType(4);
774+
pub const MEDIA_FILE_PATH: Self = Self(4);
775775
/// Media Protocol Device Path.
776-
pub const MEDIA_PROTOCOL: DeviceSubType = DeviceSubType(5);
776+
pub const MEDIA_PROTOCOL: Self = Self(5);
777777
/// PIWG Firmware File.
778-
pub const MEDIA_PIWG_FIRMWARE_FILE: DeviceSubType = DeviceSubType(6);
778+
pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6);
779779
/// PIWG Firmware Volume.
780-
pub const MEDIA_PIWG_FIRMWARE_VOLUME: DeviceSubType = DeviceSubType(7);
780+
pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7);
781781
/// Relative Offset Range.
782-
pub const MEDIA_RELATIVE_OFFSET_RANGE: DeviceSubType = DeviceSubType(8);
782+
pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8);
783783
/// RAM Disk Device Path.
784-
pub const MEDIA_RAM_DISK: DeviceSubType = DeviceSubType(9);
784+
pub const MEDIA_RAM_DISK: Self = Self(9);
785785

786786
/// BIOS Boot Specification Device Path.
787-
pub const BIOS_BOOT_SPECIFICATION: DeviceSubType = DeviceSubType(1);
787+
pub const BIOS_BOOT_SPECIFICATION: Self = Self(1);
788788

789789
/// End this instance of a Device Path and start a new one.
790-
pub const END_INSTANCE: DeviceSubType = DeviceSubType(0x01);
790+
pub const END_INSTANCE: Self = Self(0x01);
791791
/// End entire Device Path.
792-
pub const END_ENTIRE: DeviceSubType = DeviceSubType(0xff);
792+
pub const END_ENTIRE: Self = Self(0xff);
793793
}
794794

795795
/// Error returned when attempting to convert from a `&[u8]` to a

uefi/src/proto/tcg/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl PcrEvent {
165165
ptr_write_unaligned_and_add(&mut ptr, event_data_size);
166166
ptr::copy(event_data.as_ptr(), ptr, event_data.len());
167167

168-
let ptr: *mut PcrEvent =
168+
let ptr: *mut Self =
169169
ptr_meta::from_raw_parts_mut(buffer.as_mut_ptr().cast(), event_data.len());
170170
Ok(&mut *ptr)
171171
}

0 commit comments

Comments
 (0)