From c90ddc29fb997f38f3df7946f1e107580f6f1f44 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Tue, 15 Jul 2025 17:56:48 +0200 Subject: [PATCH] Fix latest clippy warnings --- src/bytes.rs | 4 ++-- src/bytes_mut.rs | 8 ++++---- tests/test_chain.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bytes.rs b/src/bytes.rs index 5c2ca18ad..262a50062 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -790,7 +790,7 @@ impl PartialEq for Bytes { impl PartialOrd for Bytes { fn partial_cmp(&self, other: &Bytes) -> Option { - self.as_slice().partial_cmp(other.as_slice()) + Some(self.cmp(other)) } } @@ -1537,7 +1537,7 @@ unsafe fn shallow_clone_vec( // pointed to by `actual` will be visible. match atom.compare_exchange(ptr as _, shared as _, Ordering::AcqRel, Ordering::Acquire) { Ok(actual) => { - debug_assert!(actual as usize == ptr as usize); + debug_assert!(core::ptr::eq(actual, ptr)); // The upgrade was successful, the new handle can be // returned. Bytes { diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 739b36ed4..997731797 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -780,7 +780,7 @@ impl BytesMut { self.ptr = vptr(v.as_mut_ptr()); self.cap = v.capacity(); debug_assert_eq!(self.len, v.len()); - return true; + true } /// Attempts to cheaply reclaim already allocated capacity for at least `additional` more @@ -986,7 +986,7 @@ impl BytesMut { // new start and updating the `len` field to reflect the new length // of the view. self.ptr = vptr(self.ptr.as_ptr().add(count)); - self.len = self.len.checked_sub(count).unwrap_or(0); + self.len = self.len.saturating_sub(count); self.cap -= count; } @@ -1284,7 +1284,7 @@ impl PartialEq for BytesMut { impl PartialOrd for BytesMut { fn partial_cmp(&self, other: &BytesMut) -> Option { - self.as_slice().partial_cmp(other.as_slice()) + Some(self.cmp(other)) } } @@ -1719,7 +1719,7 @@ impl From for Vec { rebuild_vec(bytes.ptr.as_ptr(), bytes.len, bytes.cap, off) } } else { - let shared = bytes.data as *mut Shared; + let shared = bytes.data; if unsafe { (*shared).is_unique() } { let vec = mem::replace(unsafe { &mut (*shared).vec }, Vec::new()); diff --git a/tests/test_chain.rs b/tests/test_chain.rs index cfda6b8dc..e809f44f1 100644 --- a/tests/test_chain.rs +++ b/tests/test_chain.rs @@ -135,7 +135,7 @@ fn vectored_read() { #[test] fn chain_growing_buffer() { - let mut buff = [' ' as u8; 10]; + let mut buff = [b' '; 10]; let mut vec = b"wassup".to_vec(); let mut chained = (&mut buff[..]).chain_mut(&mut vec).chain_mut(Vec::new()); // Required for potential overflow because remaining_mut for Vec is isize::MAX - vec.len(), but for chain_mut is usize::MAX