Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[package]
edition = "2018"
name = "zerocopy"
version = "0.7.32"
version = "0.7.33"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
description = "Utilities for zero-copy parsing and serialization"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
Expand All @@ -30,8 +30,8 @@ rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]

[package.metadata.ci]
# The versions of the stable and nightly compiler toolchains to use in CI.
pinned-stable = "1.74.0"
pinned-nightly = "nightly-2023-12-05"
pinned-stable = "1.78.0"
pinned-nightly = "nightly-2024-05-02"

[package.metadata.playground]
features = ["__internal_use_only_features_that_work_on_stable"]
Expand All @@ -49,7 +49,7 @@ simd-nightly = ["simd"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd"]

[dependencies]
zerocopy-derive = { version = "=0.7.32", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.7.33", path = "zerocopy-derive", optional = true }

[dependencies.byteorder]
version = "1.3"
Expand All @@ -60,7 +60,7 @@ optional = true
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.7.32", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.7.33", path = "zerocopy-derive" }

[dev-dependencies]
assert_matches = "1.5"
Expand All @@ -75,6 +75,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.85", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.7.32", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.7.33", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
6 changes: 1 addition & 5 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ mod tests {
use compatibility::*;

// A native integer type (u16, i32, etc).
#[cfg_attr(kani, allow(dead_code))]
trait Native: Arbitrary + FromBytes + AsBytes + Copy + PartialEq + Debug {
const ZERO: Self;
const MAX_VALUE: Self;
Expand All @@ -664,11 +665,6 @@ mod tests {
rng.sample(Self::DIST)
}

#[cfg(kani)]
fn any() -> Self {
kani::any()
}

fn checked_add(self, rhs: Self) -> Option<Self>;
fn checked_div(self, rhs: Self) -> Option<Self>;
fn checked_mul(self, rhs: Self) -> Option<Self>;
Expand Down
34 changes: 27 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@
// `unknown_lints` is `warn` by default and we deny warnings in CI, so without
// this attribute, any unknown lint would cause a CI failure when testing with
// our MSRV.
#![allow(unknown_lints)]
#![allow(unknown_lints, non_local_definitions)]
#![deny(renamed_and_removed_lints)]
#![deny(
anonymous_parameters,
deprecated_in_future,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
missing_copy_implementations,
missing_debug_implementations,
Expand Down Expand Up @@ -228,7 +227,18 @@
clippy::indexing_slicing,
))]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "simd-nightly", feature(stdsimd))]
#![cfg_attr(
all(feature = "simd-nightly", any(target_arch = "x86", target_arch = "x86_64")),
feature(stdarch_x86_avx512)
)]
#![cfg_attr(
all(feature = "simd-nightly", target_arch = "arm"),
feature(stdarch_arm_dsp, stdarch_arm_neon_intrinsics)
)]
#![cfg_attr(
all(feature = "simd-nightly", any(target_arch = "powerpc", target_arch = "powerpc64")),
feature(stdarch_powerpc)
)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(
__INTERNAL_USE_ONLY_NIGHLTY_FEATURES_IN_TESTS,
Expand Down Expand Up @@ -3790,7 +3800,7 @@ macro_rules! transmute {
// problem for 2018 edition crates.
unsafe {
// Clippy: It's okay to transmute a type to itself.
#[allow(clippy::useless_transmute)]
#[allow(clippy::useless_transmute, clippy::missing_transmute_annotations)]
$crate::macro_util::core_reexport::mem::transmute(e)
}
}
Expand Down Expand Up @@ -5126,9 +5136,7 @@ mod sealed {
not(feature = "alloc"),
doc = "[`Vec<u8>`]: https://doc.rust-lang.org/std/vec/struct.Vec.html"
)]
pub unsafe trait ByteSlice:
Deref<Target = [u8]> + Sized + self::sealed::ByteSliceSealed
{
pub unsafe trait ByteSlice: Deref<Target = [u8]> + Sized + sealed::ByteSliceSealed {
/// Are the [`Ref::into_ref`] and [`Ref::into_mut`] methods sound when used
/// with `Self`? If not, evaluating this constant must panic at compile
/// time.
Expand Down Expand Up @@ -6413,6 +6421,7 @@ mod tests {
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | N | N | Y | KL01 |
#[derive(KnownLayout)]
#[allow(dead_code)] // fields are never read
struct KL01(NotKnownLayout<AU32>, NotKnownLayout<AU16>);

let expected = DstLayout::for_type::<KL01>();
Expand All @@ -6423,6 +6432,7 @@ mod tests {
// ...with `align(N)`:
#[derive(KnownLayout)]
#[repr(align(64))]
#[allow(dead_code)] // fields are never read
struct KL01Align(NotKnownLayout<AU32>, NotKnownLayout<AU16>);

let expected = DstLayout::for_type::<KL01Align>();
Expand All @@ -6433,6 +6443,7 @@ mod tests {
// ...with `packed`:
#[derive(KnownLayout)]
#[repr(packed)]
#[allow(dead_code)] // fields are never read
struct KL01Packed(NotKnownLayout<AU32>, NotKnownLayout<AU16>);

let expected = DstLayout::for_type::<KL01Packed>();
Expand All @@ -6443,6 +6454,7 @@ mod tests {
// ...with `packed(N)`:
#[derive(KnownLayout)]
#[repr(packed(2))]
#[allow(dead_code)] // fields are never read
struct KL01PackedN(NotKnownLayout<AU32>, NotKnownLayout<AU16>);

assert_impl_all!(KL01PackedN: KnownLayout);
Expand All @@ -6455,6 +6467,7 @@ mod tests {
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | N | Y | Y | KL03 |
#[derive(KnownLayout)]
#[allow(dead_code)] // fields are never read
struct KL03(NotKnownLayout, u8);

let expected = DstLayout::for_type::<KL03>();
Expand All @@ -6465,6 +6478,7 @@ mod tests {
// ... with `align(N)`
#[derive(KnownLayout)]
#[repr(align(64))]
#[allow(dead_code)] // fields are never read
struct KL03Align(NotKnownLayout<AU32>, u8);

let expected = DstLayout::for_type::<KL03Align>();
Expand All @@ -6475,6 +6489,7 @@ mod tests {
// ... with `packed`:
#[derive(KnownLayout)]
#[repr(packed)]
#[allow(dead_code)] // fields are never read
struct KL03Packed(NotKnownLayout<AU32>, u8);

let expected = DstLayout::for_type::<KL03Packed>();
Expand All @@ -6485,6 +6500,7 @@ mod tests {
// ... with `packed(N)`
#[derive(KnownLayout)]
#[repr(packed(2))]
#[allow(dead_code)] // fields are never read
struct KL03PackedN(NotKnownLayout<AU32>, u8);

assert_impl_all!(KL03PackedN: KnownLayout);
Expand All @@ -6497,6 +6513,7 @@ mod tests {
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | Y | N | Y | KL05 |
#[derive(KnownLayout)]
#[allow(dead_code)] // fields are never read
struct KL05<T>(u8, T);

fn _test_kl05<T>(t: T) -> impl KnownLayout {
Expand All @@ -6506,6 +6523,7 @@ mod tests {
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | Y | Y | Y | KL07 |
#[derive(KnownLayout)]
#[allow(dead_code)] // fields are never read
struct KL07<T: KnownLayout>(u8, T);

fn _test_kl07<T: KnownLayout>(t: T) -> impl KnownLayout {
Expand Down Expand Up @@ -7656,6 +7674,7 @@ mod tests {
fn test_transparent_packed_generic_struct() {
#[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
#[repr(transparent)]
#[allow(dead_code)] // for the unused fields
struct Foo<T> {
_t: T,
_phantom: PhantomData<()>,
Expand All @@ -7666,6 +7685,7 @@ mod tests {

#[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
#[repr(packed)]
#[allow(dead_code)] // for the unused fields
struct Bar<T, U> {
_t: T,
_u: U,
Expand Down
5 changes: 4 additions & 1 deletion src/macro_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ macro_rules! assert_align_gt_eq {
($t:ident, $u: ident) => {{
// The comments here should be read in the context of this macro's
// invocations in `transmute_ref!` and `transmute_mut!`.
#[allow(clippy::missing_transmute_annotations)]
if false {
// The type wildcard in this bound is inferred to be `T` because
// `align_of.into_t()` is assigned to `t` (which has type `T`).
Expand Down Expand Up @@ -328,7 +329,7 @@ macro_rules! assert_size_eq {
// SAFETY: This code is never run.
$u = unsafe {
// Clippy: It's okay to transmute a type to itself.
#[allow(clippy::useless_transmute)]
#[allow(clippy::useless_transmute, clippy::missing_transmute_annotations)]
$crate::macro_util::core_reexport::mem::transmute($t)
};
} else {
Expand Down Expand Up @@ -478,6 +479,7 @@ mod tests {
macro_rules! test {
(#[$cfg:meta] ($($ts:ty),* ; $trailing_field_ty:ty) => $expect:expr) => {{
#[$cfg]
#[allow(dead_code)] // fields are never read
struct Test($($ts,)* $trailing_field_ty);
assert_eq!(test!(@offset $($ts),* ; $trailing_field_ty), $expect);
}};
Expand Down Expand Up @@ -617,6 +619,7 @@ mod tests {
macro_rules! test {
(#[$cfg:meta] ($($ts:ty),*) => $expect:expr) => {{
#[$cfg]
#[allow(dead_code)] // fields are never read
struct Test($($ts),*);
assert_eq!(struct_has_padding!(Test, $($ts),*), $expect);
}};
Expand Down
2 changes: 2 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,12 @@ pub(crate) mod polyfills {
// MSRV is 1.70, when that function was stabilized.
//
// TODO(#67): Once our MSRV is 1.70, remove this.
#[allow(unused)]
pub(crate) trait NonNullExt<T> {
fn slice_from_raw_parts(data: Self, len: usize) -> NonNull<[T]>;
}

#[allow(unused)]
impl<T> NonNullExt<T> for NonNull<T> {
#[inline(always)]
fn slice_from_raw_parts(data: Self, len: usize) -> NonNull<[T]> {
Expand Down
4 changes: 2 additions & 2 deletions src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T> Unalign<T> {
/// may prefer [`Deref::deref`], which is infallible.
#[inline(always)]
pub fn try_deref(&self) -> Option<&T> {
if !crate::util::aligned_to::<_, T>(self) {
if !util::aligned_to::<_, T>(self) {
return None;
}

Expand All @@ -154,7 +154,7 @@ impl<T> Unalign<T> {
/// callers may prefer [`DerefMut::deref_mut`], which is infallible.
#[inline(always)]
pub fn try_deref_mut(&mut self) -> Option<&mut T> {
if !crate::util::aligned_to::<_, T>(&*self) {
if !util::aligned_to::<_, T>(&*self) {
return None;
}

Expand Down
16 changes: 8 additions & 8 deletions tests/ui-nightly/include_value_not_from_bytes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ error[E0277]: the trait bound `UnsafeCell<u32>: FromBytes` is not satisfied
| required by a bound introduced by this call
|
= help: the following other types implement trait `FromBytes`:
isize
i8
i16
i32
i64
i128
usize
u8
()
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
ManuallyDrop<T>
and $N others
note: required by a bound in `AssertIsFromBytes`
--> tests/ui-nightly/include_value_not_from_bytes.rs:12:5
Expand Down
8 changes: 4 additions & 4 deletions tests/ui-nightly/invalid-impls/invalid-impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:26:37
|
26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T`
| ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T`, which is required by `Foo<T>: zerocopy::FromZeroes`
|
note: required for `Foo<T>` to implement `zerocopy::FromZeroes`
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:10
Expand All @@ -29,7 +29,7 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:27:36
|
27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`
| ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`, which is required by `Foo<T>: zerocopy::FromBytes`
|
note: required for `Foo<T>` to implement `zerocopy::FromBytes`
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:22
Expand All @@ -56,7 +56,7 @@ error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:28:34
|
28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T`
| ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T`, which is required by `Foo<T>: zerocopy::AsBytes`
|
note: required for `Foo<T>` to implement `zerocopy::AsBytes`
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:33
Expand All @@ -83,7 +83,7 @@ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:29:36
|
29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`
| ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`, which is required by `Foo<T>: zerocopy::Unaligned`
|
note: required for `Foo<T>` to implement `zerocopy::Unaligned`
--> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:42
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-nightly/max-align.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> tests/ui-nightly/max-align.rs:96:11
--> tests/ui-nightly/max-align.rs:96:17
|
96 | #[repr(C, align(1073741824))]
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^
16 changes: 8 additions & 8 deletions tests/ui-nightly/transmute-dst-not-frombytes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
| required by a bound introduced by this call
|
= help: the following other types implement trait `FromBytes`:
isize
i8
i16
i32
i64
i128
usize
u8
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `AssertIsFromBytes`
--> tests/ui-nightly/transmute-dst-not-frombytes.rs:18:41
Expand Down
11 changes: 1 addition & 10 deletions tests/ui-nightly/transmute-mut-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ error[E0658]: mutable references are not allowed in constants
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
= note: this compiler was built on 2024-05-01; consider upgrading it if it is out of date

error[E0015]: cannot call non-const fn `transmute_mut::<'_, '_, [u8; 2], [u8; 2]>` in constants
--> tests/ui-nightly/transmute-mut-const.rs:20:37
Expand All @@ -30,13 +31,3 @@ error[E0015]: cannot call non-const fn `transmute_mut::<'_, '_, [u8; 2], [u8; 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
--> tests/ui-nightly/transmute-mut-const.rs:20:57
|
20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
| --------------------^^^^^^^^^^^^-
| | |
| | creates a temporary value which is freed while still in use
| temporary value is freed at the end of this statement
| using this value as a constant requires that borrow lasts for `'static`
Loading