diff --git a/src/bytes.rs b/src/bytes.rs index fdc879cd2..b9264bd33 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -789,7 +789,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)) } } @@ -1536,7 +1536,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 befe16bca..4d6e80eab 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -779,7 +779,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 @@ -985,7 +985,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; } @@ -1283,7 +1283,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)) } } @@ -1718,7 +1718,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 = core::mem::take(unsafe { &mut (*shared).vec }); 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