Skip to content

Commit

Permalink
Lower our MSRV to 1.59.0
Browse files Browse the repository at this point in the history
Makes progress on #554
  • Loading branch information
joshlf committed Jan 25, 2024
1 parent 1f3910a commit 4122573
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 57 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Utilities for zero-copy parsing and serialization"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/google/zerocopy"
rust-version = "1.60.0"
rust-version = "1.59.0"

exclude = [".*"]

Expand Down Expand Up @@ -58,6 +58,10 @@ zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive" }
[dev-dependencies]
assert_matches = "1.5"
itertools = "0.11"
# We don't use this directly, but trybuild does. On the MSRV toolchain, the
# version resolver fails to select any version for once_cell unless we
# depend on it directly.
once_cell = "=1.9"
rand = { version = "0.8.5", features = ["small_rng"] }
rustversion = "1.0"
static_assertions = "1.1"
Expand All @@ -66,7 +70,7 @@ testutil = { path = "testutil" }
# and the version used in CI are guaranteed to be the same. Future versions
# sometimes change the output format slightly, so a version mismatch can cause
# CI test failures.
trybuild = { version = "=1.0.85", features = ["diff"] }
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl DstLayout {
None => Self::MIN_ALIGN,
};

assert!(align.is_power_of_two());
assert!(align.get().is_power_of_two());

DstLayout { align, size_info: SizeInfo::Sized { _size: 0 } }
}
Expand Down Expand Up @@ -542,7 +542,7 @@ impl DstLayout {
None => Self::THEORETICAL_MAX_ALIGN,
};

assert!(max_align.is_power_of_two());
assert!(max_align.get().is_power_of_two());

