diff --git a/src/doctests.rs b/src/doctests.rs new file mode 100644 index 0000000000..938e16a981 --- /dev/null +++ b/src/doctests.rs @@ -0,0 +1,125 @@ +// Copyright 2025 The Fuchsia Authors +// +// Licensed under the 2-Clause BSD 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. + +#![cfg(feature = "derive")] // Required for derives on `SliceDst` +#![allow(dead_code)] + +//! Our UI test framework, built on the `trybuild` crate, does not support +//! testing for post-monomorphization errors. Instead, we use doctests, which +//! are able to test for post-monomorphization errors. + +use crate::*; + +#[derive(KnownLayout, FromBytes, IntoBytes, Immutable)] +#[repr(C)] +#[allow(missing_debug_implementations, missing_copy_implementations)] +pub struct SliceDst { + pub t: T, + pub u: [U], +} + +#[allow(clippy::must_use_candidate, clippy::missing_inline_in_public_items, clippy::todo)] +impl SliceDst { + pub fn new() -> &'static SliceDst { + todo!() + } + + pub fn new_mut() -> &'static mut SliceDst { + todo!() + } +} + +/// We require that the alignment of the destination type is not larger than the +/// alignment of the source type. +/// +/// ```compile_fail,E0080 +/// let increase_alignment: &u16 = zerocopy::transmute_ref!(&[0u8; 2]); +/// ``` +/// +/// ```compile_fail,E0080 +/// let mut src = [0u8; 2]; +/// let increase_alignment: &mut u16 = zerocopy::transmute_mut!(&mut src); +/// ``` +enum TransmuteRefMutAlignmentIncrease {} + +/// We require that the size of the destination type is not larger than the size +/// of the source type. +/// +/// ```compile_fail,E0080 +/// let increase_size: &[u8; 2] = zerocopy::transmute_ref!(&0u8); +/// ``` +/// +/// ```compile_fail,E0080 +/// let mut src = 0u8; +/// let increase_size: &mut [u8; 2] = zerocopy::transmute_mut!(&mut src); +/// ``` +enum TransmuteRefMutSizeIncrease {} + +/// We require that the size of the destination type is not smaller than the +/// size of the source type. +/// +/// ```compile_fail,E0080 +/// let decrease_size: &u8 = zerocopy::transmute_ref!(&[0u8; 2]); +/// ``` +/// +/// ```compile_fail,E0080 +/// let mut src = [0u8; 2]; +/// let decrease_size: &mut u8 = zerocopy::transmute_mut!(&mut src); +/// ``` +enum TransmuteRefMutSizeDecrease {} + +/// It's not possible in the general case to increase the trailing slice offset +/// during a reference transmutation - some pointer metadata values would not be +/// supportable, and so such a transmutation would be fallible. +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &SliceDst = SliceDst::new(); +/// let increase_offset: &SliceDst<[u8; 2], u8> = zerocopy::transmute_ref!(src); +/// ``` +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &mut SliceDst = SliceDst::new_mut(); +/// let increase_offset: &mut SliceDst<[u8; 2], u8> = zerocopy::transmute_mut!(src); +/// ``` +enum TransmuteRefMutDstOffsetIncrease {} + +/// Reference transmutes are not possible when the difference between the source +/// and destination types' trailing slice offsets is not a multiple of the +/// destination type's trailing slice element size. +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &SliceDst<[u8; 3], [u8; 2]> = SliceDst::new(); +/// let _: &SliceDst<[u8; 2], [u8; 2]> = zerocopy::transmute_ref!(src); +/// ``` +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &mut SliceDst<[u8; 3], [u8; 2]> = SliceDst::new_mut(); +/// let _: &mut SliceDst<[u8; 2], [u8; 2]> = zerocopy::transmute_mut!(src); +/// ``` +enum TransmuteRefMutDstOffsetNotMultiple {} + +/// Reference transmutes are not possible when the source's trailing slice +/// element size is not a multiple of the destination's. +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &SliceDst<(), [u8; 3]> = SliceDst::new(); +/// let _: &SliceDst<(), [u8; 2]> = zerocopy::transmute_ref!(src); +/// ``` +/// +/// ```compile_fail,E0080 +/// use zerocopy::doctests::SliceDst; +/// let src: &mut SliceDst<(), [u8; 3]> = SliceDst::new_mut(); +/// let _: &mut SliceDst<(), [u8; 2]> = zerocopy::transmute_mut!(src); +/// ``` +enum TransmuteRefMutDstElemSizeNotMultiple {} diff --git a/src/impls.rs b/src/impls.rs index 9f03d4ec6d..a040a79df7 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -173,40 +173,13 @@ const _: () = unsafe { }) }; -// SAFETY: `str` and `[u8]` have the same layout [1]. -// -// [1] Per https://doc.rust-lang.org/1.81.0/reference/type-layout.html#str-layout: -// -// String slices are a UTF-8 representation of characters that have the same -// layout as slices of type `[u8]`. -unsafe impl pointer::SizeEq for [u8] { - fn cast_from_raw(s: NonNull) -> NonNull<[u8]> { - cast!(s) - } -} -// SAFETY: See previous safety comment. -unsafe impl pointer::SizeEq<[u8]> for str { - fn cast_from_raw(bytes: NonNull<[u8]>) -> NonNull { - cast!(bytes) - } -} +impl_size_eq!(str, [u8]); macro_rules! unsafe_impl_try_from_bytes_for_nonzero { ($($nonzero:ident[$prim:ty]),*) => { $( unsafe_impl!(=> TryFromBytes for $nonzero; |n| { - // SAFETY: The caller promises that this is sound. - unsafe impl pointer::SizeEq<$nonzero> for Unalign<$prim> { - fn cast_from_raw(n: NonNull<$nonzero>) -> NonNull> { - cast!(n) - } - } - // SAFETY: The caller promises that this is sound. - unsafe impl pointer::SizeEq> for $nonzero { - fn cast_from_raw(p: NonNull>) -> NonNull<$nonzero> { - cast!(p) - } - } + impl_size_eq!($nonzero, Unalign<$prim>); let n = n.transmute::, invariant::Valid, _>(); $nonzero::new(n.read_unaligned().into_inner()).is_some() @@ -423,8 +396,8 @@ mod atomics { ($($($tyvar:ident)? => $atomic:ty [$prim:ty]),*) => {{ crate::util::macros::__unsafe(); - use core::{cell::UnsafeCell, ptr::NonNull}; - use crate::pointer::{TransmuteFrom, SizeEq, invariant::Valid}; + use core::cell::UnsafeCell; + use crate::pointer::{PtrInner, SizeEq, TransmuteFrom, invariant::Valid}; $( // SAFETY: The caller promised that `$atomic` and `$prim` have @@ -437,15 +410,20 @@ mod atomics { // SAFETY: The caller promised that `$atomic` and `$prim` have // the same size. unsafe impl<$($tyvar)?> SizeEq<$atomic> for $prim { - fn cast_from_raw(a: NonNull<$atomic>) -> NonNull<$prim> { - cast!(a) + #[inline] + fn cast_from_raw(a: PtrInner<'_, $atomic>) -> PtrInner<'_, $prim> { + // SAFETY: The caller promised that `$atomic` and + // `$prim` have the same size. Thus, this cast preserves + // address, referent size, and provenance. + unsafe { cast!(a) } } } - // SAFETY: The caller promised that `$atomic` and `$prim` have - // the same size. + // SAFETY: See previous safety comment. unsafe impl<$($tyvar)?> SizeEq<$prim> for $atomic { - fn cast_from_raw(p: NonNull<$prim>) -> NonNull<$atomic> { - cast!(p) + #[inline] + fn cast_from_raw(p: PtrInner<'_, $prim>) -> PtrInner<'_, $atomic> { + // SAFETY: See previous safety comment. + unsafe { cast!(p) } } } // SAFETY: The caller promised that `$atomic` and `$prim` have @@ -457,14 +435,18 @@ mod atomics { // its inner type `T`. A consequence of this guarantee is that // it is possible to convert between `T` and `UnsafeCell`. unsafe impl<$($tyvar)?> SizeEq<$atomic> for UnsafeCell<$prim> { - fn cast_from_raw(a: NonNull<$atomic>) -> NonNull> { - cast!(a) + #[inline] + fn cast_from_raw(a: PtrInner<'_, $atomic>) -> PtrInner<'_, UnsafeCell<$prim>> { + // SAFETY: See previous safety comment. + unsafe { cast!(a) } } } // SAFETY: See previous safety comment. unsafe impl<$($tyvar)?> SizeEq> for $atomic { - fn cast_from_raw(p: NonNull>) -> NonNull<$atomic> { - cast!(p) + #[inline] + fn cast_from_raw(p: PtrInner<'_, UnsafeCell<$prim>>) -> PtrInner<'_, $atomic> { + // SAFETY: See previous safety comment. + unsafe { cast!(p) } } } diff --git a/src/layout.rs b/src/layout.rs index 1582eeca3d..54cb21ad58 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -608,6 +608,216 @@ impl DstLayout { } } +pub(crate) use cast_from_raw::cast_from_raw; +mod cast_from_raw { + use crate::{pointer::PtrInner, *}; + + /// Implements [`>::cast_from_raw`][cast_from_raw]. + /// + /// # PME + /// + /// Generates a post-monomorphization error if it is not possible to satisfy + /// the soundness conditions of [`SizeEq::cast_from_raw`][cast_from_raw] + /// for `Src` and `Dst`. + /// + /// [cast_from_raw]: crate::pointer::SizeEq::cast_from_raw + // + // FIXME(#1817): Support Sized->Unsized and Unsized->Sized casts + pub(crate) fn cast_from_raw(src: PtrInner<'_, Src>) -> PtrInner<'_, Dst> + where + Src: KnownLayout + ?Sized, + Dst: KnownLayout + ?Sized, + { + // At compile time (specifically, post-monomorphization time), we need + // to compute two things: + // - Whether, given *any* `*Src`, it is possible to construct a `*Dst` + // which addresses the same number of bytes (ie, whether, for any + // `Src` pointer metadata, there exists `Dst` pointer metadata that + // addresses the same number of bytes) + // - If this is possible, any information necessary to perform the + // `Src`->`Dst` metadata conversion at runtime. + // + // Assume that `Src` and `Dst` are slice DSTs, and define: + // - `S_OFF = Src::LAYOUT.size_info.offset` + // - `S_ELEM = Src::LAYOUT.size_info.elem_size` + // - `D_OFF = Dst::LAYOUT.size_info.offset` + // - `D_ELEM = Dst::LAYOUT.size_info.elem_size` + // + // We are trying to solve the following equation: + // + // D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM + // + // At runtime, we will be attempting to compute `d_meta`, given `s_meta` + // (a runtime value) and all other parameters (which are compile-time + // values). We can solve like so: + // + // D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM + // + // d_meta * D_ELEM = S_OFF - D_OFF + s_meta * S_ELEM + // + // d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM + // + // Since `d_meta` will be a `usize`, we need the right-hand side to be + // an integer, and this needs to hold for *any* value of `s_meta` (in + // order for our conversion to be infallible - ie, to not have to reject + // certain values of `s_meta` at runtime). This means that: + // - `s_meta * S_ELEM` must be a multiple of `D_ELEM` + // - Since this must hold for any value of `s_meta`, `S_ELEM` must be a + // multiple of `D_ELEM` + // - `S_OFF - D_OFF` must be a multiple of `D_ELEM` + // + // Thus, let `OFFSET_DELTA_ELEMS = (S_OFF - D_OFF)/D_ELEM` and + // `ELEM_MULTIPLE = S_ELEM/D_ELEM`. We can rewrite the above expression + // as: + // + // d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM + // + // d_meta = OFFSET_DELTA_ELEMS + s_meta * ELEM_MULTIPLE + // + // Thus, we just need to compute the following and confirm that they + // have integer solutions in order to both a) determine whether + // infallible `Src` -> `Dst` casts are possible and, b) pre-compute the + // parameters necessary to perform those casts at runtime. These + // parameters are encapsulated in `CastParams`, which acts as a witness + // that such infallible casts are possible. + + /// The parameters required in order to perform a pointer cast from + /// `Src` to `Dst` as described above. + /// + /// These are a compile-time function of the layouts of `Src` and `Dst`. + /// + /// # Safety + /// + /// `offset_delta_elems` and `elem_multiple` must be valid as described + /// above. + /// + /// `Src`'s alignment must not be smaller than `Dst`'s alignment. + #[derive(Copy, Clone)] + struct CastParams { + offset_delta_elems: usize, + elem_multiple: usize, + } + + impl CastParams { + const fn try_compute(src: &DstLayout, dst: &DstLayout) -> Option { + if src.align.get() < dst.align.get() { + return None; + } + + let (src, dst) = if let (SizeInfo::SliceDst(src), SizeInfo::SliceDst(dst)) = + (src.size_info, dst.size_info) + { + (src, dst) + } else { + return None; + }; + + let offset_delta = if let Some(od) = src.offset.checked_sub(dst.offset) { + od + } else { + return None; + }; + + let dst_elem_size = if let Some(e) = NonZeroUsize::new(dst.elem_size) { + e + } else { + return None; + }; + + // PANICS: `dst_elem_size: NonZeroUsize`, so this won't div by zero. + #[allow(clippy::arithmetic_side_effects)] + let delta_mod_other_elem = offset_delta % dst_elem_size.get(); + + // PANICS: `dst_elem_size: NonZeroUsize`, so this won't div by zero. + #[allow(clippy::arithmetic_side_effects)] + let elem_remainder = src.elem_size % dst_elem_size.get(); + + if delta_mod_other_elem != 0 || src.elem_size < dst.elem_size || elem_remainder != 0 + { + return None; + } + + // PANICS: `dst_elem_size: NonZeroUsize`, so this won't div by zero. + #[allow(clippy::arithmetic_side_effects)] + let offset_delta_elems = offset_delta / dst_elem_size.get(); + + // PANICS: `dst_elem_size: NonZeroUsize`, so this won't div by zero. + #[allow(clippy::arithmetic_side_effects)] + let elem_multiple = src.elem_size / dst_elem_size.get(); + + // SAFETY: We checked above that `src.align >= dst.align`. + Some(CastParams { + // SAFETY: We checked above that this is an exact ratio. + offset_delta_elems, + // SAFETY: We checked above that this is an exact ratio. + elem_multiple, + }) + } + + /// # Safety + /// + /// `src_meta` describes a `Src` whose size is no larger than + /// `isize::MAX`. + /// + /// The returned metadata describes a `Dst` of the same size as the + /// original `Src`. + unsafe fn cast_metadata(self, src_meta: usize) -> usize { + #[allow(unused)] + use crate::util::polyfills::*; + + // SAFETY: `self` is a witness that the following equation + // holds: + // + // D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM + // + // Since the caller promises that `src_meta` is valid `Src` + // metadata, this math will not overflow, and the returned value + // will describe a `Dst` of the same size. + #[allow(unstable_name_collisions)] + unsafe { + self.offset_delta_elems + .unchecked_add(src_meta.unchecked_mul(self.elem_multiple)) + } + } + } + + trait Params { + const CAST_PARAMS: CastParams; + } + + impl Params for Dst + where + Src: KnownLayout + ?Sized, + Dst: KnownLayout + ?Sized, + { + const CAST_PARAMS: CastParams = + match CastParams::try_compute(&Src::LAYOUT, &Dst::LAYOUT) { + Some(params) => params, + None => const_panic!( + "cannot `transmute_ref!` or `transmute_mut!` between incompatible types" + ), + }; + } + + let src_meta = ::pointer_to_metadata(src.as_non_null().as_ptr()); + let params = >::CAST_PARAMS; + + // SAFETY: `src: PtrInner`, and so by invariant on `PtrInner`, `src`'s + // referent is no larger than `isize::MAX`. + let dst_meta = unsafe { params.cast_metadata(src_meta) }; + + let dst = ::raw_from_ptr_len(src.as_non_null().cast(), dst_meta); + + // SAFETY: By post-condition on `params.cast_metadata`, `dst` addresses + // the same number of bytes as `src`. Since `src: PtrInner`, `src` has + // provenance for its entire referent, which lives inside of a single + // allocation. Since `dst` has the same address as `src` and was + // constructed using provenance-preserving operations, it addresses a + // subset of those bytes, and has provenance for those bytes. + unsafe { PtrInner::new(dst) } + } +} + // FIXME(#67): For some reason, on our MSRV toolchain, this `allow` isn't // enforced despite having `#![allow(unknown_lints)]` at the crate root, but // putting it here works. Once our MSRV is high enough that this bug has been @@ -1451,7 +1661,7 @@ mod proofs { match size_info { SizeInfo::Sized { size } => Layout::from_size_align(size, align.get()), SizeInfo::SliceDst(TrailingSliceLayout { offset, elem_size: _ }) => { - // `SliceDst`` cannot encode an exact size, but we know + // `SliceDst` cannot encode an exact size, but we know // it is at least `offset` bytes. Layout::from_size_align(offset, align.get()) } diff --git a/src/lib.rs b/src/lib.rs index 8ecf2a240c..b749f1f90a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -338,6 +338,10 @@ pub mod util; pub mod byte_slice; pub mod byteorder; mod deprecated; + +#[doc(hidden)] +pub mod doctests; + // This module is `pub` so that zerocopy's error types and error handling // documentation is grouped together in a cohesive module. In practice, we // expect most users to use the re-export of `error`'s items to avoid identifier @@ -811,6 +815,14 @@ pub unsafe trait KnownLayout { // resulting size would not fit in a `usize`. meta.size_for_metadata(Self::LAYOUT) } + + #[doc(hidden)] + #[must_use] + #[inline(always)] + fn raw_dangling() -> NonNull { + let meta = Self::PointerMetadata::from_elem_count(0); + Self::raw_from_ptr_len(NonNull::dangling(), meta) + } } /// Efficiently produces the [`TrailingSliceLayout`] of `T`. @@ -858,7 +870,7 @@ pub trait PointerMetadata: Copy + Eq + Debug { /// /// `size_for_metadata` promises to only return `None` if the resulting size /// would not fit in a `usize`. - fn size_for_metadata(&self, layout: DstLayout) -> Option; + fn size_for_metadata(self, layout: DstLayout) -> Option; } impl PointerMetadata for () { @@ -867,7 +879,7 @@ impl PointerMetadata for () { fn from_elem_count(_elems: usize) -> () {} #[inline] - fn size_for_metadata(&self, layout: DstLayout) -> Option { + fn size_for_metadata(self, layout: DstLayout) -> Option { match layout.size_info { SizeInfo::Sized { size } => Some(size), // NOTE: This branch is unreachable, but we return `None` rather @@ -884,10 +896,10 @@ impl PointerMetadata for usize { } #[inline] - fn size_for_metadata(&self, layout: DstLayout) -> Option { + fn size_for_metadata(self, layout: DstLayout) -> Option { match layout.size_info { SizeInfo::SliceDst(TrailingSliceLayout { offset, elem_size }) => { - let slice_len = elem_size.checked_mul(*self)?; + let slice_len = elem_size.checked_mul(self)?; let without_padding = offset.checked_add(slice_len)?; without_padding.checked_add(util::padding_needed_for(without_padding, layout.align)) } @@ -3827,7 +3839,7 @@ pub unsafe trait FromBytes: FromZeros { { static_assert_dst_is_not_zst!(Self); match Ptr::from_mut(source).try_cast_into_no_leftover::<_, BecauseExclusive>(None) { - Ok(ptr) => Ok(ptr.recall_validity().as_mut()), + Ok(ptr) => Ok(ptr.recall_validity::<_, (_, (_, _))>().as_mut()), Err(err) => Err(err.map_src(|src| src.as_mut())), } } @@ -4777,7 +4789,7 @@ fn mut_from_prefix_suffix( let (slf, prefix_suffix) = Ptr::from_mut(source) .try_cast_into::<_, BecauseExclusive>(cast_type, meta) .map_err(|err| err.map_src(|s| s.as_mut()))?; - Ok((slf.recall_validity().as_mut(), prefix_suffix.as_mut())) + Ok((slf.recall_validity::<_, (_, (_, _))>().as_mut(), prefix_suffix.as_mut())) } /// Analyzes whether a type is [`IntoBytes`]. diff --git a/src/macros.rs b/src/macros.rs index da99a742d4..6de6eea01f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -102,13 +102,13 @@ macro_rules! transmute { /// This macro behaves like an invocation of this function: /// /// ```ignore -/// const fn transmute_ref<'src, 'dst, Src, Dst>(src: &'src Src) -> &'dst Dst +/// fn transmute_ref<'src, 'dst, Src, Dst>(src: &'src Src) -> &'dst Dst /// where /// 'src: 'dst, -/// Src: IntoBytes + Immutable, -/// Dst: FromBytes + Immutable, -/// size_of::() == size_of::(), +/// Src: IntoBytes + Immutable + ?Sized, +/// Dst: FromBytes + Immutable + ?Sized, /// align_of::() >= align_of::(), +/// size_compatible::(), /// { /// # /* /// ... @@ -116,13 +116,72 @@ macro_rules! transmute { /// } /// ``` /// -/// 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. +/// The types `Src` and `Dst` are inferred from the calling context; they cannot +/// be explicitly specified in the macro invocation. +/// +/// # Size compatibility +/// +/// `transmute_ref!` supports transmuting between `Sized` types or between +/// unsized (i.e., `?Sized`) types. It supports any transmutation that preserves +/// the number of bytes of the referent, even if doing so requires updating the +/// metadata stored in an unsized "fat" reference: +/// +/// ``` +/// # use zerocopy::transmute_ref; +/// # use core::mem::size_of_val; // Not in the prelude on our MSRV +/// let src: &[[u8; 2]] = &[[0, 1], [2, 3]][..]; +/// let dst: &[u8] = transmute_ref!(src); +/// +/// assert_eq!(src.len(), 2); +/// assert_eq!(dst.len(), 4); +/// assert_eq!(dst, [0, 1, 2, 3]); +/// assert_eq!(size_of_val(src), size_of_val(dst)); +/// ``` +/// +/// # Errors +/// +/// Violations of the alignment and size compatibility checks are detected +/// *after* the compiler performs monomorphization. This has two important +/// consequences. +/// +/// First, it means that generic code will *never* fail these conditions: +/// +/// ``` +/// # use zerocopy::{transmute_ref, FromBytes, IntoBytes, Immutable}; +/// fn transmute_ref(src: &Src) -> &Dst +/// where +/// Src: IntoBytes + Immutable, +/// Dst: FromBytes + Immutable, +/// { +/// transmute_ref!(src) +/// } +/// ``` +/// +/// Instead, failures will only be detected once generic code is instantiated +/// with concrete types: +/// +/// ```compile_fail,E0080 +/// # use zerocopy::{transmute_ref, FromBytes, IntoBytes, Immutable}; +/// # +/// # fn transmute_ref(src: &Src) -> &Dst +/// # where +/// # Src: IntoBytes + Immutable, +/// # Dst: FromBytes + Immutable, +/// # { +/// # transmute_ref!(src) +/// # } +/// let src: &u16 = &0; +/// let dst: &u8 = transmute_ref(src); +/// ``` +/// +/// Second, the fact that violations are detected after monomorphization means +/// that `cargo check` will usually not detect errors, even when types are +/// concrete. Instead, `cargo build` must be used to detect such errors. /// /// # Examples /// +/// Transmuting between `Sized` types: +/// /// ``` /// # use zerocopy::transmute_ref; /// let one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7]; @@ -132,38 +191,37 @@ macro_rules! transmute { /// assert_eq!(two_dimensional, &[[0, 1, 2, 3], [4, 5, 6, 7]]); /// ``` /// -/// # Use in `const` contexts +/// Transmuting between unsized types: /// -/// This macro can be invoked in `const` contexts. -/// -/// # Alignment increase error message +/// ``` +/// # use {zerocopy::*, zerocopy_derive::*}; +/// # type u16 = zerocopy::byteorder::native_endian::U16; +/// # type u32 = zerocopy::byteorder::native_endian::U32; +/// #[derive(KnownLayout, FromBytes, IntoBytes, Immutable)] +/// #[repr(C)] +/// struct SliceDst { +/// t: T, +/// u: [U], +/// } /// -/// Because of limitations on macros, the error message generated when -/// `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: +/// type Src = SliceDst; +/// type Dst = SliceDst; /// -/// ```compile_fail -/// const INCREASE_ALIGNMENT: &u16 = zerocopy::transmute_ref!(&[0u8; 2]); -/// ``` +/// let src = Src::ref_from_bytes(&[0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); +/// let dst: &Dst = transmute_ref!(src); /// -/// ...generates the following error: +/// assert_eq!(src.t.as_bytes(), [0, 1, 2, 3]); +/// assert_eq!(src.u.len(), 2); +/// assert_eq!(src.u.as_bytes(), [4, 5, 6, 7]); /// -/// ```text -/// error[E0512]: cannot transmute between types of different sizes, or dependently-sized types -/// --> src/lib.rs:1524:34 -/// | -/// 5 | const INCREASE_ALIGNMENT: &u16 = zerocopy::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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) +/// assert_eq!(dst.t.as_bytes(), [0, 1]); +/// assert_eq!(dst.u, [2, 3, 4, 5, 6, 7]); /// ``` /// -/// This is saying that `max(align_of::(), align_of::()) != -/// align_of::()`, which is equivalent to `align_of::() < -/// align_of::()`. +/// # Use in `const` contexts +/// +/// This macro can be invoked in `const` contexts only when `Src: Sized` and +/// `Dst: Sized`. #[macro_export] macro_rules! transmute_ref { ($e:expr) => {{ @@ -178,26 +236,18 @@ macro_rules! transmute_ref { #[allow(unused, clippy::diverging_sub_expression)] if false { // This branch, though never taken, ensures that the type of `e` is - // `&T` where `T: 't + Sized + IntoBytes + Immutable`, that the type of - // this macro expression is `&U` where `U: 'u + Sized + FromBytes + - // Immutable`, and that `'t` outlives `'u`. + // `&T` where `T: IntoBytes + Immutable`, and that the type of this + // macro expression is `&U` where `U: FromBytes + Immutable`. - struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); struct AssertSrcIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); struct AssertSrcIsImmutable<'a, T: ?::core::marker::Sized + $crate::Immutable>(&'a T); - struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); struct AssertDstIsFromBytes<'a, U: ?::core::marker::Sized + $crate::FromBytes>(&'a U); struct AssertDstIsImmutable<'a, T: ?::core::marker::Sized + $crate::Immutable>(&'a T); - let _ = AssertSrcIsSized(e); let _ = AssertSrcIsIntoBytes(e); let _ = AssertSrcIsImmutable(e); if true { - #[allow(unused, unreachable_code)] - let u = AssertDstIsSized(loop {}); - u.0 - } else if true { #[allow(unused, unreachable_code)] let u = AssertDstIsFromBytes(loop {}); u.0 @@ -206,36 +256,15 @@ macro_rules! transmute_ref { let u = AssertDstIsImmutable(loop {}); u.0 } - } else 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); - - &u } else { - // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `Src: IntoBytes + Immutable` and `Dst: FromBytes + - // Immutable` thanks to the uses of `AssertSrcIsIntoBytes`, - // `AssertSrcIsImmutable`, `AssertDstIsFromBytes`, and - // `AssertDstIsImmutable` above. - // - We know that `size_of::() == size_of::()` thanks to - // the use of `assert_size_eq!` above. - // - We know that `align_of::() >= align_of::()` thanks to - // the use of `assert_align_gt_eq!` above. - let u = unsafe { $crate::util::macro_util::transmute_ref(e) }; - $crate::util::macro_util::must_use(u) + use $crate::util::macro_util::TransmuteRefDst; + let t = $crate::util::macro_util::Wrap::new(e); + // SAFETY: The `if false` branch ensures that: + // - `Src: IntoBytes + Immutable` + // - `Dst: FromBytes + Immutable` + unsafe { + t.transmute_ref() + } } }} } @@ -251,8 +280,8 @@ macro_rules! transmute_ref { /// 'src: 'dst, /// Src: FromBytes + IntoBytes, /// Dst: FromBytes + IntoBytes, -/// size_of::() == size_of::(), /// align_of::() >= align_of::(), +/// size_compatible::(), /// { /// # /* /// ... @@ -260,13 +289,74 @@ macro_rules! transmute_ref { /// } /// ``` /// -/// 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. +/// The types `Src` and `Dst` are inferred from the calling context; they cannot +/// be explicitly specified in the macro invocation. +/// +/// # Size compatibility +/// +/// `transmute_mut!` supports transmuting between `Sized` types or between +/// unsized (i.e., `?Sized`) types. It supports any transmutation that preserves +/// the number of bytes of the referent, even if doing so requires updating the +/// metadata stored in an unsized "fat" reference: +/// +/// ``` +/// # use zerocopy::transmute_mut; +/// # use core::mem::size_of_val; // Not in the prelude on our MSRV +/// let src: &mut [[u8; 2]] = &mut [[0, 1], [2, 3]][..]; +/// let dst: &mut [u8] = transmute_mut!(src); +/// +/// assert_eq!(dst.len(), 4); +/// assert_eq!(dst, [0, 1, 2, 3]); +/// let dst_size = size_of_val(dst); +/// assert_eq!(src.len(), 2); +/// assert_eq!(size_of_val(src), dst_size); +/// ``` +/// +/// # Errors +/// +/// Violations of the alignment and size compatibility checks are detected +/// *after* the compiler performs monomorphization. This has two important +/// consequences. +/// +/// First, it means that generic code will *never* fail these conditions: +/// +/// ``` +/// # use zerocopy::{transmute_mut, FromBytes, IntoBytes, Immutable}; +/// fn transmute_mut(src: &mut Src) -> &mut Dst +/// where +/// Src: FromBytes + IntoBytes, +/// Dst: FromBytes + IntoBytes, +/// { +/// transmute_mut!(src) +/// } +/// ``` +/// +/// Instead, failures will only be detected once generic code is instantiated +/// with concrete types: +/// +/// ```compile_fail,E0080 +/// # use zerocopy::{transmute_mut, FromBytes, IntoBytes, Immutable}; +/// # +/// # fn transmute_mut(src: &mut Src) -> &mut Dst +/// # where +/// # Src: FromBytes + IntoBytes, +/// # Dst: FromBytes + IntoBytes, +/// # { +/// # transmute_mut!(src) +/// # } +/// let src: &mut u16 = &mut 0; +/// let dst: &mut u8 = transmute_mut(src); +/// ``` +/// +/// Second, the fact that violations are detected after monomorphization means +/// that `cargo check` will usually not detect errors, even when types are +/// concrete. Instead, `cargo build` must be used to detect such errors. +/// /// /// # Examples /// +/// Transmuting between `Sized` types: +/// /// ``` /// # use zerocopy::transmute_mut; /// let mut one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7]; @@ -280,115 +370,51 @@ macro_rules! transmute_ref { /// assert_eq!(one_dimensional, [4, 5, 6, 7, 0, 1, 2, 3]); /// ``` /// -/// # Use in `const` contexts +/// Transmuting between unsized types: /// -/// This macro can be invoked in `const` contexts. +/// ``` +/// # use {zerocopy::*, zerocopy_derive::*}; +/// # type u16 = zerocopy::byteorder::native_endian::U16; +/// # type u32 = zerocopy::byteorder::native_endian::U32; +/// #[derive(KnownLayout, FromBytes, IntoBytes, Immutable)] +/// #[repr(C)] +/// struct SliceDst { +/// t: T, +/// u: [U], +/// } /// -/// # Alignment increase error message +/// type Src = SliceDst; +/// type Dst = SliceDst; /// -/// Because of limitations on macros, the error message generated when -/// `transmute_mut!` is used to transmute from a type of lower alignment to a -/// type of higher alignment is somewhat confusing. For example, the following -/// code: +/// let mut bytes = [0, 1, 2, 3, 4, 5, 6, 7]; +/// let src = Src::mut_from_bytes(&mut bytes[..]).unwrap(); +/// let dst: &mut Dst = transmute_mut!(src); /// -/// ```compile_fail -/// const INCREASE_ALIGNMENT: &mut u16 = zerocopy::transmute_mut!(&mut [0u8; 2]); -/// ``` +/// assert_eq!(dst.t.as_bytes(), [0, 1]); +/// assert_eq!(dst.u, [2, 3, 4, 5, 6, 7]); /// -/// ...generates the following error: +/// assert_eq!(src.t.as_bytes(), [0, 1, 2, 3]); +/// assert_eq!(src.u.len(), 2); +/// assert_eq!(src.u.as_bytes(), [4, 5, 6, 7]); /// -/// ```text -/// error[E0512]: cannot transmute between types of different sizes, or dependently-sized types -/// --> src/lib.rs:1524:34 -/// | -/// 5 | const INCREASE_ALIGNMENT: &mut u16 = zerocopy::transmute_mut!(&mut [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 `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! 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 or alignment. + // because, for backwards-compatibility on v0.8.x, we use the autoref + // specialization trick to dispatch to different `transmute_mut` + // implementations: one which doesn't require `Src: KnownLayout + Dst: + // KnownLayout` when `Src: Sized + Dst: Sized`, and one which requires + // `KnownLayout` bounds otherwise. // Ensure that the source type is a mutable reference. let e: &mut _ = $e; - #[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` 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 - // writing, mutable references are banned), the error message - // appears to originate in the user's code rather than in the - // internals of this macro. - struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); - struct AssertSrcIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertSrcIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); - struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); - struct AssertDstIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertDstIsIntoBytes<'a, T: ?::core::marker::Sized + $crate::IntoBytes>(&'a T); - - if true { - let _ = AssertSrcIsSized(&*e); - } else if true { - let _ = AssertSrcIsFromBytes(&*e); - } else { - let _ = AssertSrcIsIntoBytes(&*e); - } - - if true { - #[allow(unused, unreachable_code)] - let u = AssertDstIsSized(loop {}); - &mut *u.0 - } else if true { - #[allow(unused, unreachable_code)] - let u = AssertDstIsFromBytes(loop {}); - &mut *u.0 - } else { - #[allow(unused, unreachable_code)] - let u = AssertDstIsIntoBytes(loop {}); - &mut *u.0 - } - } else 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); - - &mut u - } else { - // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `size_of::() == size_of::()` thanks to - // the use of `assert_size_eq!` above. - // - We know that `align_of::() >= align_of::()` thanks to - // the use of `assert_align_gt_eq!` above. - let u = unsafe { $crate::util::macro_util::transmute_mut(e) }; - $crate::util::macro_util::must_use(u) - } + #[allow(unused)] + use $crate::util::macro_util::TransmuteMutDst as _; + let t = $crate::util::macro_util::Wrap::new(e); + t.transmute_mut() }} } @@ -997,8 +1023,18 @@ macro_rules! cryptocorrosion_derive_traits { #[cfg(test)] mod tests { - use crate::util::testutil::*; use crate::*; + use crate::{ + byteorder::native_endian::{U16, U32}, + util::testutil::*, + }; + + #[derive(KnownLayout, Immutable, FromBytes, IntoBytes, PartialEq, Debug)] + #[repr(C)] + struct SliceDst { + a: T, + b: [U], + } #[test] fn test_transmute() { @@ -1038,6 +1074,18 @@ mod tests { assert_eq!(x.into_inner(), 1); } + // A `Sized` type which doesn't implement `KnownLayout` (it is "not + // `KnownLayout`", or `Nkl`). + // + // This permits us to test that `transmute_ref!` and `transmute_mut!` work + // for types which are `Sized + !KnownLayout`. When we added support for + // slice DSTs in #1924, this new support relied on `KnownLayout`, but we + // need to make sure to remain backwards-compatible with code which ueses + // these macros with types which are `!KnownLayout`. + #[derive(FromBytes, IntoBytes, Immutable, PartialEq, Eq, Debug)] + #[repr(transparent)] + struct Nkl(T); + #[test] fn test_transmute_ref() { // Test that memory is transmuted as expected. @@ -1055,6 +1103,65 @@ mod tests { const X: &'static [[u8; 2]; 4] = transmute_ref!(&ARRAY_OF_U8S); assert_eq!(*X, ARRAY_OF_ARRAYS); + // Before 1.61.0, we can't define the `const fn transmute_ref` function + // that we do on and after 1.61.0. + #[cfg(not(zerocopy_generic_bounds_in_const_fn_1_61_0))] + { + // Test that `transmute_ref!` supports non-`KnownLayout` `Sized` types. + const ARRAY_OF_NKL_U8S: Nkl<[u8; 8]> = Nkl([0u8, 1, 2, 3, 4, 5, 6, 7]); + const ARRAY_OF_NKL_ARRAYS: Nkl<[[u8; 2]; 4]> = Nkl([[0, 1], [2, 3], [4, 5], [6, 7]]); + const X_NKL: &Nkl<[[u8; 2]; 4]> = transmute_ref!(&ARRAY_OF_NKL_U8S); + assert_eq!(*X_NKL, ARRAY_OF_NKL_ARRAYS); + } + + #[cfg(zerocopy_generic_bounds_in_const_fn_1_61_0)] + { + // Call through a generic function to make sure our autoref + // specialization trick works even when types are generic. + const fn transmute_ref(t: &T) -> &U + where + T: IntoBytes + Immutable, + U: FromBytes + Immutable, + { + transmute_ref!(t) + } + + // Test that `transmute_ref!` supports non-`KnownLayout` `Sized` types. + const ARRAY_OF_NKL_U8S: Nkl<[u8; 8]> = Nkl([0u8, 1, 2, 3, 4, 5, 6, 7]); + const ARRAY_OF_NKL_ARRAYS: Nkl<[[u8; 2]; 4]> = Nkl([[0, 1], [2, 3], [4, 5], [6, 7]]); + const X_NKL: &Nkl<[[u8; 2]; 4]> = transmute_ref(&ARRAY_OF_NKL_U8S); + assert_eq!(*X_NKL, ARRAY_OF_NKL_ARRAYS); + } + + // Test that `transmute_ref!` works on slice DSTs in and that memory is + // transmuted as expected. + let slice_dst_of_u8s = + SliceDst::::ref_from_bytes(&[0, 1, 2, 3, 4, 5][..]).unwrap(); + let slice_dst_of_u16s = + SliceDst::::ref_from_bytes(&[0, 1, 2, 3, 4, 5][..]).unwrap(); + let x: &SliceDst = transmute_ref!(slice_dst_of_u8s); + assert_eq!(x, slice_dst_of_u16s); + + let slice_dst_of_u8s = + SliceDst::::ref_from_bytes(&[0, 1, 2, 3, 4, 5][..]).unwrap(); + let x: &[u8] = transmute_ref!(slice_dst_of_u8s); + assert_eq!(x, [0, 1, 2, 3, 4, 5]); + + let x: &[u8] = transmute_ref!(slice_dst_of_u16s); + assert_eq!(x, [0, 1, 2, 3, 4, 5]); + + let x: &[U16] = transmute_ref!(slice_dst_of_u16s); + let slice_of_u16s: &[U16] = <[U16]>::ref_from_bytes(&[0, 1, 2, 3, 4, 5][..]).unwrap(); + assert_eq!(x, slice_of_u16s); + + // Test that transmuting from a type with larger trailing slice offset + // and larger trailing slice element works. + let bytes = &[0, 1, 2, 3, 4, 5, 6, 7][..]; + let slice_dst_big = SliceDst::::ref_from_bytes(bytes).unwrap(); + let slice_dst_small = SliceDst::::ref_from_bytes(bytes).unwrap(); + let x: &SliceDst = transmute_ref!(slice_dst_big); + assert_eq!(x, slice_dst_small); + // Test that it's legal to transmute a reference while shrinking the // lifetime (note that `X` has the lifetime `'static`). let x: &[u8; 8] = transmute_ref!(X); @@ -1198,6 +1305,15 @@ mod tests { let x: &mut [u8; 8] = transmute_mut!(&mut array_of_arrays); assert_eq!(*x, array_of_u8s); } + + // Test that `transmute_mut!` supports non-`KnownLayout` types. + let mut array_of_u8s = Nkl([0u8, 1, 2, 3, 4, 5, 6, 7]); + let mut array_of_arrays = Nkl([[0, 1], [2, 3], [4, 5], [6, 7]]); + let x: &mut Nkl<[[u8; 2]; 4]> = transmute_mut!(&mut array_of_u8s); + assert_eq!(*x, array_of_arrays); + let x: &mut Nkl<[u8; 8]> = transmute_mut!(&mut array_of_arrays); + assert_eq!(*x, array_of_u8s); + // Test that `transmute_mut!` supports decreasing alignment. let mut u = AU64(0); let array = [0, 0, 0, 0, 0, 0, 0, 0]; @@ -1209,6 +1325,31 @@ mod tests { #[allow(clippy::useless_transmute)] let y: &u8 = transmute_mut!(&mut x); assert_eq!(*y, 0); + + // Test that `transmute_mut!` works on slice DSTs in and that memory is + // transmuted as expected. + let mut bytes = [0, 1, 2, 3, 4, 5, 6]; + let slice_dst_of_u8s = SliceDst::::mut_from_bytes(&mut bytes[..]).unwrap(); + let mut bytes = [0, 1, 2, 3, 4, 5, 6]; + let slice_dst_of_u16s = SliceDst::::mut_from_bytes(&mut bytes[..]).unwrap(); + let x: &mut SliceDst = transmute_mut!(slice_dst_of_u8s); + assert_eq!(x, slice_dst_of_u16s); + + // Test that `transmute_mut!` works on slices that memory is transmuted + // as expected. + let array_of_u16s: &mut [u16] = &mut [0u16, 1, 2]; + let array_of_i16s: &mut [i16] = &mut [0i16, 1, 2]; + let x: &mut [i16] = transmute_mut!(array_of_u16s); + assert_eq!(x, array_of_i16s); + + // Test that transmuting from a type with larger trailing slice offset + // and larger trailing slice element works. + let mut bytes = [0, 1, 2, 3, 4, 5, 6, 7]; + let slice_dst_big = SliceDst::::mut_from_bytes(&mut bytes[..]).unwrap(); + let mut bytes = [0, 1, 2, 3, 4, 5, 6, 7]; + let slice_dst_small = SliceDst::::mut_from_bytes(&mut bytes[..]).unwrap(); + let x: &mut SliceDst = transmute_mut!(slice_dst_big); + assert_eq!(x, slice_dst_small); } #[test] diff --git a/src/pointer/inner.rs b/src/pointer/inner.rs index e32e5334dc..5287ccb944 100644 --- a/src/pointer/inner.rs +++ b/src/pointer/inner.rs @@ -16,7 +16,7 @@ use crate::{ AlignmentError, CastError, KnownLayout, MetadataOf, SizeError, SplitAt, }; -pub(crate) use _def::PtrInner; +pub use _def::PtrInner; mod _def { use super::*; @@ -25,7 +25,8 @@ mod _def { /// `PtrInner<'a, T>` is [covariant] in `'a` and invariant in `T`. /// /// [covariant]: https://doc.rust-lang.org/reference/subtyping.html - pub(crate) struct PtrInner<'a, T> + #[allow(missing_debug_implementations)] + pub struct PtrInner<'a, T> where T: ?Sized, { @@ -68,6 +69,7 @@ mod _def { impl<'a, T: 'a + ?Sized> Copy for PtrInner<'a, T> {} impl<'a, T: 'a + ?Sized> Clone for PtrInner<'a, T> { + #[inline(always)] fn clone(&self) -> PtrInner<'a, T> { // SAFETY: None of the invariants on `ptr` are affected by having // multiple copies of a `PtrInner`. @@ -98,7 +100,9 @@ mod _def { /// Note that this method does not consume `self`. The caller should /// watch out for `unsafe` code which uses the returned `NonNull` in a /// way that violates the safety invariants of `self`. - pub(crate) const fn as_non_null(&self) -> NonNull { + #[inline(always)] + #[must_use] + pub const fn as_non_null(&self) -> NonNull { self.ptr } } diff --git a/src/pointer/mod.rs b/src/pointer/mod.rs index 748ffbde87..6005bc78f7 100644 --- a/src/pointer/mod.rs +++ b/src/pointer/mod.rs @@ -15,7 +15,7 @@ mod ptr; mod transmute; #[doc(hidden)] -pub(crate) use transmute::*; +pub use {inner::PtrInner, transmute::*}; #[doc(hidden)] pub use { invariant::{BecauseExclusive, BecauseImmutable, Read}, diff --git a/src/pointer/ptr.rs b/src/pointer/ptr.rs index fc94d19e9e..375420f352 100644 --- a/src/pointer/ptr.rs +++ b/src/pointer/ptr.rs @@ -391,9 +391,8 @@ mod _conversions { U: TransmuteFromPtr + SizeEq + ?Sized, { // SAFETY: - // - This cast preserves address and provenance - // - `U: SizeEq` guarantees that this cast preserves the number - // of bytes in the referent + // - `SizeEq::cast_from_raw` promises to preserve address, + // provenance, and the number of bytes in the referent // - If aliasing is `Shared`, then by `U: TransmuteFromPtr`, at // least one of the following holds: // - `T: Immutable` and `U: Immutable`, in which case it is @@ -403,7 +402,7 @@ mod _conversions { // operate on these references simultaneously // - By `U: TransmuteFromPtr`, it is // sound to perform this transmute. - unsafe { self.transmute_unchecked(|t: NonNull| U::cast_from_raw(t)) } + unsafe { self.transmute_unchecked(|ptr| SizeEq::cast_from_raw(ptr).as_non_null()) } } #[doc(hidden)] @@ -421,7 +420,7 @@ mod _conversions { // referent simultaneously // - By `T: TransmuteFromPtr`, it is // sound to perform this transmute. - let ptr = unsafe { self.transmute_unchecked(|t| t) }; + let ptr = unsafe { self.transmute_unchecked(|t| t.as_non_null()) }; // SAFETY: `self` and `ptr` have the same address and referent type. // Therefore, if `self` satisfies `I::Alignment`, then so does // `ptr`. @@ -465,12 +464,12 @@ mod _conversions { ) -> Ptr<'a, U, (I::Aliasing, Unaligned, V)> where V: Validity, - F: FnOnce(NonNull) -> NonNull, + F: FnOnce(PtrInner<'_, T>) -> NonNull, { // SAFETY: By invariant on `self`, `self.as_inner().as_non_null()` // either references a zero-sized byte range, or else it references // a byte range contained inside of a single allocated objection. - let ptr = cast(self.as_inner().as_non_null()); + let ptr = cast(self.as_inner()); // SAFETY: // @@ -536,7 +535,7 @@ mod _conversions { // validity of the other. let ptr = unsafe { #[allow(clippy::as_conversions)] - self.transmute_unchecked(NonNull::cast::>) + self.transmute_unchecked(|ptr| ptr.as_non_null().cast::>()) }; ptr.bikeshed_recall_aligned() } @@ -912,7 +911,7 @@ mod _casts { /// around the address space. #[doc(hidden)] #[inline] - pub unsafe fn cast_unsized_unchecked) -> NonNull>( + pub unsafe fn cast_unsized_unchecked) -> NonNull>( self, cast: F, ) -> Ptr<'a, U, (I::Aliasing, Unaligned, I::Validity)> @@ -960,7 +959,7 @@ mod _casts { where T: MutationCompatible, U: 'a + ?Sized + CastableFrom, - F: FnOnce(NonNull) -> NonNull, + F: FnOnce(PtrInner<'_, T>) -> NonNull, { // SAFETY: Because `T: MutationCompatible`, one // of the following holds: @@ -1004,8 +1003,11 @@ mod _casts { // returned pointer addresses the same bytes as `p` // - `slice_from_raw_parts_mut` and `.cast` both preserve provenance let ptr: Ptr<'a, [u8], _> = unsafe { - self.cast_unsized(|p: NonNull| { - let ptr = core::ptr::slice_from_raw_parts_mut(p.cast::().as_ptr(), bytes); + self.cast_unsized(|p: PtrInner<'_, T>| { + let ptr = core::ptr::slice_from_raw_parts_mut( + p.as_non_null().cast::().as_ptr(), + bytes, + ); // SAFETY: `ptr` has the same address as `p`, which is // non-null. core::ptr::NonNull::new_unchecked(ptr) @@ -1013,7 +1015,7 @@ mod _casts { }; let ptr = ptr.bikeshed_recall_aligned(); - ptr.recall_validity() + ptr.recall_validity::<_, (_, (_, _))>() } } @@ -1232,7 +1234,7 @@ mod _casts { // inner type `T`. A consequence of this guarantee is that it is // possible to convert between `T` and `UnsafeCell`. #[allow(clippy::as_conversions)] - let ptr = unsafe { self.transmute_unchecked(cast!()) }; + let ptr = unsafe { self.transmute_unchecked(|ptr| cast!(ptr).as_non_null()) }; // SAFETY: `UnsafeCell` has the same alignment as `T` [1], // and so if `self` is guaranteed to be aligned, then so is the diff --git a/src/pointer/transmute.rs b/src/pointer/transmute.rs index 121bb37058..297f943aa3 100644 --- a/src/pointer/transmute.rs +++ b/src/pointer/transmute.rs @@ -10,10 +10,12 @@ use core::{ cell::{Cell, UnsafeCell}, mem::{ManuallyDrop, MaybeUninit}, num::Wrapping, - ptr::NonNull, }; -use crate::{pointer::invariant::*, FromBytes, Immutable, IntoBytes, Unalign}; +use crate::{ + pointer::{invariant::*, PtrInner}, + FromBytes, Immutable, IntoBytes, Unalign, +}; /// Transmutations which are sound to attempt, conditional on validating the bit /// validity of the destination type. @@ -129,10 +131,12 @@ pub enum BecauseMutationCompatible {} // exists, no mutation is permitted except via that `Ptr` // - Aliasing is `Shared`, `Src: Immutable`, and `Dst: Immutable`, in which // case no mutation is possible via either `Ptr` -// - `Dst: TransmuteFrom`, and so the set of `DV`-valid `Dst`s is -// a supserset of the set of `SV`-valid `Src`s -// - Reverse transmutation: `Src: TransmuteFrom`, and so the set of -// `DV`-valid `Dst`s is a subset of the set of `SV`-valid `Src`s +// - `Dst: TransmuteFrom`. Since `Dst: SizeEq`, this bound +// guarantees that the set of `DV`-valid `Dst`s is a supserset of the set of +// `SV`-valid `Src`s. +// - Reverse transmutation: `Src: TransmuteFrom`. Since `Dst: +// SizeEq`, this guarantees that the set of `DV`-valid `Dst`s is a subset +// of the set of `SV`-valid `Src`s. // - No safe code, given access to `src` and `dst`, can cause undefined // behavior: By `Dst: MutationCompatible`, at least one of // the following holds: @@ -204,13 +208,13 @@ pub unsafe trait InvariantsEq {} // SAFETY: Trivially sound to have multiple `&T` pointing to the same referent. unsafe impl InvariantsEq for T {} -// SAFETY: `Dst: InvariantsEq + TransmuteFrom`, and `Src: -// TransmuteFrom`. -unsafe impl - MutationCompatible for Dst +// SAFETY: `Dst: InvariantsEq + TransmuteFrom`, and `Src: +// TransmuteFrom`. +unsafe impl + MutationCompatible for Dst where - Src: TransmuteFrom, - Dst: TransmuteFrom + InvariantsEq, + Src: TransmuteFrom, + Dst: TransmuteFrom + InvariantsEq, { } @@ -272,10 +276,14 @@ where /// /// # Safety /// -/// The set of bit patterns allowed to appear in the referent of a `Ptr` must be a subset of the set allowed to appear in the referent of a -/// `Ptr`. -pub unsafe trait TransmuteFrom: SizeEq {} +/// Given `src: Ptr` and `dst: Ptr`, if the +/// referents of `src` and `dst` are the same size, then the set of bit patterns +/// allowed to appear in `src`'s referent must be a subset of the set allowed to +/// appear in `dst`'s referent. +/// +/// If the referents are not the same size, then `Dst: TransmuteFrom` conveys no safety guarantee. +pub unsafe trait TransmuteFrom {} /// # Safety /// @@ -286,14 +294,15 @@ pub unsafe trait TransmuteFrom: SizeEq {} /// any `t: *mut T`, `t as *mut Self` produces a pointer which addresses the /// same number of bytes as `t`. pub unsafe trait SizeEq { - fn cast_from_raw(t: NonNull) -> NonNull; + fn cast_from_raw(t: PtrInner<'_, T>) -> PtrInner<'_, Self>; } // SAFETY: `T` trivially has the same size and vtable kind as `T`, and since // pointer `*mut T -> *mut T` pointer casts are no-ops, this cast trivially // preserves referent size (when `T: ?Sized`). unsafe impl SizeEq for T { - fn cast_from_raw(t: NonNull) -> NonNull { + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, T>) -> PtrInner<'_, T> { t } } @@ -304,7 +313,7 @@ unsafe impl SizeEq for T { unsafe impl TransmuteFrom for Dst where Src: IntoBytes + ?Sized, - Dst: SizeEq + ?Sized, + Dst: ?Sized, { } @@ -314,7 +323,7 @@ where unsafe impl TransmuteFrom for Dst where Src: ?Sized, - Dst: FromBytes + SizeEq + ?Sized, + Dst: FromBytes + ?Sized, { } @@ -327,7 +336,7 @@ where unsafe impl TransmuteFrom for Dst where Src: ?Sized, - Dst: SizeEq + ?Sized, + Dst: ?Sized, { } @@ -340,7 +349,7 @@ where unsafe impl TransmuteFrom for Dst where Src: ?Sized, - Dst: SizeEq + ?Sized, + Dst: ?Sized, V: Validity, { } @@ -448,14 +457,20 @@ unsafe impl TransmuteFrom for MaybeUninit {} // `MaybeUninit` is guaranteed to have the same size, alignment, and ABI as // `T` unsafe impl SizeEq for MaybeUninit { - fn cast_from_raw(t: NonNull) -> NonNull> { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, T>) -> PtrInner<'_, MaybeUninit> { + // SAFETY: Per preceding safety comment, `MaybeUninit` and `T` have + // the same size, and so this cast preserves referent size. + unsafe { cast!(t) } } } // SAFETY: See previous safety comment. unsafe impl SizeEq> for T { - fn cast_from_raw(t: NonNull>) -> NonNull { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, MaybeUninit>) -> PtrInner<'_, T> { + // SAFETY: Per preceding safety comment, `MaybeUninit` and `T` have + // the same size, and so this cast preserves referent size. + unsafe { cast!(t) } } } diff --git a/src/ref.rs b/src/ref.rs index 40f8db6310..423bf84988 100644 --- a/src/ref.rs +++ b/src/ref.rs @@ -658,7 +658,7 @@ where let ptr = Ptr::from_mut(b.into_byte_slice_mut()) .try_cast_into_no_leftover::(None) .expect("zerocopy internal error: into_ref should be infallible"); - let ptr = ptr.recall_validity(); + let ptr = ptr.recall_validity::<_, (_, (_, _))>(); ptr.as_mut() } } diff --git a/src/util/macro_util.rs b/src/util/macro_util.rs index c11d18bb7b..4e331062fc 100644 --- a/src/util/macro_util.rs +++ b/src/util/macro_util.rs @@ -18,22 +18,22 @@ #![allow(missing_debug_implementations)] use core::{ + marker::PhantomData, mem::{self, ManuallyDrop}, - ptr::NonNull, }; // FIXME(#29), FIXME(https://github.com/rust-lang/rust/issues/69835): Remove // this `cfg` when `size_of_val_raw` is stabilized. #[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)] #[cfg(not(target_pointer_width = "16"))] -use core::ptr; +use core::ptr::{self, NonNull}; use crate::{ pointer::{ invariant::{self, BecauseExclusive, BecauseImmutable, Invariants}, - TryTransmuteFromPtr, + BecauseInvariantsEq, InvariantsEq, SizeEq, TryTransmuteFromPtr, }, - FromBytes, Immutable, IntoBytes, Ptr, TryFromBytes, ValidityError, + FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, Ptr, TryFromBytes, ValidityError, }; /// Projects the type of the field at `Index` in `Self`. @@ -469,69 +469,6 @@ macro_rules! assert_size_eq { }}; } -/// Transmutes a reference of one type to a reference of another type. -/// -/// # Safety -/// -/// The caller must guarantee that: -/// - `Src: IntoBytes + Immutable` -/// - `Dst: FromBytes + Immutable` -/// - `size_of::() == size_of::()` -/// - `align_of::() >= align_of::()` -#[inline(always)] -pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - src: &'src Src, -) -> &'dst Dst { - let src: *const Src = src; - let dst = src.cast::(); - // SAFETY: - // - We know that it is sound to view the target type of the input reference - // (`Src`) as the target type of the output reference (`Dst`) because the - // caller has guaranteed that `Src: IntoBytes`, `Dst: FromBytes`, and - // `size_of::() == size_of::()`. - // - We know that there are no `UnsafeCell`s, and thus we don't have to - // worry about `UnsafeCell` overlap, because `Src: Immutable` and `Dst: - // Immutable`. - // - The caller has guaranteed that alignment is not increased. - // - We know that the returned lifetime will not outlive the input lifetime - // thanks to the lifetime bounds on this function. - // - // FIXME(#67): Once our MSRV is 1.58, replace this `transmute` with `&*dst`. - #[allow(clippy::transmute_ptr_to_ref)] - unsafe { - mem::transmute(dst) - } -} - -/// Transmutes a mutable reference of one type to a mutable reference of another -/// type. -/// -/// # Safety -/// -/// The caller must guarantee that: -/// - `Src: FromBytes + IntoBytes` -/// - `Dst: FromBytes + IntoBytes` -/// - `size_of::() == size_of::()` -/// - `align_of::() >= align_of::()` -// FIXME(#686): Consider removing the `Immutable` requirement. -#[inline(always)] -pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - src: &'src mut Src, -) -> &'dst mut Dst { - let src: *mut Src = src; - let dst = src.cast::(); - // SAFETY: - // - We know that it is sound to view the target type of the input reference - // (`Src`) as the target type of the output reference (`Dst`) and - // vice-versa because the caller has guaranteed that `Src: FromBytes + - // IntoBytes`, `Dst: FromBytes + IntoBytes`, and `size_of::() == - // size_of::()`. - // - The caller has guaranteed that alignment is not increased. - // - We know that the returned lifetime will not outlive the input lifetime - // thanks to the lifetime bounds on this function. - unsafe { &mut *dst } -} - /// Is a given source a valid instance of `Dst`? /// /// If so, returns `src` casted to a `Ptr`. Otherwise returns `None`. @@ -580,7 +517,7 @@ where // `Src`. // - `p as *mut Dst` is a provenance-preserving cast #[allow(clippy::as_conversions)] - let c_ptr = unsafe { src.cast_unsized(NonNull::cast::) }; + let c_ptr = unsafe { src.cast_unsized(|ptr| ptr.as_non_null().cast::()) }; match c_ptr.try_into_valid() { Ok(ptr) => Ok(ptr), @@ -594,7 +531,7 @@ where // to the size of `Src`. // - `p as *mut Src` is a provenance-preserving cast #[allow(clippy::as_conversions)] - let ptr = unsafe { ptr.cast_unsized(NonNull::cast::) }; + let ptr = unsafe { ptr.cast_unsized(|ptr| ptr.as_non_null().cast::()) }; // 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. @@ -647,7 +584,11 @@ where // // `MaybeUninit` is guaranteed to have the same size, alignment, and // ABI as `T` - let ptr: Ptr<'_, Dst, _> = unsafe { ptr.cast_unsized(NonNull::>::cast) }; + let ptr: Ptr<'_, Dst, _> = unsafe { + ptr.cast_unsized(|ptr: crate::pointer::PtrInner<'_, mem::MaybeUninit>| { + ptr.as_non_null().cast() + }) + }; if Dst::is_bit_valid(ptr.forget_aligned()) { // SAFETY: Since `Dst::is_bit_valid`, we know that `ptr`'s referent is @@ -733,7 +674,183 @@ where let ptr = unsafe { ptr.assume_alignment::() }; Ok(ptr.as_mut()) } - Err(err) => Err(err.map_src(|ptr| ptr.recall_validity().as_mut())), + Err(err) => { + Err(err.map_src(|ptr| ptr.recall_validity::<_, (_, BecauseInvariantsEq)>().as_mut())) + } + } +} + +// Used in `transmute_ref!` and friends. +// +// This permits us to use the autoref specialization trick to dispatch to +// associated functions for `transmute_ref` and `transmute_mut` when both `Src` +// and `Dst` are `Sized`, and to trait methods otherwise. The associated +// functions, unlike the trait methods, do not require a `KnownLayout` bound. +// This permits us to add support for transmuting references to unsized types +// without breaking backwards-compatibility (on v0.8.x) with the old +// implementation, which did not require a `KnownLayout` bound to transmute +// sized types. +#[derive(Copy, Clone)] +pub struct Wrap(pub Src, pub PhantomData); + +impl Wrap { + #[inline(always)] + pub const fn new(src: Src) -> Self { + Wrap(src, PhantomData) + } +} + +impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> { + /// # Safety + /// The caller must guarantee that: + /// - `Src: IntoBytes + Immutable` + /// - `Dst: FromBytes + Immutable` + /// + /// # PME + /// + /// Instantiating this method PMEs unless both: + /// - `mem::size_of::() == mem::size_of::()` + /// - `mem::align_of::() <= mem::align_of::()` + #[inline(always)] + #[must_use] + pub const unsafe fn transmute_ref(self) -> &'a Dst { + static_assert!(Src, Dst => mem::size_of::() == mem::size_of::()); + static_assert!(Src, Dst => mem::align_of::() <= mem::align_of::()); + + let src: *const Src = self.0; + let dst = src.cast::(); + // SAFETY: + // - We know that it is sound to view the target type of the input reference + // (`Src`) as the target type of the output reference (`Dst`) because the + // caller has guaranteed that `Src: IntoBytes`, `Dst: FromBytes`, and + // `size_of::() == size_of::()`. + // - We know that there are no `UnsafeCell`s, and thus we don't have to + // worry about `UnsafeCell` overlap, because `Src: Immutable` and `Dst: + // Immutable`. + // - The caller has guaranteed that alignment is not increased. + // - We know that the returned lifetime will not outlive the input lifetime + // thanks to the lifetime bounds on this function. + // + // FIXME(#67): Once our MSRV is 1.58, replace this `transmute` with `&*dst`. + #[allow(clippy::transmute_ptr_to_ref)] + unsafe { + mem::transmute(dst) + } + } +} + +impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> { + /// Transmutes a mutable reference of one type to a mutable reference of another + /// type. + /// + /// # PME + /// + /// Instantiating this method PMEs unless both: + /// - `mem::size_of::() == mem::size_of::()` + /// - `mem::align_of::() <= mem::align_of::()` + #[inline(always)] + #[must_use] + pub fn transmute_mut(self) -> &'a mut Dst + where + Src: FromBytes + IntoBytes, + Dst: FromBytes + IntoBytes, + { + static_assert!(Src, Dst => mem::size_of::() == mem::size_of::()); + static_assert!(Src, Dst => mem::align_of::() <= mem::align_of::()); + + let src: *mut Src = self.0; + let dst = src.cast::(); + // SAFETY: + // - We know that it is sound to view the target type of the input + // reference (`Src`) as the target type of the output reference + // (`Dst`) and vice-versa because `Src: FromBytes + IntoBytes`, `Dst: + // FromBytes + IntoBytes`, and (as asserted above) `size_of::() + // == size_of::()`. + // - We asserted above that alignment will not increase. + // - We know that the returned lifetime will not outlive the input + // lifetime thanks to the lifetime bounds on this function. + unsafe { &mut *dst } + } +} + +pub trait TransmuteRefDst<'a> { + type Dst: ?Sized; + + #[must_use] + fn transmute_ref(self) -> &'a Self::Dst; +} + +impl<'a, Src: ?Sized, Dst: ?Sized> TransmuteRefDst<'a> for Wrap<&'a Src, &'a Dst> +where + Src: KnownLayout + IntoBytes + Immutable, + Dst: KnownLayout + FromBytes + Immutable, +{ + type Dst = Dst; + + #[inline(always)] + fn transmute_ref(self) -> &'a Dst { + static_assert!(Src: ?Sized + KnownLayout, Dst: ?Sized + KnownLayout => { + Src::LAYOUT.align.get() >= Dst::LAYOUT.align.get() + }, "cannot transmute reference when destination type has higher alignment than source type"); + + // SAFETY: We only use `S` as `S` and `D` as `D`. + unsafe { + unsafe_with_size_eq!(, D> { + let ptr = Ptr::from_ref(self.0) + .transmute::, invariant::Valid, BecauseImmutable>() + .recall_validity::() + .transmute::, invariant::Initialized, (crate::pointer::BecauseMutationCompatible, _)>() + .recall_validity::(); + + #[allow(unused_unsafe)] + // SAFETY: The preceding `static_assert!` ensures that + // `T::LAYOUT.align >= U::LAYOUT.align`. Since `self.0` is + // validly-aligned for `T`, it is also validly-aligned for `U`. + let ptr = unsafe { ptr.assume_alignment() }; + + &ptr.as_ref().0 + }) + } + } +} + +pub trait TransmuteMutDst<'a> { + type Dst: ?Sized; + #[must_use] + fn transmute_mut(self) -> &'a mut Self::Dst; +} + +impl<'a, Src: ?Sized, Dst: ?Sized> TransmuteMutDst<'a> for Wrap<&'a mut Src, &'a mut Dst> +where + Src: KnownLayout + FromBytes + IntoBytes, + Dst: KnownLayout + FromBytes + IntoBytes, +{ + type Dst = Dst; + + #[inline(always)] + fn transmute_mut(self) -> &'a mut Dst { + static_assert!(Src: ?Sized + KnownLayout, Dst: ?Sized + KnownLayout => { + Src::LAYOUT.align.get() >= Dst::LAYOUT.align.get() + }, "cannot transmute reference when destination type has higher alignment than source type"); + + // SAFETY: We only use `S` as `S` and `D` as `D`. + unsafe { + unsafe_with_size_eq!(, D> { + let ptr = Ptr::from_mut(self.0) + .transmute::, invariant::Valid, _>() + .recall_validity::() + .transmute::, invariant::Initialized, _>() + .recall_validity::(); + + #[allow(unused_unsafe)] + // SAFETY: The preceding `static_assert!` ensures that + // `T::LAYOUT.align >= U::LAYOUT.align`. Since `self.0` is + // validly-aligned for `T`, it is also validly-aligned for `U`. + let ptr = unsafe { ptr.assume_alignment() }; + + &mut ptr.as_mut().0 + }) + } } } diff --git a/src/util/macros.rs b/src/util/macros.rs index d3cfdfad5b..78a4ebf2ac 100644 --- a/src/util/macros.rs +++ b/src/util/macros.rs @@ -233,7 +233,7 @@ macro_rules! impl_for_transmute_from { TryFromBytes for $ty:ty [<$repr:ty>] ) => { #[inline] - fn is_bit_valid(candidate: Maybe<'_, Self, A>) -> bool { + fn is_bit_valid(candidate: $crate::Maybe<'_, Self, A>) -> bool { // SAFETY: This macro ensures that `$repr` and `Self` have the same // size and bit validity. Thus, a bit-valid instance of `$repr` is // also a bit-valid instance of `Self`. @@ -648,14 +648,15 @@ macro_rules! static_assert { const ASSERT: bool; } - impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?,)*> StaticAssert for ($($tyvar,)*) { + // NOTE: We use `PhantomData` so we can support unsized types. + impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?,)*> StaticAssert for ($(core::marker::PhantomData<$tyvar>,)*) { const ASSERT: bool = { const_assert!($condition $(, $args)*); $condition }; } - const_assert!(<($($tyvar,)*) as StaticAssert>::ASSERT); + const_assert!(<($(core::marker::PhantomData<$tyvar>,)*) as StaticAssert>::ASSERT); }}; } @@ -688,9 +689,18 @@ macro_rules! cast { }; } }; - ($p:ident) => { - cast!()($p) - }; + ($p:expr) => {{ + let ptr: crate::pointer::PtrInner<'_, _> = $p; + let ptr = ptr.as_non_null(); + let ptr = cast!()(ptr); + // SAFETY: The caller promises that the cast preserves or shrinks + // referent size. By invariant on `$p: PtrInner` (guaranteed by type + // annotation above), `$p` refers to a byte range entirely contained + // inside of a single allocation, has provenance for that whole byte + // range, and will not outlive the allocation. All of these conditions + // are preserved when preserving or shrinking referent size. + crate::pointer::PtrInner::new(ptr) + }}; } /// Implements `TransmuteFrom` and `SizeEq` for `T` and `$wrapper`. @@ -701,27 +711,30 @@ macro_rules! cast { /// same size in the sense of `SizeEq`. macro_rules! unsafe_impl_for_transparent_wrapper { (T $(: ?$optbound:ident)? => $wrapper:ident) => {{ - use core::ptr::NonNull; - use crate::pointer::{TransmuteFrom, SizeEq, invariant::Valid}; - crate::util::macros::__unsafe(); - // SAFETY: The caller promises that `T` and `$wrapper` have the - // same bit validity. + use crate::pointer::{TransmuteFrom, PtrInner, SizeEq, invariant::Valid}; + + // SAFETY: The caller promises that `T` and `$wrapper` have the same + // bit validity. unsafe impl TransmuteFrom for $wrapper {} // SAFETY: See previous safety comment. unsafe impl TransmuteFrom<$wrapper, Valid, Valid> for T {} // SAFETY: The caller promises that `T` and `$wrapper` satisfy // `SizeEq`. unsafe impl SizeEq for $wrapper { - fn cast_from_raw(t: NonNull) -> NonNull<$wrapper> { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, T>) -> PtrInner<'_, $wrapper> { + // SAFETY: See previous safety comment. + unsafe { cast!(t) } } } // SAFETY: See previous safety comment. unsafe impl SizeEq<$wrapper> for T { - fn cast_from_raw(t: NonNull<$wrapper>) -> NonNull { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, $wrapper>) -> PtrInner<'_, T> { + // SAFETY: See previous safety comment. + unsafe { cast!(t) } } } }}; @@ -730,8 +743,7 @@ macro_rules! unsafe_impl_for_transparent_wrapper { macro_rules! impl_transitive_transmute_from { ($($tyvar:ident $(: ?$optbound:ident)?)? => $t:ty => $u:ty => $v:ty) => { const _: () = { - use core::ptr::NonNull; - use crate::pointer::{TransmuteFrom, SizeEq, invariant::Valid}; + use crate::pointer::{TransmuteFrom, PtrInner, SizeEq, invariant::Valid}; // SAFETY: Since `$u: SizeEq<$t>` and `$v: SizeEq`, this impl is // transitively sound. @@ -740,8 +752,10 @@ macro_rules! impl_transitive_transmute_from { $u: SizeEq<$t>, $v: SizeEq<$u>, { - fn cast_from_raw(t: NonNull<$t>) -> NonNull<$v> { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, $t>) -> PtrInner<'_, $v> { + let u = <$u as SizeEq<_>>::cast_from_raw(t); + <$v as SizeEq<_>>::cast_from_raw(u) } } @@ -758,30 +772,154 @@ macro_rules! impl_transitive_transmute_from { }; } +#[rustfmt::skip] macro_rules! impl_size_eq { ($t:ty, $u:ty) => { const _: () = { - use crate::pointer::SizeEq; - use core::ptr::NonNull; - - static_assert!(=> mem::size_of::<$t>() == mem::size_of::<$u>()); + use crate::{KnownLayout, pointer::{PtrInner, SizeEq}}; + + static_assert!(=> { + let t = <$t as KnownLayout>::LAYOUT; + let u = <$u as KnownLayout>::LAYOUT; + t.align.get() >= u.align.get() && match (t.size_info, u.size_info) { + (SizeInfo::Sized { size: t }, SizeInfo::Sized { size: u }) => t == u, + ( + SizeInfo::SliceDst(TrailingSliceLayout { offset: t_offset, elem_size: t_elem_size }), + SizeInfo::SliceDst(TrailingSliceLayout { offset: u_offset, elem_size: u_elem_size }) + ) => t_offset == u_offset && t_elem_size == u_elem_size, + _ => false, + } + }); - // SAFETY: We've asserted that their sizes are equal. + // SAFETY: See inline. unsafe impl SizeEq<$t> for $u { - fn cast_from_raw(t: NonNull<$t>) -> NonNull<$u> { - cast!(t) + #[inline(always)] + fn cast_from_raw(t: PtrInner<'_, $t>) -> PtrInner<'_, $u> { + // SAFETY: We've asserted that their + // `KnownLayout::LAYOUT.size_info`s are equal, and so this + // cast is guaranteed to preserve address and referent size. + // It trivially preserves provenance. + unsafe { cast!(t) } } } - // SAFETY: We've asserted that their sizes are equal. + // SAFETY: See previous safety comment. unsafe impl SizeEq<$u> for $t { - fn cast_from_raw(u: NonNull<$u>) -> NonNull<$t> { - cast!(u) + #[inline(always)] + fn cast_from_raw(u: PtrInner<'_, $u>) -> PtrInner<'_, $t> { + // SAFETY: See previous safety comment. + unsafe { cast!(u) } } } }; }; } +/// Invokes `$blk` in a context in which `$src<$t>` and `$dst<$u>` implement +/// `SizeEq`. +/// +/// This macro emits code which implements `SizeEq`, and ensures that the impl +/// is sound via PME. +/// +/// # Safety +/// +/// Inside of `$blk`, the caller must only use `$src` and `$dst` as `$src<$t>` +/// and `$dst<$u>`. The caller must not use `$src` or `$dst` to wrap any other +/// types. +macro_rules! unsafe_with_size_eq { + (<$src:ident<$t:ident>, $dst:ident<$u:ident>> $blk:expr) => {{ + crate::util::macros::__unsafe(); + + use crate::{KnownLayout, pointer::PtrInner}; + + #[repr(transparent)] + struct $src(T); + + #[repr(transparent)] + struct $dst(U); + + // SAFETY: Since `$src` is a `#[repr(transparent)]` wrapper around + // `T`, it has the same bit validity and size as `T`. + unsafe_impl_for_transparent_wrapper!(T: ?Sized => $src); + + // SAFETY: Since `$dst` is a `#[repr(transparent)]` wrapper around + // `T`, it has the same bit validity and size as `T`. + unsafe_impl_for_transparent_wrapper!(T: ?Sized => $dst); + + // SAFETY: `$src` is a `#[repr(transparent)]` wrapper around `T` with + // no added semantics. + unsafe impl InvariantsEq<$src> for T {} + + // SAFETY: `$dst` is a `#[repr(transparent)]` wrapper around `T` with + // no added semantics. + unsafe impl InvariantsEq<$dst> for T {} + + // SAFETY: See inline for the soundness of this impl when + // `cast_from_raw` is actually instantiated (otherwise, PMEs may not be + // triggered). + // + // We manually instantiate `cast_from_raw` below to ensure that this PME + // can be triggered, and the caller promises not to use `$src` and + // `$dst` with any wrapped types other than `$t` and `$u` respectively. + unsafe impl SizeEq<$src> for $dst + where + T: KnownLayout, + U: KnownLayout, + { + fn cast_from_raw(src: PtrInner<'_, $src>) -> PtrInner<'_, Self> { + // SAFETY: `crate::layout::cast_from_raw` promises to satisfy + // the safety invariants of `SizeEq::cast_from_raw`, or to + // generate a PME. Since `$src` and `$dst` are + // `#[repr(transparent)]` wrappers around `T` and `U` + // respectively, a `cast_from_raw` impl which satisfies the + // conditions for casting from `NonNull` to `NonNull` also + // satisfies the conditions for casting from `NonNull<$src>` + // to `NonNull<$dst>`. + + // SAFETY: By the preceding safety comment, this cast preserves + // referent size. + let src: PtrInner<'_, T> = unsafe { cast!(src) }; + let dst: PtrInner<'_, U> = crate::layout::cast_from_raw(src); + // SAFETY: By the preceding safety comment, this cast preserves + // referent size. + unsafe { cast!(dst) } + } + } + + // See safety comment on the preceding `unsafe impl` block for an + // explanation of why we need this block. + if 1 == 0 { + let ptr = <$t as KnownLayout>::raw_dangling(); + #[allow(unused_unsafe)] + // SAFETY: This call is never executed. + let ptr = unsafe { crate::pointer::PtrInner::new(ptr) }; + #[allow(unused_unsafe)] + // SAFETY: This call is never executed. + let ptr = unsafe { cast!(ptr) }; + let _ = <$dst<$u> as SizeEq<$src<$t>>>::cast_from_raw(ptr); + } + + impl_for_transmute_from!(T: ?Sized + TryFromBytes => TryFromBytes for $src[]); + impl_for_transmute_from!(T: ?Sized + FromBytes => FromBytes for $src[]); + impl_for_transmute_from!(T: ?Sized + FromZeros => FromZeros for $src[]); + impl_for_transmute_from!(T: ?Sized + IntoBytes => IntoBytes for $src[]); + + impl_for_transmute_from!(U: ?Sized + TryFromBytes => TryFromBytes for $dst[]); + impl_for_transmute_from!(U: ?Sized + FromBytes => FromBytes for $dst[]); + impl_for_transmute_from!(U: ?Sized + FromZeros => FromZeros for $dst[]); + impl_for_transmute_from!(U: ?Sized + IntoBytes => IntoBytes for $dst[]); + + // SAFETY: `$src` is a `#[repr(transparent)]` wrapper around `T`, and + // so permits interior mutation exactly when `T` does. + unsafe_impl!(T: ?Sized + Immutable => Immutable for $src); + + // SAFETY: `$dst` is a `#[repr(transparent)]` wrapper around `T`, and + // so permits interior mutation exactly when `T` does. + unsafe_impl!(T: ?Sized + Immutable => Immutable for $dst); + + $blk + }}; +} + /// A no-op `unsafe fn` for use in macro expansions. /// /// Calling this function in a macro expansion ensures that the macro's caller diff --git a/src/util/mod.rs b/src/util/mod.rs index 05f655bde4..3fba7cc760 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -631,19 +631,19 @@ pub(crate) mod polyfills { // FIXME(#67): Once our MSRV is high enough, remove this. #[allow(unused)] pub(crate) trait NumExt { - /// Subtract without checking for underflow. + /// Add without checking for overflow. /// /// # Safety /// - /// The caller promises that the subtraction will not underflow. - unsafe fn unchecked_sub(self, rhs: Self) -> Self; + /// The caller promises that the addition will not overflow. + unsafe fn unchecked_add(self, rhs: Self) -> Self; - /// Add without checking for overflow. + /// Subtract without checking for underflow. /// /// # Safety /// - /// The caller promises that the addition will not overflow. - unsafe fn unchecked_add(self, rhs: Self) -> Self; + /// The caller promises that the subtraction will not underflow. + unsafe fn unchecked_sub(self, rhs: Self) -> Self; /// Multiply without checking for overflow. /// @@ -653,48 +653,42 @@ pub(crate) mod polyfills { unsafe fn unchecked_mul(self, rhs: Self) -> Self; } + // NOTE on coverage: these will never be tested in nightly since they're + // polyfills for a feature which has been stabilized on our nightly + // toolchain. impl NumExt for usize { - // NOTE on coverage: this will never be tested in nightly since it's a - // polyfill for a feature which has been stabilized on our nightly - // toolchain. #[cfg_attr( all(coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS), coverage(off) )] #[inline(always)] - unsafe fn unchecked_sub(self, rhs: usize) -> usize { - match self.checked_sub(rhs) { + unsafe fn unchecked_add(self, rhs: usize) -> usize { + match self.checked_add(rhs) { Some(x) => x, None => { - // SAFETY: The caller promises that the subtraction will not + // SAFETY: The caller promises that the addition will not // underflow. unsafe { core::hint::unreachable_unchecked() } } } } - // NOTE on coverage: this will never be tested in nightly since it's a - // polyfill for a feature which has been stabilized on our nightly - // toolchain. #[cfg_attr( all(coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS), coverage(off) )] #[inline(always)] - unsafe fn unchecked_add(self, rhs: usize) -> usize { - match self.checked_add(rhs) { + unsafe fn unchecked_sub(self, rhs: usize) -> usize { + match self.checked_sub(rhs) { Some(x) => x, None => { - // SAFETY: The caller promises that the addition will not - // overflow. + // SAFETY: The caller promises that the subtraction will not + // underflow. unsafe { core::hint::unreachable_unchecked() } } } } - // NOTE on coverage: this will never be tested in nightly since it's a - // polyfill for a feature which has been stabilized on our nightly - // toolchain. #[cfg_attr( all(coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS), coverage(off) diff --git a/tests/ui-msrv/transmute-mut-alignment-increase.rs b/tests/ui-msrv/transmute-mut-alignment-increase.rs deleted file mode 120000 index dc82d95801..0000000000 --- a/tests/ui-msrv/transmute-mut-alignment-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-alignment-increase.stderr b/tests/ui-msrv/transmute-mut-alignment-increase.stderr deleted file mode 100644 index 7b771b8521..0000000000 --- a/tests/ui-msrv/transmute-mut-alignment-increase.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-alignment-increase.rs:20:39 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [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) - -error[E0658]: mutable references are not allowed in constants - --> tests/ui-msrv/transmute-mut-alignment-increase.rs:20:54 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^ - | - = note: see issue #57349 for more information - -error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> tests/ui-msrv/transmute-mut-alignment-increase.rs:20:39 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0716]: temporary value dropped while borrowed - --> tests/ui-msrv/transmute-mut-alignment-increase.rs:20:59 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]); - | --------------------^^^^^^^^- - | | | - | | creates a temporary which is freed while still in use - | temporary value is freed at the end of this statement - | using this value as a constant requires that borrow lasts for `'static` diff --git a/tests/ui-msrv/transmute-mut-dst-generic.rs b/tests/ui-msrv/transmute-mut-dst-generic.rs deleted file mode 120000 index 81b26b7f3e..0000000000 --- a/tests/ui-msrv/transmute-mut-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-dst-generic.stderr b/tests/ui-msrv/transmute-mut-dst-generic.stderr deleted file mode 100644 index f6b54ce1c2..0000000000 --- a/tests/ui-msrv/transmute-mut-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-mut-dst-not-a-reference.stderr b/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr index eaff00fd27..295aa211ab 100644 --- a/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr @@ -7,43 +7,3 @@ error[E0308]: mismatched types = note: expected type `usize` found mutable reference `&mut _` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr b/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr index 3f92e0d4e4..abb87e63fd 100644 --- a/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr +++ b/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr @@ -4,9 +4,4 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | -note: required by `AssertDstIsFromBytes` - --> tests/ui-msrv/transmute-mut-dst-not-frombytes.rs:24:38 - | -24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr b/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr index 4ceffcd010..2f4da83a59 100644 --- a/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr +++ b/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr @@ -4,9 +4,4 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | -note: required by `AssertDstIsIntoBytes` - --> tests/ui-msrv/transmute-mut-dst-not-intobytes.rs:24:36 - | -24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-dst-unsized.stderr b/tests/ui-msrv/transmute-mut-dst-unsized.stderr index e54fac982c..087d7b816c 100644 --- a/tests/ui-msrv/transmute-mut-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-mut-dst-unsized.stderr @@ -5,90 +5,4 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertDstIsSized` - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-size-decrease.rs b/tests/ui-msrv/transmute-mut-size-decrease.rs deleted file mode 120000 index cefc2c8a83..0000000000 --- a/tests/ui-msrv/transmute-mut-size-decrease.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-size-decrease.stderr b/tests/ui-msrv/transmute-mut-size-decrease.stderr deleted file mode 100644 index ee3261ed28..0000000000 --- a/tests/ui-msrv/transmute-mut-size-decrease.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:32 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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) - -error[E0658]: mutable references are not allowed in constants - --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:47 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^ - | - = note: see issue #57349 for more information - -error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:32 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0716]: temporary value dropped while borrowed - --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:52 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | --------------------^^^^^^^^- - | | | - | | creates a temporary which is freed while still in use - | temporary value is freed at the end of this statement - | using this value as a constant requires that borrow lasts for `'static` diff --git a/tests/ui-msrv/transmute-mut-size-increase.rs b/tests/ui-msrv/transmute-mut-size-increase.rs deleted file mode 120000 index 1d87f69028..0000000000 --- a/tests/ui-msrv/transmute-mut-size-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-size-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-size-increase.stderr b/tests/ui-msrv/transmute-mut-size-increase.stderr deleted file mode 100644 index 242493ff0a..0000000000 --- a/tests/ui-msrv/transmute-mut-size-increase.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-size-increase.rs:17:37 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = 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) - -error[E0658]: mutable references are not allowed in constants - --> tests/ui-msrv/transmute-mut-size-increase.rs:17:52 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | ^^^^^^^^ - | - = note: see issue #57349 for more information - -error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> tests/ui-msrv/transmute-mut-size-increase.rs:17:37 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0716]: temporary value dropped while borrowed - --> tests/ui-msrv/transmute-mut-size-increase.rs:17:57 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | --------------------^^^- - | | | - | | creates a temporary which is freed while still in use - | temporary value is freed at the end of this statement - | using this value as a constant requires that borrow lasts for `'static` diff --git a/tests/ui-msrv/transmute-mut-src-dst-generic.rs b/tests/ui-msrv/transmute-mut-src-dst-generic.rs deleted file mode 120000 index 95d723c8ce..0000000000 --- a/tests/ui-msrv/transmute-mut-src-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-dst-generic.stderr b/tests/ui-msrv/transmute-mut-src-dst-generic.stderr deleted file mode 100644 index f41be15ad3..0000000000 --- a/tests/ui-msrv/transmute-mut-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-mut-src-dst-unsized.rs b/tests/ui-msrv/transmute-mut-src-dst-unsized.rs deleted file mode 120000 index d550b895ce..0000000000 --- a/tests/ui-msrv/transmute-mut-src-dst-unsized.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-dst-unsized.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr b/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr deleted file mode 100644 index ff2d7d198d..0000000000 --- a/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr +++ /dev/null @@ -1,222 +0,0 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertSrcIsSized` - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertDstIsSized` - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_mut` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_mut` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-src-generic.rs b/tests/ui-msrv/transmute-mut-src-generic.rs deleted file mode 120000 index a400382268..0000000000 --- a/tests/ui-msrv/transmute-mut-src-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-generic.stderr b/tests/ui-msrv/transmute-mut-src-generic.stderr deleted file mode 100644 index 319fc27a8b..0000000000 --- a/tests/ui-msrv/transmute-mut-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-mut-src-not-frombytes.stderr b/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr index ebb8e0bafe..01dd91fa32 100644 --- a/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr +++ b/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr @@ -4,22 +4,4 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied 24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` | -note: required by `AssertSrcIsFromBytes` - --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = 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/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` - | -note: required by a bound in `AssertSrcIsFromBytes` - --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const 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) diff --git a/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr b/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr index 7522b32a69..5b8735628b 100644 --- a/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr +++ b/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr @@ -4,22 +4,4 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` | -note: required by `AssertSrcIsIntoBytes` - --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = 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/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` - | -note: required by a bound in `AssertSrcIsIntoBytes` - --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-mut-src-unsized.stderr b/tests/ui-msrv/transmute-mut-src-unsized.stderr index df471dc458..bacd62f336 100644 --- a/tests/ui-msrv/transmute-mut-src-unsized.stderr +++ b/tests/ui-msrv/transmute-mut-src-unsized.stderr @@ -1,179 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` + --> tests/ui-msrv/transmute-mut-src-unsized.rs:17:35 | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time +17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertSrcIsSized` - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` + = note: required because of the requirements on the impl of `TransmuteMutDst<'_>` for `Wrap<&mut [u8], &mut [u8; 1]>` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_mut` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all function arguments must have a statically known size - = 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/transmute-ref-alignment-increase.rs b/tests/ui-msrv/transmute-ref-alignment-increase.rs deleted file mode 120000 index f2818c150f..0000000000 --- a/tests/ui-msrv/transmute-ref-alignment-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-alignment-increase.stderr b/tests/ui-msrv/transmute-ref-alignment-increase.stderr deleted file mode 100644 index bbf5058287..0000000000 --- a/tests/ui-msrv/transmute-ref-alignment-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-alignment-increase.rs:20:35 - | -20 | const INCREASE_ALIGNMENT: &AU16 = 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/transmute-ref-dst-generic.rs b/tests/ui-msrv/transmute-ref-dst-generic.rs deleted file mode 120000 index 4eb38159ca..0000000000 --- a/tests/ui-msrv/transmute-ref-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-dst-generic.stderr b/tests/ui-msrv/transmute-ref-dst-generic.stderr deleted file mode 100644 index ec7ec74894..0000000000 --- a/tests/ui-msrv/transmute-ref-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-ref-dst-mutable.stderr b/tests/ui-msrv/transmute-ref-dst-mutable.stderr index 3189cd0d4b..5ccf2cd20d 100644 --- a/tests/ui-msrv/transmute-ref-dst-mutable.stderr +++ b/tests/ui-msrv/transmute-ref-dst-mutable.stderr @@ -27,23 +27,3 @@ error[E0308]: mismatched types = note: expected mutable reference `&mut u8` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability - | - = note: expected mutable reference `&mut u8` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability - | - = note: expected mutable reference `&mut u8` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr b/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr index 60a79caeba..9a61c4c7ce 100644 --- a/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr @@ -27,23 +27,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-dst-unsized.stderr b/tests/ui-msrv/transmute-ref-dst-unsized.stderr index 5967222fb0..11b38acb8b 100644 --- a/tests/ui-msrv/transmute-ref-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-ref-dst-unsized.stderr @@ -5,90 +5,4 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertDstIsSized` - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_ref` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-size-decrease.rs b/tests/ui-msrv/transmute-ref-size-decrease.rs deleted file mode 120000 index 05cca6b17d..0000000000 --- a/tests/ui-msrv/transmute-ref-size-decrease.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-size-decrease.stderr b/tests/ui-msrv/transmute-ref-size-decrease.stderr deleted file mode 100644 index 95669f9063..0000000000 --- a/tests/ui-msrv/transmute-ref-size-decrease.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-size-decrease.rs:17:28 - | -17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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/transmute-ref-size-increase.rs b/tests/ui-msrv/transmute-ref-size-increase.rs deleted file mode 120000 index 0f10c6ed04..0000000000 --- a/tests/ui-msrv/transmute-ref-size-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-size-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-size-increase.stderr b/tests/ui-msrv/transmute-ref-size-increase.stderr deleted file mode 100644 index 10f0e1038c..0000000000 --- a/tests/ui-msrv/transmute-ref-size-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-size-increase.rs:17:33 - | -17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | - = 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/transmute-ref-src-dst-generic.rs b/tests/ui-msrv/transmute-ref-src-dst-generic.rs deleted file mode 120000 index 5990caeb83..0000000000 --- a/tests/ui-msrv/transmute-ref-src-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-dst-generic.stderr b/tests/ui-msrv/transmute-ref-src-dst-generic.stderr deleted file mode 100644 index eb3268fa8f..0000000000 --- a/tests/ui-msrv/transmute-ref-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-ref-src-dst-not-references.stderr b/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr index 1826e28a52..2c5e23b6dd 100644 --- a/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr @@ -40,23 +40,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-src-dst-unsized.rs b/tests/ui-msrv/transmute-ref-src-dst-unsized.rs deleted file mode 120000 index a99540440a..0000000000 --- a/tests/ui-msrv/transmute-ref-src-dst-unsized.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-dst-unsized.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr b/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr deleted file mode 100644 index af59584992..0000000000 --- a/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr +++ /dev/null @@ -1,222 +0,0 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertSrcIsSized` - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertDstIsSized` - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_ref` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_ref` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ref-src-generic.rs b/tests/ui-msrv/transmute-ref-src-generic.rs deleted file mode 120000 index 343d517d5b..0000000000 --- a/tests/ui-msrv/transmute-ref-src-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-generic.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-generic.stderr b/tests/ui-msrv/transmute-ref-src-generic.stderr deleted file mode 100644 index 4cb3e51bc7..0000000000 --- a/tests/ui-msrv/transmute-ref-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = 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/transmute-ref-src-unsized.stderr b/tests/ui-msrv/transmute-ref-src-unsized.stderr index b3705bca36..736a653033 100644 --- a/tests/ui-msrv/transmute-ref-src-unsized.stderr +++ b/tests/ui-msrv/transmute-ref-src-unsized.stderr @@ -1,179 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `AssertSrcIsSized` - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` + = note: required because of the requirements on the impl of `TransmuteRefDst<'_>` for `Wrap<&[u8], &[u8; 1]>` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute` - --> $RUST/core/src/intrinsics.rs - | - | pub fn transmute(e: T) -> U; - | ^ required by this bound in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by `MaxAlignsOf::::new` - --> src/util/macro_util.rs - | - | pub fn new(_t: T, _u: U) -> MaxAlignsOf { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by this bound in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by this bound in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by this bound in `transmute_ref` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all function arguments must have a statically known size - = 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-frombytes.stderr b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr index 0052bb6446..f088592e82 100644 --- a/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr +++ b/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr @@ -4,24 +4,6 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = 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` - | -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 @@ -30,11 +12,6 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = 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 @@ -43,9 +20,4 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = 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 7a1365ab8d..76ace191ec 100644 --- a/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr @@ -4,24 +4,6 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = 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` - | -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 @@ -30,11 +12,6 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = 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 @@ -43,9 +20,4 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | -note: required by `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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-alignment-increase.rs b/tests/ui-nightly/transmute-mut-alignment-increase.rs deleted file mode 100644 index daf2ed1d02..0000000000 --- a/tests/ui-nightly/transmute-mut-alignment-increase.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 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::transmute_mut; - -fn main() {} - -// `transmute_mut!` does not support transmuting from a type of smaller -// alignment to one of larger alignment. -const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]); diff --git a/tests/ui-nightly/transmute-mut-alignment-increase.stderr b/tests/ui-nightly/transmute-mut-alignment-increase.stderr deleted file mode 100644 index e0b418058f..0000000000 --- a/tests/ui-nightly/transmute-mut-alignment-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-alignment-increase.rs:20:39 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-const.stderr b/tests/ui-nightly/transmute-mut-const.stderr index 5d9ecd87fd..9396f611f4 100644 --- a/tests/ui-nightly/transmute-mut-const.stderr +++ b/tests/ui-nightly/transmute-mut-const.stderr @@ -13,7 +13,7 @@ note: `const` item defined here | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `#[warn(const_item_mutation)]` on by default -error[E0015]: cannot call non-const function `transmute_mut::<'_, '_, [u8; 2], [u8; 2]>` in constants +error[E0015]: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants --> tests/ui-nightly/transmute-mut-const.rs:20:37 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); diff --git a/tests/ui-nightly/transmute-mut-dst-generic.rs b/tests/ui-nightly/transmute-mut-dst-generic.rs deleted file mode 100644 index e61c573ad5..0000000000 --- a/tests/ui-nightly/transmute-mut-dst-generic.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 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, FromBytes, Immutable, IntoBytes}; - -fn main() {} - -fn transmute_mut(u: &mut u8) -> &mut T { - // `transmute_mut!` requires the destination type to be concrete. - transmute_mut!(u) -} diff --git a/tests/ui-nightly/transmute-mut-dst-generic.stderr b/tests/ui-nightly/transmute-mut-dst-generic.stderr deleted file mode 100644 index f278558cf8..0000000000 --- a/tests/ui-nightly/transmute-mut-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr index 4c4e4b7b6d..f1c445813c 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr @@ -7,56 +7,3 @@ error[E0308]: mismatched types = note: expected type `usize` found mutable reference `&mut _` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&mut _` - | arguments to this function are incorrect - | - = note: expected type `usize` - found mutable reference `&mut _` -help: the return type of this call is `&mut _` due to the type of the argument passed - --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr index 1da794871f..17d4607874 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr +++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr @@ -2,10 +2,7 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied --> tests/ui-nightly/transmute-mut-dst-not-frombytes.rs:24:38 | 24 | const DST_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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -18,9 +15,12 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-nightly/transmute-mut-dst-not-frombytes.rs:24:38 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr b/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr index 2696d4043e..14f968087c 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr +++ b/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr @@ -2,10 +2,7 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied --> tests/ui-nightly/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `IntoBytes` is not implemented for `Dst` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -18,9 +15,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-nightly/transmute-mut-dst-not-intobytes.rs:24:36 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-unsized.stderr b/tests/ui-nightly/transmute-mut-dst-unsized.stderr index 549cf405f3..2f64a8d67a 100644 --- a/tests/ui-nightly/transmute-mut-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-mut-dst-unsized.stderr @@ -1,59 +1,3 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 | @@ -61,9 +5,12 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` --> src/util/macro_util.rs | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` + | impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> { + | ^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` +... + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-size-decrease.rs b/tests/ui-nightly/transmute-mut-size-decrease.rs deleted file mode 100644 index c6eec3a9c2..0000000000 --- a/tests/ui-nightly/transmute-mut-size-decrease.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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; - -fn main() {} - -// We require that the size of the destination type is not smaller than the size -// of the source type. -const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); diff --git a/tests/ui-nightly/transmute-mut-size-decrease.stderr b/tests/ui-nightly/transmute-mut-size-decrease.stderr deleted file mode 100644 index ac1e35cec7..0000000000 --- a/tests/ui-nightly/transmute-mut-size-decrease.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-size-decrease.rs:17:32 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-size-increase.rs b/tests/ui-nightly/transmute-mut-size-increase.rs deleted file mode 100644 index a4657c2838..0000000000 --- a/tests/ui-nightly/transmute-mut-size-increase.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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; - -fn main() {} - -// `transmute_mut!` does not support transmuting from a smaller type to a larger -// one. -const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); diff --git a/tests/ui-nightly/transmute-mut-size-increase.stderr b/tests/ui-nightly/transmute-mut-size-increase.stderr deleted file mode 100644 index d343bd65e6..0000000000 --- a/tests/ui-nightly/transmute-mut-size-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-size-increase.rs:17:37 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = 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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.rs b/tests/ui-nightly/transmute-mut-src-dst-generic.rs deleted file mode 100644 index 1eccb5159b..0000000000 --- a/tests/ui-nightly/transmute-mut-src-dst-generic.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 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, FromBytes, Immutable, IntoBytes}; - -fn main() {} - -fn transmute_mut( - t: &mut T, -) -> &mut U { - // `transmute_mut!` requires the source and destination types to be - // concrete. - transmute_mut!(t) -} diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.stderr b/tests/ui-nightly/transmute-mut-src-dst-generic.stderr deleted file mode 100644 index eb5c498cec..0000000000 --- a/tests/ui-nightly/transmute-mut-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr b/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr index d177d5734c..df3cf2dba0 100644 --- a/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr +++ b/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr @@ -13,32 +13,3 @@ help: consider mutably borrowing here | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize); | ++++ - -warning: this function depends on never type fallback being `()` - --> tests/ui-nightly/transmute-mut-src-dst-not-references.rs:17:1 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-nightly/transmute-mut-src-dst-not-references.rs:17:44 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-mut-src-dst-not-references.rs:17:44 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-dst-unsized.rs b/tests/ui-nightly/transmute-mut-src-dst-unsized.rs deleted file mode 100644 index 1bebcf2d68..0000000000 --- a/tests/ui-nightly/transmute-mut-src-dst-unsized.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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; - -fn main() {} - -// `transmute_mut!` does not support transmuting between unsized source and -// destination types. -const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); diff --git a/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr b/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr deleted file mode 100644 index fa82aee592..0000000000 --- a/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr +++ /dev/null @@ -1,183 +0,0 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-generic.rs b/tests/ui-nightly/transmute-mut-src-generic.rs deleted file mode 100644 index 3877619cab..0000000000 --- a/tests/ui-nightly/transmute-mut-src-generic.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 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, FromBytes, Immutable, IntoBytes}; - -fn main() {} - -fn transmute_mut(t: &mut T) -> &mut u8 { - // `transmute_mut!` requires the source type to be concrete. - transmute_mut!(t) -} diff --git a/tests/ui-nightly/transmute-mut-src-generic.stderr b/tests/ui-nightly/transmute-mut-src-generic.stderr deleted file mode 100644 index 26b185639d..0000000000 --- a/tests/ui-nightly/transmute-mut-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-immutable.stderr b/tests/ui-nightly/transmute-mut-src-immutable.stderr index e05b6cdd68..7b7969d5d5 100644 --- a/tests/ui-nightly/transmute-mut-src-immutable.stderr +++ b/tests/ui-nightly/transmute-mut-src-immutable.stderr @@ -9,32 +9,3 @@ error[E0308]: mismatched types | = note: expected mutable reference `&mut _` found reference `&u8` - -warning: this function depends on never type fallback being `()` - --> tests/ui-nightly/transmute-mut-src-immutable.rs:15:1 - | -15 | fn ref_src_immutable() { - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-nightly/transmute-mut-src-immutable.rs:17:22 - | -17 | let _: &mut u8 = transmute_mut!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-mut-src-immutable.rs:17:22 - | -17 | let _: &mut u8 = transmute_mut!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr b/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr index bc84580b45..12b7674f0e 100644 --- a/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr @@ -13,32 +13,3 @@ help: consider mutably borrowing here | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize); | ++++ - -warning: this function depends on never type fallback being `()` - --> tests/ui-nightly/transmute-mut-src-not-a-reference.rs:17:1 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-nightly/transmute-mut-src-not-a-reference.rs:17:38 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-mut-src-not-a-reference.rs:17:38 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr b/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr index 3510954a82..ed9cd85597 100644 --- a/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr +++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr @@ -1,30 +1,3 @@ -error[E0277]: the trait bound `Src: FromBytes` is not satisfied - --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const 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/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const 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/transmute-mut-src-not-frombytes.rs:24:38 | @@ -42,9 +15,12 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertSrcIsFromBytes` - --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr b/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr index fb53bacc09..96281f0a9c 100644 --- a/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr +++ b/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr @@ -1,30 +1,3 @@ -error[E0277]: the trait bound `Src: IntoBytes` is not satisfied - --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `IntoBytes` is not implemented for `Src` - | required by a bound introduced by this call - | - = 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/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `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/transmute-mut-src-not-intobytes.rs:24:36 | @@ -42,9 +15,12 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertSrcIsIntoBytes` - --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-src-unsized.rs b/tests/ui-nightly/transmute-mut-src-unsized.rs index 413dd68d89..473070aecb 100644 --- a/tests/ui-nightly/transmute-mut-src-unsized.rs +++ b/tests/ui-nightly/transmute-mut-src-unsized.rs @@ -12,5 +12,6 @@ use zerocopy::transmute_mut; fn main() {} -// `transmute_mut!` does not support transmuting from an unsized source type. +// `transmute_mut!` does not support transmuting from an unsized source type to +// a sized destination type. const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); diff --git a/tests/ui-nightly/transmute-mut-src-unsized.stderr b/tests/ui-nightly/transmute-mut-src-unsized.stderr index d98188636e..4b99fa6c42 100644 --- a/tests/ui-nightly/transmute-mut-src-unsized.stderr +++ b/tests/ui-nightly/transmute-mut-src-unsized.stderr @@ -1,127 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` + --> tests/ui-nightly/transmute-mut-src-unsized.rs:17:35 | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call +17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` + = note: required for `Wrap<&mut [u8], &mut [u8; 1]>` to implement `TransmuteMutDst<'_>` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-alignment-increase.rs b/tests/ui-nightly/transmute-ref-alignment-increase.rs deleted file mode 100644 index 7d202d51d1..0000000000 --- a/tests/ui-nightly/transmute-ref-alignment-increase.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 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::transmute_ref; - -fn main() {} - -// `transmute_ref!` does not support transmuting from a type of smaller -// alignment to one of larger alignment. -const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]); diff --git a/tests/ui-nightly/transmute-ref-alignment-increase.stderr b/tests/ui-nightly/transmute-ref-alignment-increase.stderr deleted file mode 100644 index 30fabe5a66..0000000000 --- a/tests/ui-nightly/transmute-ref-alignment-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-alignment-increase.rs:20:35 - | -20 | const INCREASE_ALIGNMENT: &AU16 = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-dst-generic.rs b/tests/ui-nightly/transmute-ref-dst-generic.rs deleted file mode 100644 index 665c9c0990..0000000000 --- a/tests/ui-nightly/transmute-ref-dst-generic.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 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_ref, FromBytes, Immutable}; - -fn main() {} - -fn transmute_ref(u: &u8) -> &T { - // `transmute_ref!` requires the destination type to be concrete. - transmute_ref!(u) -} diff --git a/tests/ui-nightly/transmute-ref-dst-generic.stderr b/tests/ui-nightly/transmute-ref-dst-generic.stderr deleted file mode 100644 index 4c94d501c2..0000000000 --- a/tests/ui-nightly/transmute-ref-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-dst-mutable.stderr b/tests/ui-nightly/transmute-ref-dst-mutable.stderr index abae5e08b9..0cbdd176b8 100644 --- a/tests/ui-nightly/transmute-ref-dst-mutable.stderr +++ b/tests/ui-nightly/transmute-ref-dst-mutable.stderr @@ -27,36 +27,3 @@ error[E0308]: mismatched types = note: expected mutable reference `&mut u8` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability - | - = note: expected mutable reference `&mut u8` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | types differ in mutability - | arguments to this function are incorrect - | - = note: expected mutable reference `&mut u8` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr index 896bddd43b..847d54732e 100644 --- a/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr @@ -27,36 +27,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&_` - | arguments to this function are incorrect - | - = note: expected type `usize` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-dst-unsized.stderr b/tests/ui-nightly/transmute-ref-dst-unsized.stderr index 2bb6f6bc76..ffa7ba568b 100644 --- a/tests/ui-nightly/transmute-ref-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-ref-dst-unsized.stderr @@ -1,59 +1,3 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 | @@ -61,9 +5,12 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` +note: required by a bound in `Wrap::<&'a Src, &'a Dst>::transmute_ref` --> src/util/macro_util.rs | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` + | impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> { + | ^^^ required by this bound in `Wrap::<&Src, &Dst>::transmute_ref` +... + | pub const unsafe fn transmute_ref(self) -> &'a Dst { + | ------------- required by a bound in this associated function = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-size-decrease.rs b/tests/ui-nightly/transmute-ref-size-decrease.rs deleted file mode 100644 index 1d66a54ef7..0000000000 --- a/tests/ui-nightly/transmute-ref-size-decrease.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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_ref; - -fn main() {} - -// 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. -const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]); diff --git a/tests/ui-nightly/transmute-ref-size-decrease.stderr b/tests/ui-nightly/transmute-ref-size-decrease.stderr deleted file mode 100644 index 793ecc54c0..0000000000 --- a/tests/ui-nightly/transmute-ref-size-decrease.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-size-decrease.rs:17:28 - | -17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-size-increase.rs b/tests/ui-nightly/transmute-ref-size-increase.rs deleted file mode 100644 index cdca560b30..0000000000 --- a/tests/ui-nightly/transmute-ref-size-increase.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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_ref; - -fn main() {} - -// `transmute_ref!` does not support transmuting from a smaller type to a larger -// one. -const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8); diff --git a/tests/ui-nightly/transmute-ref-size-increase.stderr b/tests/ui-nightly/transmute-ref-size-increase.stderr deleted file mode 100644 index 40c69f63c4..0000000000 --- a/tests/ui-nightly/transmute-ref-size-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-size-increase.rs:17:33 - | -17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | - = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.rs b/tests/ui-nightly/transmute-ref-src-dst-generic.rs deleted file mode 100644 index 0482a59d4d..0000000000 --- a/tests/ui-nightly/transmute-ref-src-dst-generic.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 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_ref, FromBytes, Immutable, IntoBytes}; - -fn main() {} - -fn transmute_ref(t: &T) -> &U { - // `transmute_ref!` requires the source and destination types to be - // concrete. - transmute_ref!(t) -} diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.stderr b/tests/ui-nightly/transmute-ref-src-dst-generic.stderr deleted file mode 100644 index 6a3a4fd95b..0000000000 --- a/tests/ui-nightly/transmute-ref-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr index 7b30a108fa..0f1f7fc7b3 100644 --- a/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr @@ -43,76 +43,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&_` - | arguments to this function are incorrect - | - = note: expected type `usize` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: this function depends on never type fallback being `()` - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:1 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: IntoBytes` will fail - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-dst-unsized.rs b/tests/ui-nightly/transmute-ref-src-dst-unsized.rs deleted file mode 100644 index 6bfe7ffdfd..0000000000 --- a/tests/ui-nightly/transmute-ref-src-dst-unsized.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 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_ref; - -fn main() {} - -// `transmute_ref!` does not support transmuting between unsized source and -// destination types. -const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); diff --git a/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr b/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr deleted file mode 100644 index b732a6cb1c..0000000000 --- a/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr +++ /dev/null @@ -1,183 +0,0 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32 - | -17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-generic.rs b/tests/ui-nightly/transmute-ref-src-generic.rs deleted file mode 100644 index 11e6ffcfdb..0000000000 --- a/tests/ui-nightly/transmute-ref-src-generic.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 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_ref, Immutable, IntoBytes}; - -fn main() {} - -fn transmute_ref(t: &T) -> &u8 { - // `transmute_ref!` requires the source type to be concrete. - transmute_ref!(t) -} diff --git a/tests/ui-nightly/transmute-ref-src-generic.stderr b/tests/ui-nightly/transmute-ref-src-generic.stderr deleted file mode 100644 index a168f44bb4..0000000000 --- a/tests/ui-nightly/transmute-ref-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr b/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr index 49a236af1e..be477c6c5e 100644 --- a/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr @@ -13,43 +13,3 @@ help: consider borrowing here | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize); | + - -warning: this function depends on never type fallback being `()` - --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:1 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: IntoBytes` will fail - --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-unsized.stderr b/tests/ui-nightly/transmute-ref-src-unsized.stderr index 57a5cb7cf0..cd4d16a0c3 100644 --- a/tests/ui-nightly/transmute-ref-src-unsized.stderr +++ b/tests/ui-nightly/transmute-ref-src-unsized.stderr @@ -1,127 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` + = note: required for `Wrap<&[u8], &[u8; 1]>` to implement `TransmuteRefDst<'_>` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr index 5a55338881..a6206f1f95 100644 --- a/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr +++ b/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr @@ -1,30 +1,3 @@ -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 | @@ -42,21 +15,21 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertSrcIsFromBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -69,21 +42,21 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -96,9 +69,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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.stderr b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr index 66868266d2..e4bacd047a 100644 --- a/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr @@ -1,30 +1,3 @@ -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` - | required by a bound introduced by this call - | - = 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 `Src: IntoBytes` is not satisfied --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 | @@ -42,21 +15,21 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertSrcIsIntoBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -69,21 +42,21 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -96,9 +69,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-alignment-increase.rs b/tests/ui-stable/transmute-mut-alignment-increase.rs deleted file mode 120000 index dc82d95801..0000000000 --- a/tests/ui-stable/transmute-mut-alignment-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-alignment-increase.stderr b/tests/ui-stable/transmute-mut-alignment-increase.stderr deleted file mode 100644 index 2b02f27c90..0000000000 --- a/tests/ui-stable/transmute-mut-alignment-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-alignment-increase.rs:20:39 - | -20 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-const.stderr b/tests/ui-stable/transmute-mut-const.stderr index 2a3388e0d2..d5c2aabfd0 100644 --- a/tests/ui-stable/transmute-mut-const.stderr +++ b/tests/ui-stable/transmute-mut-const.stderr @@ -13,7 +13,7 @@ note: `const` item defined here | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `#[warn(const_item_mutation)]` on by default -error[E0015]: cannot call non-const function `transmute_mut::<'_, '_, [u8; 2], [u8; 2]>` in constants +error[E0015]: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants --> tests/ui-stable/transmute-mut-const.rs:20:37 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); diff --git a/tests/ui-stable/transmute-mut-dst-generic.rs b/tests/ui-stable/transmute-mut-dst-generic.rs deleted file mode 120000 index 81b26b7f3e..0000000000 --- a/tests/ui-stable/transmute-mut-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-dst-generic.stderr b/tests/ui-stable/transmute-mut-dst-generic.stderr deleted file mode 100644 index 0000eb0bab..0000000000 --- a/tests/ui-stable/transmute-mut-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-dst-generic.rs:17:5 - | -17 | transmute_mut!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr b/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr index c17eba9e40..1f438badec 100644 --- a/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr @@ -7,56 +7,3 @@ error[E0308]: mismatched types = note: expected type `usize` found mutable reference `&mut _` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` - | - = note: expected type `usize` - found mutable reference `&mut _` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&mut _` - | arguments to this function are incorrect - | - = note: expected type `usize` - found mutable reference `&mut _` -help: the return type of this call is `&mut _` due to the type of the argument passed - --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr b/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr index 5cc4bee82b..f25fc43cf3 100644 --- a/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr +++ b/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr @@ -2,10 +2,7 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied --> tests/ui-stable/transmute-mut-dst-not-frombytes.rs:24:38 | 24 | const DST_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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -18,9 +15,12 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-stable/transmute-mut-dst-not-frombytes.rs:24:38 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr b/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr index ba82af574f..45c274d46f 100644 --- a/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr +++ b/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr @@ -2,10 +2,7 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied --> tests/ui-stable/transmute-mut-dst-not-intobytes.rs:24:36 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `IntoBytes` is not implemented for `Dst` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -18,9 +15,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-stable/transmute-mut-dst-not-intobytes.rs:24:36 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-dst-unsized.stderr b/tests/ui-stable/transmute-mut-dst-unsized.stderr index 86c1088731..a3c550a31d 100644 --- a/tests/ui-stable/transmute-mut-dst-unsized.stderr +++ b/tests/ui-stable/transmute-mut-dst-unsized.stderr @@ -1,59 +1,3 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 | @@ -61,9 +5,12 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` --> src/util/macro_util.rs | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` + | impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> { + | ^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` +... + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-size-decrease.rs b/tests/ui-stable/transmute-mut-size-decrease.rs deleted file mode 120000 index cefc2c8a83..0000000000 --- a/tests/ui-stable/transmute-mut-size-decrease.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-size-decrease.stderr b/tests/ui-stable/transmute-mut-size-decrease.stderr deleted file mode 100644 index 239991357d..0000000000 --- a/tests/ui-stable/transmute-mut-size-decrease.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-size-decrease.rs:17:32 - | -17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-size-increase.rs b/tests/ui-stable/transmute-mut-size-increase.rs deleted file mode 120000 index 1d87f69028..0000000000 --- a/tests/ui-stable/transmute-mut-size-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-size-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-size-increase.stderr b/tests/ui-stable/transmute-mut-size-increase.stderr deleted file mode 100644 index 1427c7b0e9..0000000000 --- a/tests/ui-stable/transmute-mut-size-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-size-increase.rs:17:37 - | -17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = 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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-dst-generic.rs b/tests/ui-stable/transmute-mut-src-dst-generic.rs deleted file mode 120000 index 95d723c8ce..0000000000 --- a/tests/ui-stable/transmute-mut-src-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-src-dst-generic.stderr b/tests/ui-stable/transmute-mut-src-dst-generic.stderr deleted file mode 100644 index 2fd87ed86b..0000000000 --- a/tests/ui-stable/transmute-mut-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-src-dst-generic.rs:20:5 - | -20 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-dst-not-references.stderr b/tests/ui-stable/transmute-mut-src-dst-not-references.stderr index df3ba2b6aa..c0d9e0f0d3 100644 --- a/tests/ui-stable/transmute-mut-src-dst-not-references.stderr +++ b/tests/ui-stable/transmute-mut-src-dst-not-references.stderr @@ -13,32 +13,3 @@ help: consider mutably borrowing here | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize); | ++++ - -warning: this function depends on never type fallback being `()` - --> tests/ui-stable/transmute-mut-src-dst-not-references.rs:17:1 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-stable/transmute-mut-src-dst-not-references.rs:17:44 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-mut-src-dst-not-references.rs:17:44 - | -17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-dst-unsized.rs b/tests/ui-stable/transmute-mut-src-dst-unsized.rs deleted file mode 120000 index d550b895ce..0000000000 --- a/tests/ui-stable/transmute-mut-src-dst-unsized.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-dst-unsized.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-src-generic.rs b/tests/ui-stable/transmute-mut-src-generic.rs deleted file mode 120000 index a400382268..0000000000 --- a/tests/ui-stable/transmute-mut-src-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-mut-src-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-src-generic.stderr b/tests/ui-stable/transmute-mut-src-generic.stderr deleted file mode 100644 index 400b0a8166..0000000000 --- a/tests/ui-stable/transmute-mut-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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 `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-src-generic.rs:17:5 - | -17 | transmute_mut!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-immutable.stderr b/tests/ui-stable/transmute-mut-src-immutable.stderr index 2d82fc3ca5..0115c791d3 100644 --- a/tests/ui-stable/transmute-mut-src-immutable.stderr +++ b/tests/ui-stable/transmute-mut-src-immutable.stderr @@ -9,32 +9,3 @@ error[E0308]: mismatched types | = note: expected mutable reference `&mut _` found reference `&u8` - -warning: this function depends on never type fallback being `()` - --> tests/ui-stable/transmute-mut-src-immutable.rs:15:1 - | -15 | fn ref_src_immutable() { - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-stable/transmute-mut-src-immutable.rs:17:22 - | -17 | let _: &mut u8 = transmute_mut!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-mut-src-immutable.rs:17:22 - | -17 | let _: &mut u8 = transmute_mut!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-not-a-reference.stderr b/tests/ui-stable/transmute-mut-src-not-a-reference.stderr index 09e43faed5..8c1d9b47ba 100644 --- a/tests/ui-stable/transmute-mut-src-not-a-reference.stderr +++ b/tests/ui-stable/transmute-mut-src-not-a-reference.stderr @@ -13,32 +13,3 @@ help: consider mutably borrowing here | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize); | ++++ - -warning: this function depends on never type fallback being `()` - --> tests/ui-stable/transmute-mut-src-not-a-reference.rs:17:1 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: FromBytes` will fail - --> tests/ui-stable/transmute-mut-src-not-a-reference.rs:17:38 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-mut-src-not-a-reference.rs:17:38 - | -17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-not-frombytes.stderr b/tests/ui-stable/transmute-mut-src-not-frombytes.stderr index 1f1f31f0b8..e35a049e99 100644 --- a/tests/ui-stable/transmute-mut-src-not-frombytes.stderr +++ b/tests/ui-stable/transmute-mut-src-not-frombytes.stderr @@ -1,30 +1,3 @@ -error[E0277]: the trait bound `Src: FromBytes` is not satisfied - --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const 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/transmute-mut-src-not-frombytes.rs:24:38 - | -24 | const 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/transmute-mut-src-not-frombytes.rs:24:38 | @@ -42,9 +15,12 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertSrcIsFromBytes` - --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-not-intobytes.stderr b/tests/ui-stable/transmute-mut-src-not-intobytes.stderr index 03dc9f646e..4cc3f97622 100644 --- a/tests/ui-stable/transmute-mut-src-not-intobytes.stderr +++ b/tests/ui-stable/transmute-mut-src-not-intobytes.stderr @@ -1,30 +1,3 @@ -error[E0277]: the trait bound `Src: IntoBytes` is not satisfied - --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `IntoBytes` is not implemented for `Src` - | required by a bound introduced by this call - | - = 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/transmute-mut-src-not-intobytes.rs:24:36 - | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `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/transmute-mut-src-not-intobytes.rs:24:36 | @@ -42,9 +15,12 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertSrcIsIntoBytes` - --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-mut-src-unsized.stderr b/tests/ui-stable/transmute-mut-src-unsized.stderr index d11f520139..4ef157ea23 100644 --- a/tests/ui-stable/transmute-mut-src-unsized.stderr +++ b/tests/ui-stable/transmute-mut-src-unsized.stderr @@ -1,127 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` + --> tests/ui-stable/transmute-mut-src-unsized.rs:17:35 | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call +17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35 - | -16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_mut` - --> src/util/macro_util.rs - | - | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_mut` + = note: required for `Wrap<&mut [u8], &mut [u8; 1]>` to implement `TransmuteMutDst<'_>` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-alignment-increase.rs b/tests/ui-stable/transmute-ref-alignment-increase.rs deleted file mode 120000 index f2818c150f..0000000000 --- a/tests/ui-stable/transmute-ref-alignment-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-alignment-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-alignment-increase.stderr b/tests/ui-stable/transmute-ref-alignment-increase.stderr deleted file mode 100644 index cd99ff2ec2..0000000000 --- a/tests/ui-stable/transmute-ref-alignment-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-alignment-increase.rs:20:35 - | -20 | const INCREASE_ALIGNMENT: &AU16 = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-dst-generic.rs b/tests/ui-stable/transmute-ref-dst-generic.rs deleted file mode 120000 index 4eb38159ca..0000000000 --- a/tests/ui-stable/transmute-ref-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-dst-generic.stderr b/tests/ui-stable/transmute-ref-dst-generic.stderr deleted file mode 100644 index e30b9f67a6..0000000000 --- a/tests/ui-stable/transmute-ref-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `u8` (8 bits) - = note: target type: `T` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-dst-generic.rs:17:5 - | -17 | transmute_ref!(u) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (8 bits) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-dst-mutable.stderr b/tests/ui-stable/transmute-ref-dst-mutable.stderr index 1ca4020503..c70f6ea618 100644 --- a/tests/ui-stable/transmute-ref-dst-mutable.stderr +++ b/tests/ui-stable/transmute-ref-dst-mutable.stderr @@ -27,36 +27,3 @@ error[E0308]: mismatched types = note: expected mutable reference `&mut u8` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability - | - = note: expected mutable reference `&mut u8` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | types differ in mutability - | arguments to this function are incorrect - | - = note: expected mutable reference `&mut u8` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22 - | -18 | let _: &mut u8 = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr index 631796f1ad..ab3f90c2fd 100644 --- a/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr @@ -27,36 +27,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&_` - | arguments to this function are incorrect - | - = note: expected type `usize` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36 - | -17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-dst-unsized.stderr b/tests/ui-stable/transmute-ref-dst-unsized.stderr index dde0e3b004..7acd4a4a03 100644 --- a/tests/ui-stable/transmute-ref-dst-unsized.stderr +++ b/tests/ui-stable/transmute-ref-dst-unsized.stderr @@ -1,59 +1,3 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsSized` - --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 - | -17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `std::intrinsics::transmute` - --> $RUST/core/src/intrinsics/mod.rs - | - | pub const unsafe fn transmute(src: Src) -> Dst; - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute` - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 | @@ -61,9 +5,12 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` +note: required by a bound in `Wrap::<&'a Src, &'a Dst>::transmute_ref` --> src/util/macro_util.rs | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` + | impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> { + | ^^^ required by this bound in `Wrap::<&Src, &Dst>::transmute_ref` +... + | pub const unsafe fn transmute_ref(self) -> &'a Dst { + | ------------- required by a bound in this associated function = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-size-decrease.rs b/tests/ui-stable/transmute-ref-size-decrease.rs deleted file mode 120000 index 05cca6b17d..0000000000 --- a/tests/ui-stable/transmute-ref-size-decrease.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-size-decrease.stderr b/tests/ui-stable/transmute-ref-size-decrease.stderr deleted file mode 100644 index f353b26ece..0000000000 --- a/tests/ui-stable/transmute-ref-size-decrease.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-size-decrease.rs:17:28 - | -17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `[u8; 2]` (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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-size-increase.rs b/tests/ui-stable/transmute-ref-size-increase.rs deleted file mode 120000 index 0f10c6ed04..0000000000 --- a/tests/ui-stable/transmute-ref-size-increase.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-size-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-size-increase.stderr b/tests/ui-stable/transmute-ref-size-increase.stderr deleted file mode 100644 index f51eb63f4b..0000000000 --- a/tests/ui-stable/transmute-ref-size-increase.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-size-increase.rs:17:33 - | -17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8); - | ^^^^^^^^^^^^^^^^^^^^ - | - = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-dst-generic.rs b/tests/ui-stable/transmute-ref-src-dst-generic.rs deleted file mode 120000 index 5990caeb83..0000000000 --- a/tests/ui-stable/transmute-ref-src-dst-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-dst-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-dst-generic.stderr b/tests/ui-stable/transmute-ref-src-dst-generic.stderr deleted file mode 100644 index 0905dc6d5f..0000000000 --- a/tests/ui-stable/transmute-ref-src-dst-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = note: target type: `U` (this type does not have a fixed size) - = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-src-dst-generic.rs:18:5 - | -18 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-dst-not-references.stderr b/tests/ui-stable/transmute-ref-src-dst-not-references.stderr index be9b687a52..8a80e991e6 100644 --- a/tests/ui-stable/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-stable/transmute-ref-src-dst-not-references.stderr @@ -43,76 +43,3 @@ error[E0308]: mismatched types = note: expected type `usize` found reference `&_` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` - | - = note: expected type `usize` - found reference `&_` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected `usize`, found `&_` - | arguments to this function are incorrect - | - = note: expected type `usize` - found reference `&_` -help: the return type of this call is `&_` due to the type of the argument passed - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ this argument influences the return type of `must_use` -note: function defined here - --> src/util/macro_util.rs - | - | pub const fn must_use(t: T) -> T { - | ^^^^^^^^ - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: this function depends on never type fallback being `()` - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:1 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: IntoBytes` will fail - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39 - | -17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-dst-unsized.rs b/tests/ui-stable/transmute-ref-src-dst-unsized.rs deleted file mode 120000 index a99540440a..0000000000 --- a/tests/ui-stable/transmute-ref-src-dst-unsized.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-dst-unsized.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-generic.rs b/tests/ui-stable/transmute-ref-src-generic.rs deleted file mode 120000 index 343d517d5b..0000000000 --- a/tests/ui-stable/transmute-ref-src-generic.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-ref-src-generic.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-generic.stderr b/tests/ui-stable/transmute-ref-src-generic.stderr deleted file mode 100644 index b6bbd1648a..0000000000 --- a/tests/ui-stable/transmute-ref-src-generic.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `T` (this type does not have a fixed size) - = 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 `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-ref-src-generic.rs:17:5 - | -17 | transmute_ref!(t) - | ^^^^^^^^^^^^^^^^^ - | - = note: source type: `AlignOf` (size can vary because of T) - = note: target type: `MaxAlignsOf` (size can vary because of T) - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-not-a-reference.stderr b/tests/ui-stable/transmute-ref-src-not-a-reference.stderr index 9ee45c1459..622c3db9ac 100644 --- a/tests/ui-stable/transmute-ref-src-not-a-reference.stderr +++ b/tests/ui-stable/transmute-ref-src-not-a-reference.stderr @@ -13,43 +13,3 @@ help: consider borrowing here | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize); | + - -warning: this function depends on never type fallback being `()` - --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:1 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the types explicitly -note: in edition 2024, the requirement `!: IntoBytes` will fail - --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default - = note: this warning originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: never type fallback affects this call to an `unsafe` function - --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:34 - | -17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this changes meaning in Rust 2024 and in a future release in all editions! - = note: for more information, see - = help: specify the type explicitly - = note: this warning originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-ref-src-unsized.stderr b/tests/ui-stable/transmute-ref-src-unsized.stderr index 16e985cde5..30937fda28 100644 --- a/tests/ui-stable/transmute-ref-src-unsized.stderr +++ b/tests/ui-stable/transmute-ref-src-unsized.stderr @@ -1,127 +1,8 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time +error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsSized` - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsSized` - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AlignOf::::into_t` - --> src/util/macro_util.rs - | - | impl AlignOf { - | ^ required by this bound in `AlignOf::::into_t` -... - | pub fn into_t(self) -> T { - | ------ required by a bound in this associated function - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: the left-hand-side of an assignment must have a statically known size - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `MaxAlignsOf` - --> src/util/macro_util.rs - | - | pub union MaxAlignsOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `MaxAlignsOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `AlignOf` - --> src/util/macro_util.rs - | - | pub struct AlignOf { - | ^ required by the implicit `Sized` requirement on this type parameter in `AlignOf` - = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 - | -16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `transmute_ref` - --> src/util/macro_util.rs - | - | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( - | ^^^ required by the implicit `Sized` requirement on this type parameter in `transmute_ref` + = note: required for `Wrap<&[u8], &[u8; 1]>` to implement `TransmuteRefDst<'_>` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr b/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr index 9c60ac19b3..ce76df018c 100644 --- a/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr +++ b/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr @@ -1,30 +1,3 @@ -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 | @@ -42,21 +15,21 @@ error[E0277]: the trait bound `Src: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertSrcIsFromBytes` - --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -69,21 +42,21 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -96,9 +69,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-stable/try_transmute_mut-src-not-frombytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 371917bbbb..8681adc529 100644 --- a/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr +++ b/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr @@ -1,30 +1,3 @@ -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` - | required by a bound introduced by this call - | - = 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 `Src: IntoBytes` is not satisfied --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 | @@ -42,21 +15,21 @@ error[E0277]: the trait bound `Src: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertSrcIsIntoBytes` - --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function + | where + | Src: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(FromBytes)]` to `Dst` = help: the following other types implement trait `FromBytes`: @@ -69,21 +42,21 @@ error[E0277]: the trait bound `Dst: FromBytes` is not satisfied AtomicU16 AtomicU32 and $N others -note: required by a bound in `AssertDstIsFromBytes` - --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` = help: the following other types implement trait `IntoBytes`: @@ -96,9 +69,12 @@ error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied AtomicIsize AtomicU16 and $N others -note: required by a bound in `AssertDstIsIntoBytes` - --> tests/ui-stable/try_transmute_mut-src-not-intobytes.rs:23:40 +note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` + --> src/util/macro_util.rs | -23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsIntoBytes` + | pub fn transmute_mut(self) -> &'a mut Dst + | ------------- required by a bound in this associated function +... + | Dst: FromBytes + IntoBytes, + | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/src/enum.rs b/zerocopy-derive/src/enum.rs index 264cd0a042..cc3a30c17a 100644 --- a/zerocopy-derive/src/enum.rs +++ b/zerocopy-derive/src/enum.rs @@ -263,8 +263,8 @@ pub(crate) fn derive_is_bit_valid( // original type. let variant = unsafe { variants.cast_unsized_unchecked( - |p: core_reexport::ptr::NonNull<___ZerocopyVariants #ty_generics>| { - p.cast::<#variant_struct_ident #ty_generics>() + |p: #zerocopy_crate::pointer::PtrInner<'_, ___ZerocopyVariants #ty_generics>| { + p.as_non_null().cast::<#variant_struct_ident #ty_generics>() } ) }; @@ -324,15 +324,15 @@ pub(crate) fn derive_is_bit_valid( // - There are no `UnsafeCell`s in the tag because it is a // primitive integer. let tag_ptr = unsafe { - candidate.reborrow().cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { - p.cast::<___ZerocopyTagPrimitive>() + candidate.reborrow().cast_unsized_unchecked(|p: #zerocopy_crate::pointer::PtrInner<'_, Self>| { + p.as_non_null().cast::<___ZerocopyTagPrimitive>() }) }; // SAFETY: `tag_ptr` is casted from `candidate`, whose referent // is `Initialized`. Since we have not written uninitialized // bytes into the referent, `tag_ptr` is also `Initialized`. let tag_ptr = unsafe { tag_ptr.assume_initialized() }; - tag_ptr.recall_validity().read_unaligned::<#zerocopy_crate::BecauseImmutable>() + tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<#zerocopy_crate::BecauseImmutable>() }; // SAFETY: @@ -346,8 +346,8 @@ pub(crate) fn derive_is_bit_valid( // original enum, and so preserves the locations of any // `UnsafeCell`s. let raw_enum = unsafe { - candidate.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { - p.cast::<___ZerocopyRawEnum #ty_generics>() + candidate.cast_unsized_unchecked(|p: #zerocopy_crate::pointer::PtrInner<'_, Self>| { + p.as_non_null().cast::<___ZerocopyRawEnum #ty_generics>() }) }; // SAFETY: `cast_unsized_unchecked` removes the initialization @@ -364,8 +364,8 @@ pub(crate) fn derive_is_bit_valid( // subfield pointer just points to a smaller portion of the // overall struct. let variants = unsafe { - raw_enum.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyRawEnum #ty_generics>| { - let p = p.as_ptr(); + raw_enum.cast_unsized_unchecked( |p: #zerocopy_crate::pointer::PtrInner<'_, ___ZerocopyRawEnum #ty_generics>| { + let p = p.as_non_null().as_ptr(); let ptr = core_reexport::ptr::addr_of_mut!((*p).variants); // SAFETY: `ptr` is a projection into `p`, which is // `NonNull`, and guaranteed not to wrap around the address diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 3ee1ac203b..c32af9135f 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -768,8 +768,8 @@ fn derive_try_from_bytes_struct( // the same byte ranges in the returned pointer's referent // as they do in `*slf` let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: #zerocopy_crate::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).#field_names); // SAFETY: `cast_unsized_unchecked` promises that // `slf` will either reference a zero-sized byte @@ -839,8 +839,8 @@ fn derive_try_from_bytes_union( // `self_type_trait_bounds`, neither `*slf` nor the // returned pointer's referent contain any `UnsafeCell`s let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: #zerocopy_crate::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).#field_names); // SAFETY: `cast_unsized_unchecked` promises that // `slf` will either reference a zero-sized byte diff --git a/zerocopy-derive/src/output_tests.rs b/zerocopy-derive/src/output_tests.rs index 9eb7cdd82c..acb9f90f86 100644 --- a/zerocopy-derive/src/output_tests.rs +++ b/zerocopy-derive/src/output_tests.rs @@ -596,8 +596,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -608,8 +608,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -618,8 +618,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -628,8 +628,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -638,8 +638,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -648,8 +648,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).5); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -658,8 +658,8 @@ fn test_try_from_bytes_enum() { <[(X, Y); N] as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).6); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -706,8 +706,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -718,8 +718,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -728,8 +728,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -738,8 +738,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -750,8 +750,8 @@ fn test_try_from_bytes_enum() { ) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -779,18 +779,18 @@ fn test_try_from_bytes_enum() { } let tag = { let tag_ptr = unsafe { - candidate.reborrow().cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyTagPrimitive>() }) + candidate.reborrow().cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyTagPrimitive>() }) }; let tag_ptr = unsafe { tag_ptr.assume_initialized() }; - tag_ptr.recall_validity().read_unaligned::<::zerocopy::BecauseImmutable>() + tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<::zerocopy::BecauseImmutable>() }; let raw_enum = unsafe { - candidate.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }) + candidate.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; let variants = unsafe { - raw_enum.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyRawEnum<'a, N, X, Y>>| { - let p = p.as_ptr(); + raw_enum.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| { + let p = p.as_non_null().as_ptr(); let ptr = core_reexport::ptr::addr_of_mut!((*p).variants); unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) } }) @@ -800,8 +800,8 @@ fn test_try_from_bytes_enum() { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; @@ -810,8 +810,8 @@ fn test_try_from_bytes_enum() { } ___ZEROCOPY_TAG_TupleLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; @@ -920,8 +920,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -932,8 +932,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -942,8 +942,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -952,8 +952,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -962,8 +962,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -972,8 +972,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).5); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -982,8 +982,8 @@ fn test_try_from_bytes_enum() { <[(X, Y); N] as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).6); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1030,8 +1030,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1042,8 +1042,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1052,8 +1052,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1062,8 +1062,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1074,8 +1074,8 @@ fn test_try_from_bytes_enum() { ) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1103,18 +1103,18 @@ fn test_try_from_bytes_enum() { } let tag = { let tag_ptr = unsafe { - candidate.reborrow().cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyTagPrimitive> ()}) + candidate.reborrow().cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyTagPrimitive> ()}) }; let tag_ptr = unsafe { tag_ptr.assume_initialized() }; - tag_ptr.recall_validity().read_unaligned::<::zerocopy::BecauseImmutable>() + tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<::zerocopy::BecauseImmutable>() }; let raw_enum = unsafe { - candidate.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyRawEnum<'a, N, X, Y>> ()}) + candidate.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyRawEnum<'a, N, X, Y>> ()}) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; let variants = unsafe { - raw_enum.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyRawEnum<'a, N, X, Y>>| { - let p = p.as_ptr(); + raw_enum.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| { + let p = p.as_non_null().as_ptr(); let ptr = core_reexport::ptr::addr_of_mut!((*p).variants); unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) } }) @@ -1124,8 +1124,8 @@ fn test_try_from_bytes_enum() { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; @@ -1134,8 +1134,8 @@ fn test_try_from_bytes_enum() { } ___ZEROCOPY_TAG_TupleLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; @@ -1244,8 +1244,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1256,8 +1256,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1266,8 +1266,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1276,8 +1276,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1286,8 +1286,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1296,8 +1296,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).5); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1306,8 +1306,8 @@ fn test_try_from_bytes_enum() { <[(X, Y); N] as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).6); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1354,8 +1354,8 @@ fn test_try_from_bytes_enum() { true && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).0); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1366,8 +1366,8 @@ fn test_try_from_bytes_enum() { > as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).1); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1376,8 +1376,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).2); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1386,8 +1386,8 @@ fn test_try_from_bytes_enum() { ::is_bit_valid(field_candidate) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).3); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1398,8 +1398,8 @@ fn test_try_from_bytes_enum() { ) } && { let field_candidate = unsafe { - let project = |slf: core_reexport::ptr::NonNull| { - let slf = slf.as_ptr(); + let project = |slf: ::zerocopy::pointer::PtrInner<'_, Self>| { + let slf = slf.as_non_null().as_ptr(); let field = core_reexport::ptr::addr_of_mut!((*slf).4); unsafe { core_reexport::ptr::NonNull::new_unchecked(field) } }; @@ -1427,18 +1427,18 @@ fn test_try_from_bytes_enum() { } let tag = { let tag_ptr = unsafe { - candidate.reborrow().cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyTagPrimitive> ()}) + candidate.reborrow().cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyTagPrimitive> ()}) }; let tag_ptr = unsafe { tag_ptr.assume_initialized() }; - tag_ptr.recall_validity().read_unaligned::<::zerocopy::BecauseImmutable>() + tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<::zerocopy::BecauseImmutable>() }; let raw_enum = unsafe { - candidate.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull| { p.cast::<___ZerocopyRawEnum<'a, N, X, Y>> ()}) + candidate.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, Self>| { p.as_non_null().cast::<___ZerocopyRawEnum<'a, N, X, Y>> ()}) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; let variants = unsafe { - raw_enum.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyRawEnum<'a, N, X, Y>>| { - let p = p.as_ptr(); + raw_enum.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| { + let p = p.as_non_null().as_ptr(); let ptr = core_reexport::ptr::addr_of_mut!((*p).variants); unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) } }) @@ -1448,8 +1448,8 @@ fn test_try_from_bytes_enum() { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_StructLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; @@ -1458,8 +1458,8 @@ fn test_try_from_bytes_enum() { } ___ZEROCOPY_TAG_TupleLike => { let variant = unsafe { - variants.cast_unsized_unchecked(|p: core_reexport::ptr::NonNull<___ZerocopyVariants<'a, N, X, Y>>| { - p.cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() + variants.cast_unsized_unchecked(|p: ::zerocopy::pointer::PtrInner<'_, ___ZerocopyVariants<'a, N, X, Y>>| { + p.as_non_null().cast::<___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>>() }) }; let variant = unsafe { variant.assume_initialized() }; diff --git a/zerocopy-derive/tests/include.rs b/zerocopy-derive/tests/include.rs index a65d61fc48..d5c3de52ff 100644 --- a/zerocopy-derive/tests/include.rs +++ b/zerocopy-derive/tests/include.rs @@ -123,7 +123,7 @@ pub mod util { // SAFETY: `T` and `MaybeUninit` have the same layout, so this is a // size-preserving cast. It is also a provenance-preserving cast. - let ptr = unsafe { ptr.cast_unsized_unchecked(|p| p.cast()) }; + let ptr = unsafe { ptr.cast_unsized_unchecked(|p| p.as_non_null().cast()) }; assert!(::is_bit_valid(ptr)); } } diff --git a/zerocopy-derive/tests/struct_try_from_bytes.rs b/zerocopy-derive/tests/struct_try_from_bytes.rs index 26d757dbcd..57d1727d4f 100644 --- a/zerocopy-derive/tests/struct_try_from_bytes.rs +++ b/zerocopy-derive/tests/struct_try_from_bytes.rs @@ -78,7 +78,7 @@ fn two_bad() { // the same bytes as `c`. // - The cast preserves provenance. // - Neither the input nor output types contain any `UnsafeCell`s. - let candidate = unsafe { candidate.cast_unsized_unchecked(|p| p.cast::()) }; + let candidate = unsafe { candidate.cast_unsized_unchecked(|p| p.as_non_null().cast::()) }; // SAFETY: `candidate`'s referent is as-initialized as `Two`. let candidate = unsafe { candidate.assume_initialized() }; @@ -110,7 +110,7 @@ fn un_sized() { // - Neither the input nor output types contain any `UnsafeCell`s. let candidate = unsafe { candidate.cast_unsized_unchecked(|p| { - imp::core::ptr::NonNull::new_unchecked(p.as_ptr() as *mut Unsized) + imp::core::ptr::NonNull::new_unchecked(p.as_non_null().as_ptr() as *mut Unsized) }) }; @@ -168,8 +168,9 @@ fn test_maybe_from_bytes() { // the same bytes as `c`. // - The cast preserves provenance. // - Neither the input nor output types contain any `UnsafeCell`s. - let candidate = - unsafe { candidate.cast_unsized_unchecked(|p| p.cast::>()) }; + let candidate = unsafe { + candidate.cast_unsized_unchecked(|p| p.as_non_null().cast::>()) + }; // SAFETY: `[u8]` consists entirely of initialized bytes. let candidate = unsafe { candidate.assume_initialized() }; diff --git a/zerocopy-derive/tests/union_try_from_bytes.rs b/zerocopy-derive/tests/union_try_from_bytes.rs index 80bae235ba..044e1e3fd5 100644 --- a/zerocopy-derive/tests/union_try_from_bytes.rs +++ b/zerocopy-derive/tests/union_try_from_bytes.rs @@ -73,7 +73,7 @@ fn two_bad() { // the same bytes as `c`. // - The cast preserves provenance. // - Neither the input nor output types contain any `UnsafeCell`s. - let candidate = unsafe { candidate.cast_unsized_unchecked(|p| p.cast::()) }; + let candidate = unsafe { candidate.cast_unsized_unchecked(|p| p.as_non_null().cast::()) }; // SAFETY: `candidate`'s referent is as-initialized as `Two`. let candidate = unsafe { candidate.assume_initialized() }; @@ -102,7 +102,8 @@ fn bool_and_zst() { // the same bytes as `c`. // - The cast preserves provenance. // - Neither the input nor output types contain any `UnsafeCell`s. - let candidate = unsafe { candidate.cast_unsized_unchecked(|p| p.cast::()) }; + let candidate = + unsafe { candidate.cast_unsized_unchecked(|p| p.as_non_null().cast::()) }; // SAFETY: `candidate`'s referent is fully initialized. let candidate = unsafe { candidate.assume_initialized() }; @@ -131,8 +132,9 @@ fn test_maybe_from_bytes() { // the same bytes as `c`. // - The cast preserves provenance. // - Neither the input nor output types contain any `UnsafeCell`s. - let candidate = - unsafe { candidate.cast_unsized_unchecked(|p| p.cast::>()) }; + let candidate = unsafe { + candidate.cast_unsized_unchecked(|p| p.as_non_null().cast::>()) + }; // SAFETY: `[u8]` consists entirely of initialized bytes. let candidate = unsafe { candidate.assume_initialized() };