Bump MSRV to 1.57 (#788)

This commit is contained in:
Paolo Barbolini
2025-07-16 10:33:07 +02:00
committed by GitHub
parent f29e93951d
commit 3e44f88f5f
9 changed files with 21 additions and 60 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ name = "bytes"
# - Update CHANGELOG.md. # - Update CHANGELOG.md.
# - Create "v1.x.y" git tag. # - Create "v1.x.y" git tag.
version = "1.10.1" version = "1.10.1"
edition = "2018" edition = "2021"
rust-version = "1.39" rust-version = "1.57"
license = "MIT" license = "MIT"
authors = [ authors = [
"Carl Lerche <[email protected]>", "Carl Lerche <[email protected]>",
+1 -1
View File
@@ -1 +1 @@
msrv = "1.39" msrv = "1.57"
+4 -4
View File
@@ -3,7 +3,7 @@ use crate::buf::{limit, Chain, Limit, UninitSlice};
use crate::buf::{writer, Writer}; use crate::buf::{writer, Writer};
use crate::{panic_advance, panic_does_not_fit, TryGetError}; use crate::{panic_advance, panic_does_not_fit, TryGetError};
use core::{mem, ptr, usize}; use core::{mem, ptr};
use alloc::{boxed::Box, vec::Vec}; use alloc::{boxed::Box, vec::Vec};
@@ -1503,7 +1503,7 @@ unsafe impl BufMut for &mut [u8] {
} }
// Lifetime dance taken from `impl Write for &mut [u8]`. // Lifetime dance taken from `impl Write for &mut [u8]`.
let (_, b) = core::mem::replace(self, &mut []).split_at_mut(cnt); let (_, b) = core::mem::take(self).split_at_mut(cnt);
*self = b; *self = b;
} }
@@ -1559,7 +1559,7 @@ unsafe impl BufMut for &mut [core::mem::MaybeUninit<u8>] {
} }
// Lifetime dance taken from `impl Write for &mut [u8]`. // Lifetime dance taken from `impl Write for &mut [u8]`.
let (_, b) = core::mem::replace(self, &mut []).split_at_mut(cnt); let (_, b) = core::mem::take(self).split_at_mut(cnt);
*self = b; *self = b;
} }
@@ -1600,7 +1600,7 @@ unsafe impl BufMut for Vec<u8> {
#[inline] #[inline]
fn remaining_mut(&self) -> usize { fn remaining_mut(&self) -> usize {
// A vector can never have more than isize::MAX bytes // A vector can never have more than isize::MAX bytes
core::isize::MAX as usize - self.len() isize::MAX as usize - self.len()
} }
#[inline] #[inline]
+1 -18
View File
@@ -163,24 +163,7 @@ impl<T: Buf> Buf for Take<T> {
} }
const LEN: usize = 16; const LEN: usize = 16;
let mut slices: [IoSlice<'a>; LEN] = [ let mut slices: [IoSlice<'a>; LEN] = [IoSlice::new(&[]); LEN];
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
IoSlice::new(&[]),
];
let cnt = self let cnt = self
.inner .inner
+7 -8
View File
@@ -1,8 +1,7 @@
use core::iter::FromIterator;
use core::mem::{self, ManuallyDrop}; use core::mem::{self, ManuallyDrop};
use core::ops::{Deref, RangeBounds}; use core::ops::{Deref, RangeBounds};
use core::ptr::NonNull; use core::ptr::NonNull;
use core::{cmp, fmt, hash, ptr, slice, usize}; use core::{cmp, fmt, hash, ptr, slice};
use alloc::{ use alloc::{
alloc::{dealloc, Layout}, alloc::{dealloc, Layout},
@@ -16,7 +15,7 @@ use crate::buf::IntoIter;
#[allow(unused)] #[allow(unused)]
use crate::loom::sync::atomic::AtomicMut; use crate::loom::sync::atomic::AtomicMut;
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use crate::{offset_from, Buf, BytesMut}; use crate::{Buf, BytesMut};
/// A cheaply cloneable and sliceable chunk of contiguous memory. /// A cheaply cloneable and sliceable chunk of contiguous memory.
/// ///
@@ -1235,7 +1234,7 @@ unsafe fn promotable_to_vec(
let buf = f(shared); let buf = f(shared);
let cap = offset_from(ptr, buf) + len; let cap = ptr.offset_from(buf) as usize + len;
// Copy back buffer // Copy back buffer
ptr::copy(ptr, buf, len); ptr::copy(ptr, buf, len);
@@ -1263,7 +1262,7 @@ unsafe fn promotable_to_mut(
debug_assert_eq!(kind, KIND_VEC); debug_assert_eq!(kind, KIND_VEC);
let buf = f(shared); let buf = f(shared);
let off = offset_from(ptr, buf); let off = ptr.offset_from(buf) as usize;
let cap = off + len; let cap = off + len;
let v = Vec::from_raw_parts(buf, cap, cap); let v = Vec::from_raw_parts(buf, cap, cap);
@@ -1348,7 +1347,7 @@ unsafe fn promotable_is_unique(data: &AtomicPtr<()>) -> bool {
} }
unsafe fn free_boxed_slice(buf: *mut u8, offset: *const u8, len: usize) { unsafe fn free_boxed_slice(buf: *mut u8, offset: *const u8, len: usize) {
let cap = offset_from(offset, buf) + len; let cap = offset.offset_from(buf) as usize + len;
dealloc(buf, Layout::from_size_align(cap, 1).unwrap()) dealloc(buf, Layout::from_size_align(cap, 1).unwrap())
} }
@@ -1444,7 +1443,7 @@ unsafe fn shared_to_mut_impl(shared: *mut Shared, ptr: *const u8, len: usize) ->
let cap = shared.cap; let cap = shared.cap;
// Rebuild Vec // Rebuild Vec
let off = offset_from(ptr, buf); let off = ptr.offset_from(buf) as usize;
let v = Vec::from_raw_parts(buf, len + off, cap); let v = Vec::from_raw_parts(buf, len + off, cap);
let mut b = BytesMut::from_vec(v); let mut b = BytesMut::from_vec(v);
@@ -1510,7 +1509,7 @@ unsafe fn shallow_clone_vec(
// vector. // vector.
let shared = Box::new(Shared { let shared = Box::new(Shared {
buf, buf,
cap: offset_from(offset, buf) + len, cap: offset.offset_from(buf) as usize + len,
// Initialize refcount to 2. One for this reference, and one // Initialize refcount to 2. One for this reference, and one
// for the new clone that will be returned from // for the new clone that will be returned from
// `shallow_clone`. // `shallow_clone`.
+6 -7
View File
@@ -1,8 +1,7 @@
use core::iter::FromIterator;
use core::mem::{self, ManuallyDrop, MaybeUninit}; use core::mem::{self, ManuallyDrop, MaybeUninit};
use core::ops::{Deref, DerefMut}; use core::ops::{Deref, DerefMut};
use core::ptr::{self, NonNull}; use core::ptr::{self, NonNull};
use core::{cmp, fmt, hash, isize, slice, usize}; use core::{cmp, fmt, hash, slice};
use alloc::{ use alloc::{
borrow::{Borrow, BorrowMut}, borrow::{Borrow, BorrowMut},
@@ -17,7 +16,7 @@ use crate::bytes::Vtable;
#[allow(unused)] #[allow(unused)]
use crate::loom::sync::atomic::AtomicMut; use crate::loom::sync::atomic::AtomicMut;
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use crate::{offset_from, Buf, BufMut, Bytes, TryGetError}; use crate::{Buf, BufMut, Bytes, TryGetError};
/// A unique reference to a contiguous slice of memory. /// A unique reference to a contiguous slice of memory.
/// ///
@@ -694,7 +693,7 @@ impl BytesMut {
let v_capacity = v.capacity(); let v_capacity = v.capacity();
let ptr = v.as_mut_ptr(); let ptr = v.as_mut_ptr();
let offset = offset_from(self.ptr.as_ptr(), ptr); let offset = self.ptr.as_ptr().offset_from(ptr) as usize;
// Compare the condition in the `kind == KIND_VEC` case above // Compare the condition in the `kind == KIND_VEC` case above
// for more details. // for more details.
@@ -1722,7 +1721,7 @@ impl From<BytesMut> for Vec<u8> {
let shared = bytes.data as *mut Shared; let shared = bytes.data as *mut Shared;
if unsafe { (*shared).is_unique() } { if unsafe { (*shared).is_unique() } {
let vec = mem::replace(unsafe { &mut (*shared).vec }, Vec::new()); let vec = core::mem::take(unsafe { &mut (*shared).vec });
unsafe { release_shared(shared) }; unsafe { release_shared(shared) };
@@ -1797,7 +1796,7 @@ unsafe fn shared_v_to_vec(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> V
let shared = &mut *shared; let shared = &mut *shared;
// Drop shared // Drop shared
let mut vec = mem::replace(&mut shared.vec, Vec::new()); let mut vec = core::mem::take(&mut shared.vec);
release_shared(shared); release_shared(shared);
// Copy back buffer // Copy back buffer
@@ -1823,7 +1822,7 @@ unsafe fn shared_v_to_mut(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> B
let v = &mut shared.vec; let v = &mut shared.vec;
let v_capacity = v.capacity(); let v_capacity = v.capacity();
let v_ptr = v.as_mut_ptr(); let v_ptr = v.as_mut_ptr();
let offset = offset_from(ptr as *mut u8, v_ptr); let offset = ptr.offset_from(v_ptr) as usize;
let cap = v_capacity - offset; let cap = v_capacity - offset;
let ptr = vptr(ptr as *mut u8); let ptr = vptr(ptr as *mut u8);
-17
View File
@@ -114,7 +114,6 @@ fn abort() -> ! {
#[inline(always)] #[inline(always)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
fn saturating_sub_usize_u64(a: usize, b: u64) -> usize { fn saturating_sub_usize_u64(a: usize, b: u64) -> usize {
use core::convert::TryFrom;
match usize::try_from(b) { match usize::try_from(b) {
Ok(b) => a.saturating_sub(b), Ok(b) => a.saturating_sub(b),
Err(_) => 0, Err(_) => 0,
@@ -124,7 +123,6 @@ fn saturating_sub_usize_u64(a: usize, b: u64) -> usize {
#[inline(always)] #[inline(always)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
fn min_u64_usize(a: u64, b: usize) -> usize { fn min_u64_usize(a: u64, b: usize) -> usize {
use core::convert::TryFrom;
match usize::try_from(a) { match usize::try_from(a) {
Ok(a) => usize::min(a, b), Ok(a) => usize::min(a, b),
Err(_) => b, Err(_) => b,
@@ -182,18 +180,3 @@ fn panic_does_not_fit(size: usize, nbytes: usize) -> ! {
size, nbytes size, nbytes
); );
} }
/// Precondition: dst >= original
///
/// The following line is equivalent to:
///
/// ```rust,ignore
/// self.ptr.as_ptr().offset_from(ptr) as usize;
/// ```
///
/// But due to min rust is 1.39 and it is only stabilized
/// in 1.47, we cannot use it.
#[inline]
fn offset_from(dst: *const u8, original: *const u8) -> usize {
dst as usize - original as usize
}
-1
View File
@@ -4,7 +4,6 @@ use bytes::buf::UninitSlice;
use bytes::{BufMut, BytesMut}; use bytes::{BufMut, BytesMut};
use core::fmt::Write; use core::fmt::Write;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use core::usize;
#[test] #[test]
fn test_vec_as_mut_buf() { fn test_vec_as_mut_buf() {
-2
View File
@@ -5,7 +5,6 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::panic::{self, AssertUnwindSafe}; use std::panic::{self, AssertUnwindSafe};
use std::usize;
const LONG: &[u8] = b"mary had a little lamb, little lamb, little lamb"; const LONG: &[u8] = b"mary had a little lamb, little lamb, little lamb";
const SHORT: &[u8] = b"hello world"; const SHORT: &[u8] = b"hello world";
@@ -82,7 +81,6 @@ fn fmt() {
#[test] #[test]
fn fmt_write() { fn fmt_write() {
use std::fmt::Write; use std::fmt::Write;
use std::iter::FromIterator;
let s = String::from_iter((0..10).map(|_| "abcdefg")); let s = String::from_iter((0..10).map(|_| "abcdefg"));
let mut a = BytesMut::with_capacity(64); let mut a = BytesMut::with_capacity(64);