// We use Kani to prove that this method is robust to future increases
// in Rust's maximum allowed alignment. However, if such a change ever
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ macro_rules! unsafe_impl {
=> $trait:ident for $ty:ty $(; |$candidate:ident $(: MaybeAligned<$ref_repr:ty>)? $(: Maybe<$ptr_repr:ty>)?| $is_bit_valid:expr)?
) => {
$(#[$attr])*
unsafe impl<$(const $constname: $constty,)* $($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> $trait for $ty {
unsafe impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),* $(, const $constname: $constty,)*> $trait for $ty {
unsafe_impl!(@method $trait $(; |$candidate: $(MaybeAligned<$ref_repr>)? $(Maybe<$ptr_repr>)?| $is_bit_valid)?);
}
};
Expand Down Expand Up @@ -341,7 +341,7 @@ macro_rules! impl_known_layout {
use core::ptr::NonNull;

// SAFETY: Delegates safety to `DstLayout::for_type`.
unsafe impl<$(const $constvar : $constty,)? $($tyvar $(: ?$optbound)?)?> KnownLayout for $ty {
unsafe impl<$($tyvar $(: ?$optbound)?)? $(, const $constvar : $constty)?> KnownLayout for $ty {
#[allow(clippy::missing_inline_in_public_items)]
fn only_derive_is_allowed_to_implement_this_trait() where Self: Sized {}

Expand Down
7 changes: 4 additions & 3 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ mod def {
}
}

#[allow(unreachable_pub)] // This is a false positive on our MSRV toolchain.
pub use def::Ptr;

/// Used to define the system of [invariants][invariant] of `Ptr`.
Expand Down Expand Up @@ -1088,7 +1089,7 @@ mod tests {

// - If `size_of::<T>() == 0`, `N == 4`
// - Else, `N == 4 * size_of::<T>()`
fn test<const N: usize, T: ?Sized + KnownLayout + FromBytes>() {
fn test<T: ?Sized + KnownLayout + FromBytes, const N: usize>() {
let mut bytes = [MaybeUninit::<u8>::uninit(); N];
let initialized = [MaybeUninit::new(0u8); N];
for start in 0..=bytes.len() {
Expand Down Expand Up @@ -1183,11 +1184,11 @@ mod tests {
$({
const S: usize = core::mem::size_of::<$ty>();
const N: usize = if S == 0 { 4 } else { S * 4 };
test::<N, $ty>();
test::<$ty, N>();
// We don't support casting into DSTs whose trailing slice
// element is a ZST.
if S > 0 {
test::<N, [$ty]>();
test::<[$ty], N>();
}
// TODO: Test with a slice DST once we have any that
// implement `KnownLayout + FromBytes`.
Expand Down
3 changes: 1 addition & 2 deletions tests/ui-msrv/transmute-mut-alignment-increase.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ error[E0658]: mutable references are not allowed in constants
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information

error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], AU16>` in constants
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> tests/ui-msrv/transmute-mut-alignment-increase.rs:19:39
|
19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
Expand Down
3 changes: 1 addition & 2 deletions tests/ui-msrv/transmute-mut-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ error[E0658]: mutable references are not allowed in constants
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information

error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], [u8; 2]>` in constants
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> tests/ui-msrv/transmute-mut-const.rs:20:37
|
20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
Expand Down
3 changes: 1 addition & 2 deletions tests/ui-msrv/transmute-mut-size-decrease.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ error[E0658]: mutable references are not allowed in constants
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information

error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], u8>` in constants
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> tests/ui-msrv/transmute-mut-size-decrease.rs:17:32
|
17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
Expand Down
3 changes: 1 addition & 2 deletions tests/ui-msrv/transmute-mut-size-increase.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ error[E0658]: mutable references are not allowed in constants
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information

error[E0015]: cannot call non-const fn `transmute_mut::<u8, [u8; 2]>` in constants
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> tests/ui-msrv/transmute-mut-size-increase.rs:17:37
|
17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
Expand Down
12 changes: 0 additions & 12 deletions tests/ui-msrv/transmute-ptr-to-usize.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
|
= help: the following implementations were found:
<usize as AsBytes>
<f32 as AsBytes>
<f64 as AsBytes>
<i128 as AsBytes>
and $N others
note: required by a bound in `AssertIsIntoBytes`
--> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
|
Expand All @@ -23,12 +17,6 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
|
= help: the following implementations were found:
<usize as AsBytes>
<f32 as AsBytes>
<f64 as AsBytes>
<i128 as AsBytes>
and $N others
note: required by a bound in `AssertIsIntoBytes`
--> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
|
Expand Down
8 changes: 6 additions & 2 deletions zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Custom derive for traits from the zerocopy crate"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/google/zerocopy"
rust-version = "1.60.0"
rust-version = "1.59.0"

# We prefer to include tests when publishing to crates.io so that Crater [1] can
# detect regressions in our test suite. These two tests are excessively large,
Expand All @@ -32,11 +32,15 @@ quote = "1.0.10"
syn = "2.0.31"

[dev-dependencies]
# We don't use this directly, but trybuild does. On the MSRV toolchain, the
# version resolver fails to select any version for once_cell unless we
# depend on it directly.
once_cell = "=1.9"
static_assertions = "1.1"
testutil = { path = "../testutil" }
# Pinned to a specific version so that the version used for local development
# and the version used in CI are guaranteed to be the same. Future versions
# sometimes change the output format slightly, so a version mismatch can cause
# CI test failures.
trybuild = { version = "=1.0.85", features = ["diff"] }
trybuild = { version = "=1.0.89", features = ["diff"] }
zerocopy = { path = "../", features = ["derive"] }
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/enum_known_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ assert_impl_all!(Baz: KnownLayout);

#[derive(KnownLayout)]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + KnownLayout, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -43,4 +43,4 @@ where
Variant([T; N], PhantomData<&'a &'b ()>),
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: KnownLayout);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/enum_no_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assert_impl_all!(Baz: NoCell);

#[derive(NoCell)]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + NoCell>
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + NoCell, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -47,4 +47,4 @@ where
UnsafeCell(PhantomData<UnsafeCell<()>>, &'a UnsafeCell<()>),
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromBytes);

#[derive(FromZeros, FromBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromBytes, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -76,4 +76,4 @@ where
'b: 'a,
T: 'a + 'b + FromBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromBytes);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_from_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromZeros);

#[derive(FromZeros)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeros>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromZeros, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -74,4 +74,4 @@ where
'b: 'a,
T: 'a + 'b + FromZeros;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeros);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromZeros);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_known_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ assert_impl_all!(TypeParams<'static, AU16, IntoIter<()>>: KnownLayout);

#[derive(KnownLayout)]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + KnownLayout, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -62,4 +62,4 @@ where
'b: 'a,
T: 'a + 'b + KnownLayout;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: KnownLayout);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_no_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ assert_impl_all!(WithAssocType<UnsafeCell<u8>>: NoCell);

#[derive(NoCell)]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + NoCell>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + NoCell, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
PhantomData<UnsafeCell<()>>,
Expand All @@ -98,4 +98,4 @@ where
'b: 'a,
T: 'a + 'b + NoCell;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ assert_impl_all!(Unsized: IntoBytes);

#[derive(IntoBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + IntoBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + IntoBytes, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -158,4 +158,4 @@ where
'b: 'a,
T: 'a + 'b + IntoBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: IntoBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: IntoBytes);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_try_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: TryFromBytes);

#[derive(TryFromBytes, FromZeros, FromBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + TryFromBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + TryFromBytes, const N: usize>(
PhantomData<&'a &'b ()>,
[T],
)
Expand All @@ -142,7 +142,7 @@ where
'b: 'a,
T: 'a + 'b + TryFromBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: TryFromBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: TryFromBytes);

#[derive(Debug, PartialEq, Eq, TryFromBytes, KnownLayout)]
#[repr(C, packed)]
Expand Down
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_unaligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ assert_impl_all!(TypeParams<'static, [u8], IntoIter<()>>: Unaligned);

#[derive(Unaligned)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + Unaligned>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + Unaligned, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -97,4 +97,4 @@ where
'b: 'a,
T: 'a + 'b + Unaligned;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: Unaligned);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: Unaligned);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/union_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromBytes);

#[derive(FromZeros, FromBytes)]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromBytes>
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromBytes, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -69,4 +69,4 @@ where
b: PhantomData<&'a &'b ()>,
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromBytes);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/union_from_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromZeros);

#[derive(FromZeros)]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeros>
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromZeros, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -69,4 +69,4 @@ where
b: PhantomData<&'a &'b ()>,
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeros);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromZeros);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/union_known_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: KnownLayout);

#[derive(KnownLayout)]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + KnownLayout, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -62,4 +62,4 @@ where
b: PhantomData<&'a &'b ()>,
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: KnownLayout);
Loading

0 comments on commit 4122573

Please sign in to comment.