Skip to content

Commit 7d61816

Browse files
authored
Merge pull request #1271 from phip1611/clippy
clippy: add use_self and const fn
2 parents 1c8e869 + 43607ce commit 7d61816

File tree

36 files changed

+214
-201
lines changed

36 files changed

+214
-201
lines changed

uefi-raw/src/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
1111
#![no_std]
1212
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
13-
#![deny(missing_debug_implementations)]
14-
#![deny(clippy::all)]
15-
#![deny(clippy::ptr_as_ptr, unused)]
16-
#![deny(clippy::must_use_candidate)]
13+
#![deny(
14+
clippy::all,
15+
clippy::missing_const_for_fn,
16+
clippy::must_use_candidate,
17+
clippy::ptr_as_ptr,
18+
clippy::use_self,
19+
missing_debug_implementations,
20+
unused
21+
)]
1722

1823
#[macro_use]
1924
mod enums;

uefi-raw/src/status.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ impl Status {
104104
#[inline]
105105
#[must_use]
106106
pub fn is_success(self) -> bool {
107-
self == Status::SUCCESS
107+
self == Self::SUCCESS
108108
}
109109

110110
/// Returns true if status code indicates a warning.
111111
#[inline]
112112
#[must_use]
113113
pub fn is_warning(self) -> bool {
114-
(self != Status::SUCCESS) && (self.0 & Self::ERROR_BIT == 0)
114+
(self != Self::SUCCESS) && (self.0 & Self::ERROR_BIT == 0)
115115
}
116116

117117
/// Returns true if the status code indicates an error.

uefi-raw/src/table/boot.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ impl MemoryDescriptor {
367367
}
368368

369369
impl Default for MemoryDescriptor {
370-
fn default() -> MemoryDescriptor {
371-
MemoryDescriptor {
370+
fn default() -> Self {
371+
Self {
372372
ty: MemoryType::RESERVED,
373373
phys_start: 0,
374374
virt_start: 0,
@@ -439,9 +439,9 @@ impl MemoryType {
439439
/// Construct a custom `MemoryType`. Values in the range `0x8000_0000..=0xffff_ffff` are free for use if you are
440440
/// an OS loader.
441441
#[must_use]
442-
pub const fn custom(value: u32) -> MemoryType {
442+
pub const fn custom(value: u32) -> Self {
443443
assert!(value >= 0x80000000);
444-
MemoryType(value)
444+
Self(value)
445445
}
446446
}
447447

uefi-raw/src/table/revision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Revision {
6161
let major = major as u32;
6262
let minor = minor as u32;
6363
let value = (major << 16) | minor;
64-
Revision(value)
64+
Self(value)
6565
}
6666

6767
/// Returns the major revision.

uefi-raw/src/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Display for Time {
111111

112112
/// The padding fields of `Time` are ignored for comparison.
113113
impl PartialEq for Time {
114-
fn eq(&self, other: &Time) -> bool {
114+
fn eq(&self, other: &Self) -> bool {
115115
self.year == other.year
116116
&& self.month == other.month
117117
&& self.day == other.day

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/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Handle {
3939

4040
/// Get the underlying raw pointer.
4141
#[must_use]
42-
pub fn as_ptr(&self) -> *mut c_void {
42+
pub const fn as_ptr(&self) -> *mut c_void {
4343
self.0.as_ptr()
4444
}
4545

@@ -78,7 +78,7 @@ impl Event {
7878

7979
/// Get the underlying raw pointer.
8080
#[must_use]
81-
pub fn as_ptr(&self) -> *mut c_void {
81+
pub const fn as_ptr(&self) -> *mut c_void {
8282
self.0.as_ptr()
8383
}
8484
}

uefi/src/data_types/owned_strs.rs

+4-4
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

+7-7
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,
@@ -524,7 +524,7 @@ impl CStr16 {
524524

525525
/// Returns if the string is empty. This ignores the null character.
526526
#[must_use]
527-
pub fn is_empty(&self) -> bool {
527+
pub const fn is_empty(&self) -> bool {
528528
self.num_chars() == 0
529529
}
530530

@@ -566,7 +566,7 @@ impl CStr16 {
566566
/// Returns the underlying bytes as slice including the terminating null
567567
/// character.
568568
#[must_use]
569-
pub fn as_bytes(&self) -> &[u8] {
569+
pub const fn as_bytes(&self) -> &[u8] {
570570
unsafe { slice::from_raw_parts(self.0.as_ptr().cast(), self.num_bytes()) }
571571
}
572572
}
@@ -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/data_types/unaligned_slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
2828
/// The `data` pointer must point to a packed array of at least
2929
/// `len` elements of type `T`. The pointer must remain valid for as
3030
/// long as the `'a` lifetime.
31-
pub unsafe fn new(data: *const T, len: usize) -> Self {
31+
pub const unsafe fn new(data: *const T, len: usize) -> Self {
3232
Self {
3333
data,
3434
len,

uefi/src/fs/dir_entry_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct UefiDirectoryIter(UefiDirectoryHandle);
1818
impl UefiDirectoryIter {
1919
/// Constructor.
2020
#[must_use]
21-
pub fn new(handle: UefiDirectoryHandle) -> Self {
21+
pub const fn new(handle: UefiDirectoryHandle) -> Self {
2222
Self(handle)
2323
}
2424
}

uefi/src/fs/file_system/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct FileSystem<'a>(ScopedProtocol<'a, SimpleFileSystemProtocol>);
2626
impl<'a> FileSystem<'a> {
2727
/// Constructor.
2828
#[must_use]
29-
pub fn new(proto: ScopedProtocol<'a, SimpleFileSystemProtocol>) -> Self {
29+
pub const fn new(proto: ScopedProtocol<'a, SimpleFileSystemProtocol>) -> Self {
3030
Self(proto)
3131
}
3232

uefi/src/fs/path/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Path {
2121

2222
/// Returns the underlying string.
2323
#[must_use]
24-
pub fn to_cstr16(&self) -> &CStr16 {
24+
pub const fn to_cstr16(&self) -> &CStr16 {
2525
&self.0
2626
}
2727

@@ -79,7 +79,7 @@ impl Path {
7979

8080
/// Returns of the path is empty.
8181
#[must_use]
82-
pub fn is_empty(&self) -> bool {
82+
pub const fn is_empty(&self) -> bool {
8383
self.to_cstr16().is_empty()
8484
}
8585
}

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/helpers/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn system_table() -> SystemTable<Boot> {
5454
/// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
5555
/// epoch. Limited functionality might work after exiting them, such as logging
5656
/// to the debugcon device.
57+
#[allow(clippy::missing_const_for_fn)]
5758
pub fn init() -> Result<()> {
5859
// Setup logging and memory allocation
5960

@@ -72,6 +73,7 @@ pub fn init() -> Result<()> {
7273
Ok(())
7374
}
7475

76+
#[allow(clippy::missing_const_for_fn)]
7577
pub(crate) fn exit() {
7678
#[cfg(feature = "logger")]
7779
logger::disable();

uefi/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@
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+
clippy::missing_const_for_fn
97+
)]
9498
#![deny(missing_debug_implementations)]
9599

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

uefi/src/mem/memory_map/impl_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl MemoryMapBackingMemory {
315315
/// takes into account that, as you go, more (small) allocations might
316316
/// happen.
317317
#[must_use]
318-
fn safe_allocation_size_hint(mmm: MemoryMapMeta) -> usize {
318+
const fn safe_allocation_size_hint(mmm: MemoryMapMeta) -> usize {
319319
// Allocate space for extra entries beyond the current size of the
320320
// memory map. The value of 8 matches the value in the Linux kernel:
321321
// https://github.com/torvalds/linux/blob/e544a07438/drivers/firmware/efi/libstub/efistub.h#L173
@@ -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/gop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl GraphicsOutput {
102102

103103
/// Returns a [`ModeIter`].
104104
#[must_use]
105-
pub fn modes<'a>(&'a self, bs: &'a BootServices) -> ModeIter {
105+
pub const fn modes<'a>(&'a self, bs: &'a BootServices) -> ModeIter {
106106
ModeIter {
107107
gop: self,
108108
bs,

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
}

0 commit comments

Comments
 (0)