diff --git a/Cargo.toml b/Cargo.toml index e01a8e882dc..c2194f6af88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ authors = ["Joshua Liebow-Feeser "] 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 = [".*"] @@ -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" @@ -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. diff --git a/src/lib.rs b/src/lib.rs index f4fb1de894c..463cdde3281 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 } } } @@ -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 diff --git a/src/macros.rs b/src/macros.rs index a1eb2a36b17..e14920534ac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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)?); } }; @@ -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 {} diff --git a/src/pointer/ptr.rs b/src/pointer/ptr.rs index cfdaf10a209..d67f3fb4736 100644 --- a/src/pointer/ptr.rs +++ b/src/pointer/ptr.rs @@ -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`. @@ -1088,7 +1089,7 @@ mod tests { // - If `size_of::() == 0`, `N == 4` // - Else, `N == 4 * size_of::()` - fn test() { + fn test() { let mut bytes = [MaybeUninit::::uninit(); N]; let initialized = [MaybeUninit::new(0u8); N]; for start in 0..=bytes.len() { @@ -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::(); + test::<$ty, N>(); // We don't support casting into DSTs whose trailing slice // element is a ZST. if S > 0 { - test::(); + test::<[$ty], N>(); } // TODO: Test with a slice DST once we have any that // implement `KnownLayout + FromBytes`. diff --git a/zerocopy-derive/Cargo.toml b/zerocopy-derive/Cargo.toml index cb405e184dd..e1de1244d0b 100644 --- a/zerocopy-derive/Cargo.toml +++ b/zerocopy-derive/Cargo.toml @@ -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"] } diff --git a/zerocopy-derive/tests/enum_known_layout.rs b/zerocopy-derive/tests/enum_known_layout.rs index 49a6765e535..98fc8c7bbe3 100644 --- a/zerocopy-derive/tests/enum_known_layout.rs +++ b/zerocopy-derive/tests/enum_known_layout.rs @@ -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, @@ -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); diff --git a/zerocopy-derive/tests/enum_no_cell.rs b/zerocopy-derive/tests/enum_no_cell.rs index 4324a5ed21a..97bb0a5b2d2 100644 --- a/zerocopy-derive/tests/enum_no_cell.rs +++ b/zerocopy-derive/tests/enum_no_cell.rs @@ -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, @@ -47,4 +47,4 @@ where UnsafeCell(PhantomData>, &'a UnsafeCell<()>), } -assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell); +assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell); diff --git a/zerocopy-derive/tests/struct_from_bytes.rs b/zerocopy-derive/tests/struct_from_bytes.rs index a02b357efd3..234805dd244 100644 --- a/zerocopy-derive/tests/struct_from_bytes.rs +++ b/zerocopy-derive/tests/struct_from_bytes.rs @@ -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 ()>, ) @@ -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); diff --git a/zerocopy-derive/tests/struct_from_zeros.rs b/zerocopy-derive/tests/struct_from_zeros.rs index 3568f100737..304025f027e 100644 --- a/zerocopy-derive/tests/struct_from_zeros.rs +++ b/zerocopy-derive/tests/struct_from_zeros.rs @@ -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 ()>, ) @@ -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); diff --git a/zerocopy-derive/tests/struct_known_layout.rs b/zerocopy-derive/tests/struct_known_layout.rs index 68d1284de91..0ec299168f1 100644 --- a/zerocopy-derive/tests/struct_known_layout.rs +++ b/zerocopy-derive/tests/struct_known_layout.rs @@ -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 ()>, ) @@ -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); diff --git a/zerocopy-derive/tests/struct_no_cell.rs b/zerocopy-derive/tests/struct_no_cell.rs index 2205cc61a84..bf43bffbdd4 100644 --- a/zerocopy-derive/tests/struct_no_cell.rs +++ b/zerocopy-derive/tests/struct_no_cell.rs @@ -87,7 +87,7 @@ assert_impl_all!(WithAssocType>: 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>, @@ -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); diff --git a/zerocopy-derive/tests/struct_to_bytes.rs b/zerocopy-derive/tests/struct_to_bytes.rs index df072af799f..2d807d82b47 100644 --- a/zerocopy-derive/tests/struct_to_bytes.rs +++ b/zerocopy-derive/tests/struct_to_bytes.rs @@ -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 ()>, ) @@ -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); diff --git a/zerocopy-derive/tests/struct_try_from_bytes.rs b/zerocopy-derive/tests/struct_try_from_bytes.rs index 28664f7c772..48d97ad4548 100644 --- a/zerocopy-derive/tests/struct_try_from_bytes.rs +++ b/zerocopy-derive/tests/struct_try_from_bytes.rs @@ -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], ) @@ -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)] diff --git a/zerocopy-derive/tests/struct_unaligned.rs b/zerocopy-derive/tests/struct_unaligned.rs index a7db4322a63..87b4539f6b0 100644 --- a/zerocopy-derive/tests/struct_unaligned.rs +++ b/zerocopy-derive/tests/struct_unaligned.rs @@ -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 ()>, ) @@ -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); diff --git a/zerocopy-derive/tests/union_from_bytes.rs b/zerocopy-derive/tests/union_from_bytes.rs index be9d1744c88..e720b538f9c 100644 --- a/zerocopy-derive/tests/union_from_bytes.rs +++ b/zerocopy-derive/tests/union_from_bytes.rs @@ -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, @@ -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); diff --git a/zerocopy-derive/tests/union_from_zeros.rs b/zerocopy-derive/tests/union_from_zeros.rs index 2bdfc288345..6f5eb8eae31 100644 --- a/zerocopy-derive/tests/union_from_zeros.rs +++ b/zerocopy-derive/tests/union_from_zeros.rs @@ -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, @@ -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); diff --git a/zerocopy-derive/tests/union_known_layout.rs b/zerocopy-derive/tests/union_known_layout.rs index 337ab4afefb..bd43ba10dbc 100644 --- a/zerocopy-derive/tests/union_known_layout.rs +++ b/zerocopy-derive/tests/union_known_layout.rs @@ -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, @@ -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); diff --git a/zerocopy-derive/tests/union_no_cell.rs b/zerocopy-derive/tests/union_no_cell.rs index dec2a835999..c46a99c72b4 100644 --- a/zerocopy-derive/tests/union_no_cell.rs +++ b/zerocopy-derive/tests/union_no_cell.rs @@ -52,7 +52,7 @@ assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: NoCell); #[derive(NoCell)] #[repr(C)] -union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + NoCell> +union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + NoCell, const N: usize> where 'a: 'b, 'b: 'a, @@ -64,4 +64,4 @@ where d: &'a UnsafeCell<()>, } -assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell); +assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell);