8000 Merge pull request #1271 from phip1611/clippy · rust-osdev/uefi-rs@7d61816 · GitHub
[go: up one dir, main page]

Skip to content 8000

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

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

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

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

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: 7 additions & 7 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,
@@ -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

Lines changed: 1 addition & 1 deletion
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,

0 commit comments

Comments
 (0)
0