diff --git a/src/impls.rs b/src/impls.rs index a79b82e7d7..c5b8694732 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -1164,6 +1164,24 @@ mod tests { } } + pub(super) trait TestTryFromMut { + #[allow(clippy::needless_lifetimes)] + fn test_try_from_mut<'bytes>( + &self, + bytes: &'bytes mut [u8], + ) -> Option>; + } + + impl TestTryFromMut for AutorefWrapper { + #[allow(clippy::needless_lifetimes)] + fn test_try_from_mut<'bytes>( + &self, + bytes: &'bytes mut [u8], + ) -> Option> { + Some(T::try_mut_from_bytes(bytes).ok()) + } + } + pub(super) trait TestTryReadFrom { fn test_try_read_from(&self, bytes: &[u8]) -> Option>; } @@ -1255,6 +1273,25 @@ mod tests { None } + #[allow(clippy::needless_lifetimes)] + fn test_try_from_mut<'bytes>(&mut self, _bytes: &'bytes mut [u8]) -> Option> { + assert_on_allowlist!( + test_try_from_mut($ty): + Option>>, + Option<&'static UnsafeCell>, + Option<&'static mut UnsafeCell>, + Option>>, + Option, + Option, + Option, + Option, + *const NotZerocopy, + *mut NotZerocopy + ); + + None + } + fn test_try_read_from(&mut self, _bytes: &[u8]) -> Option> { assert_on_allowlist!( test_try_read_from($ty): @@ -1363,8 +1400,10 @@ mod tests { let bytes_mut = &mut vec.as_mut_slice()[offset..offset+size]; bytes_mut.copy_from_slice(bytes); - let res = <$ty as TryFromBytes>::try_mut_from_bytes(bytes_mut); - assert!(res.is_ok(), "{}::try_mut_from_bytes({:?}): got `Err`, expected `Ok`", stringify!($ty), val); + let res = ww.test_try_from_mut(bytes_mut); + if let Some(res) = res { + assert!(res.is_some(), "{}::try_mut_from_bytes({:?}): got `None`, expected `Some`", stringify!($ty), val); + } } let res = bytes.and_then(|bytes| ww.test_try_read_from(bytes)); @@ -1384,8 +1423,11 @@ mod tests { assert!(res.is_none(), "{}::try_ref_from_bytes({:?}): got Some, expected None", stringify!($ty), c); } - let res = <$ty as TryFromBytes>::try_mut_from_bytes(c); - assert!(res.is_err(), "{}::try_mut_from_bytes({:?}): got Ok, expected Err", stringify!($ty), c); + let res = w.test_try_from_mut(c); + if let Some(res) = res { + assert!(res.is_none(), "{}::try_mut_from_bytes({:?}): got Some, expected None", stringify!($ty), c); + } + let res = w.test_try_read_from(c); if let Some(res) = res { diff --git a/src/lib.rs b/src/lib.rs index b6c7876730..b97393f765 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1713,8 +1713,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: [u8; 2], /// trailing_dst: [()], @@ -1731,17 +1731,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -1769,7 +1769,7 @@ pub unsafe trait TryFromBytes { #[inline] fn try_mut_from_bytes(bytes: &mut [u8]) -> Result<&mut Self, TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { static_assert_dst_is_not_zst!(Self); match Ptr::from_mut(bytes).try_cast_into_no_leftover::(None) { @@ -1821,8 +1821,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: [u8; 2], /// trailing_dst: [()], @@ -1839,17 +1839,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -1882,7 +1882,7 @@ pub unsafe trait TryFromBytes { source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { static_assert_dst_is_not_zst!(Self); try_mut_from_prefix_suffix(source, CastType::Prefix, None) @@ -1916,8 +1916,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: u16, /// trailing_dst: [()], @@ -1934,17 +1934,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -1977,7 +1977,7 @@ pub unsafe trait TryFromBytes { source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { static_assert_dst_is_not_zst!(Self); try_mut_from_prefix_suffix(source, CastType::Suffix, None).map(swap) @@ -2286,17 +2286,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -2330,8 +2330,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: NonZeroU16, /// trailing_dst: [()], @@ -2351,7 +2351,7 @@ pub unsafe trait TryFromBytes { count: usize, ) -> Result<&mut Self, TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { match Ptr::from_mut(source).try_cast_into_no_leftover::(Some(count)) { @@ -2397,17 +2397,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -2443,8 +2443,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: NonZeroU16, /// trailing_dst: [()], @@ -2464,7 +2464,7 @@ pub unsafe trait TryFromBytes { count: usize, ) -> Result<(&mut Self, &mut [u8]), TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { try_mut_from_prefix_suffix(source, CastType::Prefix, Some(count)) } @@ -2492,17 +2492,17 @@ pub unsafe trait TryFromBytes { /// # use zerocopy_derive::*; /// /// // The only valid value of this type is the byte `0xC0` - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(u8)] /// enum C0 { xC0 = 0xC0 } /// /// // The only valid value of this type is the bytes `0xC0C0`. - /// #[derive(TryFromBytes, KnownLayout)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] /// #[repr(C)] /// struct C0C0(C0, C0); /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct Packet { /// magic_number: C0C0, /// mug_size: u8, @@ -2538,8 +2538,8 @@ pub unsafe trait TryFromBytes { /// use zerocopy::*; /// # use zerocopy_derive::*; /// - /// #[derive(TryFromBytes, KnownLayout)] - /// #[repr(C)] + /// #[derive(TryFromBytes, IntoBytes, KnownLayout)] + /// #[repr(C, packed)] /// struct ZSTy { /// leading_sized: NonZeroU16, /// trailing_dst: [()], @@ -2559,7 +2559,7 @@ pub unsafe trait TryFromBytes { count: usize, ) -> Result<(&mut [u8], &mut Self), TryCastError<&mut [u8], Self>> where - Self: KnownLayout, + Self: KnownLayout + IntoBytes, { try_mut_from_prefix_suffix(source, CastType::Suffix, Some(count)).map(swap) } @@ -2771,7 +2771,7 @@ fn try_ref_from_prefix_suffix( +fn try_mut_from_prefix_suffix( candidate: &mut [u8], cast_type: CastType, meta: Option, diff --git a/src/macros.rs b/src/macros.rs index d1d32c81b4..51200bf54e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -249,8 +249,8 @@ macro_rules! transmute_ref { /// const fn transmute_mut<'src, 'dst, Src, Dst>(src: &'src mut Src) -> &'dst mut Dst /// where /// 'src: 'dst, -/// Src: FromBytes + IntoBytes + Immutable, -/// Dst: FromBytes + IntoBytes + Immutable, +/// Src: FromBytes + IntoBytes, +/// Dst: FromBytes + IntoBytes, /// size_of::() == size_of::(), /// align_of::() >= align_of::(), /// { @@ -325,9 +325,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 + IntoBytes + Immutable` - // and that the type of this macro expression is `&mut U` where `U: - // 'u + Sized + FromBytes + IntoBytes + Immutable`. + // `&mut T` where `T: 't + Sized + FromBytes + IntoBytes` and that + // the type of this macro expression is `&mut U` where `U: 'u + + // Sized + FromBytes + IntoBytes`. // We use immutable references here rather than mutable so that, if // this macro is used in a const context (in which, as of this @@ -577,8 +577,8 @@ macro_rules! try_transmute_ref { /// ```ignore /// fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> /// where -/// Src: IntoBytes, -/// Dst: TryFromBytes, +/// Src: FromBytes + IntoBytes, +/// Dst: TryFromBytes + IntoBytes, /// size_of::() == size_of::(), /// align_of::() >= align_of::(), /// { @@ -888,9 +888,9 @@ mod tests { #[test] fn test_try_transmute_mut() { // Test that memory is transmuted with `try_transmute_mut` as expected. - let array_of_bools = &mut [false, true, false, true, false, true, false, true]; + let array_of_u8s = &mut [0u8, 1, 0, 1, 0, 1, 0, 1]; let array_of_arrays = &mut [[0u8, 1], [0, 1], [0, 1], [0, 1]]; - let x: Result<&mut [[u8; 2]; 4], _> = try_transmute_mut!(array_of_bools); + let x: Result<&mut [[u8; 2]; 4], _> = try_transmute_mut!(array_of_u8s); assert_eq!(x, Ok(array_of_arrays)); let array_of_bools = &mut [false, true, false, true, false, true, false, true]; @@ -903,8 +903,8 @@ mod tests { let array_of_bools = &mut [false, true, false, true, false, true, false, true]; let array_of_arrays = &mut [[0u8, 1], [0, 1], [0, 1], [0, 1]]; { - let x: Result<&mut [[u8; 2]; 4], _> = try_transmute_mut!(array_of_bools); - assert_eq!(x, Ok(array_of_arrays)); + let x: Result<&mut [bool; 8], _> = try_transmute_mut!(array_of_arrays); + assert_eq!(x, Ok(array_of_bools)); } // Test that `try_transmute_mut!` supports decreasing alignment. diff --git a/src/util/macro_util.rs b/src/util/macro_util.rs index fcc7ca2397..1ee8a36d4e 100644 --- a/src/util/macro_util.rs +++ b/src/util/macro_util.rs @@ -26,7 +26,7 @@ use core::ptr::{self, NonNull}; use crate::{ pointer::invariant::{self, BecauseExclusive, BecauseImmutable, Invariants}, - Immutable, IntoBytes, Ptr, TryFromBytes, Unalign, ValidityError, + FromBytes, Immutable, IntoBytes, Ptr, TryFromBytes, Unalign, ValidityError, }; /// Projects the type of the field at `Index` in `Self`. @@ -538,6 +538,8 @@ fn try_cast_or_pme( ValidityError, Dst>, > where + // TODO(#2226): There should be a `Src: FromBytes` bound here, but doing so + // requires deeper surgery. Src: IntoBytes + invariant::Read, Dst: TryFromBytes + invariant::Read, I: Invariants, @@ -658,8 +660,8 @@ where #[inline(always)] pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> where - Src: IntoBytes, - Dst: TryFromBytes, + Src: FromBytes + IntoBytes, + Dst: TryFromBytes + IntoBytes, { match try_cast_or_pme::(Ptr::from_mut(src)) { Ok(ptr) => { diff --git a/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr index a682314f09..0879aff9e5 100644 --- a/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr +++ b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -17,10 +17,33 @@ error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satis note: required by a bound in `try_transmute_mut` --> src/util/macro_util.rs | - | Dst: TryFromBytes, + | Dst: TryFromBytes + IntoBytes, | ^^^^^^^^^^^^ required by this bound in `try_transmute_mut` = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `zerocopy::IntoBytes`: + () + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + and $N others +note: required by a bound in `try_transmute_mut` + --> src/util/macro_util.rs + | + | Dst: TryFromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `try_transmute_mut` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied --> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:33 | diff --git a/tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs new file mode 120000 index 0000000000..b0e1ecf000 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-src-not-frombytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr new file mode 100644 index 0000000000..5d47d0122f --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr @@ -0,0 +1,100 @@ +error[E0277]: the trait bound `Src: FromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Src` + | required by a bound introduced by this call + | + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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: FromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` + | + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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 `Dst: FromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr index ff726ab6d9..5afba09b9f 100644 --- a/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr @@ -1,25 +1,100 @@ -error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied - --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:19:52 +error[E0277]: the trait bound `Src: IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 | -19 | let src_not_into_bytes: Result<&mut AU16, _> = try_transmute_mut!(src); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` - | required by a bound introduced by this call +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Src` + | required by a bound introduced by this call | - = help: the following other types implement trait `zerocopy::IntoBytes`: + = help: the following other types implement trait `IntoBytes`: () - AU16 AtomicBool AtomicI16 AtomicI32 AtomicI64 AtomicI8 AtomicIsize + AtomicU16 and $N others -note: required by a bound in `try_transmute_mut` - --> src/util/macro_util.rs +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 | - | Src: IntoBytes, - | ^^^^^^^^^ required by this bound in `try_transmute_mut` - = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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: IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` + | + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 `Dst: FromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr index ae0d3114af..29b392ef80 100644 --- a/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr +++ b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -44,10 +44,37 @@ note: required by a bound in `try_transmute_mut` | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> | ----------------- required by a bound in this function ... - | Dst: TryFromBytes, + | Dst: TryFromBytes + IntoBytes, | ^^^^^^^^^^^^ required by this bound in `try_transmute_mut` = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:63 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` + | + = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` + = help: the following other types implement trait `zerocopy::IntoBytes`: + () + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + and $N others +note: required by a bound in `try_transmute_mut` + --> src/util/macro_util.rs + | + | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `try_transmute_mut` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied --> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:63 | diff --git a/tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs new file mode 100644 index 0000000000..12b2e0d328 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs @@ -0,0 +1,24 @@ +// Copyright 2024 The Fuchsia Authors +// +// Licensed under a BSD-style license , Apache License, Version 2.0 +// , or the MIT +// license , at your option. +// This file may not be copied, modified, or distributed except according to +// those terms. + +extern crate zerocopy; + +use zerocopy::transmute_mut; + +#[derive(zerocopy::IntoBytes)] +#[repr(C)] +struct Src; + +#[derive(zerocopy::TryFromBytes)] +#[repr(C)] +struct Dst; + +fn main() { + // `try_transmute_mut` requires that the source type implements `FromBytes` + let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); +} diff --git a/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr new file mode 100644 index 0000000000..5a55338881 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr @@ -0,0 +1,104 @@ +error[E0277]: the trait bound `Src: FromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Src` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Src` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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: FromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` + | + = note: Consider adding `#[derive(FromBytes)]` to `Src` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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 `Dst: FromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Dst` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(IntoBytes)]` to `Dst` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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/try_transmute_mut-src-not-intobytes.rs b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs index 1987bf15b2..fa3b7032d0 100644 --- a/tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs +++ b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs @@ -6,15 +6,19 @@ // This file may not be copied, modified, or distributed except according to // those terms. -include!("../../zerocopy-derive/tests/include.rs"); - extern crate zerocopy; -use util::{NotZerocopy, AU16}; -use zerocopy::try_transmute_mut; +use zerocopy::transmute_mut; + +#[derive(zerocopy::FromBytes)] +#[repr(C)] +struct Src; + +#[derive(zerocopy::TryFromBytes)] +#[repr(C)] +struct Dst; fn main() { // `try_transmute_mut` requires that the source type implements `IntoBytes` - let src = &mut NotZerocopy(AU16(0)); - let src_not_into_bytes: Result<&mut AU16, _> = try_transmute_mut!(src); + let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); } diff --git a/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr index 44b7e66233..66868266d2 100644 --- a/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr @@ -1,26 +1,104 @@ -error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied - --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:19:52 +error[E0277]: the trait bound `Src: IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 | -19 | let src_not_into_bytes: Result<&mut AU16, _> = try_transmute_mut!(src); - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Src` + | required by a bound introduced by this call | - = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` - = help: the following other types implement trait `zerocopy::IntoBytes`: + = note: Consider adding `#[derive(IntoBytes)]` to `Src` + = help: the following other types implement trait `IntoBytes`: () - AU16 AtomicBool AtomicI16 AtomicI32 AtomicI64 AtomicI8 AtomicIsize + AtomicU16 and $N others -note: required by a bound in `try_transmute_mut` - --> src/util/macro_util.rs - | - | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> - | ----------------- required by a bound in this function - | where - | Src: IntoBytes, - | ^^^^^^^^^ required by this bound in `try_transmute_mut` - = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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: IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` + | + = note: Consider adding `#[derive(IntoBytes)]` to `Src` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 `Dst: FromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Dst` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(IntoBytes)]` to `Dst` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr index 7f608de647..0fc9f2b51e 100644 --- a/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr +++ b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -44,10 +44,37 @@ note: required by a bound in `try_transmute_mut` | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> | ----------------- required by a bound in this function ... - | Dst: TryFromBytes, + | Dst: TryFromBytes + IntoBytes, | ^^^^^^^^^^^^ required by this bound in `try_transmute_mut` = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs:20:63 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` + | + = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` + = help: the following other types implement trait `zerocopy::IntoBytes`: + () + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + and $N others +note: required by a bound in `try_transmute_mut` + --> src/util/macro_util.rs + | + | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `try_transmute_mut` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied --> tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs:20:63 | diff --git a/tests/ui-stable/try_transmute_mut-src-not-frombytes.rs b/tests/ui-stable/try_transmute_mut-src-not-frombytes.rs new file mode 120000 index 0000000000..b0e1ecf000 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-src-not-frombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-src-not-frombytes.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr b/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr new file mode 100644 index 0000000000..9c60ac19b3 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr @@ -0,0 +1,104 @@ +error[E0277]: the trait bound `Src: FromBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Src` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Src` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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: FromBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` + | + = note: Consider adding `#[derive(FromBytes)]` to `Src` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertSrcIsFromBytes` + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + = 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 `Dst: FromBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Dst` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(IntoBytes)]` to `Dst` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr index a5185e12ef..371917bbbb 100644 --- a/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr @@ -1,26 +1,104 @@ -error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied - --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:19:52 +error[E0277]: the trait bound `Src: IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 | -19 | let src_not_into_bytes: Result<&mut AU16, _> = try_transmute_mut!(src); - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Src` + | required by a bound introduced by this call | - = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` - = help: the following other types implement trait `zerocopy::IntoBytes`: + = note: Consider adding `#[derive(IntoBytes)]` to `Src` + = help: the following other types implement trait `IntoBytes`: () - AU16 AtomicBool AtomicI16 AtomicI32 AtomicI64 AtomicI8 AtomicIsize + AtomicU16 and $N others -note: required by a bound in `try_transmute_mut` - --> src/util/macro_util.rs - | - | pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> - | ----------------- required by a bound in this function - | where - | Src: IntoBytes, - | ^^^^^^^^^ required by this bound in `try_transmute_mut` - = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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: IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` + | + = note: Consider adding `#[derive(IntoBytes)]` to `Src` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertSrcIsIntoBytes` + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 `Dst: FromBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(FromBytes)]` to `Dst` + = help: the following other types implement trait `FromBytes`: + () + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + AtomicU32 + and $N others +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + = 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 `Dst: IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `IntoBytes` is not implemented for `Dst` + | required by a bound introduced by this call + | + = note: Consider adding `#[derive(IntoBytes)]` to `Dst` + = help: the following other types implement trait `IntoBytes`: + () + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + AtomicIsize + AtomicU16 + and $N others +note: required by a bound in `AssertDstIsIntoBytes` + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 + | +23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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)