From 02806fcff95e3e042d84118926bc11eed1f37233 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Sat, 6 Jan 2024 21:43:35 +0000 Subject: [PATCH] Address clippy lints Signed-off-by: Nick Spinale --- crates/sel4-async/block-io/src/lib.rs | 2 +- crates/sel4-async/block-io/src/operation.rs | 2 ++ crates/sel4-async/time/src/lib.rs | 6 +++++- crates/sel4-externally-shared/src/atomics/mod.rs | 2 ++ crates/sel4-externally-shared/src/atomics/ops.rs | 4 ++-- crates/sel4-externally-shared/src/lib.rs | 2 ++ .../src/ops/unordered_atomic_ops.rs | 1 + crates/sel4-newlib/src/errno.rs | 1 + crates/sel4-shared-ring-buffer/block-io/src/lib.rs | 6 +++--- crates/sel4-shared-ring-buffer/block-io/src/owned.rs | 8 +++++--- .../bookkeeping/src/slot_set_semaphore.rs | 3 +++ crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs | 2 +- 12 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/sel4-async/block-io/src/lib.rs b/crates/sel4-async/block-io/src/lib.rs index 9669b3913..c73bf5728 100644 --- a/crates/sel4-async/block-io/src/lib.rs +++ b/crates/sel4-async/block-io/src/lib.rs @@ -603,7 +603,7 @@ pub async fn read_bytes, A: ReadAccess>( pub async fn write_bytes, A: ReadAccess + WriteAccess>( io: &T, offset: u64, - buf: &mut [u8], + buf: &[u8], ) -> Result<(), T::Error> { read_or_write_bytes(io, offset, Operation::write(buf)).await } diff --git a/crates/sel4-async/block-io/src/operation.rs b/crates/sel4-async/block-io/src/operation.rs index d80c7b7af..f3952e662 100644 --- a/crates/sel4-async/block-io/src/operation.rs +++ b/crates/sel4-async/block-io/src/operation.rs @@ -170,6 +170,7 @@ impl<'a, A: Access> Iterator for OperationChunks<'a, A> { } impl<'a> Operation<'a, ReadOnly> { + #[allow(clippy::explicit_auto_deref)] pub fn as_read(&'a mut self) -> &'a mut [u8] { match self { Self::Read { buf, .. } => buf, @@ -179,6 +180,7 @@ impl<'a> Operation<'a, ReadOnly> { } impl<'a> Operation<'a, WriteOnly> { + #[allow(clippy::explicit_auto_deref)] pub fn as_write(&'a self) -> &'a [u8] { match self { Self::Read { witness, .. } => *witness, diff --git a/crates/sel4-async/time/src/lib.rs b/crates/sel4-async/time/src/lib.rs index 063e3cefc..50a2ddc47 100644 --- a/crates/sel4-async/time/src/lib.rs +++ b/crates/sel4-async/time/src/lib.rs @@ -45,7 +45,9 @@ impl TimerShared { fn mark_expired(&mut self) { assert!(!self.expired); self.expired = true; - self.waker.take().map(Waker::wake); + if let Some(waker) = self.waker.take() { + waker.wake(); + }; } } @@ -71,6 +73,7 @@ impl TimerManagerShared { } impl TimerManager { + #![allow(clippy::new_without_default)] pub fn new() -> Self { Self { shared: Rc::new(RefCell::new(TimerManagerShared::new())), @@ -155,6 +158,7 @@ pub struct Timeout { impl Future for Timeout { type Output = Result; + #[allow(clippy::redundant_pattern_matching)] fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.project(); if let Poll::Ready(v) = this.value.poll(cx) { diff --git a/crates/sel4-externally-shared/src/atomics/mod.rs b/crates/sel4-externally-shared/src/atomics/mod.rs index 367a71eba..51d179cd1 100644 --- a/crates/sel4-externally-shared/src/atomics/mod.rs +++ b/crates/sel4-externally-shared/src/atomics/mod.rs @@ -41,6 +41,7 @@ impl fmt::Debug for AtomicPtr<'_, T, A> { } impl<'a, T, A> AtomicPtr<'a, T, A> { + #[allow(clippy::missing_safety_doc)] pub const unsafe fn new(pointer: NonNull) -> Self { AtomicPtr { pointer, @@ -62,6 +63,7 @@ impl<'a, T, A> AtomicPtr<'a, T, A> { } } +#[allow(clippy::missing_safety_doc)] pub unsafe trait Atomic: AtomicSealed + Copy { const IS_SIGNED: bool; } diff --git a/crates/sel4-externally-shared/src/atomics/ops.rs b/crates/sel4-externally-shared/src/atomics/ops.rs index 6e170bad4..6033c5e8f 100644 --- a/crates/sel4-externally-shared/src/atomics/ops.rs +++ b/crates/sel4-externally-shared/src/atomics/ops.rs @@ -129,9 +129,9 @@ impl<'a, T: Atomic, A: Readable + Writable> AtomicPtr<'a, T, A> { where F: FnMut(T) -> Option, { - let mut prev = self.load(fetch_order.into()); + let mut prev = self.load(fetch_order); while let Some(next) = f(prev) { - match self.compare_exchange_weak(prev, next, set_order.into(), fetch_order.into()) { + match self.compare_exchange_weak(prev, next, set_order, fetch_order) { x @ Ok(_) => return x, Err(next_prev) => prev = next_prev, } diff --git a/crates/sel4-externally-shared/src/lib.rs b/crates/sel4-externally-shared/src/lib.rs index f971dcf4e..89f02d53a 100644 --- a/crates/sel4-externally-shared/src/lib.rs +++ b/crates/sel4-externally-shared/src/lib.rs @@ -31,6 +31,8 @@ pub type ExternallySharedRef<'a, T, A = ReadWrite> = VolatileRef<'a, T, A, Exter pub type ExternallySharedPtr<'a, T, A = ReadWrite> = VolatilePtr<'a, T, A, ExternallySharedOps>; pub trait ExternallySharedRefExt<'a, T: ?Sized, A: Access> { + #[allow(clippy::missing_safety_doc)] + #[allow(clippy::new_ret_no_self)] unsafe fn new(pointer: NonNull) -> ExternallySharedRef<'a, T, A>; } diff --git a/crates/sel4-externally-shared/src/ops/unordered_atomic_ops.rs b/crates/sel4-externally-shared/src/ops/unordered_atomic_ops.rs index 56ff2dd1c..3b2fab9f4 100644 --- a/crates/sel4-externally-shared/src/ops/unordered_atomic_ops.rs +++ b/crates/sel4-externally-shared/src/ops/unordered_atomic_ops.rs @@ -33,6 +33,7 @@ impl UnitaryOps for Unordere } } +#[allow(clippy::missing_safety_doc)] pub unsafe trait UnsignedPrimitiveWithUnorderedAtomics {} macro_rules! impl_unsigned_primitive_with_unordered_atomics { diff --git a/crates/sel4-newlib/src/errno.rs b/crates/sel4-newlib/src/errno.rs index 140645cc0..54139d81b 100644 --- a/crates/sel4-newlib/src/errno.rs +++ b/crates/sel4-newlib/src/errno.rs @@ -21,6 +21,7 @@ pub(crate) fn set_errno(err: c_int) { } } +#[allow(dead_code)] pub(crate) mod values { use super::*; diff --git a/crates/sel4-shared-ring-buffer/block-io/src/lib.rs b/crates/sel4-shared-ring-buffer/block-io/src/lib.rs index 9c151042c..80e936fb0 100644 --- a/crates/sel4-shared-ring-buffer/block-io/src/lib.rs +++ b/crates/sel4-shared-ring-buffer/block-io/src/lib.rs @@ -78,7 +78,7 @@ impl async fn request<'a>( &'a self, start_block_idx: u64, - mut operation: Operation<'a, P>, + operation: Operation<'a, P>, ) -> Result<(), Error> { let request_index = { let sem = self.shared.borrow().owned.slot_set_semaphore().clone(); @@ -89,7 +89,7 @@ impl .issue_request( &mut reservation, start_block_idx, - &mut IssueRequestBuf::new(&mut operation), + &mut IssueRequestBuf::new(&operation), ) .map_err(ErrorOrUserError::unwrap_error)? }; @@ -147,7 +147,7 @@ pub struct RequestFuture<'a, N, P: Access, A: AbstractBounceBufferAllocator, F: } impl<'a, N, P: Access, A: AbstractBounceBufferAllocator, F: FnMut()> RequestFuture<'a, N, P, A, F> { - fn poll_inner<'b>(&'b mut self, cx: &mut Context<'_>) -> Poll> + fn poll_inner<'b>(&'b mut self, cx: &Context<'_>) -> Poll> where 'a: 'b, { diff --git a/crates/sel4-shared-ring-buffer/block-io/src/owned.rs b/crates/sel4-shared-ring-buffer/block-io/src/owned.rs index 226d3ef94..c4f391648 100644 --- a/crates/sel4-shared-ring-buffer/block-io/src/owned.rs +++ b/crates/sel4-shared-ring-buffer/block-io/src/owned.rs @@ -174,7 +174,7 @@ impl ) } - pub fn issue_request<'a>( + pub fn issue_request( &mut self, reservation: &mut SlotSetReservation<'_, S, NUM_SLOT_POOLS>, start_block_idx: u64, @@ -209,7 +209,7 @@ impl self.requests .occupy(Occupied { - req: req.clone(), + req, state: OccupiedState::Pending { waker: None }, }) .unwrap(); @@ -355,7 +355,9 @@ impl }, }; - waker.map(Waker::wake); + if let Some(waker) = waker { + waker.wake(); + } } OccupiedState::Canceled => { let range = occupied.req.buf().encoded_addr_range(); diff --git a/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs b/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs index b34df25aa..1105f34d5 100644 --- a/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs +++ b/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs @@ -23,6 +23,7 @@ pub trait SlotSemaphore { } pub trait AsyncSlotSemaphore: SlotSemaphore { + #[allow(clippy::needless_lifetimes)] fn take<'a>( &'a self, n: usize, @@ -205,6 +206,7 @@ impl From for Error { pub struct SlotSemaphoreClosedError(()); impl SlotSemaphoreClosedError { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self(()) } @@ -214,6 +216,7 @@ impl SlotSemaphoreClosedError { pub struct SlotReservationExhaustedError(()); impl SlotReservationExhaustedError { + #![allow(clippy::new_without_default)] pub fn new() -> Self { Self(()) } diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs index 2adc31575..e3b1785df 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs @@ -104,7 +104,7 @@ impl Inner { while let Some(desc) = self.rx_ring_buffers.used_mut().dequeue()? { let ix = desc.cookie(); - if !(ix < self.rx_buffers.capacity()) { + if ix >= self.rx_buffers.capacity() { return Err(PeerMisbehaviorError::OutOfBoundsCookie); }