From 24b5a9b2958a8fe02f71a0a267b02604c8560992 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Thu, 14 Dec 2023 10:23:16 -0800 Subject: [PATCH] Rename AsBytes to IntoBytes (#700) Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]` is a valid transformation. This slightly changes the meaning of `AsBytes` and makes `IntoBytes` a more appropriate name since it only permits value rather than reference transmutations. This also brings the pair of `FromBytes` and `IntoBytes` in line with the standard library `From` and `Into` traits from a naming perspective. Closes #695 --- CONTRIBUTING.md | 2 +- README.md | 4 +- src/byteorder.rs | 24 +- src/lib.rs | 603 +++++++++--------- src/macro_util.rs | 16 +- src/macros.rs | 4 +- src/util.rs | 2 +- src/wrappers.rs | 6 +- .../invalid-impls/invalid-impls.stderr | 34 +- .../ui-msrv/transmute-mut-dst-not-asbytes.rs | 1 - .../transmute-mut-dst-not-intobytes.rs | 1 + ...=> transmute-mut-dst-not-intobytes.stderr} | 8 +- .../ui-msrv/transmute-mut-src-not-asbytes.rs | 1 - .../transmute-mut-src-not-intobytes.rs | 1 + ...=> transmute-mut-src-not-intobytes.stderr} | 16 +- tests/ui-msrv/transmute-ptr-to-usize.stderr | 8 +- .../ui-msrv/transmute-ref-src-not-asbytes.rs | 1 - .../transmute-ref-src-not-intobytes.rs | 1 + ...=> transmute-ref-src-not-intobytes.stderr} | 16 +- tests/ui-msrv/transmute-src-not-asbytes.rs | 1 - tests/ui-msrv/transmute-src-not-intobytes.rs | 1 + ...err => transmute-src-not-intobytes.stderr} | 16 +- .../ui-nightly/invalid-impls/invalid-impls.rs | 4 +- .../invalid-impls/invalid-impls.stderr | 36 +- tests/ui-nightly/transmute-mut-dst-generic.rs | 4 +- .../transmute-mut-dst-not-frombytes.rs | 4 +- ....rs => transmute-mut-dst-not-intobytes.rs} | 4 +- .../transmute-mut-dst-not-intobytes.stderr} | 8 +- .../transmute-mut-dst-not-nocell.rs | 4 +- .../transmute-mut-src-dst-generic.rs | 4 +- tests/ui-nightly/transmute-mut-src-generic.rs | 4 +- .../transmute-mut-src-not-frombytes.rs | 4 +- ....rs => transmute-mut-src-not-intobytes.rs} | 4 +- .../transmute-mut-src-not-intobytes.stderr} | 16 +- .../transmute-mut-src-not-nocell.rs | 4 +- .../ui-nightly/transmute-ptr-to-usize.stderr | 8 +- .../transmute-ref-src-dst-generic.rs | 4 +- tests/ui-nightly/transmute-ref-src-generic.rs | 4 +- ....rs => transmute-ref-src-not-intobytes.rs} | 2 +- ...=> transmute-ref-src-not-intobytes.stderr} | 16 +- .../transmute-ref-src-not-nocell.rs | 2 +- ...ytes.rs => transmute-src-not-intobytes.rs} | 2 +- ...err => transmute-src-not-intobytes.stderr} | 16 +- .../invalid-impls/invalid-impls.stderr | 36 +- .../transmute-mut-dst-not-asbytes.rs | 1 - .../transmute-mut-dst-not-intobytes.rs | 1 + .../transmute-mut-dst-not-intobytes.stderr} | 8 +- .../transmute-mut-src-not-asbytes.rs | 1 - .../transmute-mut-src-not-intobytes.rs | 1 + .../transmute-mut-src-not-intobytes.stderr} | 16 +- tests/ui-stable/transmute-ptr-to-usize.stderr | 8 +- .../transmute-ref-src-not-asbytes.rs | 1 - .../transmute-ref-src-not-intobytes.rs | 1 + ...=> transmute-ref-src-not-intobytes.stderr} | 16 +- tests/ui-stable/transmute-src-not-asbytes.rs | 1 - .../ui-stable/transmute-src-not-intobytes.rs | 1 + ...err => transmute-src-not-intobytes.stderr} | 16 +- zerocopy-derive/src/lib.rs | 32 +- zerocopy-derive/src/repr.rs | 2 +- .../{enum_as_bytes.rs => enum_to_bytes.rs} | 48 +- zerocopy-derive/tests/paths_and_modules.rs | 10 +- zerocopy-derive/tests/priv_in_pub.rs | 6 +- ...{struct_as_bytes.rs => struct_to_bytes.rs} | 66 +- .../tests/ui-msrv/derive_transparent.stderr | 36 +- zerocopy-derive/tests/ui-msrv/enum.stderr | 2 +- .../tests/ui-msrv/late_compile_pass.stderr | 6 +- zerocopy-derive/tests/ui-msrv/struct.stderr | 22 +- zerocopy-derive/tests/ui-msrv/union.stderr | 14 +- .../tests/ui-nightly/derive_transparent.rs | 6 +- .../ui-nightly/derive_transparent.stderr | 36 +- zerocopy-derive/tests/ui-nightly/enum.stderr | 2 +- .../tests/ui-nightly/late_compile_pass.rs | 6 +- .../tests/ui-nightly/late_compile_pass.stderr | 6 +- zerocopy-derive/tests/ui-nightly/struct.rs | 14 +- .../tests/ui-nightly/struct.stderr | 26 +- zerocopy-derive/tests/ui-nightly/union.rs | 10 +- zerocopy-derive/tests/ui-nightly/union.stderr | 16 +- .../tests/ui-stable/derive_transparent.stderr | 36 +- zerocopy-derive/tests/ui-stable/enum.stderr | 2 +- .../tests/ui-stable/late_compile_pass.stderr | 6 +- zerocopy-derive/tests/ui-stable/struct.stderr | 22 +- zerocopy-derive/tests/ui-stable/union.stderr | 14 +- .../{union_as_bytes.rs => union_to_bytes.rs} | 28 +- zerocopy-derive/tests/util.rs | 4 +- 84 files changed, 757 insertions(+), 750 deletions(-) delete mode 120000 tests/ui-msrv/transmute-mut-dst-not-asbytes.rs create mode 120000 tests/ui-msrv/transmute-mut-dst-not-intobytes.rs rename tests/ui-msrv/{transmute-mut-dst-not-asbytes.stderr => transmute-mut-dst-not-intobytes.stderr} (69%) delete mode 120000 tests/ui-msrv/transmute-mut-src-not-asbytes.rs create mode 120000 tests/ui-msrv/transmute-mut-src-not-intobytes.rs rename tests/ui-msrv/{transmute-mut-src-not-asbytes.stderr => transmute-mut-src-not-intobytes.stderr} (69%) delete mode 120000 tests/ui-msrv/transmute-ref-src-not-asbytes.rs create mode 120000 tests/ui-msrv/transmute-ref-src-not-intobytes.rs rename tests/ui-msrv/{transmute-ref-src-not-asbytes.stderr => transmute-ref-src-not-intobytes.stderr} (69%) delete mode 120000 tests/ui-msrv/transmute-src-not-asbytes.rs create mode 120000 tests/ui-msrv/transmute-src-not-intobytes.rs rename tests/ui-msrv/{transmute-src-not-asbytes.stderr => transmute-src-not-intobytes.stderr} (71%) rename tests/ui-nightly/{transmute-mut-dst-not-asbytes.rs => transmute-mut-dst-not-intobytes.rs} (86%) rename tests/{ui-stable/transmute-mut-dst-not-asbytes.stderr => ui-nightly/transmute-mut-dst-not-intobytes.stderr} (79%) rename tests/ui-nightly/{transmute-mut-src-not-asbytes.rs => transmute-mut-src-not-intobytes.rs} (79%) rename tests/{ui-stable/transmute-mut-src-not-asbytes.stderr => ui-nightly/transmute-mut-src-not-intobytes.stderr} (78%) rename tests/ui-nightly/{transmute-ref-src-not-asbytes.rs => transmute-ref-src-not-intobytes.rs} (89%) rename tests/ui-nightly/{transmute-ref-src-not-asbytes.stderr => transmute-ref-src-not-intobytes.stderr} (78%) rename tests/ui-nightly/{transmute-src-not-asbytes.rs => transmute-src-not-intobytes.rs} (89%) rename tests/ui-nightly/{transmute-src-not-asbytes.stderr => transmute-src-not-intobytes.stderr} (79%) delete mode 120000 tests/ui-stable/transmute-mut-dst-not-asbytes.rs create mode 120000 tests/ui-stable/transmute-mut-dst-not-intobytes.rs rename tests/{ui-nightly/transmute-mut-dst-not-asbytes.stderr => ui-stable/transmute-mut-dst-not-intobytes.stderr} (79%) delete mode 120000 tests/ui-stable/transmute-mut-src-not-asbytes.rs create mode 120000 tests/ui-stable/transmute-mut-src-not-intobytes.rs rename tests/{ui-nightly/transmute-mut-src-not-asbytes.stderr => ui-stable/transmute-mut-src-not-intobytes.stderr} (78%) delete mode 120000 tests/ui-stable/transmute-ref-src-not-asbytes.rs create mode 120000 tests/ui-stable/transmute-ref-src-not-intobytes.rs rename tests/ui-stable/{transmute-ref-src-not-asbytes.stderr => transmute-ref-src-not-intobytes.stderr} (78%) delete mode 120000 tests/ui-stable/transmute-src-not-asbytes.rs create mode 120000 tests/ui-stable/transmute-src-not-intobytes.rs rename tests/ui-stable/{transmute-src-not-asbytes.stderr => transmute-src-not-intobytes.stderr} (79%) rename zerocopy-derive/tests/{enum_as_bytes.rs => enum_to_bytes.rs} (52%) rename zerocopy-derive/tests/{struct_as_bytes.rs => struct_to_bytes.rs} (72%) rename zerocopy-derive/tests/{union_as_bytes.rs => union_to_bytes.rs} (70%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 929e80996b..aeefb7c7e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -157,7 +157,7 @@ name of that subsystem in square brackets, omitting any "zerocopy" prefix zerocopy-derive crate: ```text -[derive] Support AsBytes on types with parameters +[derive] Support IntoBytes on types with parameters ``` The body may be omitted if the subject is self-explanatory; e.g. when fixing a diff --git a/README.md b/README.md index a99cd3401b..82cf7bd782 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Zerocopy provides four core marker traits, each of which can be derived instance of a type - `FromBytes` indicates that a type may safely be converted from an arbitrary byte sequence -- `AsBytes` indicates that a type may safely be converted *to* a byte +- `IntoBytes` indicates that a type may safely be converted *to* a byte sequence - `Unaligned` indicates that a type's alignment requirement is 1 @@ -77,7 +77,7 @@ for network parsing. - **`simd`** When the `simd` feature is enabled, `FromZeros`, `FromBytes`, and - `AsBytes` impls are emitted for all stable SIMD types which exist on the + `IntoBytes` 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 invalid. For more information, see the Unsafe Code Guidelines Reference diff --git a/src/byteorder.rs b/src/byteorder.rs index 73f3fcd6fc..2df3dc7e00 100644 --- a/src/byteorder.rs +++ b/src/byteorder.rs @@ -16,7 +16,7 @@ //! this module - [`U16`], [`I16`], [`U32`], [`F64`], etc. Unlike their native //! counterparts, these types have alignment 1, and take a type parameter //! specifying the byte order in which the bytes are stored in memory. Each type -//! implements the [`FromBytes`], [`AsBytes`], and [`Unaligned`] traits. +//! implements the [`FromBytes`], [`IntoBytes`], and [`Unaligned`] traits. //! //! These two properties, taken together, make these types useful for defining //! data structures whose memory layout matches a wire format such as that of a @@ -35,10 +35,10 @@ //! //! ```rust,edition2021 //! # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them -//! use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeros, NoCell, Ref, Unaligned}; +//! use zerocopy::{IntoBytes, ByteSlice, FromBytes, FromZeros, NoCell, Ref, Unaligned}; //! use zerocopy::byteorder::network_endian::U16; //! -//! #[derive(FromZeros, FromBytes, AsBytes, NoCell, Unaligned)] +//! #[derive(FromZeros, FromBytes, IntoBytes, NoCell, Unaligned)] //! #[repr(C)] //! struct UdpHeader { //! src_port: U16, @@ -265,7 +265,7 @@ order to uphold the invariants that a) the layout of `", stringify!($name), "` has endianness `O` and that, b) the layout of `", stringify!($native), "` has the platform's native endianness. -`", stringify!($name), "` implements [`FromBytes`], [`AsBytes`], and [`Unaligned`], +`", stringify!($name), "` implements [`FromBytes`], [`IntoBytes`], and [`Unaligned`], making it useful for parsing and serialization. See the module documentation for an example of how it can be used for parsing UDP packets. @@ -273,10 +273,10 @@ example of how it can be used for parsing UDP packets. [`get`]: crate::byteorder::", stringify!($name), "::get [`set`]: crate::byteorder::", stringify!($name), "::set [`FromBytes`]: crate::FromBytes -[`AsBytes`]: crate::AsBytes +[`IntoBytes`]: crate::IntoBytes [`Unaligned`]: crate::Unaligned"), #[derive(Copy, Clone, Eq, PartialEq, Hash)] - #[cfg_attr(any(feature = "derive", test), derive(KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned))] + #[cfg_attr(any(feature = "derive", test), derive(KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned))] #[repr(transparent)] pub struct $name([u8; $bytes], PhantomData); } @@ -288,12 +288,12 @@ 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`, `FromZeros`, `FromBytes`, `AsBytes`, and + /// are `NoCell`, `FromZeros`, `FromBytes`, `IntoBytes`, and /// `Unaligned`. impl_or_verify!(O => NoCell 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 => IntoBytes for $name); impl_or_verify!(O => Unaligned for $name); } @@ -607,7 +607,7 @@ mod tests { use { super::*, - crate::{AsBytes, FromBytes, Unaligned}, + crate::{FromBytes, IntoBytes, Unaligned}, }; #[cfg(not(kani))] @@ -655,7 +655,7 @@ mod tests { use compatibility::*; // A native integer type (u16, i32, etc). - trait Native: Arbitrary + FromBytes + AsBytes + NoCell + Copy + PartialEq + Debug { + trait Native: Arbitrary + FromBytes + IntoBytes + NoCell + Copy + PartialEq + Debug { const ZERO: Self; const MAX_VALUE: Self; @@ -692,13 +692,13 @@ mod tests { } trait ByteArray: - FromBytes + AsBytes + NoCell + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq + FromBytes + IntoBytes + NoCell + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq { /// Invert the order of the bytes in the array. fn invert(self) -> Self; } - trait ByteOrderType: FromBytes + AsBytes + Unaligned + Copy + Eq + Debug { + trait ByteOrderType: FromBytes + IntoBytes + Unaligned + Copy + Eq + Debug { type Native: Native; type ByteArray: ByteArray; diff --git a/src/lib.rs b/src/lib.rs index 427f943ab4..2529a862b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ //! instance of a type //! - [`FromBytes`] indicates that a type may safely be converted from an //! arbitrary byte sequence -//! - [`AsBytes`] indicates that a type may safely be converted *to* a byte +//! - [`IntoBytes`] indicates that a type may safely be converted *to* a byte //! sequence //! - [`Unaligned`] indicates that a type's alignment requirement is 1 //! @@ -77,7 +77,7 @@ //! //! - **`simd`** //! When the `simd` feature is enabled, `FromZeros`, `FromBytes`, and -//! `AsBytes` impls are emitted for all stable SIMD types which exist on the +//! `IntoBytes` 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 //! invalid. For more information, see the Unsafe Code Guidelines Reference @@ -1960,7 +1960,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1986,7 +1986,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<&mut [u8], Self>::new(bytes).map(Ref::into_mut) } @@ -2007,7 +2007,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2033,7 +2033,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from_prefix(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<&mut [u8], Self>::new_from_prefix(bytes).map(|(r, _)| r.into_mut()) } @@ -2053,7 +2053,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -2073,7 +2073,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from_suffix(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<&mut [u8], Self>::new_from_suffix(bytes).map(|(_, r)| r.into_mut()) } @@ -2247,7 +2247,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2273,7 +2273,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from(bytes: &mut [u8]) -> Option<&mut [Self]> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<_, [Self]>::new_slice(bytes).map(|r| r.into_mut_slice()) } @@ -2300,7 +2300,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2328,7 +2328,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from_prefix(bytes: &mut [u8], count: usize) -> Option<(&mut [Self], &mut [u8])> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, b)| (r.into_mut_slice(), b)) } @@ -2355,7 +2355,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2383,7 +2383,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from_suffix(bytes: &mut [u8], count: usize) -> Option<(&mut [u8], &mut [Self])> where - Self: Sized + AsBytes + NoCell, + Self: Sized + IntoBytes + NoCell, { Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(b, r)| (b, r.into_mut_slice())) } @@ -2500,16 +2500,16 @@ pub unsafe trait FromBytes: FromZeros { } } -/// Analyzes whether a type is [`AsBytes`]. +/// Analyzes whether a type is [`IntoBytes`]. /// /// This derive analyzes, at compile time, whether the annotated type satisfies -/// the [safety conditions] of `AsBytes` and implements `AsBytes` if it is +/// the [safety conditions] of `IntoBytes` and implements `IntoBytes` if it is /// sound to do so. This derive can be applied to structs, enums, and unions; /// e.g.: /// /// ``` -/// # use zerocopy_derive::{AsBytes}; -/// #[derive(AsBytes)] +/// # use zerocopy_derive::{IntoBytes}; +/// #[derive(IntoBytes)] /// #[repr(C)] /// struct MyStruct { /// # /* @@ -2517,7 +2517,7 @@ pub unsafe trait FromBytes: FromZeros { /// # */ /// } /// -/// #[derive(AsBytes)] +/// #[derive(IntoBytes)] /// #[repr(u8)] /// enum MyEnum { /// # Variant, @@ -2526,7 +2526,7 @@ pub unsafe trait FromBytes: FromZeros { /// # */ /// } /// -/// #[derive(AsBytes)] +/// #[derive(IntoBytes)] /// #[repr(C)] /// union MyUnion { /// # variant: u8, @@ -2536,47 +2536,47 @@ pub unsafe trait FromBytes: FromZeros { /// } /// ``` /// -/// [safety conditions]: trait@AsBytes#safety +/// [safety conditions]: trait@IntoBytes#safety /// /// # Error Messages /// -/// Due to the way that the custom derive for `AsBytes` is implemented, you may -/// get an error like this: +/// Due to the way that the custom derive for `IntoBytes` is implemented, you +/// may get an error like this: /// /// ```text /// error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied /// --> lib.rs:23:10 /// | -/// 1 | #[derive(AsBytes)] +/// 1 | #[derive(IntoBytes)] /// | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` /// | /// = help: the trait `ShouldBe` is implemented for `HasPadding` /// ``` /// /// This error indicates that the type being annotated has padding bytes, which -/// is illegal for `AsBytes` types. Consider reducing the alignment of some +/// is illegal for `IntoBytes` types. Consider reducing the alignment of some /// fields by using types in the [`byteorder`] module, adding explicit struct /// fields where those padding bytes would be, or using `#[repr(packed)]`. See -/// the Rust Reference's page on [type layout] for more information -/// about type layout and padding. +/// the Rust Reference's page on [type layout] for more information about type +/// layout and padding. /// /// [type layout]: https://doc.rust-lang.org/reference/type-layout.html /// /// # Analysis /// /// *This section describes, roughly, the analysis performed by this derive to -/// determine whether it is sound to implement `AsBytes` for a given type. +/// determine whether it is sound to implement `IntoBytes` for a given type. /// Unless you are modifying the implementation of this derive, or attempting to -/// manually implement `AsBytes` for a type yourself, you don't need to read +/// manually implement `IntoBytes` for a type yourself, you don't need to read /// this section.* /// /// If a type has the following properties, then this derive can implement -/// `AsBytes` for that type: +/// `IntoBytes` for that type: /// /// - If the type is a struct: /// - It must have a defined representation (`repr(C)`, `repr(transparent)`, /// or `repr(packed)`). -/// - All of its fields must be `AsBytes`. +/// - All of its fields must be `IntoBytes`. /// - Its layout must have no padding. This is always true for /// `repr(transparent)` and `repr(packed)`. For `repr(C)`, see the layout /// algorithm described in the [Rust Reference]. @@ -2592,22 +2592,23 @@ pub unsafe trait FromBytes: FromZeros { /// [Rust Reference]: https://doc.rust-lang.org/reference/type-layout.html #[cfg(any(feature = "derive", test))] #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] -pub use zerocopy_derive::AsBytes; +pub use zerocopy_derive::IntoBytes; -/// Types that can be viewed as an immutable slice of initialized bytes. +/// Types that can be converted to an immutable slice of initialized bytes. /// -/// Any `AsBytes` type can be viewed as a slice of initialized bytes of the same -/// size. This is useful for efficiently serializing structured data as raw +/// Any `IntoBytes` type can be converted to a slice of initialized bytes of the +/// same size. This is useful for efficiently serializing structured data as raw /// bytes. /// /// # Implementation /// /// **Do not implement this trait yourself!** Instead, use -/// [`#[derive(AsBytes)]`][derive] (requires the `derive` Cargo feature); e.g.: +/// [`#[derive(IntoBytes)]`][derive] (requires the `derive` Cargo feature); +/// e.g.: /// /// ``` -/// # use zerocopy_derive::AsBytes; -/// #[derive(AsBytes)] +/// # use zerocopy_derive::IntoBytes; +/// #[derive(IntoBytes)] /// #[repr(C)] /// struct MyStruct { /// # /* @@ -2615,7 +2616,7 @@ pub use zerocopy_derive::AsBytes; /// # */ /// } /// -/// #[derive(AsBytes)] +/// #[derive(IntoBytes)] /// #[repr(u8)] /// enum MyEnum { /// # Variant0, @@ -2624,7 +2625,7 @@ pub use zerocopy_derive::AsBytes; /// # */ /// } /// -/// #[derive(AsBytes)] +/// #[derive(IntoBytes)] /// #[repr(C)] /// union MyUnion { /// # variant: u8, @@ -2635,41 +2636,41 @@ pub use zerocopy_derive::AsBytes; /// ``` /// /// This derive performs a sophisticated, compile-time safety analysis to -/// determine whether a type is `AsBytes`. See the [derive +/// determine whether a type is `IntoBytes`. See the [derive /// documentation][derive] for guidance on how to interpret error messages /// produced by the derive's analysis. /// /// # Safety /// -/// *This section describes what is required in order for `T: AsBytes`, and +/// *This section describes what is required in order for `T: IntoBytes`, and /// what unsafe code may assume of such types. If you don't plan on implementing -/// `AsBytes` manually, and you don't plan on writing unsafe code that -/// operates on `AsBytes` types, then you don't need to read this section.* +/// `IntoBytes` manually, and you don't plan on writing unsafe code that +/// operates on `IntoBytes` types, then you don't need to read this section.* /// -/// If `T: AsBytes`, then unsafe code may assume that it is sound to treat any +/// If `T: IntoBytes`, then unsafe code may assume that it is sound to treat any /// `t: T` as an immutable `[u8]` of length `size_of_val(t)`. If a type is -/// marked as `AsBytes` which violates this contract, it may cause undefined +/// marked as `IntoBytes` which violates this contract, it may cause undefined /// behavior. /// -/// `#[derive(AsBytes)]` only permits [types which satisfy these +/// `#[derive(IntoBytes)]` only permits [types which satisfy these /// requirements][derive-analysis]. /// #[cfg_attr( feature = "derive", - doc = "[derive]: zerocopy_derive::AsBytes", - doc = "[derive-analysis]: zerocopy_derive::AsBytes#analysis" + doc = "[derive]: zerocopy_derive::IntoBytes", + doc = "[derive-analysis]: zerocopy_derive::IntoBytes#analysis" )] #[cfg_attr( not(feature = "derive"), - doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.AsBytes.html"), - doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.AsBytes.html#analysis"), + doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.IntoBytes.html"), + doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.IntoBytes.html#analysis"), )] -pub unsafe trait AsBytes { +pub unsafe trait IntoBytes { // The `Self: Sized` bound makes it so that this function doesn't prevent - // `AsBytes` from being object safe. Note that other `AsBytes` methods + // `IntoBytes` from being object safe. Note that other `IntoBytes` methods // prevent object safety, but those provide a benefit in exchange for object // safety. If at some point we remove those methods, change their type - // signatures, or move them out of this trait so that `AsBytes` is object + // signatures, or move them out of this trait so that `IntoBytes` is object // safe again, it's important that this function not prevent object safety. #[doc(hidden)] fn only_derive_is_allowed_to_implement_this_trait() @@ -2684,10 +2685,10 @@ pub unsafe trait AsBytes { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, NoCell)] + /// #[derive(IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2726,7 +2727,7 @@ pub unsafe trait AsBytes { // within a single allocation. // - `slf` is non-null. // - `slf` is trivially aligned to `align_of::() == 1`. - // - `Self: AsBytes` ensures that all of the bytes of `slf` are + // - `Self: IntoBytes` ensures that all of the bytes of `slf` are // initialized. // - Since `slf` is derived from `self`, and `self` is an immutable // reference, the only other references to this memory region that @@ -2750,11 +2751,11 @@ pub unsafe trait AsBytes { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// # use zerocopy_derive::*; /// /// # #[derive(Eq, PartialEq, Debug)] - /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + /// #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2802,7 +2803,7 @@ pub unsafe trait AsBytes { // within a single allocation. // - `slf` is non-null. // - `slf` is trivially aligned to `align_of::() == 1`. - // - `Self: AsBytes` ensures that all of the bytes of `slf` are + // - `Self: IntoBytes` ensures that all of the bytes of `slf` are // initialized. // - `Self: FromBytes` ensures that no write to this memory region // could result in it containing an invalid `Self`. @@ -2823,10 +2824,10 @@ pub unsafe trait AsBytes { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, NoCell)] + /// #[derive(IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2853,7 +2854,7 @@ pub unsafe trait AsBytes { /// `None` and leaves the target bytes unmodified: /// /// ``` - /// # use zerocopy::AsBytes; + /// # use zerocopy::IntoBytes; /// # let header = u128::MAX; /// let mut excessive_bytes = &mut [0u8; 128][..]; /// @@ -2883,10 +2884,10 @@ pub unsafe trait AsBytes { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, NoCell)] + /// #[derive(IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2913,7 +2914,7 @@ pub unsafe trait AsBytes { /// `None` and leaves the target bytes unmodified: /// /// ``` - /// # use zerocopy::AsBytes; + /// # use zerocopy::IntoBytes; /// # let header = u128::MAX; /// let mut insufficent_bytes = &mut [0, 0][..]; /// @@ -2940,10 +2941,10 @@ pub unsafe trait AsBytes { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, NoCell)] + /// #[derive(IntoBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2977,7 +2978,7 @@ pub unsafe trait AsBytes { /// `None` and leaves the target bytes unmodified: /// /// ``` - /// # use zerocopy::AsBytes; + /// # use zerocopy::IntoBytes; /// # let header = u128::MAX; /// let mut insufficent_bytes = &mut [0, 0][..]; /// @@ -3000,6 +3001,11 @@ pub unsafe trait AsBytes { } } +/// Deprecated: prefer [`IntoBytes`] instead. +#[deprecated(since = "0.8.0", note = "`AsBytes` was renamed to `IntoBytes`")] +#[doc(hidden)] +pub use IntoBytes as AsBytes; + /// Types with no alignment requirement. /// /// WARNING: Do not implement this trait yourself! Instead, use @@ -3036,11 +3042,11 @@ safety_comment! { /// - `NoCell`: `()` self-evidently does not contain any `UnsafeCell`s. /// - `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. + /// - `IntoBytes`: 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, FromZeros, FromBytes, AsBytes, Unaligned); + unsafe_impl!((): NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); assert_unaligned!(()); } @@ -3049,7 +3055,7 @@ safety_comment! { /// - `NoCell`: These types self-evidently do not contain any `UnsafeCell`s. /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: all bit /// patterns are valid for numeric types [1] - /// - `AsBytes`: numeric types have no padding bytes [1] + /// - `IntoBytes`: numeric types have no padding bytes [1] /// - `Unaligned` (`u8` and `i8` only): The reference [2] specifies the size /// of `u8` and `i8` as 1 byte. We also know that: /// - Alignment is >= 1 [3] @@ -3079,21 +3085,21 @@ 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, FromZeros, FromBytes, AsBytes, Unaligned); - unsafe_impl!(i8: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + unsafe_impl!(u8: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + unsafe_impl!(i8: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); assert_unaligned!(u8, i8); - 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); + unsafe_impl!(u16: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(i16: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(u32: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(i32: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(u64: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(i64: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(u128: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(i128: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(usize: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(isize: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(f32: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(f64: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); } safety_comment! { @@ -3101,15 +3107,15 @@ safety_comment! { /// - `NoCell`: `bool` self-evidently does not contain any `UnsafeCell`s. /// - `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 - /// initialized. + /// - `IntoBytes`: 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 initialized. /// - `Unaligned`: Per the reference [1], "[a]n object with the boolean type /// has a size and alignment of 1 each." /// /// [1] https://doc.rust-lang.org/reference/types/boolean.html - unsafe_impl!(bool: NoCell, FromZeros, AsBytes, Unaligned); + unsafe_impl!(bool: NoCell, FromZeros, IntoBytes, Unaligned); assert_unaligned!(bool); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` @@ -3157,12 +3163,12 @@ safety_comment! { /// 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. - /// - `AsBytes`: `char` is per reference [1] "represented as a 32-bit - /// unsigned word" (`u32`) which is `AsBytes`. Note that unlike `u32`, not - /// all bit patterns are valid for `char`. + /// - `IntoBytes`: `char` is per reference [1] "represented as a 32-bit + /// unsigned word" (`u32`) which is `IntoBytes`. Note that unlike `u32`, + /// not all bit patterns are valid for `char`. /// /// [1] https://doc.rust-lang.org/reference/types/textual.html - unsafe_impl!(char: NoCell, FromZeros, AsBytes); + unsafe_impl!(char: NoCell, FromZeros, IntoBytes); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` /// closure: @@ -3201,19 +3207,19 @@ safety_comment! { /// SAFETY: /// Per the Reference [1], `str` has the same layout as `[u8]`. /// - `NoCell`: `[u8]` does not contain any `UnsafeCell`s. - /// - `FromZeros`, `AsBytes`, `Unaligned`: `[u8]` is `FromZeros`, `AsBytes`, - /// and `Unaligned`. + /// - `FromZeros`, `IntoBytes`, `Unaligned`: `[u8]` is `FromZeros`, + /// `IntoBytes`, 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 `FromZeros` and `AsBytes`; having the same + /// - Improve safety proof for `FromZeros` and `IntoBytes`; 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, FromZeros, AsBytes, Unaligned); + unsafe_impl!(str: NoCell, FromZeros, IntoBytes, Unaligned); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` /// closure: @@ -3244,10 +3250,10 @@ safety_comment! { } safety_comment! { - // `NonZeroXxx` is `AsBytes`, but not `FromZeros` or `FromBytes`. + // `NonZeroXxx` is `IntoBytes`, but not `FromZeros` or `FromBytes`. // /// SAFETY: - /// - `AsBytes`: `NonZeroXxx` has the same layout as its associated + /// - `IntoBytes`: `NonZeroXxx` has the same layout as its associated /// primitive. Since it is the same size, this guarantees it has no /// padding - integers have no padding, and there's no room for padding /// if it can represent all of the same values except 0. @@ -3272,19 +3278,19 @@ safety_comment! { /// [2] https://doc.rust-lang.org/stable/std/num/struct.NonZeroI8.html /// TODO(https://github.com/rust-lang/rust/pull/104082): Cite documentation /// that layout is the same as primitive layout. - unsafe_impl!(NonZeroU8: NoCell, AsBytes, Unaligned); - unsafe_impl!(NonZeroI8: NoCell, AsBytes, Unaligned); + unsafe_impl!(NonZeroU8: NoCell, IntoBytes, Unaligned); + unsafe_impl!(NonZeroI8: NoCell, IntoBytes, Unaligned); assert_unaligned!(NonZeroU8, NonZeroI8); - unsafe_impl!(NonZeroU16: NoCell, AsBytes); - unsafe_impl!(NonZeroI16: NoCell, AsBytes); - unsafe_impl!(NonZeroU32: NoCell, AsBytes); - unsafe_impl!(NonZeroI32: NoCell, AsBytes); - unsafe_impl!(NonZeroU64: NoCell, AsBytes); - unsafe_impl!(NonZeroI64: NoCell, AsBytes); - unsafe_impl!(NonZeroU128: NoCell, AsBytes); - unsafe_impl!(NonZeroI128: NoCell, AsBytes); - unsafe_impl!(NonZeroUsize: NoCell, AsBytes); - unsafe_impl!(NonZeroIsize: NoCell, AsBytes); + unsafe_impl!(NonZeroU16: NoCell, IntoBytes); + unsafe_impl!(NonZeroI16: NoCell, IntoBytes); + unsafe_impl!(NonZeroU32: NoCell, IntoBytes); + unsafe_impl!(NonZeroI32: NoCell, IntoBytes); + unsafe_impl!(NonZeroU64: NoCell, IntoBytes); + unsafe_impl!(NonZeroI64: NoCell, IntoBytes); + unsafe_impl!(NonZeroU128: NoCell, IntoBytes); + unsafe_impl!(NonZeroI128: NoCell, IntoBytes); + unsafe_impl!(NonZeroUsize: NoCell, IntoBytes); + unsafe_impl!(NonZeroIsize: NoCell, IntoBytes); /// SAFETY: /// - The safety requirements for `unsafe_impl!` with an `is_bit_valid` /// closure: @@ -3326,8 +3332,8 @@ safety_comment! { safety_comment! { /// SAFETY: /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`, - /// `AsBytes`: The Rust compiler reuses `0` value to represent `None`, so - /// `size_of::>() == size_of::()`; see + /// `IntoBytes`: The Rust compiler reuses `0` value to represent `None`, + /// so `size_of::>() == size_of::()`; see /// `NonZeroXxx` documentation. /// - `Unaligned`: `NonZeroU8` and `NonZeroI8` document that /// `Option` and `Option` both have size 1. [1] [2] @@ -3343,19 +3349,19 @@ safety_comment! { /// /// TODO(https://github.com/rust-lang/rust/pull/104082): Cite documentation /// for layout guarantees. - unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); - unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); assert_unaligned!(Option, Option); - 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); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); + unsafe_impl!(Option: TryFromBytes, FromZeros, FromBytes, IntoBytes); } safety_comment! { @@ -3409,7 +3415,7 @@ safety_comment! { /// - `NoCell`: `PhantomData` has no fields. /// - `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 + /// - `IntoBytes`: Since `PhantomData` has size 0, it contains no padding /// bytes. /// - `Unaligned`: Per the preceding reference, `PhantomData` has alignment /// 1. @@ -3419,7 +3425,7 @@ safety_comment! { unsafe_impl!(T: ?Sized => TryFromBytes 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 => IntoBytes for PhantomData); unsafe_impl!(T: ?Sized => Unaligned for PhantomData); assert_unaligned!(PhantomData<()>, PhantomData, PhantomData); } @@ -3448,10 +3454,10 @@ safety_comment! { /// `T: FromBytes`, then all initialized byte sequences are valid /// instances of `Wrapping`. Thus, `impl FromBytes for Wrapping /// where T: FromBytes` is a sound impl. - /// - `AsBytes`: Since `Wrapping` has the same bit validity as `T`, if - /// `T: AsBytes`, then all valid instances of `Wrapping` have all of - /// their bytes initialized. Thus, `impl AsBytes for Wrapping where T: - /// AsBytes` is a valid impl. + /// - `IntoBytes`: Since `Wrapping` has the same bit validity as `T`, if + /// `T: IntoBytes`, then all valid instances of `Wrapping` have all of + /// their bytes initialized. Thus, `impl IntoBytes for Wrapping where + /// T: IntoBytes` is a valid impl. /// - `Unaligned`: Since `Wrapping` has the same layout as `T`, /// `Wrapping` has alignment 1 exactly when `T` does. /// @@ -3481,12 +3487,12 @@ safety_comment! { }); unsafe_impl!(T: FromZeros => FromZeros for Wrapping); unsafe_impl!(T: FromBytes => FromBytes for Wrapping); - unsafe_impl!(T: AsBytes => AsBytes for Wrapping); + unsafe_impl!(T: IntoBytes => IntoBytes for Wrapping); unsafe_impl!(T: Unaligned => Unaligned for Wrapping); assert_unaligned!(Wrapping<()>, Wrapping); } safety_comment! { - // `MaybeUninit` is `FromZeros` and `FromBytes`, but never `AsBytes` + // `MaybeUninit` is `FromZeros` and `FromBytes`, but never `IntoBytes` // since it may contain uninitialized bytes. // /// SAFETY: @@ -3518,10 +3524,10 @@ safety_comment! { /// 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`. - /// - `AsBytes`: Since it has the same layout as `T`, and since it's unsound - /// to let safe code access a `ManuallyDrop` whose inner value is + /// - `IntoBytes`: Since it has the same layout as `T`, and since it's + /// unsound to let safe code access a `ManuallyDrop` whose inner value is /// uninitialized, safe code can only ever access a `ManuallyDrop` whose - /// contents are a valid `T`. Since `T: AsBytes`, this means that safe + /// contents are a valid `T`. Since `T: IntoBytes`, this means that safe /// code can only ever access a `ManuallyDrop` with all initialized bytes. /// - `Unaligned`: `ManuallyDrop` has the same layout (and thus alignment) /// as `T`, and `T: Unaligned` guarantees that that alignment is 1. @@ -3539,15 +3545,15 @@ safety_comment! { unsafe_impl!(T: ?Sized + NoCell => NoCell 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 + IntoBytes => IntoBytes for ManuallyDrop); unsafe_impl!(T: ?Sized + Unaligned => Unaligned for ManuallyDrop); assert_unaligned!(ManuallyDrop<()>, ManuallyDrop); } safety_comment! { /// SAFETY: - /// - `FromZeros`, `FromBytes`, `AsBytes`: `UnsafeCell` has the same bit - /// validity as `T` [1], and so implements these traits exactly when `T` - /// does. + /// - `FromZeros`, `FromBytes`, `IntoBytes`: `UnsafeCell` has the same + /// bit validity as `T` [1], and so implements these traits exactly when + /// `T` does. /// - `Unaligned`: `UnsafeCell` has the same representation as `T`, and /// so has alignment 1 exactly when `T` does. [2] /// @@ -3559,7 +3565,7 @@ safety_comment! { /// type `T`. unsafe_impl!(T: ?Sized + FromZeros => FromZeros for UnsafeCell); unsafe_impl!(T: ?Sized + FromBytes => FromBytes for UnsafeCell); - unsafe_impl!(T: ?Sized + AsBytes => AsBytes for UnsafeCell); + unsafe_impl!(T: ?Sized + IntoBytes => IntoBytes for UnsafeCell); unsafe_impl!(T: ?Sized + Unaligned => Unaligned for UnsafeCell); assert_unaligned!(UnsafeCell<()>, UnsafeCell); } @@ -3579,7 +3585,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`, `FromZeros`, `FromBytes`, and - /// `AsBytes` if `T` is (respectively). Furthermore, since an array/slice + /// `IntoBytes` if `T` is (respectively). Furthermore, since an array/slice /// has "the same alignment of `T`", `[T]` and `[T; N]` are `Unaligned` if /// `T` is. /// @@ -3590,7 +3596,7 @@ safety_comment! { unsafe_impl!(const N: usize, T: NoCell => NoCell 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: IntoBytes => IntoBytes for [T; N]); unsafe_impl!(const N: usize, T: Unaligned => Unaligned for [T; N]); assert_unaligned!([(); 0], [(); 1], [u8; 0], [u8; 1]); unsafe_impl!(T: NoCell => NoCell for [T]); @@ -3632,7 +3638,7 @@ safety_comment! { }); unsafe_impl!(T: FromZeros => FromZeros for [T]); unsafe_impl!(T: FromBytes => FromBytes for [T]); - unsafe_impl!(T: AsBytes => AsBytes for [T]); + unsafe_impl!(T: IntoBytes => IntoBytes for [T]); unsafe_impl!(T: Unaligned => Unaligned for [T]); } safety_comment! { @@ -3642,9 +3648,9 @@ safety_comment! { /// pointer is considered "null". [1] No operations which require /// provenance are legal on null pointers, so this is not a footgun. /// - /// NOTE(#170): Implementing `FromBytes` and `AsBytes` for raw pointers + /// NOTE(#170): Implementing `FromBytes` and `IntoBytes` for raw pointers /// would be sound, but carries provenance footguns. We want to support - /// `FromBytes` and `AsBytes` for raw pointers eventually, but we are + /// `FromBytes` and `IntoBytes` for raw pointers eventually, but we are /// holding off until we can figure out how to address those footguns. /// /// [1] TODO(https://github.com/rust-lang/rust/pull/116988): Cite the @@ -3716,9 +3722,9 @@ 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`, `FromZeros`, `FromBytes`, or `AsBytes`, that SIMD -// type is also `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, or -// `AsBytes` respectively. +// `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, or `IntoBytes`, that +// SIMD type is also `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`, or +// `IntoBytes` respectively. // - Since no upper bound is placed on the alignment, no SIMD type can be // guaranteed to be `Unaligned`. // @@ -3729,7 +3735,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`, `FromZeros`, `FromBytes`, or `AsBytes` is next to zero, as +// `TryFromBytes`, `FromZeros`, `FromBytes`, or `IntoBytes` 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. @@ -3740,12 +3746,12 @@ safety_comment! { #[cfg_attr(doc_cfg, doc(cfg(feature = "simd")))] mod simd { /// Defines a module which implements `TryFromBytes`, `FromZeros`, - /// `FromBytes`, and `AsBytes` for a set of types from a module in + /// `FromBytes`, and `IntoBytes` 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 `FromZeros`, `FromBytes`, and `AsBytes` for. + /// to implement `FromZeros`, `FromBytes`, and `IntoBytes` 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. @@ -3761,7 +3767,7 @@ mod simd { safety_comment! { /// SAFETY: /// See comment on module definition for justification. - $( unsafe_impl!($typ: NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes); )* + $( unsafe_impl!($typ: NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes); )* } } }; @@ -3818,7 +3824,7 @@ mod simd { /// size. /// /// The expression `$e` must have a concrete type, `T`, which implements -/// `AsBytes`. The `transmute!` expression must also have a concrete type, `U` +/// `IntoBytes`. The `transmute!` expression must also have a concrete type, `U` /// (`U` is inferred from the calling context), and `U` must implement /// `FromBytes`. /// @@ -3847,11 +3853,11 @@ macro_rules! transmute { let e = $e; if false { // This branch, though never taken, ensures that the type of `e` is - // `AsBytes` and that the type of this macro invocation expression + // `IntoBytes` and that the type of this macro invocation expression // is `FromBytes`. - struct AssertIsAsBytes(T); - let _ = AssertIsAsBytes(e); + struct AssertIsIntoBytes(T); + let _ = AssertIsIntoBytes(e); struct AssertIsFromBytes(U); #[allow(unused, unreachable_code)] @@ -3860,7 +3866,7 @@ macro_rules! transmute { } else { // SAFETY: `core::mem::transmute` ensures that the type of `e` and // the type of this macro invocation expression have the same size. - // We know this transmute is safe thanks to the `AsBytes` and + // We know this transmute is safe thanks to the `IntoBytes` and // `FromBytes` bounds enforced by the `false` branch. // // We use this reexport of `core::mem::transmute` because we know it @@ -3884,9 +3890,10 @@ macro_rules! transmute { /// immutable reference of another type of the same size. /// /// The expression `$e` must have a concrete type, `&T` or `&mut T`, where `T: -/// Sized + AsBytes`. The `transmute_ref!` expression must also have a concrete -/// type, `&U` (`U` is inferred from the calling context), where `U: Sized + -/// FromBytes`. It must be the case that `align_of::() >= align_of::()`. +/// Sized + IntoBytes`. The `transmute_ref!` expression must also have a +/// concrete type, `&U` (`U` is inferred from the calling context), where `U: +/// Sized + FromBytes`. It must be the case that `align_of::() >= +/// align_of::()`. /// /// The lifetime of the input type, `&T` or `&mut T`, must be the same as or /// outlive the lifetime of the output type, `&U`. @@ -3944,19 +3951,19 @@ macro_rules! transmute_ref { #[allow(unused, clippy::diverging_sub_expression)] if false { // This branch, though never taken, ensures that the type of `e` is - // `&T` where `T: 't + Sized + AsBytes + NoCell`, that the type of + // `&T` where `T: 't + Sized + IntoBytes + NoCell`, that the type of // this macro expression is `&U` where `U: 'u + Sized + FromBytes + // NoCell`, and that `'t` outlives `'u`. struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); - struct AssertSrcIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertSrcIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); struct AssertSrcIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); struct AssertDstIsFromBytes<'a, U: ?::core::marker::Sized + $crate::FromBytes>(&'a U); struct AssertDstIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); let _ = AssertSrcIsSized(e); - let _ = AssertSrcIsAsBytes(e); + let _ = AssertSrcIsIntoBytes(e); let _ = AssertSrcIsNoCell(e); if true { @@ -3992,8 +3999,8 @@ macro_rules! transmute_ref { &u } else { // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `Src: AsBytes + NoCell` and `Dst: FromBytes + - // NoCell` thanks to the uses of `AssertSrcIsAsBytes`, + // - We know that `Src: IntoBytes + NoCell` and `Dst: FromBytes + + // NoCell` thanks to the uses of `AssertSrcIsIntoBytes`, // `AssertSrcIsNoCell`, `AssertDstIsFromBytes`, and // `AssertDstIsNoCell`` above. // - We know that `size_of::() == size_of::()` thanks to @@ -4009,7 +4016,7 @@ macro_rules! transmute_ref { /// another type of the same size. /// /// The expression `$e` must have a concrete type, `&mut T`, where `T: Sized + -/// AsBytes`. The `transmute_mut!` expression must also have a concrete type, +/// IntoBytes`. The `transmute_mut!` expression must also have a concrete type, /// `&mut U` (`U` is inferred from the calling context), where `U: Sized + /// FromBytes`. It must be the case that `align_of::() >= align_of::()`. /// @@ -4072,9 +4079,9 @@ macro_rules! transmute_mut { #[allow(unused, clippy::diverging_sub_expression)] if false { // This branch, though never taken, ensures that the type of `e` is - // `&mut T` where `T: 't + Sized + FromBytes + AsBytes + NoCell` and - // that the type of this macro expression is `&mut U` where `U: 'u + - // Sized + FromBytes + AsBytes + NoCell`. + // `&mut T` where `T: 't + Sized + FromBytes + IntoBytes + NoCell` + // and that the type of this macro expression is `&mut U` where `U: + // 'u + Sized + FromBytes + IntoBytes + NoCell`. // We use immutable references here rather than mutable so that, if // this macro is used in a const context (in which, as of this @@ -4083,11 +4090,11 @@ macro_rules! transmute_mut { // internals of this macro. struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); struct AssertSrcIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertSrcIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertSrcIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); struct AssertSrcIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); struct AssertDstIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertDstIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertDstIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); struct AssertDstIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); if true { @@ -4095,7 +4102,7 @@ macro_rules! transmute_mut { } else if true { let _ = AssertSrcIsFromBytes(&*e); } else if true { - let _ = AssertSrcIsAsBytes(&*e); + let _ = AssertSrcIsIntoBytes(&*e); } else { let _ = AssertSrcIsNoCell(&*e); } @@ -4110,7 +4117,7 @@ macro_rules! transmute_mut { &mut *u.0 } else if true { #[allow(unused, unreachable_code)] - let u = AssertDstIsAsBytes(loop {}); + let u = AssertDstIsIntoBytes(loop {}); &mut *u.0 } else { #[allow(unused, unreachable_code)] @@ -4137,11 +4144,11 @@ macro_rules! transmute_mut { &mut u } else { // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `Src: FromBytes + AsBytes + NoCell` and `Dst: - // FromBytes + AsBytes + NoCell` thanks to the uses of - // `AssertSrcIsFromBytes`, `AssertSrcIsAsBytes`, + // - We know that `Src: FromBytes + IntoBytes + NoCell` and `Dst: + // FromBytes + IntoBytes + NoCell` thanks to the uses of + // `AssertSrcIsFromBytes`, `AssertSrcIsIntoBytes`, // `AssertSrcIsNoCell`, `AssertDstIsFromBytes`, - // `AssertDstIsAsBytes`, and `AssertDstIsNoCell` above. + // `AssertDstIsIntoBytes`, and `AssertDstIsNoCell` above. // - We know that `size_of::() == size_of::()` thanks to // the use of `assert_size_eq!` above. // - We know that `align_of::() >= align_of::()` thanks to @@ -4213,9 +4220,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, FromZeros, NoCell, Ref, Unaligned}; +/// use zerocopy::{IntoBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeros, NoCell, Ref, Unaligned}; /// -/// #[derive(FromZeros, FromBytes, AsBytes, NoCell, Unaligned)] +/// #[derive(FromZeros, FromBytes, IntoBytes, NoCell, Unaligned)] /// #[repr(C)] /// struct UdpHeader { /// src_port: [u8; 2], @@ -4807,7 +4814,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { /// Converts this `Ref` into a mutable reference. /// @@ -4847,7 +4854,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { /// Converts this `Ref` into a mutable slice reference. /// @@ -4949,7 +4956,7 @@ where impl Ref where B: ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { /// Creates a mutable reference to `T` with a specific lifetime. /// @@ -5003,7 +5010,7 @@ where impl Ref where B: ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { /// Creates a mutable reference to `[T]` with a specific lifetime. /// @@ -5073,7 +5080,7 @@ where impl Ref where B: ByteSliceMut, - T: AsBytes, + T: IntoBytes, { /// Writes the bytes of `t` and then forgets `t`. #[inline] @@ -5082,7 +5089,7 @@ where // at least `size_of::()` bytes long, and that it is at least as // aligned as `align_of::()`. Writing `t` to the buffer will allow // all of the bytes of `t` to be accessed as a `[u8]`, but because `T: - // AsBytes`, we know this is sound. + // IntoBytes`, we know this is sound. unsafe { ptr::write(self.0.as_mut_ptr().cast::(), t) } } } @@ -5108,7 +5115,7 @@ where impl DerefMut for Ref where B: ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { #[inline] fn deref_mut(&mut self) -> &mut T { @@ -5143,7 +5150,7 @@ where impl DerefMut for Ref where B: ByteSliceMut, - T: FromBytes + AsBytes + NoCell, + T: FromBytes + IntoBytes + NoCell, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -5647,7 +5654,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, FromZeros, FromBytes, AsBytes, Unaligned, NoCell)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, IntoBytes, Unaligned, NoCell)] #[repr(transparent)] struct Unsized([u8]); @@ -6940,7 +6947,7 @@ mod tests { assert_eq!(u64::read_from_prefix(&bytes_with_suffix[..]), Some(0)); assert_eq!(u64::read_from_suffix(&bytes_with_suffix[..]), Some(VAL)); - // Test `AsBytes::{write_to, write_to_prefix, write_to_suffix}`. + // Test `IntoBytes::{write_to, write_to_prefix, write_to_suffix}`. let mut bytes = [0u8; 8]; assert_eq!(VAL.write_to(&mut bytes[..]), Some(())); @@ -6967,7 +6974,7 @@ mod tests { // Test that the source expression's value is forgotten rather than // dropped. - #[derive(AsBytes)] + #[derive(IntoBytes)] #[repr(transparent)] struct PanicOnDrop(()); impl Drop for PanicOnDrop { @@ -7656,8 +7663,8 @@ mod tests { } #[test] - fn test_as_bytes_methods() { - /// Run a series of tests by calling `AsBytes` methods on `t`. + fn test_to_methods() { + /// Run a series of tests by calling `IntoBytes` methods on `t`. /// /// `bytes` is the expected byte sequence returned from `t.as_bytes()` /// before `t` has been modified. `post_mutation` is the expected @@ -7665,7 +7672,7 @@ mod tests { /// has had its bits flipped (by applying `^= 0xFF`). /// /// `N` is the size of `t` in bytes. - fn test( + fn test( t: &mut T, bytes: &[u8], post_mutation: &T, @@ -7722,7 +7729,7 @@ mod tests { assert_eq!(too_many_bytes[0], 123); } - #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes, NoCell)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, IntoBytes, NoCell)] #[repr(C)] struct Foo { a: u32, @@ -7751,7 +7758,7 @@ mod tests { #[test] fn test_array() { - #[derive(FromZeros, FromBytes, AsBytes, NoCell)] + #[derive(FromZeros, FromBytes, IntoBytes, NoCell)] #[repr(C)] struct Foo { a: [u16; 33], @@ -7815,24 +7822,24 @@ mod tests { #[test] fn test_transparent_packed_generic_struct() { - #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + #[derive(IntoBytes, FromZeros, FromBytes, Unaligned)] #[repr(transparent)] struct Foo { _t: T, _phantom: PhantomData<()>, } - assert_impl_all!(Foo: FromZeros, FromBytes, AsBytes); + assert_impl_all!(Foo: FromZeros, FromBytes, IntoBytes); assert_impl_all!(Foo: Unaligned); - #[derive(AsBytes, FromZeros, FromBytes, Unaligned)] + #[derive(IntoBytes, FromZeros, FromBytes, Unaligned)] #[repr(packed)] struct Bar { _t: T, _u: U, } - assert_impl_all!(Bar: FromZeros, FromBytes, AsBytes, Unaligned); + assert_impl_all!(Bar: FromZeros, FromBytes, IntoBytes, Unaligned); } #[test] @@ -7964,7 +7971,7 @@ mod tests { // unsound (ie, if our `is_bit_valid` impl is buggy). // // The following code was tried, but it doesn't work because - // a) some types are not `AsBytes` and, b) some types are + // a) some types are not `IntoBytes` and, b) some types are // not `Sized`. // // let r = <$ty as TryFromBytes>::try_from_ref(val.as_bytes()).unwrap(); @@ -8008,51 +8015,51 @@ 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, 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); - assert_impls!(NonZeroI32: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroU64: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroI64: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroU128: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroI128: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroUsize: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !Unaligned); - assert_impls!(NonZeroIsize: KnownLayout, NoCell, TryFromBytes, AsBytes, !FromBytes, !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); + assert_impls!((): KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(u8: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(i8: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(u16: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(i16: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(u32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(i32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(u64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(i64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(u128: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(i128: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(usize: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(isize: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(f32: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(f64: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + + assert_impls!(bool: KnownLayout, NoCell, TryFromBytes, FromZeros, IntoBytes, Unaligned, !FromBytes); + assert_impls!(char: KnownLayout, NoCell, TryFromBytes, FromZeros, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(str: KnownLayout, NoCell, TryFromBytes, FromZeros, IntoBytes, Unaligned, !FromBytes); + + assert_impls!(NonZeroU8: KnownLayout, NoCell, TryFromBytes, IntoBytes, Unaligned, !FromZeros, !FromBytes); + assert_impls!(NonZeroI8: KnownLayout, NoCell, TryFromBytes, IntoBytes, Unaligned, !FromZeros, !FromBytes); + assert_impls!(NonZeroU16: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroI16: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroU32: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroI32: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroU64: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroI64: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroU128: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroI128: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroUsize: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + assert_impls!(NonZeroIsize: KnownLayout, NoCell, TryFromBytes, IntoBytes, !FromBytes, !Unaligned); + + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); // Implements none of the ZC traits. struct NotZerocopy; @@ -8070,55 +8077,55 @@ mod tests { ) -> (NotZerocopy, NotZerocopy); #[cfg(feature = "alloc")] - 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, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, NoCell, FromZeros, !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>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); - assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); - - assert_impls!(MaybeUninit: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, Unaligned, !AsBytes); - assert_impls!(MaybeUninit: KnownLayout, TryFromBytes, FromZeros, FromBytes, !NoCell, !AsBytes, !Unaligned); - assert_impls!(MaybeUninit>: KnownLayout, TryFromBytes, FromZeros, FromBytes, Unaligned, !NoCell, !AsBytes); - - assert_impls!(Wrapping: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); - assert_impls!(Wrapping: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Wrapping>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); - - 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); + assert_impls!(Option>>: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option<&'static UnsafeCell>: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option<&'static [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option<&'static mut UnsafeCell>: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option<&'static mut [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option>>: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + + assert_impls!(PhantomData: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(PhantomData>: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(PhantomData<[u8]>: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + + assert_impls!(ManuallyDrop: KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned, !TryFromBytes); + assert_impls!(ManuallyDrop<[u8]>: KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned, !TryFromBytes); + assert_impls!(ManuallyDrop: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(ManuallyDrop<[NotZerocopy]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(ManuallyDrop>: KnownLayout, FromZeros, FromBytes, IntoBytes, Unaligned, !NoCell, !TryFromBytes); + assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: KnownLayout, FromZeros, FromBytes, IntoBytes, Unaligned, !NoCell, !TryFromBytes); + + assert_impls!(MaybeUninit: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, Unaligned, !IntoBytes); + assert_impls!(MaybeUninit: KnownLayout, TryFromBytes, FromZeros, FromBytes, !NoCell, !IntoBytes, !Unaligned); + assert_impls!(MaybeUninit>: KnownLayout, TryFromBytes, FromZeros, FromBytes, Unaligned, !NoCell, !IntoBytes); + + assert_impls!(Wrapping: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!(Wrapping: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(Wrapping>: KnownLayout, FromZeros, FromBytes, IntoBytes, Unaligned, !NoCell, !TryFromBytes); + + assert_impls!(Unalign: KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned, !TryFromBytes); + assert_impls!(Unalign: Unaligned, !NoCell, !KnownLayout, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes); + + assert_impls!([u8]: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned); + assert_impls!([bool]: KnownLayout, NoCell, TryFromBytes, FromZeros, IntoBytes, Unaligned, !FromBytes); + assert_impls!([NotZerocopy]: !KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!([u8; 0]: KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned, !TryFromBytes); + assert_impls!([NotZerocopy; 0]: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!([u8; 1]: KnownLayout, NoCell, FromZeros, FromBytes, IntoBytes, Unaligned, !TryFromBytes); + assert_impls!([NotZerocopy; 1]: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + + assert_impls!(*const NotZerocopy: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(*mut NotZerocopy: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(*const [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(*mut [NotZerocopy]: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(*const dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); + assert_impls!(*mut dyn Debug: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !IntoBytes, !Unaligned); #[cfg(feature = "simd")] { @@ -8128,7 +8135,7 @@ mod tests { { use core::arch::$arch::{$($typ),*}; use crate::*; - $( assert_impls!($typ: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, !Unaligned); )* + $( assert_impls!($typ: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, !Unaligned); )* } }; } diff --git a/src/macro_util.rs b/src/macro_util.rs index 7bedae2fa8..59dddb5a82 100644 --- a/src/macro_util.rs +++ b/src/macro_util.rs @@ -11,9 +11,9 @@ //! These are defined here `zerocopy` rather than in code generated by macros or //! by `zerocopy-derive` so that they can be compiled once rather than //! recompiled for every invocation (e.g., if they were defined in generated -//! code, then deriving `AsBytes` and `FromBytes` on three different types would -//! result in the code in question being emitted and compiled six different -//! times). +//! code, then deriving `IntoBytes` and `FromBytes` on three different types +//! would result in the code in question being emitted and compiled six +//! different times). #![allow(missing_debug_implementations)] @@ -342,7 +342,7 @@ macro_rules! assert_size_eq { /// # Safety /// /// The caller must guarantee that: -/// - `Src: AsBytes + NoCell` +/// - `Src: IntoBytes + NoCell` /// - `Dst: FromBytes + NoCell` /// - `size_of::() == size_of::()` /// - `align_of::() >= align_of::()` @@ -355,7 +355,7 @@ pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( // SAFETY: // - We know that it is sound to view the target type of the input reference // (`Src`) as the target type of the output reference (`Dst`) because the - // caller has guaranteed that `Src: AsBytes`, `Dst: FromBytes`, and + // caller has guaranteed that `Src: IntoBytes`, `Dst: FromBytes`, and // `size_of::() == size_of::()`. // - We know that there are no `UnsafeCell`s, and thus we don't have to // worry about `UnsafeCell` overlap, because `Src: NoCell` and `Dst: @@ -372,8 +372,8 @@ pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( /// # Safety /// /// The caller must guarantee that: -/// - `Src: FromBytes + AsBytes + NoCell` -/// - `Dst: FromBytes + AsBytes + NoCell` +/// - `Src: FromBytes + IntoBytes + NoCell` +/// - `Dst: FromBytes + IntoBytes + NoCell` /// - `size_of::() == size_of::()` /// - `align_of::() >= align_of::()` // TODO(#686): Consider removing the `NoCell` requirement. @@ -387,7 +387,7 @@ pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( // - We know that it is sound to view the target type of the input reference // (`Src`) as the target type of the output reference (`Dst`) and // vice-versa because the caller has guaranteed that `Src: FromBytes + - // AsBytes`, `Dst: FromBytes + AsBytes`, and `size_of::() == + // IntoBytes`, `Dst: FromBytes + IntoBytes`, and `size_of::() == // size_of::()`. // - We know that there are no `UnsafeCell`s, and thus we don't have to // worry about `UnsafeCell` overlap, because `Src: NoCell` diff --git a/src/macros.rs b/src/macros.rs index d897261220..c3d473e7dc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -272,7 +272,7 @@ macro_rules! opt_fn { /// /// ```rust,ignore /// // Note that these derives are gated by `feature = "derive"` -/// #[cfg_attr(any(feature = "derive", test), derive(FromZeros, FromBytes, AsBytes, Unaligned))] +/// #[cfg_attr(any(feature = "derive", test), derive(FromZeros, FromBytes, IntoBytes, Unaligned))] /// #[repr(transparent)] /// struct Wrapper(T); /// @@ -282,7 +282,7 @@ macro_rules! opt_fn { /// /// zerocopy trait if `T` implements that trait. /// 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: IntoBytes => IntoBytes for Wrapper); /// impl_or_verify!(T: Unaligned => Unaligned for Wrapper); /// } /// ``` diff --git a/src/util.rs b/src/util.rs index 3e35f1592f..48190f7be8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -768,7 +768,7 @@ pub(crate) mod testutil { NoCell, FromZeros, FromBytes, - AsBytes, + IntoBytes, Eq, PartialEq, Ord, diff --git a/src/wrappers.rs b/src/wrappers.rs index b06e109bf8..be5e0fedc1 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, FromZeros, FromBytes, AsBytes, Unaligned) + derive(NoCell, KnownLayout, FromZeros, FromBytes, IntoBytes, Unaligned) )] #[repr(C, packed)] pub struct Unalign(T); @@ -73,14 +73,14 @@ 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 - /// `FromZeros`, `FromBytes`, or `AsBytes` exactly when `T` is as well. + /// `FromZeros`, `FromBytes`, or `IntoBytes` 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: FromZeros => FromZeros for Unalign); impl_or_verify!(T: FromBytes => FromBytes for Unalign); - impl_or_verify!(T: AsBytes => AsBytes for Unalign); + impl_or_verify!(T: IntoBytes => IntoBytes for Unalign); } // Note that `Unalign: Clone` only if `T: Copy`. Since the inner `T` may not be diff --git a/tests/ui-msrv/invalid-impls/invalid-impls.stderr b/tests/ui-msrv/invalid-impls/invalid-impls.stderr index 506a8a8a13..e4656f9279 100644 --- a/tests/ui-msrv/invalid-impls/invalid-impls.stderr +++ b/tests/ui-msrv/invalid-impls/invalid-impls.stderr @@ -12,7 +12,7 @@ error[E0277]: the trait bound `T: zerocopy::TryFromBytes` is not satisfied note: required because of the requirements on the impl of `zerocopy::TryFromBytes` for `Foo` --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs @@ -44,7 +44,7 @@ error[E0277]: the trait bound `T: FromZeroes` is not satisfied note: required because of the requirements on the impl of `FromZeroes` for `Foo` --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:24 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs @@ -76,7 +76,7 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied note: required because of the requirements on the impl of `zerocopy::FromBytes` for `Foo` --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:35 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs @@ -94,22 +94,22 @@ help: consider restricting type parameter `T` 28 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo); | +++++++++++++++++++++ -error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied +error[E0277]: the trait bound `T: AsBytes` is not satisfied --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | | impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {} - | ^^^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T` + | ^^^^^^^^ the trait `AsBytes` is not implemented for `T` | ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:1 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ---------------------------------------- in this macro invocation +29 | impl_or_verify!(T => IntoBytes for Foo); + | ------------------------------------------ in this macro invocation | -note: required because of the requirements on the impl of `zerocopy::AsBytes` for `Foo` +note: required because of the requirements on the impl of `AsBytes` for `Foo` --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:46 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | @@ -118,13 +118,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:1 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ---------------------------------------- in this macro invocation +29 | impl_or_verify!(T => IntoBytes 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` | -29 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo); - | +++++++++++++++++++ +29 | impl_or_verify!(T: zerocopy::IntoBytes => IntoBytes for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied --> tests/ui-msrv/invalid-impls/../../../src/macros.rs @@ -138,10 +138,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:55 + --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:57 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::Subtrait` --> tests/ui-msrv/invalid-impls/../../../src/macros.rs | diff --git a/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs b/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs deleted file mode 120000 index 2f968ddb0b..0000000000 --- a/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-dst-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-dst-not-intobytes.rs b/tests/ui-msrv/transmute-mut-dst-not-intobytes.rs new file mode 120000 index 0000000000..34e3307388 --- /dev/null +++ b/tests/ui-msrv/transmute-mut-dst-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-dst-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr b/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr similarity index 69% rename from tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr rename to tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr index 7e2dd78b8f..8dc9ba1cd3 100644 --- a/tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr +++ b/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr @@ -1,12 +1,12 @@ error[E0277]: the trait bound `Dst: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-mut-dst-not-asbytes.rs:24:36 + --> tests/ui-msrv/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Dst` | -note: required by a bound in `AssertDstIsAsBytes` - --> tests/ui-msrv/transmute-mut-dst-not-asbytes.rs:24:36 +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-msrv/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-src-not-asbytes.rs b/tests/ui-msrv/transmute-mut-src-not-asbytes.rs deleted file mode 120000 index e98230daac..0000000000 --- a/tests/ui-msrv/transmute-mut-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-not-intobytes.rs b/tests/ui-msrv/transmute-mut-src-not-intobytes.rs new file mode 120000 index 0000000000..0086f2a962 --- /dev/null +++ b/tests/ui-msrv/transmute-mut-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-not-asbytes.stderr b/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr similarity index 69% rename from tests/ui-msrv/transmute-mut-src-not-asbytes.stderr rename to tests/ui-msrv/transmute-mut-src-not-intobytes.stderr index 4056975829..22a4869587 100644 --- a/tests/ui-msrv/transmute-mut-src-not-asbytes.stderr +++ b/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr @@ -1,25 +1,25 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ptr-to-usize.stderr b/tests/ui-msrv/transmute-ptr-to-usize.stderr index 06b1bbaf2d..d8ba8576f5 100644 --- a/tests/ui-msrv/transmute-ptr-to-usize.stderr +++ b/tests/ui-msrv/transmute-ptr-to-usize.stderr @@ -10,11 +10,11 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied and $N others -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied @@ -29,9 +29,9 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied and $N others -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-src-not-asbytes.rs b/tests/ui-msrv/transmute-ref-src-not-asbytes.rs deleted file mode 120000 index d8768b7bb4..0000000000 --- a/tests/ui-msrv/transmute-ref-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-not-intobytes.rs b/tests/ui-msrv/transmute-ref-src-not-intobytes.rs new file mode 120000 index 0000000000..6602ca352d --- /dev/null +++ b/tests/ui-msrv/transmute-ref-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr b/tests/ui-msrv/transmute-ref-src-not-intobytes.stderr similarity index 69% rename from tests/ui-msrv/transmute-ref-src-not-asbytes.stderr rename to tests/ui-msrv/transmute-ref-src-not-intobytes.stderr index a49128cea0..a38b21813f 100644 --- a/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-msrv/transmute-ref-src-not-intobytes.stderr @@ -1,25 +1,25 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-src-not-asbytes.rs b/tests/ui-msrv/transmute-src-not-asbytes.rs deleted file mode 120000 index 999d9cea6a..0000000000 --- a/tests/ui-msrv/transmute-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-src-not-intobytes.rs b/tests/ui-msrv/transmute-src-not-intobytes.rs new file mode 120000 index 0000000000..7dd68a7037 --- /dev/null +++ b/tests/ui-msrv/transmute-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-src-not-asbytes.stderr b/tests/ui-msrv/transmute-src-not-intobytes.stderr similarity index 71% rename from tests/ui-msrv/transmute-src-not-asbytes.stderr rename to tests/ui-msrv/transmute-src-not-intobytes.stderr index 93eeda0c26..55df15f9ca 100644 --- a/tests/ui-msrv/transmute-src-not-asbytes.stderr +++ b/tests/ui-msrv/transmute-src-not-intobytes.stderr @@ -1,25 +1,25 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-msrv/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-msrv/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-msrv/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-msrv/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/invalid-impls/invalid-impls.rs b/tests/ui-nightly/invalid-impls/invalid-impls.rs index 25c7625213..f849189e66 100644 --- a/tests/ui-nightly/invalid-impls/invalid-impls.rs +++ b/tests/ui-nightly/invalid-impls/invalid-impls.rs @@ -19,12 +19,12 @@ use zerocopy_derive::*; fn main() {} -#[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +#[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] #[repr(transparent)] struct Foo(T); impl_or_verify!(T => TryFromBytes 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 => IntoBytes 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 e21986c525..25c73cd2f0 100644 --- a/tests/ui-nightly/invalid-impls/invalid-impls.stderr +++ b/tests/ui-nightly/invalid-impls/invalid-impls.stderr @@ -7,7 +7,7 @@ error[E0277]: the trait bound `T: zerocopy::TryFromBytes` is not satisfied note: required for `Foo` to implement `zerocopy::TryFromBytes` --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs @@ -34,7 +34,7 @@ error[E0277]: the trait bound `T: FromZeroes` is not satisfied note: required for `Foo` to implement `FromZeroes` --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:24 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs @@ -61,7 +61,7 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied note: required for `Foo` to implement `zerocopy::FromBytes` --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:35 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs @@ -79,17 +79,17 @@ help: consider restricting type parameter `T` 28 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo); | +++++++++++++++++++++ -error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied - --> tests/ui-nightly/invalid-impls/invalid-impls.rs:29:34 +error[E0277]: the trait bound `T: AsBytes` is not satisfied + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:29:36 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T` +29 | impl_or_verify!(T => IntoBytes for Foo); + | ^^^^^^ the trait `AsBytes` is not implemented for `T` | -note: required for `Foo` to implement `zerocopy::AsBytes` +note: required for `Foo` to implement `AsBytes` --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:46 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-nightly/invalid-impls/../../../src/macros.rs | @@ -98,13 +98,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:29:1 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ---------------------------------------- in this macro invocation - = note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) +29 | impl_or_verify!(T => IntoBytes for Foo); + | ------------------------------------------ in this macro invocation + = note: this error originates in the derive macro `IntoBytes` 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` | -29 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo); - | +++++++++++++++++++ +29 | impl_or_verify!(T: zerocopy::IntoBytes => IntoBytes for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied --> tests/ui-nightly/invalid-impls/invalid-impls.rs:30:36 @@ -113,10 +113,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:55 + --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:57 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, 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-generic.rs b/tests/ui-nightly/transmute-mut-dst-generic.rs index fc5eacf99d..8fcd22c281 100644 --- a/tests/ui-nightly/transmute-mut-dst-generic.rs +++ b/tests/ui-nightly/transmute-mut-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell}; +use zerocopy::{transmute_mut, FromBytes, IntoBytes, NoCell}; fn main() {} -fn transmute_mut(u: &mut u8) -> &mut T { +fn transmute_mut(u: &mut u8) -> &mut T { // `transmute_mut!` requires the destination type to be concrete. transmute_mut!(u) } diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs index 72f97d86d1..03f156decf 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs b/tests/ui-nightly/transmute-mut-dst-not-intobytes.rs similarity index 86% rename from tests/ui-nightly/transmute-mut-dst-not-asbytes.rs rename to tests/ui-nightly/transmute-mut-dst-not-intobytes.rs index 16ea706dec..57647b83b7 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-intobytes.rs @@ -12,7 +12,7 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Src; @@ -20,5 +20,5 @@ struct Src; #[repr(C)] struct Dst; -// `transmute_mut` requires that the destination type implements `AsBytes` +// `transmute_mut` requires that the destination type implements `IntoBytes` const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); diff --git a/tests/ui-stable/transmute-mut-dst-not-asbytes.stderr b/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr similarity index 79% rename from tests/ui-stable/transmute-mut-dst-not-asbytes.stderr rename to tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr index f3cacca09d..f5e467c2b6 100644 --- a/tests/ui-stable/transmute-mut-dst-not-asbytes.stderr +++ b/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Dst: AsBytes` is not satisfied - --> tests/ui-stable/transmute-mut-dst-not-asbytes.rs:24:36 + --> tests/ui-nightly/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,9 +17,9 @@ error[E0277]: the trait bound `Dst: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertDstIsAsBytes` - --> tests/ui-stable/transmute-mut-dst-not-asbytes.rs:24:36 +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-nightly/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-not-nocell.rs b/tests/ui-nightly/transmute-mut-dst-not-nocell.rs index 3a8eb7b361..85984a8137 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-nocell.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-nocell.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.rs b/tests/ui-nightly/transmute-mut-src-dst-generic.rs index 76bc520f52..71412783b0 100644 --- a/tests/ui-nightly/transmute-mut-src-dst-generic.rs +++ b/tests/ui-nightly/transmute-mut-src-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell}; +use zerocopy::{transmute_mut, FromBytes, IntoBytes, NoCell}; fn main() {} -fn transmute_mut( +fn transmute_mut( t: &mut T, ) -> &mut U { // `transmute_mut!` requires the source and destination types to be diff --git a/tests/ui-nightly/transmute-mut-src-generic.rs b/tests/ui-nightly/transmute-mut-src-generic.rs index aa006a854e..202ca22cf1 100644 --- a/tests/ui-nightly/transmute-mut-src-generic.rs +++ b/tests/ui-nightly/transmute-mut-src-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell}; +use zerocopy::{transmute_mut, FromBytes, IntoBytes, NoCell}; fn main() {} -fn transmute_mut(t: &mut T) -> &mut u8 { +fn transmute_mut(t: &mut T) -> &mut u8 { // `transmute_mut!` requires the source type to be concrete. transmute_mut!(t) } diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs index ffff1a198c..37c80a25c8 100644 --- a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs b/tests/ui-nightly/transmute-mut-src-not-intobytes.rs similarity index 79% rename from tests/ui-nightly/transmute-mut-src-not-asbytes.rs rename to tests/ui-nightly/transmute-mut-src-not-intobytes.rs index c24328e9a4..b666155369 100644 --- a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-intobytes.rs @@ -16,9 +16,9 @@ fn main() {} #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; -// `transmute_mut` requires that the source type implements `AsBytes` +// `transmute_mut` requires that the source type implements `IntoBytes` const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); diff --git a/tests/ui-stable/transmute-mut-src-not-asbytes.stderr b/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr similarity index 78% rename from tests/ui-stable/transmute-mut-src-not-asbytes.stderr rename to tests/ui-nightly/transmute-mut-src-not-intobytes.stderr index 9fc954654e..a05ca9e53a 100644 --- a/tests/ui-stable/transmute-mut-src-not-asbytes.stderr +++ b/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-not-nocell.rs b/tests/ui-nightly/transmute-mut-src-not-nocell.rs index 7ef96e7ad1..7df4e91d6a 100644 --- a/tests/ui-nightly/transmute-mut-src-not-nocell.rs +++ b/tests/ui-nightly/transmute-mut-src-not-nocell.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-ptr-to-usize.stderr b/tests/ui-nightly/transmute-ptr-to-usize.stderr index 2fcba2fb6f..91be55c2ec 100644 --- a/tests/ui-nightly/transmute-ptr-to-usize.stderr +++ b/tests/ui-nightly/transmute-ptr-to-usize.stderr @@ -8,11 +8,11 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | required by a bound introduced by this call | = help: the trait `AsBytes` is implemented for `usize` -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied @@ -22,9 +22,9 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` | = help: the trait `AsBytes` is implemented for `usize` -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.rs b/tests/ui-nightly/transmute-ref-src-dst-generic.rs index 384e8e011a..9e080c4595 100644 --- a/tests/ui-nightly/transmute-ref-src-dst-generic.rs +++ b/tests/ui-nightly/transmute-ref-src-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_ref, AsBytes, FromBytes, NoCell}; +use zerocopy::{transmute_ref, FromBytes, IntoBytes, NoCell}; fn main() {} -fn transmute_ref(t: &T) -> &U { +fn transmute_ref(t: &T) -> &U { // `transmute_ref!` requires the source and destination types to be // concrete. transmute_ref!(t) diff --git a/tests/ui-nightly/transmute-ref-src-generic.rs b/tests/ui-nightly/transmute-ref-src-generic.rs index 836c884ad6..124853fb5b 100644 --- a/tests/ui-nightly/transmute-ref-src-generic.rs +++ b/tests/ui-nightly/transmute-ref-src-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_ref, AsBytes, NoCell}; +use zerocopy::{transmute_ref, IntoBytes, NoCell}; fn main() {} -fn transmute_ref(t: &T) -> &u8 { +fn transmute_ref(t: &T) -> &u8 { // `transmute_ref!` requires the source type to be concrete. transmute_ref!(t) } diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.rs b/tests/ui-nightly/transmute-ref-src-not-intobytes.rs similarity index 89% rename from tests/ui-nightly/transmute-ref-src-not-asbytes.rs rename to tests/ui-nightly/transmute-ref-src-not-intobytes.rs index 4a9018b5e3..e6eabcfcb4 100644 --- a/tests/ui-nightly/transmute-ref-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-ref-src-not-intobytes.rs @@ -18,5 +18,5 @@ fn main() {} #[repr(transparent)] struct Src(AU16); -// `transmute_ref` requires that the source type implements `AsBytes` +// `transmute_ref` requires that the source type implements `IntoBytes` const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr b/tests/ui-nightly/transmute-ref-src-not-intobytes.stderr similarity index 78% rename from tests/ui-nightly/transmute-ref-src-not-asbytes.stderr rename to tests/ui-nightly/transmute-ref-src-not-intobytes.stderr index 57cc76fa51..ad7893013c 100644 --- a/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-nightly/transmute-ref-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-nightly/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-nightly/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-not-nocell.rs b/tests/ui-nightly/transmute-ref-src-not-nocell.rs index b78c5fe940..2c1330302c 100644 --- a/tests/ui-nightly/transmute-ref-src-not-nocell.rs +++ b/tests/ui-nightly/transmute-ref-src-not-nocell.rs @@ -14,7 +14,7 @@ use zerocopy::transmute_ref; fn main() {} -#[derive(zerocopy::AsBytes)] +#[derive(zerocopy::IntoBytes)] #[repr(transparent)] struct Src(AU16); diff --git a/tests/ui-nightly/transmute-src-not-asbytes.rs b/tests/ui-nightly/transmute-src-not-intobytes.rs similarity index 89% rename from tests/ui-nightly/transmute-src-not-asbytes.rs rename to tests/ui-nightly/transmute-src-not-intobytes.rs index dd730216b6..ff9d22beec 100644 --- a/tests/ui-nightly/transmute-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-src-not-intobytes.rs @@ -14,5 +14,5 @@ use zerocopy::transmute; fn main() {} -// `transmute` requires that the source type implements `AsBytes` +// `transmute` requires that the source type implements `IntoBytes` const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); diff --git a/tests/ui-nightly/transmute-src-not-asbytes.stderr b/tests/ui-nightly/transmute-src-not-intobytes.stderr similarity index 79% rename from tests/ui-nightly/transmute-src-not-asbytes.stderr rename to tests/ui-nightly/transmute-src-not-intobytes.stderr index b36a820686..ffbe1be140 100644 --- a/tests/ui-nightly/transmute-src-not-asbytes.stderr +++ b/tests/ui-nightly/transmute-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-nightly/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-nightly/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-nightly/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-nightly/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/invalid-impls/invalid-impls.stderr b/tests/ui-stable/invalid-impls/invalid-impls.stderr index 7a9097a94b..9cfe7ee8bc 100644 --- a/tests/ui-stable/invalid-impls/invalid-impls.stderr +++ b/tests/ui-stable/invalid-impls/invalid-impls.stderr @@ -7,7 +7,7 @@ error[E0277]: the trait bound `T: zerocopy::TryFromBytes` is not satisfied note: required for `Foo` to implement `zerocopy::TryFromBytes` --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:10 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs @@ -34,7 +34,7 @@ error[E0277]: the trait bound `T: FromZeroes` is not satisfied note: required for `Foo` to implement `FromZeroes` --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:24 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs @@ -61,7 +61,7 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied note: required for `Foo` to implement `zerocopy::FromBytes` --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:35 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs @@ -79,17 +79,17 @@ help: consider restricting type parameter `T` 28 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo); | +++++++++++++++++++++ -error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied - --> tests/ui-stable/invalid-impls/invalid-impls.rs:29:34 +error[E0277]: the trait bound `T: AsBytes` is not satisfied + --> tests/ui-stable/invalid-impls/invalid-impls.rs:29:36 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T` +29 | impl_or_verify!(T => IntoBytes for Foo); + | ^^^^^^ the trait `AsBytes` is not implemented for `T` | -note: required for `Foo` to implement `zerocopy::AsBytes` +note: required for `Foo` to implement `AsBytes` --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:46 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, Unaligned)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro note: required by a bound in `_::Subtrait` --> tests/ui-stable/invalid-impls/../../../src/macros.rs | @@ -98,13 +98,13 @@ note: required by a bound in `_::Subtrait` | ::: tests/ui-stable/invalid-impls/invalid-impls.rs:29:1 | -29 | impl_or_verify!(T => AsBytes for Foo); - | ---------------------------------------- in this macro invocation - = note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info) +29 | impl_or_verify!(T => IntoBytes for Foo); + | ------------------------------------------ in this macro invocation + = note: this error originates in the derive macro `IntoBytes` 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` | -29 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo); - | +++++++++++++++++++ +29 | impl_or_verify!(T: zerocopy::IntoBytes => IntoBytes for Foo); + | +++++++++++++++++++++ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied --> tests/ui-stable/invalid-impls/invalid-impls.rs:30:36 @@ -113,10 +113,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:55 + --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:57 | -22 | #[derive(TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +22 | #[derive(TryFromBytes, FromZeros, FromBytes, IntoBytes, 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/tests/ui-stable/transmute-mut-dst-not-asbytes.rs b/tests/ui-stable/transmute-mut-dst-not-asbytes.rs deleted file mode 120000 index 2f968ddb0b..0000000000 --- a/tests/ui-stable/transmute-mut-dst-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-dst-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-dst-not-intobytes.rs b/tests/ui-stable/transmute-mut-dst-not-intobytes.rs new file mode 120000 index 0000000000..34e3307388 --- /dev/null +++ b/tests/ui-stable/transmute-mut-dst-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-dst-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr b/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr similarity index 79% rename from tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr rename to tests/ui-stable/transmute-mut-dst-not-intobytes.stderr index 54c8e6023f..d7e6b9ae3f 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr +++ b/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Dst: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-mut-dst-not-asbytes.rs:24:36 + --> tests/ui-stable/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,9 +17,9 @@ error[E0277]: the trait bound `Dst: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertDstIsAsBytes` - --> tests/ui-nightly/transmute-mut-dst-not-asbytes.rs:24:36 +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-stable/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-not-asbytes.rs b/tests/ui-stable/transmute-mut-src-not-asbytes.rs deleted file mode 120000 index e98230daac..0000000000 --- a/tests/ui-stable/transmute-mut-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-src-not-intobytes.rs b/tests/ui-stable/transmute-mut-src-not-intobytes.rs new file mode 120000 index 0000000000..0086f2a962 --- /dev/null +++ b/tests/ui-stable/transmute-mut-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.stderr b/tests/ui-stable/transmute-mut-src-not-intobytes.stderr similarity index 78% rename from tests/ui-nightly/transmute-mut-src-not-asbytes.stderr rename to tests/ui-stable/transmute-mut-src-not-intobytes.stderr index b755d3c654..7a4ce2e6ed 100644 --- a/tests/ui-nightly/transmute-mut-src-not-asbytes.stderr +++ b/tests/ui-stable/transmute-mut-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36 + --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ptr-to-usize.stderr b/tests/ui-stable/transmute-ptr-to-usize.stderr index 4f4d583dbe..cc6551a22d 100644 --- a/tests/ui-stable/transmute-ptr-to-usize.stderr +++ b/tests/ui-stable/transmute-ptr-to-usize.stderr @@ -8,11 +8,11 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | required by a bound introduced by this call | = help: the trait `AsBytes` is implemented for `usize` -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied @@ -22,9 +22,9 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` | = help: the trait `AsBytes` is implemented for `usize` -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertIsIntoBytes` --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30 | 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-not-asbytes.rs b/tests/ui-stable/transmute-ref-src-not-asbytes.rs deleted file mode 120000 index d8768b7bb4..0000000000 --- a/tests/ui-stable/transmute-ref-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-not-intobytes.rs b/tests/ui-stable/transmute-ref-src-not-intobytes.rs new file mode 120000 index 0000000000..6602ca352d --- /dev/null +++ b/tests/ui-stable/transmute-ref-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-not-asbytes.stderr b/tests/ui-stable/transmute-ref-src-not-intobytes.stderr similarity index 78% rename from tests/ui-stable/transmute-ref-src-not-asbytes.stderr rename to tests/ui-stable/transmute-ref-src-not-intobytes.stderr index 7303d38108..b446fa11db 100644 --- a/tests/ui-stable/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-stable/transmute-ref-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-stable/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Src: AsBytes` is not satisfied - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 + --> tests/ui-stable/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `Src: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertSrcIsAsBytes` - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/transmute-ref-src-not-intobytes.rs:22:33 | 22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-src-not-asbytes.rs b/tests/ui-stable/transmute-src-not-asbytes.rs deleted file mode 120000 index 999d9cea6a..0000000000 --- a/tests/ui-stable/transmute-src-not-asbytes.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-src-not-intobytes.rs b/tests/ui-stable/transmute-src-not-intobytes.rs new file mode 120000 index 0000000000..7dd68a7037 --- /dev/null +++ b/tests/ui-stable/transmute-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-src-not-asbytes.stderr b/tests/ui-stable/transmute-src-not-intobytes.stderr similarity index 79% rename from tests/ui-stable/transmute-src-not-asbytes.stderr rename to tests/ui-stable/transmute-src-not-intobytes.stderr index f2e834eb57..5fd73a6382 100644 --- a/tests/ui-stable/transmute-src-not-asbytes.stderr +++ b/tests/ui-stable/transmute-src-not-intobytes.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-stable/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,15 +17,15 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-stable/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32 + --> tests/ui-stable/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` @@ -40,9 +40,9 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32 +note: required by a bound in `AssertIsIntoBytes` + --> tests/ui-stable/transmute-src-not-intobytes.rs:18:32 | 18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsIntoBytes` = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 4f2d9f0482..7a2005d1fa 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 FromZeros, FromBytes, AsBytes, or Unaligned on an enum" +// for deriving FromZeros, FromBytes, IntoBytes, or Unaligned on an enum" // // This will probably require Span::error // (https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.error), @@ -308,7 +308,7 @@ pub fn derive_from_bytes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream .into() } -#[proc_macro_derive(AsBytes)] +#[proc_macro_derive(IntoBytes)] pub fn derive_as_bytes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast = syn::parse_macro_input!(ts as DeriveInput); match &ast.data { @@ -529,8 +529,8 @@ fn derive_from_bytes_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::T impl_block(ast, unn, Trait::FromBytes, RequireBoundedFields::Yes, false, None, None) } -// A struct is `AsBytes` if: -// - all fields are `AsBytes` +// A struct is `IntoBytes` if: +// - all fields are `IntoBytes` // - `repr(C)` or `repr(transparent)` and // - no padding (size of struct equals sum of size of field types) // - `repr(packed)` @@ -554,36 +554,36 @@ fn derive_as_bytes_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_macro2: // repr(packed). // - repr(transparent): The layout and ABI of the whole struct is the same // as its only non-ZST field (meaning there's no padding outside of that - // field) and we require that field to be `AsBytes` (meaning there's no + // field) and we require that field to be `IntoBytes` (meaning there's no // padding in that field). // - repr(packed): Any inter-field padding bytes are removed, meaning that // any padding bytes would need to come from the fields, all of which - // we require to be `AsBytes` (meaning they don't have any padding). + // we require to be `IntoBytes` (meaning they don't have any padding). let padding_check = if is_transparent || is_packed { None } else { Some(PaddingCheck::Struct) }; - impl_block(ast, strct, Trait::AsBytes, RequireBoundedFields::Yes, false, padding_check, None) + impl_block(ast, strct, Trait::IntoBytes, RequireBoundedFields::Yes, false, padding_check, None) } const STRUCT_UNION_AS_BYTES_CFG: Config = Config { // Since `disallowed_but_legal_combinations` is empty, this message will // never actually be emitted. - allowed_combinations_message: r#"AsBytes requires either a) repr "C" or "transparent" with all fields implementing AsBytes or, b) repr "packed""#, + allowed_combinations_message: r#"IntoBytes requires either a) repr "C" or "transparent" with all fields implementing IntoBytes or, b) repr "packed""#, derive_unaligned: false, allowed_combinations: STRUCT_UNION_ALLOWED_REPR_COMBINATIONS, disallowed_but_legal_combinations: &[], }; -// An enum is `AsBytes` if it is C-like and has a defined repr. +// An enum is `IntoBytes` if it is C-like and has a defined repr. fn derive_as_bytes_enum(ast: &DeriveInput, enm: &DataEnum) -> proc_macro2::TokenStream { if !enm.is_c_like() { - return Error::new_spanned(ast, "only C-like enums can implement AsBytes") + return Error::new_spanned(ast, "only C-like enums can implement IntoBytes") .to_compile_error(); } // We don't care what the repr is; we only care that it is one of the // allowed ones. let _: Vec = try_or_print!(ENUM_AS_BYTES_CFG.validate_reprs(ast)); - impl_block(ast, enm, Trait::AsBytes, RequireBoundedFields::No, false, None, None) + impl_block(ast, enm, Trait::IntoBytes, RequireBoundedFields::No, false, None, None) } #[rustfmt::skip] @@ -592,7 +592,7 @@ const ENUM_AS_BYTES_CFG: Config = { Config { // Since `disallowed_but_legal_combinations` is empty, this message will // never actually be emitted. - allowed_combinations_message: r#"AsBytes requires repr of "C", "u8", "u16", "u32", "u64", "usize", "i8", "i16", "i32", "i64", or "isize""#, + allowed_combinations_message: r#"IntoBytes requires repr of "C", "u8", "u16", "u32", "u64", "usize", "i8", "i16", "i32", "i64", or "isize""#, derive_unaligned: false, allowed_combinations: &[ &[C], @@ -611,8 +611,8 @@ const ENUM_AS_BYTES_CFG: Config = { } }; -// A union is `AsBytes` if: -// - all fields are `AsBytes` +// A union is `IntoBytes` if: +// - all fields are `IntoBytes` // - `repr(C)`, `repr(transparent)`, or `repr(packed)` // - no padding (size of union equals size of each field type) @@ -628,7 +628,7 @@ fn derive_as_bytes_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::Tok impl_block( ast, unn, - Trait::AsBytes, + Trait::IntoBytes, RequireBoundedFields::Yes, false, Some(PaddingCheck::Union), @@ -747,7 +747,7 @@ enum Trait { TryFromBytes, FromZeros, FromBytes, - AsBytes, + IntoBytes, Unaligned, } diff --git a/zerocopy-derive/src/repr.rs b/zerocopy-derive/src/repr.rs index f4f2788685..7d2ebfa2f4 100644 --- a/zerocopy-derive/src/repr.rs +++ b/zerocopy-derive/src/repr.rs @@ -133,7 +133,7 @@ macro_rules! define_kind_specific_repr { match Repr::from_meta(meta)? { $(Repr::$repr_variant => Ok($repr_name::$repr_variant),)* $(Repr::$repr_variant_aligned(u) => Ok($repr_name::$repr_variant_aligned(u)),)* - _ => Err(Error::new_spanned(meta, concat!("unsupported representation for deriving FromBytes, AsBytes, or Unaligned on ", $type_name))) + _ => Err(Error::new_spanned(meta, concat!("unsupported representation for deriving zerocopy trait(s) on ", $type_name))) } } } diff --git a/zerocopy-derive/tests/enum_as_bytes.rs b/zerocopy-derive/tests/enum_to_bytes.rs similarity index 52% rename from zerocopy-derive/tests/enum_as_bytes.rs rename to zerocopy-derive/tests/enum_to_bytes.rs index e305bc4cea..bed5a07694 100644 --- a/zerocopy-derive/tests/enum_as_bytes.rs +++ b/zerocopy-derive/tests/enum_to_bytes.rs @@ -8,94 +8,94 @@ #![allow(warnings)] -use {static_assertions::assert_impl_all, zerocopy::AsBytes}; +use {static_assertions::assert_impl_all, zerocopy::IntoBytes}; -// An enum is `AsBytes` if if has a defined repr. +// An enum is `IntoBytes` if if has a defined repr. -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] enum C { A, } -assert_impl_all!(C: AsBytes); +assert_impl_all!(C: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(u8)] enum U8 { A, } -assert_impl_all!(U8: AsBytes); +assert_impl_all!(U8: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(u16)] enum U16 { A, } -assert_impl_all!(U16: AsBytes); +assert_impl_all!(U16: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(u32)] enum U32 { A, } -assert_impl_all!(U32: AsBytes); +assert_impl_all!(U32: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(u64)] enum U64 { A, } -assert_impl_all!(U64: AsBytes); +assert_impl_all!(U64: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(usize)] enum Usize { A, } -assert_impl_all!(Usize: AsBytes); +assert_impl_all!(Usize: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(i8)] enum I8 { A, } -assert_impl_all!(I8: AsBytes); +assert_impl_all!(I8: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(i16)] enum I16 { A, } -assert_impl_all!(I16: AsBytes); +assert_impl_all!(I16: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(i32)] enum I32 { A, } -assert_impl_all!(I32: AsBytes); +assert_impl_all!(I32: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(i64)] enum I64 { A, } -assert_impl_all!(I64: AsBytes); +assert_impl_all!(I64: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(isize)] enum Isize { A, } -assert_impl_all!(Isize: AsBytes); +assert_impl_all!(Isize: IntoBytes); diff --git a/zerocopy-derive/tests/paths_and_modules.rs b/zerocopy-derive/tests/paths_and_modules.rs index 0525b571a8..0c173369d0 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, FromZeros, Unaligned}; +use zerocopy::{FromBytes, FromZeros, IntoBytes, Unaligned}; // Ensure that types that are use'd and types that are referenced by path work. mod foo { - use zerocopy::{AsBytes, FromBytes, FromZeros, Unaligned}; + use zerocopy::{FromBytes, FromZeros, IntoBytes, Unaligned}; - #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + #[derive(FromZeros, FromBytes, IntoBytes, Unaligned)] #[repr(C)] pub struct Foo { foo: u8, } - #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] + #[derive(FromZeros, FromBytes, IntoBytes, Unaligned)] #[repr(C)] pub struct Bar { bar: u8, @@ -30,7 +30,7 @@ mod foo { use foo::Foo; -#[derive(FromZeros, FromBytes, AsBytes, Unaligned)] +#[derive(FromZeros, FromBytes, IntoBytes, 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 754477afa6..78a052accf 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, FromZeros, KnownLayout, Unaligned}; +use zerocopy::{FromBytes, FromZeros, IntoBytes, 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, FromZeros, KnownLayout, Unaligned}; // bounds for field types (i.e., the emission of E0446 for private field // types). -#[derive(KnownLayout, AsBytes, FromZeros, FromBytes, Unaligned)] +#[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)] #[repr(C)] pub struct Public(Private); -#[derive(KnownLayout, AsBytes, FromZeros, FromBytes, Unaligned)] +#[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)] #[repr(C)] struct Private(()); diff --git a/zerocopy-derive/tests/struct_as_bytes.rs b/zerocopy-derive/tests/struct_to_bytes.rs similarity index 72% rename from zerocopy-derive/tests/struct_as_bytes.rs rename to zerocopy-derive/tests/struct_to_bytes.rs index 3c71bf07b5..df072af799 100644 --- a/zerocopy-derive/tests/struct_as_bytes.rs +++ b/zerocopy-derive/tests/struct_to_bytes.rs @@ -12,23 +12,23 @@ mod util; use std::{marker::PhantomData, mem::ManuallyDrop, option::IntoIter}; -use {static_assertions::assert_impl_all, zerocopy::AsBytes}; +use {static_assertions::assert_impl_all, zerocopy::IntoBytes}; use self::util::AU16; -// A struct is `AsBytes` if: -// - all fields are `AsBytes` +// A struct is `IntoBytes` if: +// - all fields are `IntoBytes` // - `repr(C)` or `repr(transparent)` and // - no padding (size of struct equals sum of size of field types) // - `repr(packed)` -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] struct CZst; -assert_impl_all!(CZst: AsBytes); +assert_impl_all!(CZst: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] struct C { a: u8, @@ -36,34 +36,34 @@ struct C { c: AU16, } -assert_impl_all!(C: AsBytes); +assert_impl_all!(C: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(transparent)] struct Transparent { a: u8, b: CZst, } -assert_impl_all!(Transparent: AsBytes); +assert_impl_all!(Transparent: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(transparent)] struct TransparentGeneric { a: CZst, b: T, } -assert_impl_all!(TransparentGeneric: AsBytes); -assert_impl_all!(TransparentGeneric<[u64]>: AsBytes); +assert_impl_all!(TransparentGeneric: IntoBytes); +assert_impl_all!(TransparentGeneric<[u64]>: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] struct CZstPacked; -assert_impl_all!(CZstPacked: AsBytes); +assert_impl_all!(CZstPacked: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] struct CPacked { a: u8, @@ -77,9 +77,9 @@ struct CPacked { b: u16, } -assert_impl_all!(CPacked: AsBytes); +assert_impl_all!(CPacked: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed(2))] // The same caveats as for CPacked apply - we're assuming u64 is at least // 4-byte aligned by default. Without packed(2), this should fail, as there @@ -89,9 +89,9 @@ struct CPacked2 { b: u64, } -assert_impl_all!(CPacked2: AsBytes); +assert_impl_all!(CPacked2: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] struct CPackedGeneric { t: T, @@ -103,10 +103,10 @@ struct CPackedGeneric { u: ManuallyDrop, } -assert_impl_all!(CPackedGeneric: AsBytes); -assert_impl_all!(CPackedGeneric: AsBytes); +assert_impl_all!(CPackedGeneric: IntoBytes); +assert_impl_all!(CPackedGeneric: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(packed)] struct Packed { a: u8, @@ -120,9 +120,9 @@ struct Packed { b: u16, } -assert_impl_all!(Packed: AsBytes); +assert_impl_all!(Packed: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(packed)] struct PackedGeneric { t: T, @@ -134,28 +134,28 @@ struct PackedGeneric { u: ManuallyDrop, } -assert_impl_all!(PackedGeneric: AsBytes); -assert_impl_all!(PackedGeneric: AsBytes); +assert_impl_all!(PackedGeneric: IntoBytes); +assert_impl_all!(PackedGeneric: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(transparent)] struct Unsized { a: [u8], } -assert_impl_all!(Unsized: AsBytes); +assert_impl_all!(Unsized: IntoBytes); -// Deriving `AsBytes` should work if the struct has bounded parameters. +// Deriving `IntoBytes` should work if the struct has bounded parameters. -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(transparent)] -struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + AsBytes>( +struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + IntoBytes>( [T; N], PhantomData<&'a &'b ()>, ) where 'a: 'b, 'b: 'a, - T: 'a + 'b + AsBytes; + T: 'a + 'b + IntoBytes; -assert_impl_all!(WithParams<'static, 'static, 42, u8>: AsBytes); +assert_impl_all!(WithParams<'static, 'static, 42, u8>: IntoBytes); diff --git a/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr b/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr index c012fa2f12..a2dc6e71bf 100644 --- a/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr @@ -5,10 +5,10 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required because of the requirements on the impl of `TryFromBytes` for `TransparentStruct` - --> tests/ui-msrv/derive_transparent.rs:27:19 + --> tests/ui-msrv/derive_transparent.rs:27:21 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^^^^ +27 | #[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:37:1 | @@ -23,10 +23,10 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:33 + --> tests/ui-msrv/derive_transparent.rs:27:35 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ +27 | #[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:38:1 | @@ -41,10 +41,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:44 + --> tests/ui-msrv/derive_transparent.rs:27:46 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ +27 | #[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:39:1 | @@ -55,19 +55,19 @@ note: required by a bound in `_::{closure#0}::assert_impl_all` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-msrv/derive_transparent.rs:40:1 | -40 | assert_impl_all!(TransparentStruct: AsBytes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +40 | assert_impl_all!(TransparentStruct: IntoBytes); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | note: required because of the requirements on the impl of `AsBytes` for `TransparentStruct` --> tests/ui-msrv/derive_transparent.rs:27:10 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^ +27 | #[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:40:1 | -40 | assert_impl_all!(TransparentStruct: AsBytes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all` +40 | assert_impl_all!(TransparentStruct: IntoBytes); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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: Unaligned` is not satisfied @@ -77,10 +77,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:55 + --> tests/ui-msrv/derive_transparent.rs:27:57 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ +27 | #[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] + | ^^^^^^^^^ note: required by a bound in `_::{closure#0}::assert_impl_all` --> tests/ui-msrv/derive_transparent.rs:41:1 | diff --git a/zerocopy-derive/tests/ui-msrv/enum.stderr b/zerocopy-derive/tests/ui-msrv/enum.stderr index bd850fe51c..a4aad2b9e8 100644 --- a/zerocopy-derive/tests/ui-msrv/enum.stderr +++ b/zerocopy-derive/tests/ui-msrv/enum.stderr @@ -37,7 +37,7 @@ error: TryFromBytes not supported on enum types 34 | | } | |_^ -error: unsupported representation for deriving FromBytes, AsBytes, or Unaligned on an enum +error: unsupported representation for deriving zerocopy trait(s) on an enum --> tests/ui-msrv/enum.rs:31:8 | 31 | #[repr(transparent)] diff --git a/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr b/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr index 8fe1e071b1..bc86c9b2c9 100644 --- a/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr @@ -49,11 +49,11 @@ note: required by a bound in `FromBytes` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-msrv/late_compile_pass.rs:55:10 | -55 | #[derive(AsBytes)] - | ^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +55 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `AU16: Unaligned` is not satisfied --> tests/ui-msrv/late_compile_pass.rs:65:10 diff --git a/zerocopy-derive/tests/ui-msrv/struct.stderr b/zerocopy-derive/tests/ui-msrv/struct.stderr index c7845b7285..5132d979e0 100644 --- a/zerocopy-derive/tests/ui-msrv/struct.stderr +++ b/zerocopy-derive/tests/ui-msrv/struct.stderr @@ -25,10 +25,10 @@ error: cannot derive TryFromBytes with repr(packed) error: unsupported on generic structs that are not repr(transparent) or repr(packed) --> tests/ui-msrv/struct.rs:97:10 | -97 | #[derive(AsBytes)] - | ^^^^^^^ +97 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-msrv/struct.rs:122:11 @@ -133,24 +133,24 @@ error[E0277]: the trait bound `UnsafeCell: NoCell` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-msrv/struct.rs:101:10 | -101 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +101 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the following implementations were found: as ShouldBe> = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-msrv/struct.rs:108:10 | -108 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +108 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the following implementations were found: as ShouldBe> = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-msrv/union.stderr b/zerocopy-derive/tests/ui-msrv/union.stderr index 9ce5db19ee..e69450ef9a 100644 --- a/zerocopy-derive/tests/ui-msrv/union.stderr +++ b/zerocopy-derive/tests/ui-msrv/union.stderr @@ -1,10 +1,10 @@ error: unsupported on types with type parameters --> tests/ui-msrv/union.rs:33:10 | -33 | #[derive(AsBytes)] - | ^^^^^^^ +33 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-msrv/union.rs:51:11 @@ -40,13 +40,13 @@ error[E0277]: the trait bound `UnsafeCell<()>: NoCell` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-msrv/union.rs:39:10 | -39 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +39 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the following implementations were found: as ShouldBe> = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-nightly/derive_transparent.rs b/zerocopy-derive/tests/ui-nightly/derive_transparent.rs index 0ed279e7b2..32c01f92cd 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, FromZeros, TryFromBytes, Unaligned}, + zerocopy::{FromBytes, FromZeros, IntoBytes, TryFromBytes, Unaligned}, }; use self::util::NotZerocopy; @@ -24,7 +24,7 @@ fn main() {} // Test generic transparent structs -#[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] +#[derive(IntoBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] #[repr(transparent)] struct TransparentStruct { inner: T, @@ -37,5 +37,5 @@ struct TransparentStruct { assert_impl_all!(TransparentStruct: TryFromBytes); assert_impl_all!(TransparentStruct: FromZeros); assert_impl_all!(TransparentStruct: FromBytes); -assert_impl_all!(TransparentStruct: AsBytes); +assert_impl_all!(TransparentStruct: IntoBytes); 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 29ddb14bea..3575661153 100644 --- a/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr @@ -15,10 +15,10 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied i128 and $N others note: required for `TransparentStruct` to implement `TryFromBytes` - --> tests/ui-nightly/derive_transparent.rs:27:19 + --> tests/ui-nightly/derive_transparent.rs:27:21 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -43,10 +43,10 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied i128 and $N others note: required for `TransparentStruct` to implement `FromZeroes` - --> tests/ui-nightly/derive_transparent.rs:27:33 + --> tests/ui-nightly/derive_transparent.rs:27:35 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -71,10 +71,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:44 + --> tests/ui-nightly/derive_transparent.rs:27:46 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -85,7 +85,7 @@ note: required by a bound in `_::{closure#0}::assert_impl_all` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-nightly/derive_transparent.rs:40:18 | -40 | assert_impl_all!(TransparentStruct: AsBytes); +40 | assert_impl_all!(TransparentStruct: IntoBytes); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `AsBytes`: @@ -101,14 +101,14 @@ 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, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | -40 | assert_impl_all!(TransparentStruct: AsBytes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` - = note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) +40 | assert_impl_all!(TransparentStruct: IntoBytes); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` + = note: this error originates in the derive macro `IntoBytes` 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: Unaligned` is not satisfied --> tests/ui-nightly/derive_transparent.rs:41:18 @@ -127,10 +127,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:55 + --> tests/ui-nightly/derive_transparent.rs:27:57 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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:41:1 | diff --git a/zerocopy-derive/tests/ui-nightly/enum.stderr b/zerocopy-derive/tests/ui-nightly/enum.stderr index 1683c53ee9..a4f1573e14 100644 --- a/zerocopy-derive/tests/ui-nightly/enum.stderr +++ b/zerocopy-derive/tests/ui-nightly/enum.stderr @@ -37,7 +37,7 @@ error: TryFromBytes not supported on enum types 34 | | } | |_^ -error: unsupported representation for deriving FromBytes, AsBytes, or Unaligned on an enum +error: unsupported representation for deriving zerocopy trait(s) on an enum --> tests/ui-nightly/enum.rs:31:8 | 31 | #[repr(transparent)] diff --git a/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs b/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs index 2031a3da38..d6d5ba3808 100644 --- a/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs +++ b/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs @@ -49,12 +49,12 @@ struct FromBytes1 { } // -// AsBytes errors +// IntoBytes errors // -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] -struct AsBytes1 { +struct IntoBytes1 { 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 5b19b0e26e..31b8d4feac 100644 --- a/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr @@ -92,8 +92,8 @@ note: required by a bound in `FromBytes` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-nightly/late_compile_pass.rs:55:10 | -55 | #[derive(AsBytes)] - | ^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +55 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `AsBytes`: bool @@ -107,7 +107,7 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` 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 `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `AU16: Unaligned` is not satisfied --> tests/ui-nightly/late_compile_pass.rs:65:10 diff --git a/zerocopy-derive/tests/ui-nightly/struct.rs b/zerocopy-derive/tests/ui-nightly/struct.rs index 68392c704b..7eb4297e7c 100644 --- a/zerocopy-derive/tests/ui-nightly/struct.rs +++ b/zerocopy-derive/tests/ui-nightly/struct.rs @@ -91,23 +91,23 @@ struct TryFromBytesCPackedN { } // -// AsBytes errors +// IntoBytes errors // -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] -struct AsBytes1(T); +struct IntoBytes1(T); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] -struct AsBytes2 { +struct IntoBytes2 { foo: u8, bar: AU16, } -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed(2))] -struct AsBytes3 { +struct IntoBytes3 { foo: u8, // We'd prefer to use AU64 here, but you can't use aligned types in // packed structs. diff --git a/zerocopy-derive/tests/ui-nightly/struct.stderr b/zerocopy-derive/tests/ui-nightly/struct.stderr index 66aeb70f53..f3086715c4 100644 --- a/zerocopy-derive/tests/ui-nightly/struct.stderr +++ b/zerocopy-derive/tests/ui-nightly/struct.stderr @@ -25,10 +25,10 @@ error: cannot derive TryFromBytes with repr(packed) error: unsupported on generic structs that are not repr(transparent) or repr(packed) --> tests/ui-nightly/struct.rs:97:10 | -97 | #[derive(AsBytes)] - | ^^^^^^^ +97 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-nightly/struct.rs:122:11 @@ -179,27 +179,27 @@ error[E0277]: the trait bound `UnsafeCell: NoCell` is not satisfied = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-nightly/struct.rs:101:10 | -101 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +101 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-nightly/struct.rs:108:10 | -108 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +108 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type --> tests/ui-nightly/struct.rs:71:1 diff --git a/zerocopy-derive/tests/ui-nightly/union.rs b/zerocopy-derive/tests/ui-nightly/union.rs index 80ad450b7d..660eea6e27 100644 --- a/zerocopy-derive/tests/ui-nightly/union.rs +++ b/zerocopy-derive/tests/ui-nightly/union.rs @@ -27,18 +27,18 @@ union NoCell1 { } // -// AsBytes errors +// IntoBytes errors // -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] -union AsBytes1 { +union IntoBytes1 { foo: ManuallyDrop, } -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] -union AsBytes2 { +union IntoBytes2 { foo: u8, bar: [u8; 2], } diff --git a/zerocopy-derive/tests/ui-nightly/union.stderr b/zerocopy-derive/tests/ui-nightly/union.stderr index 504693364f..c1710a6b0b 100644 --- a/zerocopy-derive/tests/ui-nightly/union.stderr +++ b/zerocopy-derive/tests/ui-nightly/union.stderr @@ -1,10 +1,10 @@ error: unsupported on types with type parameters --> tests/ui-nightly/union.rs:33:10 | -33 | #[derive(AsBytes)] - | ^^^^^^^ +33 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-nightly/union.rs:51:11 @@ -51,16 +51,16 @@ error[E0277]: the trait bound `UnsafeCell<()>: NoCell` is not satisfied = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-nightly/union.rs:39:10 | -39 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +39 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0587]: type has conflicting packed and align representation hints --> tests/ui-nightly/union.rs:68:1 diff --git a/zerocopy-derive/tests/ui-stable/derive_transparent.stderr b/zerocopy-derive/tests/ui-stable/derive_transparent.stderr index ab8fda7a65..3fb2358586 100644 --- a/zerocopy-derive/tests/ui-stable/derive_transparent.stderr +++ b/zerocopy-derive/tests/ui-stable/derive_transparent.stderr @@ -15,10 +15,10 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied i128 and $N others note: required for `TransparentStruct` to implement `TryFromBytes` - --> tests/ui-stable/derive_transparent.rs:27:19 + --> tests/ui-stable/derive_transparent.rs:27:21 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -43,10 +43,10 @@ error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied i128 and $N others note: required for `TransparentStruct` to implement `FromZeroes` - --> tests/ui-stable/derive_transparent.rs:27:33 + --> tests/ui-stable/derive_transparent.rs:27:35 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -71,10 +71,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:44 + --> tests/ui-stable/derive_transparent.rs:27:46 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | @@ -85,7 +85,7 @@ note: required by a bound in `_::{closure#0}::assert_impl_all` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-stable/derive_transparent.rs:40:18 | -40 | assert_impl_all!(TransparentStruct: AsBytes); +40 | assert_impl_all!(TransparentStruct: IntoBytes); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `AsBytes`: @@ -101,14 +101,14 @@ 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, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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 | -40 | assert_impl_all!(TransparentStruct: AsBytes); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` - = note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) +40 | assert_impl_all!(TransparentStruct: IntoBytes); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` + = note: this error originates in the derive macro `IntoBytes` 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: Unaligned` is not satisfied --> tests/ui-stable/derive_transparent.rs:41:18 @@ -127,10 +127,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:55 + --> tests/ui-stable/derive_transparent.rs:27:57 | -27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)] - | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +27 | #[derive(IntoBytes, TryFromBytes, 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:41:1 | diff --git a/zerocopy-derive/tests/ui-stable/enum.stderr b/zerocopy-derive/tests/ui-stable/enum.stderr index cb6e086acb..19d4ac20bd 100644 --- a/zerocopy-derive/tests/ui-stable/enum.stderr +++ b/zerocopy-derive/tests/ui-stable/enum.stderr @@ -37,7 +37,7 @@ error: TryFromBytes not supported on enum types 34 | | } | |_^ -error: unsupported representation for deriving FromBytes, AsBytes, or Unaligned on an enum +error: unsupported representation for deriving zerocopy trait(s) on an enum --> tests/ui-stable/enum.rs:31:8 | 31 | #[repr(transparent)] diff --git a/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr b/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr index 4a24454a0f..f0c1904ed4 100644 --- a/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr +++ b/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr @@ -89,8 +89,8 @@ note: required by a bound in `FromBytes` error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied --> tests/ui-stable/late_compile_pass.rs:55:10 | -55 | #[derive(AsBytes)] - | ^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +55 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` | = help: the following other types implement trait `AsBytes`: bool @@ -103,7 +103,7 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i128 and $N others = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `AU16: Unaligned` is not satisfied --> tests/ui-stable/late_compile_pass.rs:65:10 diff --git a/zerocopy-derive/tests/ui-stable/struct.stderr b/zerocopy-derive/tests/ui-stable/struct.stderr index 8353233644..23ac647ea3 100644 --- a/zerocopy-derive/tests/ui-stable/struct.stderr +++ b/zerocopy-derive/tests/ui-stable/struct.stderr @@ -25,10 +25,10 @@ error: cannot derive TryFromBytes with repr(packed) error: unsupported on generic structs that are not repr(transparent) or repr(packed) --> tests/ui-stable/struct.rs:97:10 | -97 | #[derive(AsBytes)] - | ^^^^^^^ +97 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-stable/struct.rs:122:11 @@ -173,22 +173,22 @@ error[E0277]: the trait bound `UnsafeCell: NoCell` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-stable/struct.rs:101:10 | -101 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +101 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-stable/struct.rs:108:10 | -108 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +108 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-stable/union.stderr b/zerocopy-derive/tests/ui-stable/union.stderr index 3738cf8df7..ecbf8a55d6 100644 --- a/zerocopy-derive/tests/ui-stable/union.stderr +++ b/zerocopy-derive/tests/ui-stable/union.stderr @@ -1,10 +1,10 @@ error: unsupported on types with type parameters --> tests/ui-stable/union.rs:33:10 | -33 | #[derive(AsBytes)] - | ^^^^^^^ +33 | #[derive(IntoBytes)] + | ^^^^^^^^^ | - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot derive Unaligned with repr(align(N > 1)) --> tests/ui-stable/union.rs:51:11 @@ -50,12 +50,12 @@ error[E0277]: the trait bound `UnsafeCell<()>: NoCell` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `NoCell` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied --> tests/ui-stable/union.rs:39:10 | -39 | #[derive(AsBytes)] - | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +39 | #[derive(IntoBytes)] + | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` | = help: the trait `ShouldBe` is implemented for `HasPadding` = help: see issue #48214 - = note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/union_as_bytes.rs b/zerocopy-derive/tests/union_to_bytes.rs similarity index 70% rename from zerocopy-derive/tests/union_as_bytes.rs rename to zerocopy-derive/tests/union_to_bytes.rs index 84f51817f2..189329a751 100644 --- a/zerocopy-derive/tests/union_as_bytes.rs +++ b/zerocopy-derive/tests/union_to_bytes.rs @@ -10,35 +10,35 @@ use std::{marker::PhantomData, option::IntoIter}; -use {static_assertions::assert_impl_all, zerocopy::AsBytes}; +use {static_assertions::assert_impl_all, zerocopy::IntoBytes}; -// A union is `AsBytes` if: -// - all fields are `AsBytes` +// A union is `IntoBytes` if: +// - all fields are `IntoBytes` // - `repr(C)` or `repr(transparent)` and // - no padding (size of union equals size of each field type) // - `repr(packed)` -#[derive(AsBytes, Clone, Copy)] +#[derive(IntoBytes, Clone, Copy)] #[repr(C)] union CZst { a: (), } -assert_impl_all!(CZst: AsBytes); +assert_impl_all!(CZst: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C)] union C { a: u8, b: u8, } -assert_impl_all!(C: AsBytes); +assert_impl_all!(C: IntoBytes); // Transparent unions are unstable; see issue #60405 // for more information. -// #[derive(AsBytes)] +// #[derive(IntoBytes)] // #[repr(transparent)] // union Transparent { // a: u8, @@ -47,24 +47,24 @@ assert_impl_all!(C: AsBytes); // is_as_bytes!(Transparent); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] union CZstPacked { a: (), } -assert_impl_all!(CZstPacked: AsBytes); +assert_impl_all!(CZstPacked: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] union CPacked { a: u8, b: i8, } -assert_impl_all!(CPacked: AsBytes); +assert_impl_all!(CPacked: IntoBytes); -#[derive(AsBytes)] +#[derive(IntoBytes)] #[repr(C, packed)] union CMultibytePacked { a: i32, @@ -72,4 +72,4 @@ union CMultibytePacked { c: f32, } -assert_impl_all!(CMultibytePacked: AsBytes); +assert_impl_all!(CMultibytePacked: IntoBytes); diff --git a/zerocopy-derive/tests/util.rs b/zerocopy-derive/tests/util.rs index 7a2982aa04..ec8d0b9a39 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, FromZeros, KnownLayout, NoCell, TryFromBytes}; +use zerocopy::{FromBytes, FromZeros, IntoBytes, KnownLayout, NoCell, TryFromBytes}; /// 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, TryFromBytes, FromZeros, FromBytes, AsBytes, Copy, Clone)] +#[derive(KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, IntoBytes, Copy, Clone)] #[repr(C, align(2))] pub struct AU16(u16);