diff --git a/README.md b/README.md index 0664c998cd..136e4b98d6 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,12 @@ Zerocopy provides four macros for safe, zero-cost casting between types: - (`try_`[try_transmute])`transmute` (conditionally) converts a value of one type to a value of another type of the same size -- `transmute_mut` converts a mutable reference of one type to a mutable - reference of another type of the same size -- `transmute_ref` converts a mutable or immutable reference - of one type to an immutable reference of another type of the same size +- (`try_`[try_transmute_mut])`transmute_mut` (conditionally) converts a + mutable reference of one type to a mutable reference of another type of + the same size +- (`try_`[try_transmute_ref])`transmute_ref` (conditionally) converts a + mutable or immutable reference of one type to an immutable reference of + another type of the same size These macros perform *compile-time* alignment and size checks, but cannot be used in generic contexts. For generic conversions, use the methods defined diff --git a/src/lib.rs b/src/lib.rs index 669d4e880f..e444004e4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,10 +60,12 @@ //! //! - ([`try_`][try_transmute])[`transmute`] (conditionally) converts a value of //! one type to a value of another type of the same size -//! - [`transmute_mut`] converts a mutable reference of one type to a mutable -//! reference of another type of the same size -//! - [`transmute_ref`] converts a mutable or immutable reference -//! of one type to an immutable reference of another type of the same size +//! - ([`try_`][try_transmute_mut])[`transmute_mut`] (conditionally) converts a +//! mutable reference of one type to a mutable reference of another type of +//! the same size +//! - ([`try_`][try_transmute_ref])[`transmute_ref`] (conditionally) converts a +//! mutable or immutable reference of one type to an immutable reference of +//! another type of the same size //! //! These macros perform *compile-time* alignment and size checks, but cannot be //! used in generic contexts. For generic conversions, use the methods defined @@ -4750,7 +4752,7 @@ macro_rules! transmute_mut { /// This macro behaves like an invocation of this function: /// /// ```ignore -/// const fn try_transmute(src: Src) -> Result> +/// fn try_transmute(src: Src) -> Result> /// where /// Src: IntoBytes, /// Dst: TryFromBytes, @@ -4784,10 +4786,9 @@ macro_rules! transmute_mut { /// /// // 2u8 → bool = error /// assert!(matches!( -/// try_transmute!(3u8), +/// try_transmute!(2u8), /// Result::::Err(ValidityError { .. }) /// )); -/// /// ``` #[macro_export] macro_rules! try_transmute { @@ -4814,6 +4815,231 @@ macro_rules! try_transmute { }} } +/// Conditionally transmutes a mutable or immutable reference of one type to an +/// immutable reference of another type of the same size. +/// +/// This macro behaves like an invocation of this function: +/// +/// ```ignore +/// fn try_transmute_ref(src: &Src) -> Result<&Dst, ValidityError<&Src, &Dst>> +/// where +/// Src: IntoBytes + Immutable, +/// Dst: TryFromBytes + Immutable, +/// size_of::() == size_of::(), +/// align_of::() >= align_of::(), +/// { +/// # /* +/// ... +/// # */ +/// } +/// ``` +/// +/// However, unlike a function, this macro can only be invoked when the types of +/// `Src` and `Dst` are completely concrete. The types `Src` and `Dst` are +/// inferred from the calling context; they cannot be explicitly specified in +/// the macro invocation. +/// +/// Note that the `Src` produced by the expression `$e` will *not* be dropped. +/// Semantically, its bits will be copied into a new value of type `Dst`, the +/// original `Src` will be forgotten, and the value of type `Dst` will be +/// returned. +/// +/// # Examples +/// +/// ``` +/// # use zerocopy::*; +/// // 0u8 → bool = false +/// assert_eq!(try_transmute_ref!(&0u8), Ok(&false)); +/// +/// // 1u8 → bool = true +/// assert_eq!(try_transmute_ref!(&1u8), Ok(&true)); +/// +/// // 2u8 → bool = error +/// assert!(matches!( +/// try_transmute_ref!(&2u8), +/// Result::<&bool, _>::Err(ValidityError { .. }) +/// )); +/// ``` +/// +/// # Alignment increase error message +/// +/// Because of limitations on macros, the error message generated when +/// `try_transmute_ref!` is used to transmute from a type of lower alignment to +/// a type of higher alignment is somewhat confusing. For example, the following +/// code: +/// +/// ```compile_fail +/// let increase_alignment: Result<&u16, _> = zerocopy::try_transmute_ref!(&[0u8; 2]); +/// ``` +/// +/// ...generates the following error: +/// +/// ```text +/// error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +/// --> example.rs:1:47 +/// | +/// 1 | let increase_alignment: Result<&u16, _> = zerocopy::try_transmute_ref!(&[0u8; 2]); +/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +/// | +/// = note: source type: `AlignOf<[u8; 2]>` (8 bits) +/// = note: target type: `MaxAlignsOf<[u8; 2], u16>` (16 bits) +/// = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `zerocopy::try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)/// ``` +/// ``` +/// +/// This is saying that `max(align_of::(), align_of::()) != +/// align_of::()`, which is equivalent to `align_of::() < +/// align_of::()`. +#[macro_export] +macro_rules! try_transmute_ref { + ($e:expr) => {{ + // NOTE: This must be a macro (rather than a function with trait bounds) + // because there's no way, in a generic context, to enforce that two + // types have the same size. `core::mem::transmute` uses compiler magic + // to enforce this so long as the types are concrete. + + // Ensure that the source type is a reference or a mutable reference + // (note that mutable references are implicitly reborrowed here). + let e: &_ = $e; + + #[allow(unreachable_code, unused, clippy::diverging_sub_expression)] + if false { + // This branch, though never taken, ensures that `size_of::() == + // size_of::()` and that that `align_of::() >= + // align_of::()`. + + // `t` is inferred to have type `T` because it's assigned to `e` (of + // type `&T`) as `&t`. + let mut t = loop {}; + e = &t; + + // `u` is inferred to have type `U` because it's used as `&u` as the + // value returned from this branch. + let u; + + $crate::assert_size_eq!(t, u); + $crate::assert_align_gt_eq!(t, u); + + Ok(&u) + } else { + $crate::macro_util::try_transmute_ref::<_, _>(e) + } + }} +} + +/// Conditionally transmutes a mutable reference of one type to a mutable +/// reference of another type of the same size. +/// +/// This macro behaves like an invocation of this function: +/// +/// ```ignore +/// fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, &mut Dst>> +/// where +/// Src: IntoBytes, +/// Dst: TryFromBytes, +/// size_of::() == size_of::(), +/// align_of::() >= align_of::(), +/// { +/// # /* +/// ... +/// # */ +/// } +/// ``` +/// +/// However, unlike a function, this macro can only be invoked when the types of +/// `Src` and `Dst` are completely concrete. The types `Src` and `Dst` are +/// inferred from the calling context; they cannot be explicitly specified in +/// the macro invocation. +/// +/// Note that the `Src` produced by the expression `$e` will *not* be dropped. +/// Semantically, its bits will be copied into a new value of type `Dst`, the +/// original `Src` will be forgotten, and the value of type `Dst` will be +/// returned. +/// +/// # Examples +/// +/// ``` +/// # use zerocopy::*; +/// // 0u8 → bool = false +/// let src = &mut 0u8; +/// assert_eq!(try_transmute_mut!(src), Ok(&mut false)); +/// +/// // 1u8 → bool = true +/// let src = &mut 1u8; +/// assert_eq!(try_transmute_mut!(src), Ok(&mut true)); +/// +/// // 2u8 → bool = error +/// let src = &mut 2u8; +/// assert!(matches!( +/// try_transmute_mut!(src), +/// Result::<&mut bool, _>::Err(ValidityError { .. }) +/// )); +/// ``` +/// +/// # Alignment increase error message +/// +/// Because of limitations on macros, the error message generated when +/// `try_transmute_ref!` is used to transmute from a type of lower alignment to +/// a type of higher alignment is somewhat confusing. For example, the following +/// code: +/// +/// ```compile_fail +/// let src = &mut [0u8; 2]; +/// let increase_alignment: Result<&mut u16, _> = zerocopy::try_transmute_mut!(src); +/// ``` +/// +/// ...generates the following error: +/// +/// ```text +/// error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +/// --> example.rs:2:51 +/// | +/// 2 | let increase_alignment: Result<&mut u16, _> = zerocopy::try_transmute_mut!(src); +/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +/// | +/// = note: source type: `AlignOf<[u8; 2]>` (8 bits) +/// = note: target type: `MaxAlignsOf<[u8; 2], u16>` (16 bits) +/// = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `zerocopy::try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +/// ``` +/// +/// This is saying that `max(align_of::(), align_of::()) != +/// align_of::()`, which is equivalent to `align_of::() < +/// align_of::()`. +#[macro_export] +macro_rules! try_transmute_mut { + ($e:expr) => {{ + // NOTE: This must be a macro (rather than a function with trait bounds) + // because there's no way, in a generic context, to enforce that two + // types have the same size. `core::mem::transmute` uses compiler magic + // to enforce this so long as the types are concrete. + + // Ensure that the source type is a mutable reference. + let e: &mut _ = $e; + + #[allow(unreachable_code, unused, clippy::diverging_sub_expression)] + if false { + // This branch, though never taken, ensures that `size_of::() == + // size_of::()` and that that `align_of::() >= + // align_of::()`. + + // `t` is inferred to have type `T` because it's assigned to `e` (of + // type `&mut T`) as `&mut t`. + let mut t = loop {}; + e = &mut t; + + // `u` is inferred to have type `U` because it's used as `&mut u` as + // the value returned from this branch. + let u; + + $crate::assert_size_eq!(t, u); + $crate::assert_align_gt_eq!(t, u); + + Ok(&mut u) + } else { + $crate::macro_util::try_transmute_mut::<_, _>(e) + } + }} +} + /// Includes a file and safely transmutes it to a value of an arbitrary type. /// /// The file will be included as a byte array, `[u8; N]`, which will be @@ -5775,6 +6001,71 @@ mod tests { mem::forget(y); } + #[test] + fn test_try_transmute_ref() { + // Test that memory is transmuted with `try_transmute_ref` as expected. + let array_of_bools = &[false, true, false, true, false, true, false, true]; + let array_of_arrays = &[[0, 1], [0, 1], [0, 1], [0, 1]]; + let x: Result<&[[u8; 2]; 4], _> = try_transmute_ref!(array_of_bools); + assert_eq!(x, Ok(array_of_arrays)); + let x: Result<&[bool; 8], _> = try_transmute_ref!(array_of_arrays); + assert_eq!(x, Ok(array_of_bools)); + + // Test that it's legal to transmute a reference while shrinking the + // lifetime. + { + let x: Result<&[[u8; 2]; 4], _> = try_transmute_ref!(array_of_bools); + assert_eq!(x, Ok(array_of_arrays)); + } + + // Test that `try_transmute_ref!` supports decreasing alignment. + let u = AU64(0); + let array = [0u8, 0, 0, 0, 0, 0, 0, 0]; + let x: Result<&[u8; 8], _> = try_transmute_ref!(&u); + assert_eq!(x, Ok(&array)); + + // Test that a mutable reference can be turned into an immutable one. + let mut x = 0u8; + #[allow(clippy::useless_transmute)] + let y: Result<&u8, _> = try_transmute_ref!(&mut x); + assert_eq!(y, Ok(&0)); + } + + #[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_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 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 [bool; 8], _> = try_transmute_mut!(array_of_arrays); + assert_eq!(x, Ok(array_of_bools)); + + // Test that it's legal to transmute a reference while shrinking the + // lifetime. + 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)); + } + + // Test that `try_transmute_mut!` supports decreasing alignment. + let u = &mut AU64(0); + let array = &mut [0u8, 0, 0, 0, 0, 0, 0, 0]; + let x: Result<&mut [u8; 8], _> = try_transmute_mut!(u); + assert_eq!(x, Ok(array)); + + // Test that a mutable reference can be turned into an immutable one. + let mut x = 0u8; + #[allow(clippy::useless_transmute)] + let y: Result<&mut u8, _> = try_transmute_mut!(&mut x); + assert_eq!(y, Ok(&mut 0)); + } + #[test] fn test_transmute_mut() { // Test that memory is transmuted as expected. diff --git a/src/macro_util.rs b/src/macro_util.rs index 68e5110d71..ff93380484 100644 --- a/src/macro_util.rs +++ b/src/macro_util.rs @@ -30,9 +30,9 @@ use core::ptr::{self, NonNull}; use crate::{ pointer::{ invariant::{self, AtLeast, Invariants}, - AliasingSafe, AliasingSafeReason, BecauseExclusive, + AliasingSafe, AliasingSafeReason, BecauseExclusive, BecauseImmutable, }, - IntoBytes, Ptr, TryFromBytes, ValidityError, + Immutable, IntoBytes, Ptr, TryFromBytes, Unalign, ValidityError, }; /// A compile-time check that should be one particular value. @@ -420,24 +420,31 @@ pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( unsafe { &mut *dst } } -/// Is a given source a valid instance of `Self`? +/// Is a given source a valid instance of `Dst`? +/// +/// If so, returns `src` casted to a `Ptr`. Otherwise returns `None`. /// /// # Safety /// -/// Unsafe code may assume that, if `is_mut_src_valid(src)` returns true, `*src` -/// is a bit-valid instance of `Dst`, and that the size of `Src` is greater than -/// or equal to the size of `Dst`. +/// Unsafe code may assume that, if `try_cast_or_pme(src)` returns `Some`, +/// `*src` is a bit-valid instance of `Dst`, and that the size of `Src` is +/// greater than or equal to the size of `Dst`. /// /// # Panics /// -/// `is_src_valid` may either produce a post-monomorphization error or a panic -/// if `Dst` is bigger than `Src`. Otherwise, `is_src_valid` panics under the -/// same circumstances as [`is_bit_valid`]. +/// `try_cast_or_pme` may either produce a post-monomorphization error or a +/// panic if `Dst` not the same size as `Src`. Otherwise, `try_cast_or_pme` +/// panics under the same circumstances as [`is_bit_valid`]. /// /// [`is_bit_valid`]: TryFromBytes::is_bit_valid #[doc(hidden)] #[inline] -fn is_src_valid(src: Ptr<'_, Src, I>) -> bool +fn try_cast_or_pme( + src: Ptr<'_, Src, I>, +) -> Result< + Ptr<'_, Dst, (I::Aliasing, invariant::Any, invariant::Valid)>, + ValidityError, Dst>, +> where Src: IntoBytes, Dst: TryFromBytes + AliasingSafe, @@ -445,12 +452,12 @@ where I::Aliasing: AtLeast, R: AliasingSafeReason, { - static_assert!(Src, Dst => mem::size_of::() >= mem::size_of::()); + static_assert!(Src, Dst => mem::size_of::() == mem::size_of::()); // SAFETY: This is a pointer cast, satisfying the following properties: // - `p as *mut Dst` addresses a subset of the `bytes` addressed by `src`, - // because we assert above that the size of `Dst` is less than or equal to - // the size of `Src`. + // because we assert above that the size of `Dst` equal to the size of + // `Src`. // - `p as *mut Dst` is a provenance-preserving cast // - Because `Dst: AliasingSafe`, either: // - `I::Aliasing` is `Exclusive` @@ -464,7 +471,30 @@ where // initialized bytes. let c_ptr = unsafe { c_ptr.assume_initialized() }; - Dst::is_bit_valid(c_ptr) + match c_ptr.try_into_valid() { + Ok(ptr) => Ok(ptr), + Err(err) => { + // Re-cast `Ptr` to `Ptr`. + let ptr = err.into_src(); + // SAFETY: This is a pointer cast, satisfying the following + // properties: + // - `p as *mut Src` addresses a subset of the `bytes` addressed by + // `ptr`, because we assert above that the size of `Dst` is equal + // to the size of `Src`. + // - `p as *mut Src` is a provenance-preserving cast + // - Because `Dst: AliasingSafe`, either: + // - `I::Aliasing` is `Exclusive` + // - `Src` and `Dst` are both `Immutable`, in which case they + // trivially contain `UnsafeCell`s at identical locations + #[allow(clippy::as_conversions)] + let ptr = unsafe { ptr.cast_unsized(|p| p as *mut Src) }; + // SAFETY: `ptr` is `src`, and has the same alignment invariant. + let ptr = unsafe { ptr.assume_alignment::() }; + // SAFETY: `ptr` is `src` and has the same validity invariant. + let ptr = unsafe { ptr.assume_validity::() }; + Err(ValidityError::new(ptr.unify_invariants())) + } + } } /// Attempts to transmute `Src` into `Dst`. @@ -479,25 +509,83 @@ where /// /// [`is_bit_valid`]: TryFromBytes::is_bit_valid #[inline(always)] -pub fn try_transmute(mut src: Src) -> Result> +pub fn try_transmute(src: Src) -> Result> where Src: IntoBytes, Dst: TryFromBytes, { - if !is_src_valid::(Ptr::from_mut(&mut src)) { - return Err(ValidityError::new(src)); + let mut src = ManuallyDrop::new(src); + let ptr = Ptr::from_mut(&mut src); + match try_cast_or_pme::<_, ManuallyDrop>, _, BecauseExclusive>(ptr) { + Ok(ptr) => { + let dst = ptr.bikeshed_recall_aligned().as_mut(); + // SAFETY: By shadowing `dst`, we ensure that `dst` is not re-used + // after taking its inner value. + let dst = unsafe { ManuallyDrop::take(dst) }; + Ok(dst.into_inner()) + } + Err(_) => Err(ValidityError::new(ManuallyDrop::into_inner(src))), } +} - let src = ManuallyDrop::new(src); +/// Attempts to transmute `&Src` into `&Dst`. +/// +/// A helper for `try_transmute_ref!`. +/// +/// # Panics +/// +/// `try_transmute_ref` may either produce a post-monomorphization error or a +/// panic if `Dst` is bigger or has a stricter alignment requirement than `Src`. +/// Otherwise, `try_transmute_ref` panics under the same circumstances as +/// [`is_bit_valid`]. +/// +/// [`is_bit_valid`]: TryFromBytes::is_bit_valid +#[inline(always)] +pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> +where + Src: IntoBytes + Immutable, + Dst: TryFromBytes + Immutable, +{ + match try_cast_or_pme::(Ptr::from_ref(src)) { + Ok(ptr) => { + static_assert!(Src, Dst => mem::align_of::() <= mem::align_of::()); + // SAFETY: We have checked that `Dst` does not have a stricter + // alignment requirement than `Src`. + let ptr = unsafe { ptr.assume_alignment::() }; + Ok(ptr.as_ref()) + } + Err(err) => Err(err.map_src(Ptr::as_ref)), + } +} - // SAFETY: By contract on `is_src_valid`, we have confirmed both that `Dst` - // is no larger than `Src`, and that `src` is a bit-valid instance of `Dst`. - // These conditions are preserved through the `ManuallyDrop` wrapper, - // which is documented to have identical and layout bit validity to its - // inner value [1]. - // - // [1]: https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html - Ok(unsafe { mem::transmute_copy(&*src) }) +/// Attempts to transmute `&mut Src` into `&mut Dst`. +/// +/// A helper for `try_transmute_mut!`. +/// +/// # Panics +/// +/// `try_transmute_mut` may either produce a post-monomorphization error or a +/// panic if `Dst` is bigger or has a stricter alignment requirement than `Src`. +/// Otherwise, `try_transmute_mut` panics under the same circumstances as +/// [`is_bit_valid`]. +/// +/// [`is_bit_valid`]: TryFromBytes::is_bit_valid +#[inline(always)] +pub fn try_transmute_mut(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>> +where + Src: IntoBytes, + Dst: TryFromBytes, +{ + match try_cast_or_pme::(Ptr::from_mut(src)) { + Ok(ptr) => { + static_assert!(Src, Dst => mem::align_of::() <= mem::align_of::()); + // SAFETY: We have checked that `Dst` does not have a stricter + // alignment requirement than `Src`. + let ptr = unsafe { ptr.assume_alignment::() }; + Ok(ptr.as_mut()) + } + Err(err) => Err(err.map_src(Ptr::as_mut)), + } } /// A function which emits a warning if its return value is not used. diff --git a/src/pointer/ptr.rs b/src/pointer/ptr.rs index f62b561704..0666d8b94a 100644 --- a/src/pointer/ptr.rs +++ b/src/pointer/ptr.rs @@ -726,7 +726,7 @@ mod _transitions { /// Helps the type system unify two distinct invariant types which are /// actually the same. - pub(super) fn unify_invariants< + pub(crate) fn unify_invariants< H: Invariants, >( self, diff --git a/tests/ui-msrv/try_transmute_mut-alignment-increase.rs b/tests/ui-msrv/try_transmute_mut-alignment-increase.rs new file mode 120000 index 0000000000..a168b513f3 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-alignment-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr b/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr new file mode 100644 index 0000000000..aa67d03d7e --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr @@ -0,0 +1,17 @@ +warning: unused variable: `increase_size` + --> tests/ui-msrv/try_transmute_mut-alignment-increase.rs:20:9 + | +20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_mut-alignment-increase.rs:20:47 + | +20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs new file mode 120000 index 0000000000..8f8b413e57 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr new file mode 100644 index 0000000000..f081e13713 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -0,0 +1,37 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `try_transmute_mut` + --> src/macro_util.rs + | + | Dst: TryFromBytes, + | ^^^^^^^^^^^^ 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: TryFromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:33 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_mut-size-decrease.rs b/tests/ui-msrv/try_transmute_mut-size-decrease.rs new file mode 120000 index 0000000000..4bbabf0cc7 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-size-decrease.stderr b/tests/ui-msrv/try_transmute_mut-size-decrease.stderr new file mode 100644 index 0000000000..6a5c78050a --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-size-decrease.stderr @@ -0,0 +1,17 @@ +warning: unused variable: `decrease_size` + --> tests/ui-msrv/try_transmute_mut-size-decrease.rs:20:9 + | +20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_decrease_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_mut-size-decrease.rs:20:45 + | +20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_mut-size-increase.rs b/tests/ui-msrv/try_transmute_mut-size-increase.rs new file mode 120000 index 0000000000..118d6ddf1f --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-size-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-size-increase.stderr b/tests/ui-msrv/try_transmute_mut-size-increase.stderr new file mode 100644 index 0000000000..b363475e5c --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-size-increase.stderr @@ -0,0 +1,25 @@ +warning: unused import: `util::AU16` + --> tests/ui-msrv/try_transmute_mut-size-increase.rs:13:5 + | +13 | use util::AU16; + | ^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused variable: `increase_size` + --> tests/ui-msrv/try_transmute_mut-size-increase.rs:20:9 + | +20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_mut-size-increase.rs:20:50 + | +20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `[u8; 2]` (16 bits) + = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs new file mode 120000 index 0000000000..89a3b9a7a5 --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr new file mode 100644 index 0000000000..95f2c2120f --- /dev/null +++ b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs:19:52 + | +19 | let src_not_into_bytes: Result<&mut AU16, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `try_transmute_mut` + --> src/macro_util.rs + | + | 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) diff --git a/tests/ui-msrv/try_transmute_ref-alignment-increase.rs b/tests/ui-msrv/try_transmute_ref-alignment-increase.rs new file mode 120000 index 0000000000..aa9a6579ee --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-alignment-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr b/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr new file mode 100644 index 0000000000..0ff43d87d4 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr @@ -0,0 +1,17 @@ +warning: unused variable: `increase_size` + --> tests/ui-msrv/try_transmute_ref-alignment-increase.rs:19:9 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_ref-alignment-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_ref-dst-mutable.rs b/tests/ui-msrv/try_transmute_ref-dst-mutable.rs new file mode 120000 index 0000000000..cb03dfb1d1 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-dst-mutable.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-dst-mutable.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr b/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr new file mode 100644 index 0000000000..41324693d2 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr @@ -0,0 +1,22 @@ +error[E0308]: mismatched types + --> tests/ui-msrv/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability + | + = note: expected mutable reference `&mut u8` + found reference `&_` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> tests/ui-msrv/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | types differ in mutability + | help: try using a variant of the expected enum: `Err($crate::macro_util::try_transmute_ref::<_, _>(e))` + | + = note: expected enum `Result<&mut u8, _>` + found enum `Result<&_, ValidityError<&u8, _>>` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs b/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs new file mode 120000 index 0000000000..05b416a55f --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr b/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr new file mode 100644 index 0000000000..0b8414abdb --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr @@ -0,0 +1,50 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` + | +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_ref-size-decrease.rs b/tests/ui-msrv/try_transmute_ref-size-decrease.rs new file mode 120000 index 0000000000..7f042862b1 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-size-decrease.stderr b/tests/ui-msrv/try_transmute_ref-size-decrease.stderr new file mode 100644 index 0000000000..a2d527d858 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-size-decrease.stderr @@ -0,0 +1,17 @@ +warning: unused variable: `decrease_size` + --> tests/ui-msrv/try_transmute_ref-size-decrease.rs:19:9 + | +19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_decrease_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_ref-size-decrease.rs:19:41 + | +19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_ref-size-increase.rs b/tests/ui-msrv/try_transmute_ref-size-increase.rs new file mode 120000 index 0000000000..3949f96753 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-size-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-size-increase.stderr b/tests/ui-msrv/try_transmute_ref-size-increase.stderr new file mode 100644 index 0000000000..44e02b42be --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-size-increase.stderr @@ -0,0 +1,17 @@ +warning: unused variable: `increase_size` + --> tests/ui-msrv/try_transmute_ref-size-increase.rs:19:9 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` + | + = note: `#[warn(unused_variables)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/try_transmute_ref-size-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs b/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs new file mode 120000 index 0000000000..c5aa135032 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr b/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr new file mode 100644 index 0000000000..9b9247ce87 --- /dev/null +++ b/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `zerocopy::Immutable` + | +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_mut-alignment-increase.rs b/tests/ui-nightly/try_transmute_mut-alignment-increase.rs new file mode 100644 index 0000000000..9cc1c675a0 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-alignment-increase.rs @@ -0,0 +1,21 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_mut; + +// `try_transmute_mut!` does not support transmuting from a type of smaller +// alignment to one of larger alignment. +fn main() { + let src = &mut [0u8; 2]; + let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); +} diff --git a/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr b/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr new file mode 100644 index 0000000000..9ff9c0e9d6 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_mut-alignment-increase.rs:20:47 + | +20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_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.rs b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs new file mode 100644 index 0000000000..89096cd1d8 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs @@ -0,0 +1,21 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::{NotZerocopy, AU16}; +use zerocopy::try_transmute_mut; + +fn main() { + // `try_transmute_mut` requires that the destination type implements + // `IntoBytes` + let src = &mut AU16(0); + let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); +} diff --git a/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr new file mode 100644 index 0000000000..fe6598e84f --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -0,0 +1,70 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:33 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `try_transmute_mut` + --> src/macro_util.rs + | + | pub fn try_transmute_mut<'a, Src, Dst>(src: &'a mut Src) -> Result<&'a mut Dst, ValidityError<&'a mut Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes, + | ^^^^^^^^^^^^ 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: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_mut-size-decrease.rs b/tests/ui-nightly/try_transmute_mut-size-decrease.rs new file mode 100644 index 0000000000..ab8211128e --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-size-decrease.rs @@ -0,0 +1,21 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_mut; + +// Although this is not a soundness requirement, we currently require that the +// size of the destination type is not smaller than the size of the source type. +fn main() { + let src = &mut AU16(0); + let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); +} diff --git a/tests/ui-nightly/try_transmute_mut-size-decrease.stderr b/tests/ui-nightly/try_transmute_mut-size-decrease.stderr new file mode 100644 index 0000000000..9a1e50e558 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_mut-size-decrease.rs:20:45 + | +20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_mut-size-increase.rs b/tests/ui-nightly/try_transmute_mut-size-increase.rs new file mode 100644 index 0000000000..9ac887f517 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-size-increase.rs @@ -0,0 +1,21 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_mut; + +// `try_transmute_mut!` does not support transmuting from a smaller type to a +// larger one. +fn main() { + let src = &mut 0u8; + let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); +} diff --git a/tests/ui-nightly/try_transmute_mut-size-increase.stderr b/tests/ui-nightly/try_transmute_mut-size-increase.stderr new file mode 100644 index 0000000000..4b71af1d6d --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-size-increase.stderr @@ -0,0 +1,17 @@ +warning: unused import: `util::AU16` + --> tests/ui-nightly/try_transmute_mut-size-increase.rs:13:5 + | +13 | use util::AU16; + | ^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_mut-size-increase.rs:20:50 + | +20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `[u8; 2]` (16 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_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 new file mode 100644 index 0000000000..1987bf15b2 --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::{NotZerocopy, AU16}; +use zerocopy::try_transmute_mut; + +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); +} diff --git a/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr new file mode 100644 index 0000000000..b2e82ce68b --- /dev/null +++ b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:19:52 + | +19 | let src_not_into_bytes: Result<&mut AU16, _> = 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/macro_util.rs + | + | pub fn try_transmute_mut<'a, Src, Dst>(src: &'a mut Src) -> Result<&'a mut Dst, ValidityError<&'a 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) diff --git a/tests/ui-nightly/try_transmute_ref-alignment-increase.rs b/tests/ui-nightly/try_transmute_ref-alignment-increase.rs new file mode 100644 index 0000000000..dc62f8672e --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-alignment-increase.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_ref; + +// `try_transmute_ref!` does not support transmuting from a type of smaller +// alignment to one of larger alignment. +fn main() { + let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); +} diff --git a/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr b/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr new file mode 100644 index 0000000000..53f4fd7ea8 --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_ref-alignment-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_ref-dst-mutable.rs b/tests/ui-nightly/try_transmute_ref-dst-mutable.rs new file mode 100644 index 0000000000..e27a12948d --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-dst-mutable.rs @@ -0,0 +1,19 @@ +// 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::try_transmute_ref; + +fn main() {} + +fn ref_dst_mutable() { + // `try_transmute_ref!` requires that its destination type be an immutable + // reference. + let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); +} diff --git a/tests/ui-nightly/try_transmute_ref-dst-mutable.stderr b/tests/ui-nightly/try_transmute_ref-dst-mutable.stderr new file mode 100644 index 0000000000..61abd7fea3 --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-dst-mutable.stderr @@ -0,0 +1,32 @@ +error[E0308]: mismatched types + --> tests/ui-nightly/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | types differ in mutability + | arguments to this enum variant are incorrect + | + = note: expected mutable reference `&mut u8` + found reference `&_` +help: the type constructed contains `&_` due to the type of the argument passed + --> tests/ui-nightly/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ this argument influences the type of `Ok` +note: tuple variant defined here + --> $RUST/core/src/result.rs + | + | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), + | ^^ + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> tests/ui-nightly/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability + | + = note: expected enum `Result<&mut u8, _>` + found enum `Result<&_, ValidityError<&u8, _>>` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs b/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs new file mode 100644 index 0000000000..3928a1cb2a --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::{NotZerocopy, AU16}; +use zerocopy::try_transmute_ref; + +fn main() { + // `try_transmute_ref` requires that the source type implements `Immutable` + // and `IntoBytes` + let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); +} diff --git a/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr b/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr new file mode 100644 index 0000000000..1646b627f6 --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr @@ -0,0 +1,96 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `zerocopy::Immutable`: + &T + &mut T + () + *const T + *mut T + AU16 + Box + F32 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_ref-size-decrease.rs b/tests/ui-nightly/try_transmute_ref-size-decrease.rs new file mode 100644 index 0000000000..ec6214abec --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-size-decrease.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_ref; + +// Although this is not a soundness requirement, we currently require that the +// size of the destination type is not smaller than the size of the source type. +fn main() { + let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); +} diff --git a/tests/ui-nightly/try_transmute_ref-size-decrease.stderr b/tests/ui-nightly/try_transmute_ref-size-decrease.stderr new file mode 100644 index 0000000000..414407279c --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_ref-size-decrease.rs:19:41 + | +19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_ref-size-increase.rs b/tests/ui-nightly/try_transmute_ref-size-increase.rs new file mode 100644 index 0000000000..ff1e8fca2a --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-size-increase.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::AU16; +use zerocopy::try_transmute_ref; + +// `try_transmute_ref!` does not support transmuting from a smaller type to a +// larger one. +fn main() { + let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); +} diff --git a/tests/ui-nightly/try_transmute_ref-size-increase.stderr b/tests/ui-nightly/try_transmute_ref-size-increase.stderr new file mode 100644 index 0000000000..91f32b751b --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-size-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/try_transmute_ref-size-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs b/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs new file mode 100644 index 0000000000..2aec95ae6c --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs @@ -0,0 +1,20 @@ +// 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. + +include!("../../zerocopy-derive/tests/include.rs"); + +extern crate zerocopy; + +use util::{NotZerocopy, AU16}; +use zerocopy::try_transmute_ref; + +fn main() { + // `try_transmute_ref` requires that the source type implements `Immutable` + // and `IntoBytes` + let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); +} diff --git a/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr b/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr new file mode 100644 index 0000000000..3e05d9b634 --- /dev/null +++ b/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr @@ -0,0 +1,51 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function + | where + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `zerocopy::Immutable`: + &T + &mut T + () + *const T + *mut T + AU16 + Box + F32 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function + | where + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_mut-alignment-increase.rs b/tests/ui-stable/try_transmute_mut-alignment-increase.rs new file mode 120000 index 0000000000..a168b513f3 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-alignment-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-alignment-increase.stderr b/tests/ui-stable/try_transmute_mut-alignment-increase.stderr new file mode 100644 index 0000000000..eb78252d93 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-alignment-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_mut-alignment-increase.rs:20:47 + | +20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_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.rs b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs new file mode 120000 index 0000000000..8f8b413e57 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr new file mode 100644 index 0000000000..326481d602 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr @@ -0,0 +1,70 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs:20:33 + | +20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `try_transmute_mut` + --> src/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, + | ^^^^^^^^^^^^ 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: TryFromBytes` 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 `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_mut-size-decrease.rs b/tests/ui-stable/try_transmute_mut-size-decrease.rs new file mode 120000 index 0000000000..4bbabf0cc7 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-size-decrease.stderr b/tests/ui-stable/try_transmute_mut-size-decrease.stderr new file mode 100644 index 0000000000..8f58170eda --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_mut-size-decrease.rs:20:45 + | +20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_mut-size-increase.rs b/tests/ui-stable/try_transmute_mut-size-increase.rs new file mode 120000 index 0000000000..118d6ddf1f --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-size-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-size-increase.stderr b/tests/ui-stable/try_transmute_mut-size-increase.stderr new file mode 100644 index 0000000000..d1e5217d82 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-size-increase.stderr @@ -0,0 +1,17 @@ +warning: unused import: `util::AU16` + --> tests/ui-stable/try_transmute_mut-size-increase.rs:13:5 + | +13 | use util::AU16; + | ^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_mut-size-increase.rs:20:50 + | +20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `[u8; 2]` (16 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_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.rs b/tests/ui-stable/try_transmute_mut-src-not-intobytes.rs new file mode 120000 index 0000000000..89a3b9a7a5 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-src-not-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_mut-src-not-intobytes.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr b/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr new file mode 100644 index 0000000000..fc2092bf65 --- /dev/null +++ b/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:19:52 + | +19 | let src_not_into_bytes: Result<&mut AU16, _> = 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/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) diff --git a/tests/ui-stable/try_transmute_ref-alignment-increase.rs b/tests/ui-stable/try_transmute_ref-alignment-increase.rs new file mode 120000 index 0000000000..aa9a6579ee --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-alignment-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-alignment-increase.stderr b/tests/ui-stable/try_transmute_ref-alignment-increase.stderr new file mode 100644 index 0000000000..9863f5a881 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-alignment-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_ref-alignment-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_ref-dst-mutable.rs b/tests/ui-stable/try_transmute_ref-dst-mutable.rs new file mode 120000 index 0000000000..cb03dfb1d1 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-dst-mutable.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-dst-mutable.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-dst-mutable.stderr b/tests/ui-stable/try_transmute_ref-dst-mutable.stderr new file mode 100644 index 0000000000..df97ad7527 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-dst-mutable.stderr @@ -0,0 +1,32 @@ +error[E0308]: mismatched types + --> tests/ui-stable/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | types differ in mutability + | arguments to this enum variant are incorrect + | + = note: expected mutable reference `&mut u8` + found reference `&_` +help: the type constructed contains `&_` due to the type of the argument passed + --> tests/ui-stable/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ this argument influences the type of `Ok` +note: tuple variant defined here + --> $RUST/core/src/result.rs + | + | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), + | ^^ + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> tests/ui-stable/try_transmute_ref-dst-mutable.rs:18:33 + | +18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability + | + = note: expected enum `Result<&mut u8, _>` + found enum `Result<&_, ValidityError<&u8, _>>` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs b/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs new file mode 120000 index 0000000000..05b416a55f --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr b/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr new file mode 100644 index 0000000000..008f39fd69 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr @@ -0,0 +1,96 @@ +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `zerocopy::Immutable`: + &T + &mut T + () + *const T + *mut T + AU16 + Box + F32 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function +... + | Dst: TryFromBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied + --> tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59 + | +19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `TryFromBytes`: + () + *const T + *mut T + AU16 + AtomicBool + AtomicI16 + AtomicI32 + AtomicI64 + and $N others +note: required by a bound in `ValidityError` + --> src/error.rs + | + | pub struct ValidityError { + | ^^^^^^^^^^^^ required by this bound in `ValidityError` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_ref-size-decrease.rs b/tests/ui-stable/try_transmute_ref-size-decrease.rs new file mode 120000 index 0000000000..7f042862b1 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-size-decrease.stderr b/tests/ui-stable/try_transmute_ref-size-decrease.stderr new file mode 100644 index 0000000000..98d012b388 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_ref-size-decrease.rs:19:41 + | +19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_ref-size-increase.rs b/tests/ui-stable/try_transmute_ref-size-increase.rs new file mode 120000 index 0000000000..3949f96753 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-size-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-size-increase.stderr b/tests/ui-stable/try_transmute_ref-size-increase.stderr new file mode 100644 index 0000000000..28438632a2 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-size-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/try_transmute_ref-size-increase.rs:19:43 + | +19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AlignOf<[u8; 2]>` (8 bits) + = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) + = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs b/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs new file mode 120000 index 0000000000..c5aa135032 --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs @@ -0,0 +1 @@ +../ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs \ No newline at end of file diff --git a/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr b/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr new file mode 100644 index 0000000000..e7474a60eb --- /dev/null +++ b/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr @@ -0,0 +1,51 @@ +error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied + --> tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function + | where + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied + --> tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs:19:48 + | +19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `zerocopy::Immutable`: + &T + &mut T + () + *const T + *mut T + AU16 + Box + F32 + and $N others +note: required by a bound in `try_transmute_ref` + --> src/macro_util.rs + | + | pub fn try_transmute_ref<'a, Src, Dst>(src: &'a Src) -> Result<&'a Dst, ValidityError<&'a Src, Dst>> + | ----------------- required by a bound in this function + | where + | Src: IntoBytes + Immutable, + | ^^^^^^^^^ required by this bound in `try_transmute_ref` + = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)