From 0cee8133af08b0770aefdff19f9ebf298ddd936a Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Thu, 7 Dec 2023 01:11:00 +0000 Subject: [PATCH] Rename `FromZeroes` to `FromZeros` Although both spellings are acceptable, "zeros" is the somewhat more common [1] spelling of the plural noun "zero". We continue to use the spelling "zeroes" for the verb; i.e., to replace bytes with the value `0`. For user convenience, `FromZeroes` is retained as a deprecated, `doc(hidden)` re-export of `FromZeros`. Closes #431 [1] https://english.stackexchange.com/questions/3824/what-is-the-plural-form-of-zero/3825#3825 --- README.md | 6 +- src/byteorder.rs | 10 +- src/lib.rs | 522 +++++++++--------- src/macros.rs | 4 +- src/util.rs | 4 +- src/wrappers.rs | 6 +- .../invalid-impls/invalid-impls.stderr | 40 +- .../ui-nightly/invalid-impls/invalid-impls.rs | 4 +- .../invalid-impls/invalid-impls.stderr | 42 +- .../transmute-mut-dst-not-asbytes.rs | 4 +- .../transmute-mut-dst-not-frombytes.rs | 2 +- .../transmute-mut-src-not-asbytes.rs | 4 +- .../transmute-mut-src-not-frombytes.rs | 2 +- .../invalid-impls/invalid-impls.stderr | 42 +- zerocopy-derive/src/lib.rs | 48 +- zerocopy-derive/tests/enum_from_bytes.rs | 14 +- ...enum_from_zeroes.rs => enum_from_zeros.rs} | 14 +- zerocopy-derive/tests/hygiene.rs | 4 +- zerocopy-derive/tests/paths_and_modules.rs | 10 +- zerocopy-derive/tests/priv_in_pub.rs | 6 +- zerocopy-derive/tests/struct_from_bytes.rs | 14 +- ...ct_from_zeroes.rs => struct_from_zeros.rs} | 40 +- .../tests/ui-msrv/derive_transparent.stderr | 26 +- zerocopy-derive/tests/ui-msrv/enum.stderr | 18 +- .../tests/ui-msrv/late_compile_pass.stderr | 10 +- .../tests/ui-nightly/derive_transparent.rs | 6 +- .../ui-nightly/derive_transparent.stderr | 26 +- zerocopy-derive/tests/ui-nightly/enum.rs | 38 +- zerocopy-derive/tests/ui-nightly/enum.stderr | 18 +- .../tests/ui-nightly/late_compile_pass.rs | 6 +- .../tests/ui-nightly/late_compile_pass.stderr | 10 +- .../tests/ui-stable/derive_transparent.stderr | 26 +- zerocopy-derive/tests/ui-stable/enum.stderr | 18 +- .../tests/ui-stable/late_compile_pass.stderr | 10 +- zerocopy-derive/tests/union_from_bytes.rs | 12 +- ...ion_from_zeroes.rs => union_from_zeros.rs} | 32 +- zerocopy-derive/tests/util.rs | 4 +- 37 files changed, 557 insertions(+), 545 deletions(-) rename zerocopy-derive/tests/{enum_from_zeroes.rs => enum_from_zeros.rs} (67%) rename zerocopy-derive/tests/{struct_from_zeroes.rs => struct_from_zeros.rs} (65%) rename zerocopy-derive/tests/{union_from_zeroes.rs => union_from_zeros.rs} (64%) diff --git a/README.md b/README.md index 3d423bd2ae..fd35b2e1dc 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ so you don't have to. ## Overview Zerocopy provides four core marker traits, each of which can be derived -(e.g., `#[derive(FromZeroes)]`): -- `FromZeroes` indicates that a sequence of zero bytes represents a valid +(e.g., `#[derive(FromZeros)]`): +- `FromZeros` indicates that a sequence of zero bytes represents a valid instance of a type - `FromBytes` indicates that a type may safely be converted from an arbitrary byte sequence @@ -76,7 +76,7 @@ for network parsing. ``` - **`simd`** - When the `simd` feature is enabled, `FromZeroes`, `FromBytes`, and + When the `simd` feature is enabled, `FromZeros`, `FromBytes`, and `AsBytes` impls are emitted for all stable SIMD types which exist on the target platform. Note that the layout of SIMD types is not yet stabilized, so these impls may be removed in the future if layout changes make them diff --git a/src/byteorder.rs b/src/byteorder.rs index cb50f2f55e..d33d11c282 100644 --- a/src/byteorder.rs +++ b/src/byteorder.rs @@ -35,10 +35,10 @@ //! //! ```rust,edition2021 //! # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them -//! use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeroes, Ref, Unaligned}; +//! use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeros, Ref, Unaligned}; //! use zerocopy::byteorder::network_endian::U16; //! -//! #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] +//! #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] //! #[repr(C)] //! struct UdpHeader { //! src_port: U16, @@ -276,7 +276,7 @@ example of how it can be used for parsing UDP packets. [`AsBytes`]: crate::AsBytes [`Unaligned`]: crate::Unaligned"), #[derive(Copy, Clone, Eq, PartialEq, Hash)] - #[cfg_attr(any(feature = "derive", test), derive(KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned))] + #[cfg_attr(any(feature = "derive", test), derive(KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned))] #[repr(transparent)] pub struct $name([u8; $bytes], PhantomData); } @@ -288,10 +288,10 @@ example of how it can be used for parsing UDP packets. /// SAFETY: /// `$name` is `repr(transparent)`, and so it has the same layout /// as its only non-zero field, which is a `u8` array. `u8` arrays - /// are `NoCell`, `FromZeroes`, `FromBytes`, `AsBytes`, and + /// are `NoCell`, `FromZeros`, `FromBytes`, `AsBytes`, and /// `Unaligned`. impl_or_verify!(O => NoCell for $name); - impl_or_verify!(O => FromZeroes for $name); + impl_or_verify!(O => FromZeros for $name); impl_or_verify!(O => FromBytes for $name); impl_or_verify!(O => AsBytes for $name); impl_or_verify!(O => Unaligned for $name); diff --git a/src/lib.rs b/src/lib.rs index 705e9d28ff..a2f6ed1beb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,8 +24,8 @@ //! # Overview //! //! Zerocopy provides four core marker traits, each of which can be derived -//! (e.g., `#[derive(FromZeroes)]`): -//! - [`FromZeroes`] indicates that a sequence of zero bytes represents a valid +//! (e.g., `#[derive(FromZeros)]`): +//! - [`FromZeros`] indicates that a sequence of zero bytes represents a valid //! instance of a type //! - [`FromBytes`] indicates that a type may safely be converted from an //! arbitrary byte sequence @@ -76,7 +76,7 @@ //! ``` //! //! - **`simd`** -//! When the `simd` feature is enabled, `FromZeroes`, `FromBytes`, and +//! When the `simd` feature is enabled, `FromZeros`, `FromBytes`, and //! `AsBytes` impls are emitted for all stable SIMD types which exist on the //! target platform. Note that the layout of SIMD types is not yet stabilized, //! so these impls may be removed in the future if layout changes make them @@ -1000,23 +1000,23 @@ safety_comment! { unsafe_impl_known_layout!(T: ?Sized + KnownLayout => #[repr(T)] ManuallyDrop); } -/// Analyzes whether a type is [`FromZeroes`]. +/// Analyzes whether a type is [`FromZeros`]. /// /// This derive analyzes, at compile time, whether the annotated type satisfies -/// the [safety conditions] of `FromZeroes` and implements `FromZeroes` if it is +/// the [safety conditions] of `FromZeros` and implements `FromZeros` if it is /// sound to do so. This derive can be applied to structs, enums, and unions; /// e.g.: /// /// ``` -/// # use zerocopy_derive::FromZeroes; -/// #[derive(FromZeroes)] +/// # use zerocopy_derive::FromZeros; +/// #[derive(FromZeros)] /// struct MyStruct { /// # /* /// ... /// # */ /// } /// -/// #[derive(FromZeroes)] +/// #[derive(FromZeros)] /// #[repr(u8)] /// enum MyEnum { /// # Variant0, @@ -1025,7 +1025,7 @@ safety_comment! { /// # */ /// } /// -/// #[derive(FromZeroes)] +/// #[derive(FromZeros)] /// union MyUnion { /// # variant: u8, /// # /* @@ -1034,32 +1034,32 @@ safety_comment! { /// } /// ``` /// -/// [safety conditions]: trait@FromZeroes#safety +/// [safety conditions]: trait@FromZeros#safety /// /// # Analysis /// /// *This section describes, roughly, the analysis performed by this derive to -/// determine whether it is sound to implement `FromZeroes` for a given type. +/// determine whether it is sound to implement `FromZeros` for a given type. /// Unless you are modifying the implementation of this derive, or attempting to -/// manually implement `FromZeroes` for a type yourself, you don't need to read +/// manually implement `FromZeros` for a type yourself, you don't need to read /// this section.* /// /// If a type has the following properties, then this derive can implement -/// `FromZeroes` for that type: +/// `FromZeros` for that type: /// -/// - If the type is a struct, all of its fields must be `FromZeroes`. +/// - If the type is a struct, all of its fields must be `FromZeros`. /// - If the type is an enum, it must be C-like (meaning that all variants have /// no fields) and it must have a variant with a discriminant of `0`. See [the /// reference] for a description of how discriminant values are chosen. /// - The type must not contain any [`UnsafeCell`]s (this is required in order /// for it to be sound to construct a `&[u8]` and a `&T` to the same region of /// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeroes -/// (`FromZeroes` is not currently implemented for, e.g., -/// `Option<&UnsafeCell<_>>`, but it could be one day). +/// long as those values can themselves be initialized from zeros (`FromZeros` +/// is not currently implemented for, e.g., `Option<&UnsafeCell<_>>`, but it +/// could be one day). /// /// This analysis is subject to change. Unsafe code may *only* rely on the -/// documented [safety conditions] of `FromZeroes`, and must *not* rely on the +/// documented [safety conditions] of `FromZeros`, and must *not* rely on the /// implementation details of this derive. /// /// [the reference]: https://doc.rust-lang.org/reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations @@ -1067,7 +1067,7 @@ safety_comment! { /// /// ## Why isn't an explicit representation required for structs? /// -/// Neither this derive, nor the [safety conditions] of `FromZeroes`, requires +/// Neither this derive, nor the [safety conditions] of `FromZeros`, requires /// that structs are marked with `#[repr(C)]`. /// /// Per the [Rust reference](reference), @@ -1078,9 +1078,9 @@ safety_comment! { /// [reference]: https://doc.rust-lang.org/reference/type-layout.html#representations /// /// Since the layout of structs only consists of padding bytes and field bytes, -/// a struct is soundly `FromZeroes` if: -/// 1. its padding is soundly `FromZeroes`, and -/// 2. its fields are soundly `FromZeroes`. +/// a struct is soundly `FromZeros` if: +/// 1. its padding is soundly `FromZeros`, and +/// 2. its fields are soundly `FromZeros`. /// /// The answer to the first question is always yes: padding bytes do not have /// any validity constraints. A [discussion] of this question in the Unsafe Code @@ -1089,13 +1089,13 @@ safety_comment! { /// /// [discussion]: https://github.com/rust-lang/unsafe-code-guidelines/issues/174 /// -/// Whether a struct is soundly `FromZeroes` therefore solely depends on whether -/// its fields are `FromZeroes`. +/// Whether a struct is soundly `FromZeros` therefore solely depends on whether +/// its fields are `FromZeros`. // TODO(#146): Document why we don't require an enum to have an explicit `repr` // attribute. #[cfg(any(feature = "derive", test))] #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] -pub use zerocopy_derive::FromZeroes; +pub use zerocopy_derive::FromZeros; /// Types which do not contain any [`UnsafeCell`]s. /// @@ -1309,26 +1309,26 @@ pub unsafe trait TryFromBytes { /// instance of the type. /// /// Any memory region of the appropriate length which is guaranteed to contain -/// only zero bytes can be viewed as any `FromZeroes` type with no runtime +/// only zero bytes can be viewed as any `FromZeros` type with no runtime /// overhead. This is useful whenever memory is known to be in a zeroed state, /// such memory returned from some allocation routines. /// /// # Implementation /// /// **Do not implement this trait yourself!** Instead, use -/// [`#[derive(FromZeroes)]`][derive] (requires the `derive` Cargo feature); +/// [`#[derive(FromZeros)]`][derive] (requires the `derive` Cargo feature); /// e.g.: /// /// ``` -/// # use zerocopy_derive::FromZeroes; -/// #[derive(FromZeroes)] +/// # use zerocopy_derive::FromZeros; +/// #[derive(FromZeros)] /// struct MyStruct { /// # /* /// ... /// # */ /// } /// -/// #[derive(FromZeroes)] +/// #[derive(FromZeros)] /// #[repr(u8)] /// enum MyEnum { /// # Variant0, @@ -1337,7 +1337,7 @@ pub unsafe trait TryFromBytes { /// # */ /// } /// -/// #[derive(FromZeroes)] +/// #[derive(FromZeros)] /// union MyUnion { /// # variant: u8, /// # /* @@ -1347,16 +1347,16 @@ pub unsafe trait TryFromBytes { /// ``` /// /// This derive performs a sophisticated, compile-time safety analysis to -/// determine whether a type is `FromZeroes`. +/// determine whether a type is `FromZeros`. /// /// # Safety /// -/// *This section describes what is required in order for `T: FromZeroes`, and +/// *This section describes what is required in order for `T: FromZeros`, and /// what unsafe code may assume of such types. If you don't plan on implementing -/// `FromZeroes` manually, and you don't plan on writing unsafe code that -/// operates on `FromZeroes` types, then you don't need to read this section.* +/// `FromZeros` manually, and you don't plan on writing unsafe code that +/// operates on `FromZeros` types, then you don't need to read this section.* /// -/// If `T: FromZeroes`, then unsafe code may assume that: +/// If `T: FromZeros`, then unsafe code may assume that: /// - It is sound to treat any initialized sequence of zero bytes of length /// `size_of::()` as a `T`. /// - Given `b: &[u8]` where `b.len() == size_of::()`, `b` is aligned to @@ -1364,31 +1364,31 @@ pub unsafe trait TryFromBytes { /// construct a `t: &T` at the same address as `b`, and it is sound for both /// `b` and `t` to be live at the same time. /// -/// If a type is marked as `FromZeroes` which violates this contract, it may +/// If a type is marked as `FromZeros` which violates this contract, it may /// cause undefined behavior. /// -/// `#[derive(FromZeroes)]` only permits [types which satisfy these +/// `#[derive(FromZeros)]` only permits [types which satisfy these /// requirements][derive-analysis]. /// #[cfg_attr( feature = "derive", - doc = "[derive]: zerocopy_derive::FromZeroes", - doc = "[derive-analysis]: zerocopy_derive::FromZeroes#analysis" + doc = "[derive]: zerocopy_derive::FromZeros", + doc = "[derive-analysis]: zerocopy_derive::FromZeros#analysis" )] #[cfg_attr( not(feature = "derive"), - doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeroes.html"), - doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeroes.html#analysis"), + doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html"), + doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html#analysis"), )] -pub unsafe trait FromZeroes { - // The `Self: Sized` bound makes it so that `FromZeroes` is still object +pub unsafe trait FromZeros { + // The `Self: Sized` bound makes it so that `FromZeros` is still object // safe. #[doc(hidden)] fn only_derive_is_allowed_to_implement_this_trait() where Self: Sized; - /// Overwrites `self` with zeroes. + /// Overwrites `self` with zeros. /// /// Sets every byte in `self` to 0. While this is similar to doing `*self = /// Self::new_zeroed()`, it differs in that `zero` does not semantically @@ -1398,10 +1398,10 @@ pub unsafe trait FromZeroes { /// # Examples /// /// ``` - /// # use zerocopy::FromZeroes; + /// # use zerocopy::FromZeros; /// # use zerocopy_derive::*; /// # - /// #[derive(FromZeroes)] + /// #[derive(FromZeros)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1433,8 +1433,8 @@ pub unsafe trait FromZeroes { // size `size_of_val(self)`. // - `u8`'s alignment is 1, and thus `self` is guaranteed to be aligned // as required by `u8`. - // - Since `Self: FromZeroes`, the all-zeroes instance is a valid - // instance of `Self.` + // - Since `Self: FromZeros`, the all-zeros instance is a valid instance + // of `Self.` // // TODO(#429): Add references to docs and quotes. unsafe { ptr::write_bytes(slf.cast::(), 0, len) }; @@ -1445,10 +1445,10 @@ pub unsafe trait FromZeroes { /// # Examples /// /// ``` - /// # use zerocopy::FromZeroes; + /// # use zerocopy::FromZeros; /// # use zerocopy_derive::*; /// # - /// #[derive(FromZeroes)] + /// #[derive(FromZeros)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1457,7 +1457,7 @@ pub unsafe trait FromZeroes { /// checksum: [u8; 2], /// } /// - /// let header: PacketHeader = FromZeroes::new_zeroed(); + /// let header: PacketHeader = FromZeros::new_zeroed(); /// /// assert_eq!(header.src_port, [0, 0]); /// assert_eq!(header.dst_port, [0, 0]); @@ -1469,7 +1469,7 @@ pub unsafe trait FromZeroes { where Self: Sized, { - // SAFETY: `FromZeroes` says that the all-zeroes bit pattern is legal. + // SAFETY: `FromZeros` says that the all-zeros bit pattern is legal. unsafe { mem::zeroed() } } @@ -1617,6 +1617,11 @@ pub unsafe trait FromZeroes { } } +/// Deprecated: prefer [`FromZeros`] instead. +#[deprecated(since = "0.8.0", note = "`FromZeroes` was renamed to `FromZeros`")] +#[doc(hidden)] +pub use FromZeros as FromZeroes; + /// Analyzes whether a type is [`FromBytes`]. /// /// This derive analyzes, at compile time, whether the annotated type satisfies @@ -1625,15 +1630,15 @@ pub unsafe trait FromZeroes { /// e.g.: /// /// ``` -/// # use zerocopy_derive::{FromBytes, FromZeroes}; -/// #[derive(FromZeroes, FromBytes)] +/// # use zerocopy_derive::{FromBytes, FromZeros}; +/// #[derive(FromZeros, FromBytes)] /// struct MyStruct { /// # /* /// ... /// # */ /// } /// -/// #[derive(FromZeroes, FromBytes)] +/// #[derive(FromZeros, FromBytes)] /// #[repr(u8)] /// enum MyEnum { /// # V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V0A, V0B, V0C, V0D, V0E, @@ -1659,7 +1664,7 @@ pub unsafe trait FromZeroes { /// # */ /// } /// -/// #[derive(FromZeroes, FromBytes)] +/// #[derive(FromZeros, FromBytes)] /// union MyUnion { /// # variant: u8, /// # /* @@ -1693,9 +1698,9 @@ pub unsafe trait FromZeroes { /// - The type must not contain any [`UnsafeCell`]s (this is required in order /// for it to be sound to construct a `&[u8]` and a `&T` to the same region of /// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeroes -/// (`FromBytes` is not currently implemented for, e.g., `Option<*const -/// UnsafeCell<_>>`, but it could be one day). +/// long as those values can themselves be initialized from zeros (`FromBytes` +/// is not currently implemented for, e.g., `Option<*const UnsafeCell<_>>`, +/// but it could be one day). /// /// [`UnsafeCell`]: core::cell::UnsafeCell /// @@ -1748,15 +1753,15 @@ pub use zerocopy_derive::FromBytes; /// e.g.: /// /// ``` -/// # use zerocopy_derive::{FromBytes, FromZeroes}; -/// #[derive(FromZeroes, FromBytes)] +/// # use zerocopy_derive::{FromBytes, FromZeros}; +/// #[derive(FromZeros, FromBytes)] /// struct MyStruct { /// # /* /// ... /// # */ /// } /// -/// #[derive(FromZeroes, FromBytes)] +/// #[derive(FromZeros, FromBytes)] /// #[repr(u8)] /// enum MyEnum { /// # V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V0A, V0B, V0C, V0D, V0E, @@ -1782,7 +1787,7 @@ pub use zerocopy_derive::FromBytes; /// # */ /// } /// -/// #[derive(FromZeroes, FromBytes)] +/// #[derive(FromZeros, FromBytes)] /// union MyUnion { /// # variant: u8, /// # /* @@ -1824,7 +1829,7 @@ pub use zerocopy_derive::FromBytes; doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromBytes.html"), doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromBytes.html#analysis"), )] -pub unsafe trait FromBytes: FromZeroes { +pub unsafe trait FromBytes: FromZeros { // The `Self: Sized` bound makes it so that `FromBytes` is still object // safe. #[doc(hidden)] @@ -1843,7 +1848,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1885,7 +1890,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1927,7 +1932,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -1959,7 +1964,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2006,7 +2011,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2052,7 +2057,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -2097,7 +2102,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2146,7 +2151,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2197,7 +2202,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2246,7 +2251,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2299,7 +2304,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2354,7 +2359,7 @@ pub unsafe trait FromBytes: FromZeroes { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2397,7 +2402,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2436,7 +2441,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2476,7 +2481,7 @@ pub unsafe trait FromBytes: FromZeroes { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeroes, FromBytes)] + /// #[derive(FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -2586,7 +2591,7 @@ pub unsafe trait FromBytes: FromZeroes { /// - The type must not contain any [`UnsafeCell`]s (this is required in order /// for it to be sound to construct a `&[u8]` and a `&T` to the same region of /// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeroes (`AsBytes` +/// long as those values can themselves be initialized from zeros (`AsBytes` /// is not currently implemented for, e.g., `Option<&UnsafeCell<_>>`, but it /// could be one day). /// @@ -2762,7 +2767,7 @@ pub unsafe trait AsBytes { /// # use zerocopy_derive::*; /// /// # #[derive(Eq, PartialEq, Debug)] - /// #[derive(AsBytes, FromZeroes, FromBytes)] + /// #[derive(AsBytes, FromZeros, FromBytes)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -3033,20 +3038,20 @@ safety_comment! { /// Per the reference [1], "the unit tuple (`()`) ... is guaranteed as a /// zero-sized type to have a size of 0 and an alignment of 1." /// - `NoCell`: `()` self-evidently does not contain any `UnsafeCell`s. - /// - `TryFromBytes` (with no validator), `FromZeroes`, `FromBytes`: There - /// is only one possible sequence of 0 bytes, and `()` is inhabited. + /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: There is + /// only one possible sequence of 0 bytes, and `()` is inhabited. /// - `AsBytes`: Since `()` has size 0, it contains no padding bytes. /// - `Unaligned`: `()` has alignment 1. /// /// [1] https://doc.rust-lang.org/reference/type-layout.html#tuple-layout - unsafe_impl!((): NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); + unsafe_impl!((): NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); assert_unaligned!(()); } safety_comment! { /// SAFETY: /// - `NoCell`: These types self-evidently do not contain any `UnsafeCell`s. - /// - `TryFromBytes` (with no validator), `FromZeroes`, `FromBytes`: all bit + /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: all bit /// patterns are valid for numeric types [1] /// - `AsBytes`: numeric types have no padding bytes [1] /// - `Unaligned` (`u8` and `i8` only): The reference [2] specifies the size @@ -3078,28 +3083,28 @@ safety_comment! { /// TODO(#278): Once we've updated the trait docs to refer to `u8`s rather /// than bits or bytes, update this comment, especially the reference to /// [1]. - unsafe_impl!(u8: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - unsafe_impl!(i8: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); + unsafe_impl!(u8: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + unsafe_impl!(i8: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); assert_unaligned!(u8, i8); - unsafe_impl!(u16: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(i16: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(u32: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(i32: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(u64: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(i64: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(u128: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(i128: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(usize: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(isize: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(f32: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(f64: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); + unsafe_impl!(u16: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(i16: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(u32: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(i32: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(u64: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(i64: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(u128: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(i128: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(usize: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(isize: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(f32: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(f64: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); } safety_comment! { /// SAFETY: /// - `NoCell`: `bool` self-evidently does not contain any `UnsafeCell`s. - /// - `FromZeroes`: Valid since "[t]he value false has the bit pattern - /// 0x00" [1]. + /// - `FromZeros`: Valid since "[t]he value false has the bit pattern 0x00" + /// [1]. /// - `AsBytes`: Since "the boolean type has a size and alignment of 1 each" /// and "The value false has the bit pattern 0x00 and the value true has /// the bit pattern 0x01" [1]. Thus, the only byte of the bool is always @@ -3108,7 +3113,7 @@ safety_comment! { /// has a size and alignment of 1 each." /// /// [1] https://doc.rust-lang.org/reference/types/boolean.html - unsafe_impl!(bool: NoCell, FromZeroes, AsBytes, Unaligned); + unsafe_impl!(bool: NoCell, FromZeros, AsBytes, Unaligned); assert_unaligned!(bool); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` @@ -3152,7 +3157,7 @@ safety_comment! { safety_comment! { /// SAFETY: /// - `NoCell`: `char` self-evidently does not contain any `UnsafeCell`s. - /// - `FromZeroes`: Per reference [1], "[a] value of type char is a Unicode + /// - `FromZeros`: Per reference [1], "[a] value of type char is a Unicode /// scalar value (i.e. a code point that is not a surrogate), represented /// as a 32-bit unsigned word in the 0x0000 to 0xD7FF or 0xE000 to /// 0x10FFFF range" which contains 0x0000. @@ -3161,7 +3166,7 @@ safety_comment! { /// all bit patterns are valid for `char`. /// /// [1] https://doc.rust-lang.org/reference/types/textual.html - unsafe_impl!(char: NoCell, FromZeroes, AsBytes); + unsafe_impl!(char: NoCell, FromZeros, AsBytes); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` /// closure: @@ -3200,19 +3205,19 @@ safety_comment! { /// SAFETY: /// Per the Reference [1], `str` has the same layout as `[u8]`. /// - `NoCell`: `[u8]` does not contain any `UnsafeCell`s. - /// - `FromZeroes`, `AsBytes`, `Unaligned`: `[u8]` is `FromZeroes`, - /// `AsBytes`, and `Unaligned`. + /// - `FromZeros`, `AsBytes`, `Unaligned`: `[u8]` is `FromZeros`, `AsBytes`, + /// and `Unaligned`. /// /// Note that we don't `assert_unaligned!(str)` because `assert_unaligned!` /// uses `align_of`, which only works for `Sized` types. /// /// TODO(#429): /// - Add quotes from documentation. - /// - Improve safety proof for `FromZeroes` and `AsBytes`; having the same + /// - Improve safety proof for `FromZeros` and `AsBytes`; having the same /// layout as `[u8]` isn't sufficient. /// /// [1] https://doc.rust-lang.org/reference/type-layout.html#str-layout - unsafe_impl!(str: NoCell, FromZeroes, AsBytes, Unaligned); + unsafe_impl!(str: NoCell, FromZeros, AsBytes, Unaligned); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` /// closure: @@ -3243,7 +3248,7 @@ safety_comment! { } safety_comment! { - // `NonZeroXxx` is `AsBytes`, but not `FromZeroes` or `FromBytes`. + // `NonZeroXxx` is `AsBytes`, but not `FromZeros` or `FromBytes`. // /// SAFETY: /// - `AsBytes`: `NonZeroXxx` has the same layout as its associated @@ -3324,7 +3329,7 @@ safety_comment! { } safety_comment! { /// SAFETY: - /// - `TryFromBytes` (with no validator), `FromZeroes`, `FromBytes`, + /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`, /// `AsBytes`: The Rust compiler reuses `0` value to represent `None`, so /// `size_of::>() == size_of::()`; see /// `NonZeroXxx` documentation. @@ -3342,26 +3347,26 @@ safety_comment! { /// /// TODO(https://github.com/rust-lang/rust/pull/104082): Cite documentation /// for layout guarantees. - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); assert_unaligned!(Option, Option); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); - unsafe_impl!(Option: TryFromBytes, FromZeroes, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes); } safety_comment! { /// SAFETY: /// The following types can be transmuted from `[0u8; size_of::()]`. [1] /// None of them contain `UnsafeCell`s, and so they all soundly implement - /// `FromZeroes`. + /// `FromZeros`. /// /// [1] Per /// https://doc.rust-lang.org/nightly/core/option/index.html#representation: @@ -3385,13 +3390,13 @@ safety_comment! { #[cfg(feature = "alloc")] unsafe_impl!( #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] - T => FromZeroes for Option> + T => FromZeros for Option> ); - unsafe_impl!(T => FromZeroes for Option<&'_ T>); - unsafe_impl!(T => FromZeroes for Option<&'_ mut T>); - unsafe_impl!(T => FromZeroes for Option>); - unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => FromZeroes for opt_fn!(...)); - unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => FromZeroes for opt_extern_c_fn!(...)); + unsafe_impl!(T => FromZeros for Option<&'_ T>); + unsafe_impl!(T => FromZeros for Option<&'_ mut T>); + unsafe_impl!(T => FromZeros for Option>); + unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => FromZeros for opt_fn!(...)); + unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => FromZeros for opt_extern_c_fn!(...)); } safety_comment! { @@ -3402,9 +3407,8 @@ safety_comment! { /// align_of::>() == 1". /// This gives: /// - `NoCell`: `PhantomData` has no fields. - /// - `TryFromBytes` (with no validator), `FromZeroes`, `FromBytes`: There - /// is only one possible sequence of 0 bytes, and `PhantomData` is - /// inhabited. + /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: There is + /// only one possible sequence of 0 bytes, and `PhantomData` is inhabited. /// - `AsBytes`: Since `PhantomData` has size 0, it contains no padding /// bytes. /// - `Unaligned`: Per the preceding reference, `PhantomData` has alignment @@ -3413,7 +3417,7 @@ safety_comment! { /// [1] https://doc.rust-lang.org/std/marker/struct.PhantomData.html#layout-1 unsafe_impl!(T: ?Sized => NoCell for PhantomData); unsafe_impl!(T: ?Sized => TryFromBytes for PhantomData); - unsafe_impl!(T: ?Sized => FromZeroes for PhantomData); + unsafe_impl!(T: ?Sized => FromZeros for PhantomData); unsafe_impl!(T: ?Sized => FromBytes for PhantomData); unsafe_impl!(T: ?Sized => AsBytes for PhantomData); unsafe_impl!(T: ?Sized => Unaligned for PhantomData); @@ -3477,22 +3481,22 @@ safety_comment! { // `Wrapping`, the same is true for `T`. unsafe { T::is_bit_valid(candidate) } }); - unsafe_impl!(T: FromZeroes => FromZeroes for Wrapping); + unsafe_impl!(T: FromZeros => FromZeros for Wrapping); unsafe_impl!(T: FromBytes => FromBytes for Wrapping); unsafe_impl!(T: AsBytes => AsBytes for Wrapping); unsafe_impl!(T: Unaligned => Unaligned for Wrapping); assert_unaligned!(Wrapping<()>, Wrapping); } safety_comment! { - // `MaybeUninit` is `FromZeroes` and `FromBytes`, but never `AsBytes` + // `MaybeUninit` is `FromZeros` and `FromBytes`, but never `AsBytes` // since it may contain uninitialized bytes. // /// SAFETY: /// - `NoCell`: `MaybeUninit` has `UnsafeCell`s exactly when `T` does, so /// `T: NoCell` guarantees that `MaybeUninit` has no `UnsafeCell`s. - /// - `TryFromBytes` (with no validator), `FromZeroes`, `FromBytes`: + /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: /// `MaybeUninit` has no restrictions on its contents. Unfortunately, - /// in addition to bit validity, `TryFromBytes`, `FromZeroes` and + /// in addition to bit validity, `TryFromBytes`, `FromZeros` and /// `FromBytes` also require that implementers contain no `UnsafeCell`s. /// Thus, we require `T: Trait` in order to ensure that `T` - and thus /// `MaybeUninit` - contains to `UnsafeCell`s. Thus, requiring that `T` @@ -3504,11 +3508,11 @@ safety_comment! { /// /// TODO(https://github.com/google/zerocopy/issues/251): If we split /// `FromBytes` and `RefFromBytes`, or if we introduce a separate - /// `NoCell`/`Freeze` trait, we can relax the trait bounds for `FromZeroes` + /// `NoCell`/`Freeze` trait, we can relax the trait bounds for `FromZeros` /// and `FromBytes`. unsafe_impl!(T: NoCell => NoCell for MaybeUninit); unsafe_impl!(T: TryFromBytes => TryFromBytes for MaybeUninit); - unsafe_impl!(T: FromZeroes => FromZeroes for MaybeUninit); + unsafe_impl!(T: FromZeros => FromZeros for MaybeUninit); unsafe_impl!(T: FromBytes => FromBytes for MaybeUninit); unsafe_impl!(T: Unaligned => Unaligned for MaybeUninit); assert_unaligned!(MaybeUninit<()>, MaybeUninit); @@ -3521,8 +3525,8 @@ safety_comment! { /// code). /// - `NoCell`: `ManuallyDrop` has `UnsafeCell`s exactly when `T` does, /// so `T: NoCell` guarantees that `ManuallyDrop` has no `UnsafeCell`s. - /// - `FromZeroes`, `FromBytes`: Since it has the same layout as `T`, any - /// valid `T` is a valid `ManuallyDrop`. If `T: FromZeroes`, a sequence + /// - `FromZeros`, `FromBytes`: Since it has the same layout as `T`, any + /// valid `T` is a valid `ManuallyDrop`. If `T: FromZeros`, a sequence /// of zero bytes is a valid `T`, and thus a valid `ManuallyDrop`. If /// `T: FromBytes`, any sequence of bytes is a valid `T`, and thus a valid /// `ManuallyDrop`. @@ -3545,7 +3549,7 @@ safety_comment! { /// https://github.com/rust-lang/rust/pull/115522) is available on stable, /// quote the stable docs instead of the nightly docs. unsafe_impl!(T: ?Sized + NoCell => NoCell for ManuallyDrop); - unsafe_impl!(T: ?Sized + FromZeroes => FromZeroes for ManuallyDrop); + unsafe_impl!(T: ?Sized + FromZeros => FromZeros for ManuallyDrop); unsafe_impl!(T: ?Sized + FromBytes => FromBytes for ManuallyDrop); unsafe_impl!(T: ?Sized + AsBytes => AsBytes for ManuallyDrop); unsafe_impl!(T: ?Sized + Unaligned => Unaligned for ManuallyDrop); @@ -3566,7 +3570,7 @@ safety_comment! { /// /// In other words, the layout of a `[T]` or `[T; N]` is a sequence of `T`s /// laid out back-to-back with no bytes in between. Therefore, `[T]` or `[T; - /// N]` are `NoCell`, `TryFromBytes`, `FromZeroes`, `FromBytes`, and + /// N]` are `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, and /// `AsBytes` if `T` is (respectively). Furthermore, since an array/slice /// has "the same alignment of `T`", `[T]` and `[T; N]` are `Unaligned` if /// `T` is. @@ -3576,7 +3580,7 @@ safety_comment! { /// /// [1] https://doc.rust-lang.org/reference/type-layout.html#array-layout unsafe_impl!(const N: usize, T: NoCell => NoCell for [T; N]); - unsafe_impl!(const N: usize, T: FromZeroes => FromZeroes for [T; N]); + unsafe_impl!(const N: usize, T: FromZeros => FromZeros for [T; N]); unsafe_impl!(const N: usize, T: FromBytes => FromBytes for [T; N]); unsafe_impl!(const N: usize, T: AsBytes => AsBytes for [T; N]); unsafe_impl!(const N: usize, T: Unaligned => Unaligned for [T; N]); @@ -3618,7 +3622,7 @@ safety_comment! { unsafe { ::is_bit_valid(elem) } ) }); - unsafe_impl!(T: FromZeroes => FromZeroes for [T]); + unsafe_impl!(T: FromZeros => FromZeros for [T]); unsafe_impl!(T: FromBytes => FromBytes for [T]); unsafe_impl!(T: AsBytes => AsBytes for [T]); unsafe_impl!(T: Unaligned => Unaligned for [T]); @@ -3626,7 +3630,7 @@ safety_comment! { safety_comment! { /// SAFETY: /// - `NoCell`: Raw pointers do not contain any `UnsafeCell`s. - /// - `FromZeroes`: For thin pointers (note that `T: Sized`), the zero + /// - `FromZeros`: For thin pointers (note that `T: Sized`), the zero /// pointer is considered "null". [1] No operations which require /// provenance are legal on null pointers, so this is not a footgun. /// @@ -3639,8 +3643,8 @@ safety_comment! { /// documentation once this PR lands. unsafe_impl!(T: ?Sized => NoCell for *const T); unsafe_impl!(T: ?Sized => NoCell for *mut T); - unsafe_impl!(T => FromZeroes for *const T); - unsafe_impl!(T => FromZeroes for *mut T); + unsafe_impl!(T => FromZeros for *const T); + unsafe_impl!(T => FromZeros for *mut T); } safety_comment! { /// SAFETY: @@ -3704,8 +3708,8 @@ safety_comment! { // Given this background, we can observe that: // - The size and bit pattern requirements of a SIMD type are equivalent to the // equivalent array type. Thus, for any SIMD type whose primitive `T` is -// `NoCell`, `TryFromBytes`, `FromZeroes`, `FromBytes`, or `AsBytes`, that -// SIMD type is also `NoCell`, `TryFromBytes`, `FromZeroes`, `FromBytes`, or +// `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, or `AsBytes`, that SIMD +// type is also `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, or // `AsBytes` respectively. // - Since no upper bound is placed on the alignment, no SIMD type can be // guaranteed to be `Unaligned`. @@ -3717,7 +3721,7 @@ safety_comment! { // // See issue #38 [2]. While this behavior is not technically guaranteed, the // likelihood that the behavior will change such that SIMD types are no longer -// `TryFromBytes`, `FromZeroes`, `FromBytes`, or `AsBytes` is next to zero, as +// `TryFromBytes`, `FromZeros`, `FromBytes`, or `AsBytes` is next to zero, as // that would defeat the entire purpose of SIMD types. Nonetheless, we put this // behavior behind the `simd` Cargo feature, which requires consumers to opt // into this stability hazard. @@ -3727,13 +3731,13 @@ safety_comment! { #[cfg(feature = "simd")] #[cfg_attr(doc_cfg, doc(cfg(feature = "simd")))] mod simd { - /// Defines a module which implements `TryFromBytes`, `FromZeroes`, + /// Defines a module which implements `TryFromBytes`, `FromZeros`, /// `FromBytes`, and `AsBytes` for a set of types from a module in /// `core::arch`. /// /// `$arch` is both the name of the defined module and the name of the /// module in `core::arch`, and `$typ` is the list of items from that module - /// to implement `FromZeroes`, `FromBytes`, and `AsBytes` for. + /// to implement `FromZeros`, `FromBytes`, and `AsBytes` for. #[allow(unused_macros)] // `allow(unused_macros)` is needed because some // target/feature combinations don't emit any impls // and thus don't use this macro. @@ -3749,7 +3753,7 @@ mod simd { safety_comment! { /// SAFETY: /// See comment on module definition for justification. - $( unsafe_impl!($typ: NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes); )* + $( unsafe_impl!($typ: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); )* } } }; @@ -4165,9 +4169,9 @@ macro_rules! include_value { /// /// ```rust /// # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them -/// use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned}; +/// use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeros, Ref, Unaligned}; /// -/// #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] +/// #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] /// #[repr(C)] /// struct UdpHeader { /// src_port: [u8; 2], @@ -4207,9 +4211,9 @@ pub struct Ref( ); /// Deprecated: prefer [`Ref`] instead. -#[deprecated(since = "0.7.0", note = "LayoutVerified has been renamed to Ref")] +#[deprecated(since = "0.7.0", note = "`LayoutVerified` was renamed to `Ref`")] #[doc(hidden)] -pub type LayoutVerified = Ref; +pub use Ref as LayoutVerified; impl Ref where @@ -5370,25 +5374,25 @@ mod alloc_support { use super::*; /// Extends a `Vec` by pushing `additional` new items onto the end of the - /// vector. The new items are initialized with zeroes. + /// vector. The new items are initialized with zeros. /// /// # Panics /// /// Panics if `Vec::reserve(additional)` fails to reserve enough memory. #[inline(always)] - pub fn extend_vec_zeroed(v: &mut Vec, additional: usize) { + pub fn extend_vec_zeroed(v: &mut Vec, additional: usize) { insert_vec_zeroed(v, v.len(), additional); } /// Inserts `additional` new items into `Vec` at `position`. - /// The new items are initialized with zeroes. + /// The new items are initialized with zeros. /// /// # Panics /// /// * Panics if `position > v.len()`. /// * Panics if `Vec::reserve(additional)` fails to reserve enough memory. #[inline] - pub fn insert_vec_zeroed(v: &mut Vec, position: usize, additional: usize) { + pub fn insert_vec_zeroed(v: &mut Vec, position: usize, additional: usize) { assert!(position <= v.len()); v.reserve(additional); // SAFETY: The `reserve` call guarantees that these cannot overflow: @@ -5599,7 +5603,7 @@ mod tests { // // This is used to test the custom derives of our traits. The `[u8]` type // gets a hand-rolled impl, so it doesn't exercise our custom derives. - #[derive(Debug, Eq, PartialEq, FromZeroes, FromBytes, AsBytes, Unaligned)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes, Unaligned)] #[repr(transparent)] struct Unsized([u8]); @@ -6839,14 +6843,14 @@ mod tests { #[test] fn test_object_safety() { fn _takes_no_cell(_: &dyn NoCell) {} - fn _takes_from_zeroes(_: &dyn FromZeroes) {} + fn _takes_from_zeros(_: &dyn FromZeros) {} fn _takes_from_bytes(_: &dyn FromBytes) {} fn _takes_unaligned(_: &dyn Unaligned) {} } #[test] - fn test_from_zeroes_only() { - // Test types that implement `FromZeroes` but not `FromBytes`. + fn test_from_zeros_only() { + // Test types that implement `FromZeros` but not `FromBytes`. assert!(!bool::new_zeroed()); assert_eq!(char::new_zeroed(), '\0'); @@ -6882,11 +6886,11 @@ mod tests { assert_eq!(u64::read_from(&VAL_BYTES[..]), Some(VAL)); // The first 8 bytes are from `VAL_BYTES` and the second 8 bytes are all - // zeroes. + // zeros. let bytes_with_prefix: [u8; 16] = transmute!([VAL_BYTES, [0; 8]]); assert_eq!(u64::read_from_prefix(&bytes_with_prefix[..]), Some(VAL)); assert_eq!(u64::read_from_suffix(&bytes_with_prefix[..]), Some(0)); - // The first 8 bytes are all zeroes and the second 8 bytes are from + // The first 8 bytes are all zeros and the second 8 bytes are from // `VAL_BYTES` let bytes_with_suffix: [u8; 16] = transmute!([[0; 8], VAL_BYTES]); assert_eq!(u64::read_from_prefix(&bytes_with_suffix[..]), Some(0)); @@ -7666,7 +7670,7 @@ mod tests { assert_eq!(too_many_bytes[0], 123); } - #[derive(Debug, Eq, PartialEq, FromZeroes, FromBytes, AsBytes)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes)] #[repr(C)] struct Foo { a: u32, @@ -7695,7 +7699,7 @@ mod tests { #[test] fn test_array() { - #[derive(FromZeroes, FromBytes, AsBytes)] + #[derive(FromZeros, FromBytes, AsBytes)] #[repr(C)] struct Foo { a: [u16; 33], @@ -7759,24 +7763,24 @@ mod tests { #[test] fn test_transparent_packed_generic_struct() { - #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] + #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] #[repr(transparent)] struct Foo { _t: T, _phantom: PhantomData<()>, } - assert_impl_all!(Foo: FromZeroes, FromBytes, AsBytes); + assert_impl_all!(Foo: FromZeros, FromBytes, AsBytes); assert_impl_all!(Foo: Unaligned); - #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] + #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] #[repr(packed)] struct Bar { _t: T, _u: U, } - assert_impl_all!(Bar: FromZeroes, FromBytes, AsBytes, Unaligned); + assert_impl_all!(Bar: FromZeros, FromBytes, AsBytes, Unaligned); } #[test] @@ -7952,28 +7956,28 @@ mod tests { // change. Of course, some impls would be invalid (e.g., `bool: // FromBytes`), and so this change detection is very important. - assert_impls!((): KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(u8: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(i8: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(u16: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(i16: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(u32: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(i32: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(u64: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(i64: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(u128: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(i128: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(usize: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(isize: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(f32: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(f64: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - - assert_impls!(bool: KnownLayout, NoCell, TryFromBytes, FromZeroes, AsBytes, Unaligned, !FromBytes); - assert_impls!(char: KnownLayout, NoCell, TryFromBytes, FromZeroes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(str: KnownLayout, NoCell, TryFromBytes, FromZeroes, AsBytes, Unaligned, !FromBytes); - - assert_impls!(NonZeroU8: KnownLayout, NoCell, TryFromBytes, AsBytes, Unaligned, !FromZeroes, !FromBytes); - assert_impls!(NonZeroI8: KnownLayout, NoCell, TryFromBytes, AsBytes, Unaligned, !FromZeroes, !FromBytes); + assert_impls!((): KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(u8: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(i8: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(u16: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(i16: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(u32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(i32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(u64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(i64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(u128: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(i128: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(usize: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(isize: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(f32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(f64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + + assert_impls!(bool: KnownLayout, NoCell, TryFromBytes, FromZeros, AsBytes, Unaligned, !FromBytes); + assert_impls!(char: KnownLayout, NoCell, TryFromBytes, FromZeros, AsBytes, !FromBytes, !Unaligned); + assert_impls!(str: KnownLayout, NoCell, TryFromBytes, FromZeros, AsBytes, Unaligned, !FromBytes); + + assert_impls!(NonZeroU8: KnownLayout, NoCell, TryFromBytes, AsBytes, Unaligned, !FromZeros, !FromBytes); + assert_impls!(NonZeroI8: KnownLayout, NoCell, TryFromBytes, AsBytes, Unaligned, !FromZeros, !FromBytes); assert_impls!(NonZeroU16: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); assert_impls!(NonZeroI16: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); assert_impls!(NonZeroU32: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); @@ -7985,18 +7989,18 @@ mod tests { assert_impls!(NonZeroUsize: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); assert_impls!(NonZeroIsize: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); // Implements none of the ZC traits. struct NotZerocopy; @@ -8014,55 +8018,55 @@ mod tests { ) -> (NotZerocopy, NotZerocopy); #[cfg(feature = "alloc")] - assert_impls!(Option>>: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option<&'static UnsafeCell>: KnownLayout, NoCell, FromZeroes, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option<&'static [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option<&'static mut UnsafeCell>: KnownLayout, NoCell, FromZeroes, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option<&'static mut [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option>>: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeroes, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - - assert_impls!(PhantomData: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(PhantomData>: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(PhantomData<[u8]>: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - - assert_impls!(ManuallyDrop: KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned, !TryFromBytes); - assert_impls!(ManuallyDrop<[u8]>: KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned, !TryFromBytes); - assert_impls!(ManuallyDrop: !NoCell, !TryFromBytes, !KnownLayout, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(ManuallyDrop<[NotZerocopy]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(ManuallyDrop>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - - assert_impls!(MaybeUninit: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, Unaligned, !AsBytes); - assert_impls!(MaybeUninit: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(MaybeUninit>: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - - assert_impls!(Wrapping: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!(Wrapping: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Wrapping>: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - - assert_impls!(Unalign: KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned, !TryFromBytes); - assert_impls!(Unalign: Unaligned, !NoCell, !KnownLayout, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes); - - assert_impls!([u8]: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, Unaligned); - assert_impls!([bool]: KnownLayout, NoCell, TryFromBytes, FromZeroes, AsBytes, Unaligned, !FromBytes); - assert_impls!([NotZerocopy]: !KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!([u8; 0]: KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned, !TryFromBytes); - assert_impls!([NotZerocopy; 0]: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!([u8; 1]: KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Unaligned, !TryFromBytes); - assert_impls!([NotZerocopy; 1]: KnownLayout, !NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - - assert_impls!(*const NotZerocopy: KnownLayout, NoCell, FromZeroes, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(*mut NotZerocopy: KnownLayout, NoCell, FromZeroes, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(*const [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(*mut [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(*const dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(*mut dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeroes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option>>: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option<&'static UnsafeCell>: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option<&'static [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option<&'static mut UnsafeCell>: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option<&'static mut [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option>>: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + + assert_impls!(PhantomData: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(PhantomData>: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(PhantomData<[u8]>: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + + assert_impls!(ManuallyDrop: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); + assert_impls!(ManuallyDrop<[u8]>: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); + assert_impls!(ManuallyDrop: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(ManuallyDrop<[NotZerocopy]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(ManuallyDrop>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + + assert_impls!(MaybeUninit: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, Unaligned, !AsBytes); + assert_impls!(MaybeUninit: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(MaybeUninit>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + + assert_impls!(Wrapping: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!(Wrapping: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Wrapping>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + + assert_impls!(Unalign: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); + assert_impls!(Unalign: Unaligned, !NoCell, !KnownLayout, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes); + + assert_impls!([u8]: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + assert_impls!([bool]: KnownLayout, NoCell, TryFromBytes, FromZeros, AsBytes, Unaligned, !FromBytes); + assert_impls!([NotZerocopy]: !KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!([u8; 0]: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); + assert_impls!([NotZerocopy; 0]: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!([u8; 1]: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); + assert_impls!([NotZerocopy; 1]: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + + assert_impls!(*const NotZerocopy: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(*mut NotZerocopy: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(*const [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(*mut [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(*const dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(*mut dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); #[cfg(feature = "simd")] { @@ -8072,7 +8076,7 @@ mod tests { { use core::arch::$arch::{$($typ),*}; use crate::*; - $( assert_impls!($typ: KnownLayout, NoCell, TryFromBytes, FromZeroes, FromBytes, AsBytes, !Unaligned); )* + $( assert_impls!($typ: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); )* } }; } diff --git a/src/macros.rs b/src/macros.rs index 2da78af7df..61e6cac108 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -262,7 +262,7 @@ macro_rules! opt_fn { /// /// ```rust,ignore /// // Note that these derives are gated by `feature = "derive"` -/// #[cfg_attr(any(feature = "derive", test), derive(FromZeroes, FromBytes, AsBytes, Unaligned))] +/// #[cfg_attr(any(feature = "derive", test), derive(FromZeros, FromBytes, AsBytes, Unaligned))] /// #[repr(transparent)] /// struct Wrapper(T); /// @@ -270,7 +270,7 @@ macro_rules! opt_fn { /// /// SAFETY: /// /// `Wrapper` is `repr(transparent)`, so it is sound to implement any /// /// zerocopy trait if `T` implements that trait. -/// impl_or_verify!(T: FromZeroes => FromZeroes for Wrapper); +/// impl_or_verify!(T: FromZeros => FromZeros for Wrapper); /// impl_or_verify!(T: FromBytes => FromBytes for Wrapper); /// impl_or_verify!(T: AsBytes => AsBytes for Wrapper); /// impl_or_verify!(T: Unaligned => Unaligned for Wrapper); diff --git a/src/util.rs b/src/util.rs index 23520f3e85..568a4f2162 100644 --- a/src/util.rs +++ b/src/util.rs @@ -698,7 +698,7 @@ pub(crate) mod testutil { #[derive( KnownLayout, NoCell, - FromZeroes, + FromZeros, FromBytes, AsBytes, Eq, @@ -727,7 +727,7 @@ pub(crate) mod testutil { } #[derive( - NoCell, FromZeroes, FromBytes, Eq, PartialEq, Ord, PartialOrd, Default, Debug, Copy, Clone, + NoCell, FromZeros, FromBytes, Eq, PartialEq, Ord, PartialOrd, Default, Debug, Copy, Clone, )] #[repr(C)] pub(crate) struct Nested { diff --git a/src/wrappers.rs b/src/wrappers.rs index ed00a98e96..b06e109bf8 100644 --- a/src/wrappers.rs +++ b/src/wrappers.rs @@ -60,7 +60,7 @@ use super::*; #[derive(Default, Copy)] #[cfg_attr( any(feature = "derive", test), - derive(NoCell, KnownLayout, FromZeroes, FromBytes, AsBytes, Unaligned) + derive(NoCell, KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned) )] #[repr(C, packed)] pub struct Unalign(T); @@ -73,12 +73,12 @@ safety_comment! { /// - `Unalign` is `repr(packed)`, so it is unaligned regardless of the /// alignment of `T`, and so we don't require that `T: Unaligned` /// - `Unalign` has the same bit validity as `T`, and so it is - /// `FromZeroes`, `FromBytes`, or `AsBytes` exactly when `T` is as well. + /// `FromZeros`, `FromBytes`, or `AsBytes` exactly when `T` is as well. /// - `NoCell`: `Unalign` has the same fields as `T`, so it contains /// `UnsafeCell`s exactly when `T` does. impl_or_verify!(T => Unaligned for Unalign); impl_or_verify!(T: NoCell => NoCell for Unalign); - impl_or_verify!(T: FromZeroes => FromZeroes for Unalign); + impl_or_verify!(T: FromZeros => FromZeros for Unalign); impl_or_verify!(T: FromBytes => FromBytes for Unalign); impl_or_verify!(T: AsBytes => AsBytes for Unalign); } diff --git a/tests/ui-msrv/invalid-impls/invalid-impls.stderr b/tests/ui-msrv/invalid-impls/invalid-impls.stderr index c1de466ece..2af2faf235 100644 --- a/tests/ui-msrv/invalid-impls/invalid-impls.stderr +++ b/tests/ui-msrv/invalid-impls/invalid-impls.stderr @@ -1,19 +1,19 @@ -error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied +error[E0277]: the trait bound `T: FromZeroes` is not satisfied --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | | impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {} - | ^^^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T` + | ^^^^^^^^ the trait `FromZeroes` is not implemented for `T` | ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:26:1 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ------------------------------------------- in this macro invocation +26 | impl_or_verify!(T => FromZeros for Foo); + | ------------------------------------------ in this macro invocation | -note: required because of the requirements on the impl of `zerocopy::FromZeroes` for `Foo` +note: required because of the requirements on the impl of `FromZeroes` for `Foo` --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^^ +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | @@ -22,13 +22,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:26:1 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ------------------------------------------- in this macro invocation +26 | impl_or_verify!(T => FromZeros for Foo); + | ------------------------------------------ in this macro invocation = note: this error originates in the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | -26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo); - | ++++++++++++++++++++++ +26 | impl_or_verify!(T: zerocopy::FromZeros => FromZeros for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied --> tests/ui-msrv/invalid-impls/../../../src/macros.rs @@ -42,10 +42,10 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied | ------------------------------------------ in this macro invocation | note: required because of the requirements on the impl of `zerocopy::FromBytes` for `Foo` - --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:22 + --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:21 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | @@ -74,10 +74,10 @@ error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied | ---------------------------------------- in this macro invocation | note: required because of the requirements on the impl of `zerocopy::AsBytes` for `Foo` - --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:33 + --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:32 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | @@ -106,10 +106,10 @@ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied | ------------------------------------------ in this macro invocation | note: required because of the requirements on the impl of `zerocopy::Unaligned` for `Foo` - --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:42 + --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:41 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | diff --git a/tests/ui-nightly/invalid-impls/invalid-impls.rs b/tests/ui-nightly/invalid-impls/invalid-impls.rs index ea963907df..d21fb68e40 100644 --- a/tests/ui-nightly/invalid-impls/invalid-impls.rs +++ b/tests/ui-nightly/invalid-impls/invalid-impls.rs @@ -19,11 +19,11 @@ use zerocopy_derive::*; fn main() {} -#[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] +#[derive(FromZeros, FromBytes, AsBytes, Unaligned)] #[repr(transparent)] struct Foo(T); -impl_or_verify!(T => FromZeroes for Foo); +impl_or_verify!(T => FromZeros for Foo); impl_or_verify!(T => FromBytes for Foo); impl_or_verify!(T => AsBytes for Foo); impl_or_verify!(T => Unaligned for Foo); diff --git a/tests/ui-nightly/invalid-impls/invalid-impls.stderr b/tests/ui-nightly/invalid-impls/invalid-impls.stderr index e5651d169e..102ace5e90 100644 --- a/tests/ui-nightly/invalid-impls/invalid-impls.stderr +++ b/tests/ui-nightly/invalid-impls/invalid-impls.stderr @@ -1,14 +1,14 @@ -error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied - --> tests/ui-nightly/invalid-impls/invalid-impls.rs:26:37 +error[E0277]: the trait bound `T: FromZeroes` is not satisfied + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:26:36 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T` +26 | impl_or_verify!(T => FromZeros for Foo); + | ^^^^^^ the trait `FromZeroes` is not implemented for `T` | -note: required for `Foo` to implement `zerocopy::FromZeroes` +note: required for `Foo` to implement `FromZeroes` --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs | @@ -17,13 +17,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:26:1 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ------------------------------------------- in this macro invocation - = note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) +26 | impl_or_verify!(T => FromZeros for Foo); + | ------------------------------------------ in this macro invocation + = note: this error originates in the derive macro `FromZeros` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | -26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo); - | ++++++++++++++++++++++ +26 | impl_or_verify!(T: zerocopy::FromZeros => FromZeros for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied --> tests/ui-nightly/invalid-impls/invalid-impls.rs:27:36 @@ -32,10 +32,10 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied | ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::FromBytes` - --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:22 + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:21 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs | @@ -59,10 +59,10 @@ error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied | ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::AsBytes` - --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:33 + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:32 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs | @@ -86,10 +86,10 @@ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied | ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::Unaligned` - --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:42 + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:41 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs | diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs index b72f12928c..3714db7c4f 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs index 102fcedc9a..1c0121fcac 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs @@ -12,7 +12,7 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] #[repr(C)] struct Src; diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs index 6a14f12fd0..4eaadece17 100644 --- a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs index 2ebe03601b..09baa1022b 100644 --- a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs @@ -16,7 +16,7 @@ fn main() {} #[repr(C)] struct Src; -#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] #[repr(C)] struct Dst; diff --git a/tests/ui-stable/invalid-impls/invalid-impls.stderr b/tests/ui-stable/invalid-impls/invalid-impls.stderr index 7737d67175..3bb4577868 100644 --- a/tests/ui-stable/invalid-impls/invalid-impls.stderr +++ b/tests/ui-stable/invalid-impls/invalid-impls.stderr @@ -1,14 +1,14 @@ -error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied - --> tests/ui-stable/invalid-impls/invalid-impls.rs:26:37 +error[E0277]: the trait bound `T: FromZeroes` is not satisfied + --> tests/ui-stable/invalid-impls/invalid-impls.rs:26:36 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T` +26 | impl_or_verify!(T => FromZeros for Foo); + | ^^^^^^ the trait `FromZeroes` is not implemented for `T` | -note: required for `Foo` to implement `zerocopy::FromZeroes` +note: required for `Foo` to implement `FromZeroes` --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs | @@ -17,13 +17,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-stable/invalid-impls/invalid-impls.rs:26:1 | -26 | impl_or_verify!(T => FromZeroes for Foo); - | ------------------------------------------- in this macro invocation - = note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) +26 | impl_or_verify!(T => FromZeros for Foo); + | ------------------------------------------ in this macro invocation + = note: this error originates in the derive macro `FromZeros` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | -26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo); - | ++++++++++++++++++++++ +26 | impl_or_verify!(T: zerocopy::FromZeros => FromZeros for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied --> tests/ui-stable/invalid-impls/invalid-impls.rs:27:36 @@ -32,10 +32,10 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied | ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::FromBytes` - --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:22 + --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:21 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs | @@ -59,10 +59,10 @@ error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied | ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::AsBytes` - --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:33 + --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:32 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs | @@ -86,10 +86,10 @@ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied | ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T` | note: required for `Foo` to implement `zerocopy::Unaligned` - --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:42 + --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:41 | -22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs | diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index a54cc11268..2c7e25658f 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -64,7 +64,7 @@ macro_rules! try_or_print { // help: required by the derive of FromBytes // // Instead, we have more verbose error messages like "unsupported representation -// for deriving FromZeroes, FromBytes, AsBytes, or Unaligned on an enum" +// for deriving FromZeros, FromBytes, AsBytes, or Unaligned on an enum" // // This will probably require Span::error // (https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.error), @@ -260,17 +260,25 @@ pub fn derive_no_cell(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { .into() } -#[proc_macro_derive(FromZeroes)] -pub fn derive_from_zeroes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { +#[proc_macro_derive(FromZeros)] +pub fn derive_from_zeros(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(ts as DeriveInput); match &ast.data { - Data::Struct(strct) => derive_from_zeroes_struct(&ast, strct), - Data::Enum(enm) => derive_from_zeroes_enum(&ast, enm), - Data::Union(unn) => derive_from_zeroes_union(&ast, unn), + Data::Struct(strct) => derive_from_zeros_struct(&ast, strct), + Data::Enum(enm) => derive_from_zeros_enum(&ast, enm), + Data::Union(unn) => derive_from_zeros_union(&ast, unn), } .into() } +/// Deprecated: prefer [`FromZeros`] instead. +#[deprecated(since = "0.8.0", note = "`FromZeroes` was renamed to `FromZeros`")] +#[doc(hidden)] +#[proc_macro_derive(FromZeroes)] +pub fn derive_from_zeroes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { + derive_from_zeros(ts) +} + #[proc_macro_derive(FromBytes)] pub fn derive_from_bytes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(ts as DeriveInput); @@ -311,20 +319,20 @@ const STRUCT_UNION_ALLOWED_REPR_COMBINATIONS: &[&[StructRepr]] = &[ &[StructRepr::C, StructRepr::Packed], ]; -// A struct is `FromZeroes` if: -// - all fields are `FromZeroes` +// A struct is `FromZeros` if: +// - all fields are `FromZeros` -fn derive_from_zeroes_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_macro2::TokenStream { - impl_block(ast, strct, Trait::FromZeroes, RequireBoundedFields::Yes, false, None, None) +fn derive_from_zeros_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_macro2::TokenStream { + impl_block(ast, strct, Trait::FromZeros, RequireBoundedFields::Yes, false, None, None) } -// An enum is `FromZeroes` if: +// An enum is `FromZeros` if: // - all of its variants are fieldless // - one of the variants has a discriminant of `0` -fn derive_from_zeroes_enum(ast: &DeriveInput, enm: &DataEnum) -> proc_macro2::TokenStream { +fn derive_from_zeros_enum(ast: &DeriveInput, enm: &DataEnum) -> proc_macro2::TokenStream { if !enm.is_c_like() { - return Error::new_spanned(ast, "only C-like enums can implement FromZeroes") + return Error::new_spanned(ast, "only C-like enums can implement FromZeros") .to_compile_error(); } @@ -344,19 +352,19 @@ fn derive_from_zeroes_enum(ast: &DeriveInput, enm: &DataEnum) -> proc_macro2::To if !has_explicit_zero_discriminant && !has_implicit_zero_discriminant { return Error::new_spanned( ast, - "FromZeroes only supported on enums with a variant that has a discriminant of `0`", + "FromZeros only supported on enums with a variant that has a discriminant of `0`", ) .to_compile_error(); } - impl_block(ast, enm, Trait::FromZeroes, RequireBoundedFields::Yes, false, None, None) + impl_block(ast, enm, Trait::FromZeros, RequireBoundedFields::Yes, false, None, None) } -// Like structs, unions are `FromZeroes` if -// - all fields are `FromZeroes` +// Like structs, unions are `FromZeros` if +// - all fields are `FromZeros` -fn derive_from_zeroes_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::TokenStream { - impl_block(ast, unn, Trait::FromZeroes, RequireBoundedFields::Yes, false, None, None) +fn derive_from_zeros_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::TokenStream { + impl_block(ast, unn, Trait::FromZeros, RequireBoundedFields::Yes, false, None, None) } // A struct is `FromBytes` if: @@ -655,7 +663,7 @@ impl PaddingCheck { enum Trait { KnownLayout, NoCell, - FromZeroes, + FromZeros, FromBytes, AsBytes, Unaligned, diff --git a/zerocopy-derive/tests/enum_from_bytes.rs b/zerocopy-derive/tests/enum_from_bytes.rs index 4717a8de20..4ca4391c03 100644 --- a/zerocopy-derive/tests/enum_from_bytes.rs +++ b/zerocopy-derive/tests/enum_from_bytes.rs @@ -12,7 +12,7 @@ mod util; use { static_assertions::assert_impl_all, - zerocopy::{FromBytes, FromZeroes}, + zerocopy::{FromBytes, FromZeros}, }; // An enum is `FromBytes` if: @@ -32,7 +32,7 @@ use { // `Variant128` has a discriminant of -128) since Rust won't automatically wrap // a signed discriminant around without you explicitly telling it to. -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u8)] enum FooU8 { Variant0, @@ -295,7 +295,7 @@ enum FooU8 { assert_impl_all!(FooU8: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(i8)] enum FooI8 { Variant0, @@ -558,7 +558,7 @@ enum FooI8 { assert_impl_all!(FooI8: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u8, align(2))] enum FooU8Align { Variant0, @@ -821,7 +821,7 @@ enum FooU8Align { assert_impl_all!(FooU8Align: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(i8, align(2))] enum FooI8Align { Variant0, @@ -1084,7 +1084,7 @@ enum FooI8Align { assert_impl_all!(FooI8Align: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u16)] enum FooU16 { Variant0, @@ -66627,7 +66627,7 @@ enum FooU16 { assert_impl_all!(FooU16: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(i16)] enum FooI16 { Variant0, diff --git a/zerocopy-derive/tests/enum_from_zeroes.rs b/zerocopy-derive/tests/enum_from_zeros.rs similarity index 67% rename from zerocopy-derive/tests/enum_from_zeroes.rs rename to zerocopy-derive/tests/enum_from_zeros.rs index c6bb675f52..2e635b8099 100644 --- a/zerocopy-derive/tests/enum_from_zeroes.rs +++ b/zerocopy-derive/tests/enum_from_zeros.rs @@ -10,26 +10,26 @@ mod util; -use {static_assertions::assert_impl_all, zerocopy::FromZeroes}; +use {static_assertions::assert_impl_all, zerocopy::FromZeros}; -#[derive(FromZeroes)] +#[derive(FromZeros)] enum Foo { A, } -assert_impl_all!(Foo: FromZeroes); +assert_impl_all!(Foo: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] enum Bar { A = 0, } -assert_impl_all!(Bar: FromZeroes); +assert_impl_all!(Bar: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] enum Baz { A = 1, B = 0, } -assert_impl_all!(Baz: FromZeroes); +assert_impl_all!(Baz: FromZeros); diff --git a/zerocopy-derive/tests/hygiene.rs b/zerocopy-derive/tests/hygiene.rs index b7b838d6c3..5795ede17b 100644 --- a/zerocopy-derive/tests/hygiene.rs +++ b/zerocopy-derive/tests/hygiene.rs @@ -22,7 +22,7 @@ use std::{marker::PhantomData, option::IntoIter}; use static_assertions::assert_impl_all; #[derive( - _zerocopy::KnownLayout, _zerocopy::FromZeroes, _zerocopy::FromBytes, _zerocopy::Unaligned, + _zerocopy::KnownLayout, _zerocopy::FromZeros, _zerocopy::FromBytes, _zerocopy::Unaligned, )] #[repr(C)] struct TypeParams<'a, T, I: Iterator> { @@ -37,7 +37,7 @@ struct TypeParams<'a, T, I: Iterator> { assert_impl_all!( TypeParams<'static, (), IntoIter<()>>: _zerocopy::KnownLayout, - _zerocopy::FromZeroes, + _zerocopy::FromZeros, _zerocopy::FromBytes, _zerocopy::Unaligned ); diff --git a/zerocopy-derive/tests/paths_and_modules.rs b/zerocopy-derive/tests/paths_and_modules.rs index a01983b097..0525b571a8 100644 --- a/zerocopy-derive/tests/paths_and_modules.rs +++ b/zerocopy-derive/tests/paths_and_modules.rs @@ -8,20 +8,20 @@ #![allow(warnings)] -use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}; +use zerocopy::{AsBytes, FromBytes, FromZeros, Unaligned}; // Ensure that types that are use'd and types that are referenced by path work. mod foo { - use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}; + use zerocopy::{AsBytes, FromBytes, FromZeros, Unaligned}; - #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] + #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] #[repr(C)] pub struct Foo { foo: u8, } - #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] + #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] #[repr(C)] pub struct Bar { bar: u8, @@ -30,7 +30,7 @@ mod foo { use foo::Foo; -#[derive(FromZeroes, FromBytes, AsBytes, Unaligned)] +#[derive(FromZeros, FromBytes, AsBytes, Unaligned)] #[repr(C)] struct Baz { foo: Foo, diff --git a/zerocopy-derive/tests/priv_in_pub.rs b/zerocopy-derive/tests/priv_in_pub.rs index 5f7d8749d3..754477afa6 100644 --- a/zerocopy-derive/tests/priv_in_pub.rs +++ b/zerocopy-derive/tests/priv_in_pub.rs @@ -6,7 +6,7 @@ // This file may not be copied, modified, or distributed except according to // those terms. -use zerocopy::{AsBytes, FromBytes, FromZeroes, KnownLayout, Unaligned}; +use zerocopy::{AsBytes, FromBytes, FromZeros, KnownLayout, Unaligned}; // These derives do not result in E0446 as of Rust 1.59.0, because of // https://github.com/rust-lang/rust/pull/90586. @@ -15,10 +15,10 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes, KnownLayout, Unaligned}; // bounds for field types (i.e., the emission of E0446 for private field // types). -#[derive(KnownLayout, AsBytes, FromZeroes, FromBytes, Unaligned)] +#[derive(KnownLayout, AsBytes, FromZeros, FromBytes, Unaligned)] #[repr(C)] pub struct Public(Private); -#[derive(KnownLayout, AsBytes, FromZeroes, FromBytes, Unaligned)] +#[derive(KnownLayout, AsBytes, FromZeros, FromBytes, Unaligned)] #[repr(C)] struct Private(()); diff --git a/zerocopy-derive/tests/struct_from_bytes.rs b/zerocopy-derive/tests/struct_from_bytes.rs index 98f03d1640..a02b357efd 100644 --- a/zerocopy-derive/tests/struct_from_bytes.rs +++ b/zerocopy-derive/tests/struct_from_bytes.rs @@ -14,7 +14,7 @@ use std::{marker::PhantomData, option::IntoIter}; use { static_assertions::assert_impl_all, - zerocopy::{FromBytes, FromZeroes}, + zerocopy::{FromBytes, FromZeros}, }; use crate::util::AU16; @@ -22,19 +22,19 @@ use crate::util::AU16; // A struct is `FromBytes` if: // - all fields are `FromBytes` -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] struct Zst; assert_impl_all!(Zst: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] struct One { a: u8, } assert_impl_all!(One: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] struct Two { a: u8, b: Zst, @@ -42,14 +42,14 @@ struct Two { assert_impl_all!(Two: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] struct Unsized { a: [u8], } assert_impl_all!(Unsized: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] struct TypeParams<'a, T: ?Sized, I: Iterator> { a: I::Item, b: u8, @@ -65,7 +65,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromBytes); // Deriving `FromBytes` should work if the struct has bounded parameters. -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(transparent)] struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromBytes>( [T; N], diff --git a/zerocopy-derive/tests/struct_from_zeroes.rs b/zerocopy-derive/tests/struct_from_zeros.rs similarity index 65% rename from zerocopy-derive/tests/struct_from_zeroes.rs rename to zerocopy-derive/tests/struct_from_zeros.rs index 75d824594b..3568f10073 100644 --- a/zerocopy-derive/tests/struct_from_zeroes.rs +++ b/zerocopy-derive/tests/struct_from_zeros.rs @@ -13,41 +13,41 @@ mod util; use std::{marker::PhantomData, option::IntoIter}; -use {static_assertions::assert_impl_all, zerocopy::FromZeroes}; +use {static_assertions::assert_impl_all, zerocopy::FromZeros}; use crate::util::AU16; -// A struct is `FromZeroes` if: -// - all fields are `FromZeroes` +// A struct is `FromZeros` if: +// - all fields are `FromZeros` -#[derive(FromZeroes)] +#[derive(FromZeros)] struct Zst; -assert_impl_all!(Zst: FromZeroes); +assert_impl_all!(Zst: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] struct One { a: bool, } -assert_impl_all!(One: FromZeroes); +assert_impl_all!(One: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] struct Two { a: bool, b: Zst, } -assert_impl_all!(Two: FromZeroes); +assert_impl_all!(Two: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] struct Unsized { a: [u8], } -assert_impl_all!(Unsized: FromZeroes); +assert_impl_all!(Unsized: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] struct TypeParams<'a, T: ?Sized, I: Iterator> { a: I::Item, b: u8, @@ -57,21 +57,21 @@ struct TypeParams<'a, T: ?Sized, I: Iterator> { f: T, } -assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromZeroes); -assert_impl_all!(TypeParams<'static, AU16, IntoIter<()>>: FromZeroes); -assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromZeroes); +assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromZeros); +assert_impl_all!(TypeParams<'static, AU16, IntoIter<()>>: FromZeros); +assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromZeros); -// Deriving `FromZeroes` should work if the struct has bounded parameters. +// Deriving `FromZeros` should work if the struct has bounded parameters. -#[derive(FromZeroes)] +#[derive(FromZeros)] #[repr(transparent)] -struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeroes>( +struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeros>( [T; N], PhantomData<&'a &'b ()>, ) where 'a: 'b, 'b: 'a, - T: 'a + 'b + FromZeroes; + T: 'a + 'b + FromZeros; -assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeroes); +assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeros); diff --git a/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr b/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr index 3b228b1551..6f295563f5 100644 --- a/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr @@ -1,19 +1,19 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-msrv/derive_transparent.rs:37:1 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` +37 | assert_impl_all!(TransparentStruct: FromZeros); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | note: required because of the requirements on the impl of `FromZeroes` for `TransparentStruct` --> tests/ui-msrv/derive_transparent.rs:27:19 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^^ +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:37:1 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all` +37 | assert_impl_all!(TransparentStruct: FromZeros); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all` = note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied @@ -23,10 +23,10 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` | note: required because of the requirements on the impl of `FromBytes` for `TransparentStruct` - --> tests/ui-msrv/derive_transparent.rs:27:31 + --> tests/ui-msrv/derive_transparent.rs:27:30 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:38:1 | @@ -43,7 +43,7 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied note: required because of the requirements on the impl of `AsBytes` for `TransparentStruct` --> tests/ui-msrv/derive_transparent.rs:27:10 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] | ^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:39:1 @@ -59,10 +59,10 @@ error[E0277]: the trait bound `NotZerocopy: Unaligned` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `NotZerocopy` | note: required because of the requirements on the impl of `Unaligned` for `TransparentStruct` - --> tests/ui-msrv/derive_transparent.rs:27:42 + --> tests/ui-msrv/derive_transparent.rs:27:41 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:40:1 | diff --git a/zerocopy-derive/tests/ui-msrv/enum.stderr b/zerocopy-derive/tests/ui-msrv/enum.stderr index fd2935baa8..0a269785db 100644 --- a/zerocopy-derive/tests/ui-msrv/enum.stderr +++ b/zerocopy-derive/tests/ui-msrv/enum.stderr @@ -23,34 +23,34 @@ error: conflicting representation hints | ^ error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout - --> tests/ui-msrv/enum.rs:42:22 + --> tests/ui-msrv/enum.rs:42:21 | -42 | #[derive(FromZeroes, FromBytes)] - | ^^^^^^^^^ +42 | #[derive(FromZeros, FromBytes)] + | ^^^^^^^^^ | = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-msrv/enum.rs:70:1 | -70 | / enum FromZeroes1 { +70 | / enum FromZeros1 { 71 | | A(u8), 72 | | } | |_^ -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-msrv/enum.rs:75:1 | -75 | / enum FromZeroes2 { +75 | / enum FromZeros2 { 76 | | A, 77 | | B(u8), 78 | | } | |_^ -error: FromZeroes only supported on enums with a variant that has a discriminant of `0` +error: FromZeros only supported on enums with a variant that has a discriminant of `0` --> tests/ui-msrv/enum.rs:81:1 | -81 | / enum FromZeroes3 { +81 | / enum FromZeros3 { 82 | | A = 1, 83 | | B, 84 | | } diff --git a/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr b/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr index 39dbcd1866..5af516a86f 100644 --- a/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr @@ -9,11 +9,11 @@ warning: unused import: `zerocopy::KnownLayout` error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-msrv/late_compile_pass.rs:28:10 | -28 | #[derive(FromZeroes)] - | ^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` +28 | #[derive(FromZeros)] + | ^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | = help: see issue #48214 - = note: this error originates in the derive macro `FromZeroes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied --> tests/ui-msrv/late_compile_pass.rs:37:10 @@ -33,8 +33,8 @@ error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied note: required by a bound in `FromBytes` --> $WORKSPACE/src/lib.rs | - | pub unsafe trait FromBytes: FromZeroes { - | ^^^^^^^^^^ required by this bound in `FromBytes` + | pub unsafe trait FromBytes: FromZeros { + | ^^^^^^^^^ required by this bound in `FromBytes` = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied diff --git a/zerocopy-derive/tests/ui-nightly/derive_transparent.rs b/zerocopy-derive/tests/ui-nightly/derive_transparent.rs index 2084d921bf..127ff169db 100644 --- a/zerocopy-derive/tests/ui-nightly/derive_transparent.rs +++ b/zerocopy-derive/tests/ui-nightly/derive_transparent.rs @@ -15,7 +15,7 @@ use core::marker::PhantomData; use { static_assertions::assert_impl_all, - zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}, + zerocopy::{AsBytes, FromBytes, FromZeros, Unaligned}, }; use self::util::NotZerocopy; @@ -24,7 +24,7 @@ fn main() {} // Test generic transparent structs -#[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] +#[derive(AsBytes, FromZeros, FromBytes, Unaligned)] #[repr(transparent)] struct TransparentStruct { inner: T, @@ -34,7 +34,7 @@ struct TransparentStruct { // It should be legal to derive these traits on a transparent struct, but it // must also ensure the traits are only implemented when the inner type // implements them. -assert_impl_all!(TransparentStruct: FromZeroes); +assert_impl_all!(TransparentStruct: FromZeros); assert_impl_all!(TransparentStruct: FromBytes); assert_impl_all!(TransparentStruct: AsBytes); assert_impl_all!(TransparentStruct: Unaligned); diff --git a/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr b/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr index f214877dfb..337b3c5b5c 100644 --- a/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr @@ -1,7 +1,7 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-nightly/derive_transparent.rs:37:18 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); +37 | assert_impl_all!(TransparentStruct: FromZeros); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `FromZeroes`: @@ -17,14 +17,14 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied note: required for `TransparentStruct` to implement `FromZeroes` --> tests/ui-nightly/derive_transparent.rs:27:19 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-nightly/derive_transparent.rs:37:1 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` - = note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) +37 | assert_impl_all!(TransparentStruct: FromZeros); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` + = note: this error originates in the derive macro `FromZeros` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied --> tests/ui-nightly/derive_transparent.rs:38:18 @@ -43,10 +43,10 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied u8 and $N others note: required for `TransparentStruct` to implement `FromBytes` - --> tests/ui-nightly/derive_transparent.rs:27:31 + --> tests/ui-nightly/derive_transparent.rs:27:30 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-nightly/derive_transparent.rs:38:1 | @@ -73,7 +73,7 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied note: required for `TransparentStruct` to implement `AsBytes` --> tests/ui-nightly/derive_transparent.rs:27:10 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-nightly/derive_transparent.rs:39:1 @@ -99,10 +99,10 @@ error[E0277]: the trait bound `NotZerocopy: Unaligned` is not satisfied U128 and $N others note: required for `TransparentStruct` to implement `Unaligned` - --> tests/ui-nightly/derive_transparent.rs:27:42 + --> tests/ui-nightly/derive_transparent.rs:27:41 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-nightly/derive_transparent.rs:40:1 | diff --git a/zerocopy-derive/tests/ui-nightly/enum.rs b/zerocopy-derive/tests/ui-nightly/enum.rs index f9f9149e08..b4a7943453 100644 --- a/zerocopy-derive/tests/ui-nightly/enum.rs +++ b/zerocopy-derive/tests/ui-nightly/enum.rs @@ -15,31 +15,31 @@ fn main() {} // Generic errors // -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr("foo")] enum Generic1 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(foo)] enum Generic2 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(transparent)] enum Generic3 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u8, u16)] enum Generic4 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] enum Generic5 { A, } @@ -63,22 +63,22 @@ enum NoCell2 { } // -// FromZeroes errors +// FromZeros errors // -#[derive(FromZeroes)] -enum FromZeroes1 { +#[derive(FromZeros)] +enum FromZeros1 { A(u8), } -#[derive(FromZeroes)] -enum FromZeroes2 { +#[derive(FromZeros)] +enum FromZeros2 { A, B(u8), } -#[derive(FromZeroes)] -enum FromZeroes3 { +#[derive(FromZeros)] +enum FromZeros3 { A = 1, B, } @@ -87,43 +87,43 @@ enum FromZeroes3 { // FromBytes errors // -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(C)] enum FromBytes1 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(usize)] enum FromBytes2 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(isize)] enum FromBytes3 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u32)] enum FromBytes4 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(i32)] enum FromBytes5 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(u64)] enum FromBytes6 { A, } -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(i64)] enum FromBytes7 { A, diff --git a/zerocopy-derive/tests/ui-nightly/enum.stderr b/zerocopy-derive/tests/ui-nightly/enum.stderr index 3fe3c7b278..4858d8616f 100644 --- a/zerocopy-derive/tests/ui-nightly/enum.stderr +++ b/zerocopy-derive/tests/ui-nightly/enum.stderr @@ -23,34 +23,34 @@ error: conflicting representation hints | ^^^^^^^ error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout - --> tests/ui-nightly/enum.rs:42:22 + --> tests/ui-nightly/enum.rs:42:21 | -42 | #[derive(FromZeroes, FromBytes)] - | ^^^^^^^^^ +42 | #[derive(FromZeros, FromBytes)] + | ^^^^^^^^^ | = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-nightly/enum.rs:70:1 | -70 | / enum FromZeroes1 { +70 | / enum FromZeros1 { 71 | | A(u8), 72 | | } | |_^ -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-nightly/enum.rs:75:1 | -75 | / enum FromZeroes2 { +75 | / enum FromZeros2 { 76 | | A, 77 | | B(u8), 78 | | } | |_^ -error: FromZeroes only supported on enums with a variant that has a discriminant of `0` +error: FromZeros only supported on enums with a variant that has a discriminant of `0` --> tests/ui-nightly/enum.rs:81:1 | -81 | / enum FromZeroes3 { +81 | / enum FromZeros3 { 82 | | A = 1, 83 | | B, 84 | | } diff --git a/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs b/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs index cd65a6ed2c..ba9931bd71 100644 --- a/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs +++ b/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs @@ -22,11 +22,11 @@ fn main() {} // the compiler will never get to that pass, and so we won't get the errors. // -// FromZeroes errors +// FromZeros errors // -#[derive(FromZeroes)] -struct FromZeroes1 { +#[derive(FromZeros)] +struct FromZeros1 { value: NotZerocopy, } diff --git a/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr b/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr index 3c45dc4e84..dc884bdd32 100644 --- a/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr @@ -9,8 +9,8 @@ warning: unused import: `zerocopy::KnownLayout` error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-nightly/late_compile_pass.rs:28:10 | -28 | #[derive(FromZeroes)] - | ^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` +28 | #[derive(FromZeros)] + | ^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `FromZeroes`: bool @@ -24,7 +24,7 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied and $N others = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - = note: this error originates in the derive macro `FromZeroes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied --> tests/ui-nightly/late_compile_pass.rs:37:10 @@ -65,8 +65,8 @@ error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied note: required by a bound in `FromBytes` --> $WORKSPACE/src/lib.rs | - | pub unsafe trait FromBytes: FromZeroes { - | ^^^^^^^^^^ required by this bound in `FromBytes` + | pub unsafe trait FromBytes: FromZeros { + | ^^^^^^^^^ required by this bound in `FromBytes` = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied diff --git a/zerocopy-derive/tests/ui-stable/derive_transparent.stderr b/zerocopy-derive/tests/ui-stable/derive_transparent.stderr index f24dd4866d..314dc35946 100644 --- a/zerocopy-derive/tests/ui-stable/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-stable/derive_transparent.stderr @@ -1,7 +1,7 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-stable/derive_transparent.rs:37:18 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); +37 | assert_impl_all!(TransparentStruct: FromZeros); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `FromZeroes`: @@ -17,14 +17,14 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied note: required for `TransparentStruct` to implement `FromZeroes` --> tests/ui-stable/derive_transparent.rs:27:19 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-stable/derive_transparent.rs:37:1 | -37 | assert_impl_all!(TransparentStruct: FromZeroes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` - = note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) +37 | assert_impl_all!(TransparentStruct: FromZeros); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` + = note: this error originates in the derive macro `FromZeros` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied --> tests/ui-stable/derive_transparent.rs:38:18 @@ -43,10 +43,10 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied u8 and $N others note: required for `TransparentStruct` to implement `FromBytes` - --> tests/ui-stable/derive_transparent.rs:27:31 + --> tests/ui-stable/derive_transparent.rs:27:30 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-stable/derive_transparent.rs:38:1 | @@ -73,7 +73,7 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied note: required for `TransparentStruct` to implement `AsBytes` --> tests/ui-stable/derive_transparent.rs:27:10 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-stable/derive_transparent.rs:39:1 @@ -99,10 +99,10 @@ error[E0277]: the trait bound `NotZerocopy: Unaligned` is not satisfied U128 and $N others note: required for `TransparentStruct` to implement `Unaligned` - --> tests/ui-stable/derive_transparent.rs:27:42 + --> tests/ui-stable/derive_transparent.rs:27:41 | -27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-stable/derive_transparent.rs:40:1 | diff --git a/zerocopy-derive/tests/ui-stable/enum.stderr b/zerocopy-derive/tests/ui-stable/enum.stderr index 5a4e2e28a9..9aa6506bac 100644 --- a/zerocopy-derive/tests/ui-stable/enum.stderr +++ b/zerocopy-derive/tests/ui-stable/enum.stderr @@ -23,34 +23,34 @@ error: conflicting representation hints | ^ error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout - --> tests/ui-stable/enum.rs:42:22 + --> tests/ui-stable/enum.rs:42:21 | -42 | #[derive(FromZeroes, FromBytes)] - | ^^^^^^^^^ +42 | #[derive(FromZeros, FromBytes)] + | ^^^^^^^^^ | = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-stable/enum.rs:70:1 | -70 | / enum FromZeroes1 { +70 | / enum FromZeros1 { 71 | | A(u8), 72 | | } | |_^ -error: only C-like enums can implement FromZeroes +error: only C-like enums can implement FromZeros --> tests/ui-stable/enum.rs:75:1 | -75 | / enum FromZeroes2 { +75 | / enum FromZeros2 { 76 | | A, 77 | | B(u8), 78 | | } | |_^ -error: FromZeroes only supported on enums with a variant that has a discriminant of `0` +error: FromZeros only supported on enums with a variant that has a discriminant of `0` --> tests/ui-stable/enum.rs:81:1 | -81 | / enum FromZeroes3 { +81 | / enum FromZeros3 { 82 | | A = 1, 83 | | B, 84 | | } diff --git a/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr b/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr index 808054ab4d..7a41d63f0c 100644 --- a/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr @@ -9,8 +9,8 @@ warning: unused import: `zerocopy::KnownLayout` error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied --> tests/ui-stable/late_compile_pass.rs:28:10 | -28 | #[derive(FromZeroes)] - | ^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` +28 | #[derive(FromZeros)] + | ^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `FromZeroes`: bool @@ -23,7 +23,7 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied i128 and $N others = help: see issue #48214 - = note: this error originates in the derive macro `FromZeroes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied --> tests/ui-stable/late_compile_pass.rs:37:10 @@ -63,8 +63,8 @@ error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied note: required by a bound in `FromBytes` --> $WORKSPACE/src/lib.rs | - | pub unsafe trait FromBytes: FromZeroes { - | ^^^^^^^^^^ required by this bound in `FromBytes` + | pub unsafe trait FromBytes: FromZeros { + | ^^^^^^^^^ required by this bound in `FromBytes` = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied diff --git a/zerocopy-derive/tests/union_from_bytes.rs b/zerocopy-derive/tests/union_from_bytes.rs index 4635735ef1..be9d1744c8 100644 --- a/zerocopy-derive/tests/union_from_bytes.rs +++ b/zerocopy-derive/tests/union_from_bytes.rs @@ -12,27 +12,27 @@ use std::{marker::PhantomData, option::IntoIter}; use { static_assertions::assert_impl_all, - zerocopy::{FromBytes, FromZeroes}, + zerocopy::{FromBytes, FromZeros}, }; // A union is `FromBytes` if: // - all fields are `FromBytes` -#[derive(Clone, Copy, FromZeroes, FromBytes)] +#[derive(Clone, Copy, FromZeros, FromBytes)] union Zst { a: (), } assert_impl_all!(Zst: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] union One { a: u8, } assert_impl_all!(One: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] union Two { a: u8, b: Zst, @@ -40,7 +40,7 @@ union Two { assert_impl_all!(Two: FromBytes); -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] union TypeParams<'a, T: Copy, I: Iterator> where I::Item: Copy, @@ -57,7 +57,7 @@ assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromBytes); // Deriving `FromBytes` should work if the union has bounded parameters. -#[derive(FromZeroes, FromBytes)] +#[derive(FromZeros, FromBytes)] #[repr(C)] union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromBytes> where diff --git a/zerocopy-derive/tests/union_from_zeroes.rs b/zerocopy-derive/tests/union_from_zeros.rs similarity index 64% rename from zerocopy-derive/tests/union_from_zeroes.rs rename to zerocopy-derive/tests/union_from_zeros.rs index 935fc1563b..2bdfc28834 100644 --- a/zerocopy-derive/tests/union_from_zeroes.rs +++ b/zerocopy-derive/tests/union_from_zeros.rs @@ -13,34 +13,34 @@ mod util; use std::{marker::PhantomData, option::IntoIter}; -use {static_assertions::assert_impl_all, zerocopy::FromZeroes}; +use {static_assertions::assert_impl_all, zerocopy::FromZeros}; -// A union is `FromZeroes` if: -// - all fields are `FromZeroes` +// A union is `FromZeros` if: +// - all fields are `FromZeros` -#[derive(Clone, Copy, FromZeroes)] +#[derive(Clone, Copy, FromZeros)] union Zst { a: (), } -assert_impl_all!(Zst: FromZeroes); +assert_impl_all!(Zst: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] union One { a: bool, } -assert_impl_all!(One: FromZeroes); +assert_impl_all!(One: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] union Two { a: bool, b: Zst, } -assert_impl_all!(Two: FromZeroes); +assert_impl_all!(Two: FromZeros); -#[derive(FromZeroes)] +#[derive(FromZeros)] union TypeParams<'a, T: Copy, I: Iterator> where I::Item: Copy, @@ -53,20 +53,20 @@ where g: PhantomData, } -assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromZeroes); +assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromZeros); -// Deriving `FromZeroes` should work if the union has bounded parameters. +// Deriving `FromZeros` should work if the union has bounded parameters. -#[derive(FromZeroes)] +#[derive(FromZeros)] #[repr(C)] -union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeroes> +union WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeros> where 'a: 'b, 'b: 'a, - T: 'a + 'b + Copy + FromZeroes, + T: 'a + 'b + Copy + FromZeros, { a: [T; N], b: PhantomData<&'a &'b ()>, } -assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeroes); +assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeros); diff --git a/zerocopy-derive/tests/util.rs b/zerocopy-derive/tests/util.rs index 796d622432..e50e575140 100644 --- a/zerocopy-derive/tests/util.rs +++ b/zerocopy-derive/tests/util.rs @@ -6,7 +6,7 @@ // This file may not be copied, modified, or distributed except according to // those terms. -use zerocopy::{AsBytes, FromBytes, FromZeroes, KnownLayout, NoCell}; +use zerocopy::{AsBytes, FromBytes, FromZeros, KnownLayout, NoCell}; /// A type that doesn't implement any zerocopy traits. pub struct NotZerocopy(T); @@ -15,6 +15,6 @@ pub struct NotZerocopy(T); /// /// Though `u16` has alignment 2 on some platforms, it's not guaranteed. By /// contrast, `AU16` is guaranteed to have alignment 2. -#[derive(KnownLayout, NoCell, FromZeroes, FromBytes, AsBytes, Copy, Clone)] +#[derive(KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Copy, Clone)] #[repr(C, align(2))] pub struct AU16(u16);