Skip to content

Commit 9ddb086

Browse files
committed
clippy: tighten clippy lints + "--fix"
Tighten the clippy lints + automatically fixes. Some of the fixes also needed manual steps.
1 parent 28da065 commit 9ddb086

File tree

17 files changed

+33
-20
lines changed

17 files changed

+33
-20
lines changed

uefi-raw/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
1515
#![deny(
1616
clippy::all,
17+
clippy::cargo,
18+
clippy::nursery,
1719
clippy::missing_const_for_fn,
1820
clippy::must_use_candidate,
1921
clippy::ptr_as_ptr,

uefi-test-runner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ qemu-exit = "3.0.0"
1616

1717
[features]
1818
# Enable the debug support protocol test.
19-
debug_support = []
19+
debug_support_protocol = []
2020

2121
# Enable the multiprocessor test. This only works if KVM is enabled.
2222
multi_processor = []

uefi-test-runner/src/proto/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn test_debug_port() {
6969
}
7070

7171
fn test_debug_support() {
72-
if cfg!(not(feature = "debug_support")) {
72+
if cfg!(not(feature = "debug_support_protocol")) {
7373
return;
7474
}
7575

uefi/src/boot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn allocate_pool(memory_type: MemoryType, size: usize) -> Result<NonNull<u8>
238238
let ptr = unsafe { (bt.allocate_pool)(memory_type, size, &mut buffer) }
239239
.to_result_with_val(|| buffer)?;
240240

241-
NonNull::new(ptr).ok_or(Status::OUT_OF_RESOURCES.into())
241+
NonNull::new(ptr).ok_or_else(|| Status::OUT_OF_RESOURCES.into())
242242
}
243243

244244
/// Frees memory allocated by [`allocate_pool`].

uefi/src/data_types/strs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl PoolString {
745745
pub unsafe fn new(text: *const Char16) -> crate::Result<Self> {
746746
NonNull::new(text.cast_mut())
747747
.map(|p| Self(PoolAllocation::new(p.cast())))
748-
.ok_or(Status::OUT_OF_RESOURCES.into())
748+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
749749
}
750750
}
751751

uefi/src/fs/file_system/fs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl FileSystem {
6363
let mut src = self
6464
.open(src_path, UefiFileMode::Read, false)?
6565
.into_regular_file()
66-
.ok_or(Error::Io(IoError {
66+
.ok_or_else(|| Error::Io(IoError {
6767
path: src_path.to_path_buf(),
6868
context: IoErrorContext::NotAFile,
6969
uefi_error: Status::INVALID_PARAMETER.into(),
@@ -91,7 +91,7 @@ impl FileSystem {
9191
let mut dest = self
9292
.open(dest_path, UefiFileMode::CreateReadWrite, false)?
9393
.into_regular_file()
94-
.ok_or(Error::Io(IoError {
94+
.ok_or_else(|| Error::Io(IoError {
9595
path: dest_path.to_path_buf(),
9696
context: IoErrorContext::OpenError,
9797
uefi_error: Status::INVALID_PARAMETER.into(),
@@ -198,7 +198,7 @@ impl FileSystem {
198198
let mut file = self
199199
.open(path, UefiFileMode::Read, false)?
200200
.into_regular_file()
201-
.ok_or(Error::Io(IoError {
201+
.ok_or_else(|| Error::Io(IoError {
202202
path: path.to_path_buf(),
203203
context: IoErrorContext::NotAFile,
204204
// We do not have a real UEFI error here as we have a logical
@@ -237,7 +237,7 @@ impl FileSystem {
237237
let dir = self
238238
.open(path, UefiFileMode::Read, false)?
239239
.into_directory()
240-
.ok_or(Error::Io(IoError {
240+
.ok_or_else(|| Error::Io(IoError {
241241
path: path.to_path_buf(),
242242
context: IoErrorContext::NotADirectory,
243243
// We do not have a real UEFI error here as we have a logical

uefi/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@
234234
#![no_std]
235235
#![deny(
236236
clippy::all,
237+
clippy::cargo,
238+
clippy::nursery,
237239
clippy::missing_const_for_fn,
238240
clippy::must_use_candidate,
239241
clippy::ptr_as_ptr,
@@ -244,6 +246,11 @@
244246
unsafe_op_in_unsafe_fn,
245247
unused
246248
)]
249+
// There is too many code affected and without an automatic fix, this is too
250+
// much mechanic work.
251+
#![allow(
252+
clippy::option_if_let_else
253+
)]
247254

248255
#[cfg(feature = "alloc")]
249256
extern crate alloc;

uefi/src/mem/memory_map/impl_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl IndexMut<usize> for MemoryMapRefMut<'_> {
270270
/// [`boot::get_memory_map`]: crate::boot::get_memory_map
271271
#[derive(Debug)]
272272
#[allow(clippy::len_without_is_empty)] // this type is never empty
273-
pub(crate) struct MemoryMapBackingMemory(NonNull<[u8]>);
273+
pub struct MemoryMapBackingMemory(NonNull<[u8]>);
274274

275275
impl MemoryMapBackingMemory {
276276
/// Constructs a new [`MemoryMapBackingMemory`].

uefi/src/mem/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use {core::alloc::Allocator, core::ptr::NonNull};
3636
///
3737
/// [`Allocator`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html
3838
/// [`alloc::alloc::Global`]: https://doc.rust-lang.org/alloc/alloc/struct.Global.html
39-
pub(crate) fn make_boxed<
39+
pub fn make_boxed<
4040
'a,
4141
// The UEFI data structure.
4242
Data: Align + ?Sized + Debug + 'a,

uefi/src/proto/ata/pass_thru.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct AtaDevice<'a> {
107107
}
108108

109109
impl AtaDevice<'_> {
110+
#[allow(clippy::needless_pass_by_ref_mut)] // cast to mutable ptr
110111
const fn proto_mut(&mut self) -> *mut AtaPassThruProtocol {
111112
ptr::from_ref(self.proto).cast_mut()
112113
}
@@ -156,7 +157,7 @@ impl AtaDevice<'_> {
156157
.to_result()?;
157158
NonNull::new(path_ptr.cast_mut())
158159
.map(|p| PoolDevicePathNode(PoolAllocation::new(p.cast())))
159-
.ok_or(Status::OUT_OF_RESOURCES.into())
160+
.ok_or_else(|| Status::OUT_OF_RESOURCES.into())
160161
}
161162
}
162163

0 commit comments

Comments
 (0)