Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b911ae

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 9b911ae

File tree

17 files changed

+61
-42
lines changed

17 files changed

+61
-42
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: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ impl FileSystem {
6363
let mut src = self
6464
.open(src_path, UefiFileMode::Read, false)?
6565
.into_regular_file()
66-
.ok_or(Error::Io(IoError {
67-
path: src_path.to_path_buf(),
68-
context: IoErrorContext::NotAFile,
69-
uefi_error: Status::INVALID_PARAMETER.into(),
70-
}))?;
66+
.ok_or_else(|| {
67+
Error::Io(IoError {
68+
path: src_path.to_path_buf(),
69+
context: IoErrorContext::NotAFile,
70+
uefi_error: Status::INVALID_PARAMETER.into(),
71+
})
72+
})?;
7173

7274
// Get the source file's size in bytes.
7375
let src_size = {
@@ -91,11 +93,13 @@ impl FileSystem {
9193
let mut dest = self
9294
.open(dest_path, UefiFileMode::CreateReadWrite, false)?
9395
.into_regular_file()
94-
.ok_or(Error::Io(IoError {
95-
path: dest_path.to_path_buf(),
96-
context: IoErrorContext::OpenError,
97-
uefi_error: Status::INVALID_PARAMETER.into(),
98-
}))?;
96+
.ok_or_else(|| {
97+
Error::Io(IoError {
98+
path: dest_path.to_path_buf(),
99+
context: IoErrorContext::OpenError,
100+
uefi_error: Status::INVALID_PARAMETER.into(),
101+
})
102+
})?;
99103

100104
// 1 MiB copy buffer.
101105
let mut chunk = vec![0; 1024 * 1024];
@@ -198,13 +202,15 @@ impl FileSystem {
198202
let mut file = self
199203
.open(path, UefiFileMode::Read, false)?
200204
.into_regular_file()
201-
.ok_or(Error::Io(IoError {
202-
path: path.to_path_buf(),
203-
context: IoErrorContext::NotAFile,
204-
// We do not have a real UEFI error here as we have a logical
205-
// problem.
206-
uefi_error: Status::INVALID_PARAMETER.into(),
207-
}))?;
205+
.ok_or_else(|| {
206+
Error::Io(IoError {
207+
path: path.to_path_buf(),
208+
context: IoErrorContext::NotAFile,
209+
// We do not have a real UEFI error here as we have a logical
210+
// problem.
211+
uefi_error: Status::INVALID_PARAMETER.into(),
212+
})
213+
})?;
208214

209215
let info = file.get_boxed_info::<UefiFileInfo>().map_err(|err| {
210216
Error::Io(IoError {
@@ -237,13 +243,15 @@ impl FileSystem {
237243
let dir = self
238244
.open(path, UefiFileMode::Read, false)?
239245
.into_directory()
240-
.ok_or(Error::Io(IoError {
241-
path: path.to_path_buf(),
242-
context: IoErrorContext::NotADirectory,
243-
// We do not have a real UEFI error here as we have a logical
244-
// problem.
245-
uefi_error: Status::INVALID_PARAMETER.into(),
246-
}))?;
246+
.ok_or_else(|| {
247+
Error::Io(IoError {
248+
path: path.to_path_buf(),
249+
context: IoErrorContext::NotADirectory,
250+
// We do not have a real UEFI error here as we have a logical
251+
// problem.
252+
uefi_error: Status::INVALID_PARAMETER.into(),
253+
})
254+
})?;
247255
Ok(UefiDirectoryIter::new(dir))
248256
}
249257

‎uefi/src/lib.rs

Lines changed: 5 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,9 @@
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(clippy::option_if_let_else)]
247252

248253
#[cfg(feature = "alloc")]
249254
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)

AltStyle によって変換されたページ (->オリジナル) /