Skip to content

Commit 6691f0e

Browse files
committed
clippy/uefi: prefer Self where possible
1 parent f2ace36 commit 6691f0e

File tree

16 files changed

+124
-121
lines changed

16 files changed

+124
-121
lines changed

uefi/src/data_types/chars.rs

Lines changed: 6 additions & 6 deletions
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/owned_strs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl CString16 {
113113

114114
impl Default for CString16 {
115115
fn default() -> Self {
116-
CString16::new()
116+
Self::new()
117117
}
118118
}
119119

@@ -141,7 +141,7 @@ impl TryFrom<&str> for CString16 {
141141
// Add trailing nul.
142142
output.push(NUL_16);
143143

144-
Ok(CString16(output))
144+
Ok(Self(output))
145145
}
146146
}
147147

@@ -175,7 +175,7 @@ impl<'a> TryFrom<&UnalignedSlice<'a, u16>> for CString16 {
175175

176176
fn try_from(input: &UnalignedSlice<u16>) -> Result<Self, Self::Error> {
177177
let v = input.to_vec();
178-
CString16::try_from(v)
178+
Self::try_from(v)
179179
}
180180
}
181181

@@ -189,7 +189,7 @@ impl From<&CStr16> for CString16 {
189189
impl From<&CString16> for String {
190190
fn from(value: &CString16) -> Self {
191191
let slice: &CStr16 = value.as_ref();
192-
String::from(slice)
192+
Self::from(slice)
193193
}
194194
}
195195

uefi/src/data_types/strs.rs

Lines changed: 5 additions & 5 deletions
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,
@@ -593,7 +593,7 @@ impl From<&CStr16> for alloc::string::String {
593593
.map(u16::from)
594594
.map(u32::from)
595595
.map(|int| char::from_u32(int).expect("Should be encodable as UTF-8"))
596-
.collect::<alloc::string::String>()
596+
.collect::<Self>()
597597
}
598598
}
599599

@@ -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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@
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::all,
94+
clippy::must_use_candidate,
95+
clippy::use_self
96+
)]
9497
#![deny(missing_debug_implementations)]
9598

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

uefi/src/mem/memory_map/impl_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl MemoryMapOwned {
373373
pub(crate) fn from_initialized_mem(buf: MemoryMapBackingMemory, meta: MemoryMapMeta) -> Self {
374374
assert!(meta.desc_size >= mem::size_of::<MemoryDescriptor>());
375375
let len = meta.entry_count();
376-
MemoryMapOwned { buf, meta, len }
376+
Self { buf, meta, len }
377377
}
378378
}
379379

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 28 additions & 28 deletions
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")]

0 commit comments

Comments
 (0)