From a8572dafd9a0a5f5f583ab4c16e62dab9b664b15 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Fri, 8 Dec 2023 09:37:33 -0800 Subject: [PATCH] Traits other than NoCell permit UnsafeCells (#682) Previously, `FromZeros`, `FromBytes`, and `AsBytes` could not be implemented for types containing `UnsafeCell`s. This is a soundness precondition for some types of reference transmutations (notably transmuting either direction between `&[u8]` and `&T`). However, some of our machinery operates only on values (e.g. `transmute!`), and that machinery should in principle be able to support types which contain `UnsafeCell`s. In this commit, we remove the "no `UnsafeCell`" restriction from `FromZeros`, `FromBytes`, and `AsBytes`. We use the recently-added `NoCell` trait as a bound on individual functions and methods where `UnsafeCell`s would be unsound. This permits some APIs to support `UnsafeCell`s which could not previously support them. Closes #251 --- src/byteorder.rs | 8 +- src/lib.rs | 413 ++++++++++-------- src/macro_util.rs | 17 +- .../include_value_not_from_bytes.stderr | 14 +- .../transmute-mut-dst-not-a-reference.stderr | 20 + tests/ui-msrv/transmute-mut-dst-not-nocell.rs | 1 + .../transmute-mut-dst-not-nocell.stderr | 12 + .../ui-msrv/transmute-mut-dst-unsized.stderr | 18 +- .../transmute-mut-src-dst-generic.stderr | 8 +- .../transmute-mut-src-dst-unsized.stderr | 54 +-- .../ui-msrv/transmute-mut-src-generic.stderr | 2 +- tests/ui-msrv/transmute-mut-src-not-nocell.rs | 1 + .../transmute-mut-src-not-nocell.stderr | 25 ++ .../ui-msrv/transmute-mut-src-unsized.stderr | 36 +- .../ui-msrv/transmute-ref-dst-mutable.stderr | 20 + .../transmute-ref-dst-not-a-reference.stderr | 20 + .../transmute-ref-dst-not-frombytes.stderr | 16 +- tests/ui-msrv/transmute-ref-dst-not-nocell.rs | 1 + .../transmute-ref-dst-not-nocell.stderr | 12 + .../ui-msrv/transmute-ref-dst-unsized.stderr | 4 +- ...ransmute-ref-src-dst-not-references.stderr | 20 + .../transmute-ref-src-dst-unsized.stderr | 12 +- .../transmute-ref-src-not-asbytes.stderr | 32 +- tests/ui-msrv/transmute-ref-src-not-nocell.rs | 1 + .../transmute-ref-src-not-nocell.stderr | 25 ++ .../ui-msrv/transmute-ref-src-unsized.stderr | 8 +- .../include_value_not_from_bytes.rs | 7 +- .../include_value_not_from_bytes.stderr | 20 +- tests/ui-nightly/transmute-mut-dst-generic.rs | 4 +- .../transmute-mut-dst-not-a-reference.stderr | 20 + .../transmute-mut-dst-not-asbytes.rs | 4 +- .../transmute-mut-dst-not-frombytes.rs | 4 +- .../transmute-mut-dst-not-nocell.rs | 24 + .../transmute-mut-dst-not-nocell.stderr | 25 ++ .../transmute-mut-dst-unsized.stderr | 21 +- .../transmute-mut-src-dst-generic.rs | 6 +- .../transmute-mut-src-dst-generic.stderr | 8 +- .../transmute-mut-src-dst-unsized.stderr | 60 +-- tests/ui-nightly/transmute-mut-src-generic.rs | 4 +- .../transmute-mut-src-generic.stderr | 2 +- .../transmute-mut-src-not-asbytes.rs | 4 +- .../transmute-mut-src-not-frombytes.rs | 4 +- .../transmute-mut-src-not-nocell.rs | 24 + .../transmute-mut-src-not-nocell.stderr | 48 ++ .../transmute-mut-src-unsized.stderr | 39 +- tests/ui-nightly/transmute-ref-dst-generic.rs | 4 +- .../transmute-ref-dst-mutable.stderr | 20 + .../transmute-ref-dst-not-a-reference.stderr | 20 + .../transmute-ref-dst-not-frombytes.rs | 6 +- .../transmute-ref-dst-not-frombytes.stderr | 22 +- .../transmute-ref-dst-not-nocell.rs | 22 + .../transmute-ref-dst-not-nocell.stderr | 25 ++ .../transmute-ref-dst-unsized.stderr | 4 +- .../transmute-ref-src-dst-generic.rs | 4 +- ...ransmute-ref-src-dst-not-references.stderr | 20 + .../transmute-ref-src-dst-unsized.stderr | 12 +- tests/ui-nightly/transmute-ref-src-generic.rs | 4 +- .../transmute-ref-src-not-asbytes.rs | 6 +- .../transmute-ref-src-not-asbytes.stderr | 34 +- .../transmute-ref-src-not-nocell.rs | 22 + .../transmute-ref-src-not-nocell.stderr | 48 ++ .../transmute-ref-src-unsized.stderr | 8 +- .../include_value_not_from_bytes.stderr | 20 +- .../transmute-mut-dst-not-a-reference.stderr | 20 + .../ui-stable/transmute-mut-dst-not-nocell.rs | 1 + .../transmute-mut-dst-not-nocell.stderr | 25 ++ .../transmute-mut-dst-unsized.stderr | 21 +- .../transmute-mut-src-dst-generic.stderr | 8 +- .../transmute-mut-src-dst-unsized.stderr | 60 +-- .../transmute-mut-src-generic.stderr | 2 +- .../ui-stable/transmute-mut-src-not-nocell.rs | 1 + .../transmute-mut-src-not-nocell.stderr | 48 ++ .../transmute-mut-src-unsized.stderr | 39 +- .../transmute-ref-dst-mutable.stderr | 20 + .../transmute-ref-dst-not-a-reference.stderr | 20 + .../transmute-ref-dst-not-frombytes.stderr | 22 +- .../ui-stable/transmute-ref-dst-not-nocell.rs | 1 + .../transmute-ref-dst-not-nocell.stderr | 25 ++ .../transmute-ref-dst-unsized.stderr | 4 +- ...ransmute-ref-src-dst-not-references.stderr | 20 + .../transmute-ref-src-dst-unsized.stderr | 12 +- .../transmute-ref-src-not-asbytes.stderr | 34 +- .../ui-stable/transmute-ref-src-not-nocell.rs | 1 + .../transmute-ref-src-not-nocell.stderr | 48 ++ .../transmute-ref-src-unsized.stderr | 8 +- 85 files changed, 1175 insertions(+), 694 deletions(-) create mode 120000 tests/ui-msrv/transmute-mut-dst-not-nocell.rs create mode 100644 tests/ui-msrv/transmute-mut-dst-not-nocell.stderr create mode 120000 tests/ui-msrv/transmute-mut-src-not-nocell.rs create mode 100644 tests/ui-msrv/transmute-mut-src-not-nocell.stderr create mode 120000 tests/ui-msrv/transmute-ref-dst-not-nocell.rs create mode 100644 tests/ui-msrv/transmute-ref-dst-not-nocell.stderr create mode 120000 tests/ui-msrv/transmute-ref-src-not-nocell.rs create mode 100644 tests/ui-msrv/transmute-ref-src-not-nocell.stderr create mode 100644 tests/ui-nightly/transmute-mut-dst-not-nocell.rs create mode 100644 tests/ui-nightly/transmute-mut-dst-not-nocell.stderr create mode 100644 tests/ui-nightly/transmute-mut-src-not-nocell.rs create mode 100644 tests/ui-nightly/transmute-mut-src-not-nocell.stderr create mode 100644 tests/ui-nightly/transmute-ref-dst-not-nocell.rs create mode 100644 tests/ui-nightly/transmute-ref-dst-not-nocell.stderr create mode 100644 tests/ui-nightly/transmute-ref-src-not-nocell.rs create mode 100644 tests/ui-nightly/transmute-ref-src-not-nocell.stderr create mode 120000 tests/ui-stable/transmute-mut-dst-not-nocell.rs create mode 100644 tests/ui-stable/transmute-mut-dst-not-nocell.stderr create mode 120000 tests/ui-stable/transmute-mut-src-not-nocell.rs create mode 100644 tests/ui-stable/transmute-mut-src-not-nocell.stderr create mode 120000 tests/ui-stable/transmute-ref-dst-not-nocell.rs create mode 100644 tests/ui-stable/transmute-ref-dst-not-nocell.stderr create mode 120000 tests/ui-stable/transmute-ref-src-not-nocell.rs create mode 100644 tests/ui-stable/transmute-ref-src-not-nocell.stderr diff --git a/src/byteorder.rs b/src/byteorder.rs index d33d11c282..73f3fcd6fc 100644 --- a/src/byteorder.rs +++ b/src/byteorder.rs @@ -35,10 +35,10 @@ //! //! ```rust,edition2021 //! # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them -//! use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeros, Ref, Unaligned}; +//! use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeros, NoCell, Ref, Unaligned}; //! use zerocopy::byteorder::network_endian::U16; //! -//! #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] +//! #[derive(FromZeros, FromBytes, AsBytes, NoCell, Unaligned)] //! #[repr(C)] //! struct UdpHeader { //! src_port: U16, @@ -655,7 +655,7 @@ mod tests { use compatibility::*; // A native integer type (u16, i32, etc). - trait Native: Arbitrary + FromBytes + AsBytes + Copy + PartialEq + Debug { + trait Native: Arbitrary + FromBytes + AsBytes + NoCell + Copy + PartialEq + Debug { const ZERO: Self; const MAX_VALUE: Self; @@ -692,7 +692,7 @@ mod tests { } trait ByteArray: - FromBytes + AsBytes + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq + FromBytes + AsBytes + NoCell + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq { /// Invert the order of the bytes in the array. fn invert(self) -> Self; diff --git a/src/lib.rs b/src/lib.rs index f5e01ef481..427f943ab4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,7 +279,7 @@ pub use zerocopy_derive::KnownLayout; pub use zerocopy_derive::NoCell; use core::{ - cell::{self, RefMut}, + cell::{self, RefMut, UnsafeCell}, cmp::Ordering, fmt::{self, Debug, Display, Formatter}, hash::Hasher, @@ -988,15 +988,21 @@ impl_known_layout!(const N: usize, T => [T; N]); safety_comment! { /// SAFETY: - /// `str` and `ManuallyDrop<[T]>` [1] have the same representations as - /// `[u8]` and `[T]` repsectively. `str` has different bit validity than - /// `[u8]`, but that doesn't affect the soundness of this impl. + /// `str`, `ManuallyDrop<[T]>` [1], and `UnsafeCell` [2] have the same + /// representations as `[u8]`, `[T]`, and `T` repsectively. `str` has + /// different bit validity than `[u8]`, but that doesn't affect the + /// soundness of this impl. /// /// [1] Per https://doc.rust-lang.org/nightly/core/mem/struct.ManuallyDrop.html: /// /// `ManuallyDrop` is guaranteed to have the same layout and bit /// validity as `T` /// + /// [2] Per https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html#memory-layout: + /// + /// `UnsafeCell` has the same in-memory representation as its inner + /// type `T`. + /// /// TODO(#429): /// - Add quotes from docs. /// - Once [1] (added in @@ -1004,6 +1010,7 @@ safety_comment! { /// quote the stable docs instead of the nightly docs. unsafe_impl_known_layout!(#[repr([u8])] str); unsafe_impl_known_layout!(T: ?Sized + KnownLayout => #[repr(T)] ManuallyDrop); + unsafe_impl_known_layout!(T: ?Sized + KnownLayout => #[repr(T)] UnsafeCell); } /// Analyzes whether a type is [`FromZeros`]. @@ -1057,19 +1064,12 @@ safety_comment! { /// - If the type is an enum, it must be C-like (meaning that all variants have /// no fields) and it must have a variant with a discriminant of `0`. See [the /// reference] for a description of how discriminant values are chosen. -/// - The type must not contain any [`UnsafeCell`]s (this is required in order -/// for it to be sound to construct a `&[u8]` and a `&T` to the same region of -/// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeros (`FromZeros` -/// is not currently implemented for, e.g., `Option<&UnsafeCell<_>>`, but it -/// could be one day). /// /// This analysis is subject to change. Unsafe code may *only* rely on the /// documented [safety conditions] of `FromZeros`, and must *not* rely on the /// implementation details of this derive. /// /// [the reference]: https://doc.rust-lang.org/reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations -/// [`UnsafeCell`]: core::cell::UnsafeCell /// /// ## Why isn't an explicit representation required for structs? /// @@ -1193,6 +1193,12 @@ pub unsafe trait NoCell { /// including changes that only affect soundness, which may cause code which /// uses those items to silently become unsound. /// +/// ## `UnsafeCell` +/// +/// `TryFromBytes` may not be implemented for any type which contains an +/// [`UnsafeCell`]. This is a temporary limitation and will be lifted once +/// [`try_from_ref`] has a [`NoCell`] bound. +/// /// [undefined behavior]: https://raphlinus.github.io/programming/rust/2018/08/17/undefined-behavior.html /// [github-repo]: https://github.com/google/zerocopy /// [`try_from_ref`]: TryFromBytes::try_from_ref @@ -1280,9 +1286,8 @@ pub unsafe trait TryFromBytes { /// Note that Rust's bit validity rules are still being decided. As such, /// there exist types whose bit validity is ambiguous. See the /// `TryFromBytes` docs for a discussion of how these cases are handled. - // TODO(#251): In a future in which we distinguish between `FromBytes` and - // `RefFromBytes`, this requires `where Self: RefFromBytes` to disallow - // interior mutability. + // TODO(#251): Require `Self: NoCell` and allow `TryFromBytes` types to + // contain `UnsafeCell`s. #[inline] #[doc(hidden)] // TODO(#5): Finalize name before remove this attribute. fn try_from_ref(bytes: &[u8]) -> Option<&Self> @@ -1296,10 +1301,9 @@ pub unsafe trait TryFromBytes { // references exist to this memory region. // - Since `[u8]` contains no `UnsafeCell`s, we know there are no // `&UnsafeCell` references to this memory region. - // - Since we don't permit implementing `TryFromBytes` for types which - // contain `UnsafeCell`s, there are no `UnsafeCell`s in `Self`, and so - // the requirement that all references contain `UnsafeCell`s at the - // same offsets is trivially satisfied. + // - Since `TryFromBytes` types may not contain any `UnsafeCell`s, the + // requirement that all references contain `UnsafeCell`s at the same + // offsets is trivially satisfied. // - All bytes of `bytes` are initialized. // // This call may panic. If that happens, it doesn't cause any soundness @@ -1312,8 +1316,7 @@ pub unsafe trait TryFromBytes { // SAFETY: // - `is_bit_valid` guarantees that `*maybe_self` contains a valid // `Self`. - // - `TryFromBytes` may only be implemented for types which do not - // contain any `UnsafeCell`s. + // - `TryFromBytes` types may not contain any `UnsafeCell`s. Some(unsafe { maybe_self.into_ref_unchecked() }) } } @@ -1369,16 +1372,9 @@ pub unsafe trait TryFromBytes { /// `FromZeros` manually, and you don't plan on writing unsafe code that /// operates on `FromZeros` types, then you don't need to read this section.* /// -/// If `T: FromZeros`, then unsafe code may assume that: -/// - It is sound to treat any initialized sequence of zero bytes of length -/// `size_of::()` as a `T`. -/// - Given `b: &[u8]` where `b.len() == size_of::()`, `b` is aligned to -/// `align_of::()`, and `b` contains only zero bytes, it is sound to -/// construct a `t: &T` at the same address as `b`, and it is sound for both -/// `b` and `t` to be live at the same time. -/// -/// If a type is marked as `FromZeros` which violates this contract, it may -/// cause undefined behavior. +/// If `T: FromZeros`, then unsafe code may assume that it is sound to produce a +/// `T` whose bytes are all initialized to zero. If a type is marked as +/// `FromZeros` which violates this contract, it may cause undefined behavior. /// /// `#[derive(FromZeros)]` only permits [types which satisfy these /// requirements][derive-analysis]. @@ -1708,14 +1704,6 @@ pub use FromZeros as FromZeroes; /// bit pattern is a valid one). Be very careful when using the `C`, /// `usize`, or `isize` representations, as their size is /// platform-dependent. -/// - The type must not contain any [`UnsafeCell`]s (this is required in order -/// for it to be sound to construct a `&[u8]` and a `&T` to the same region of -/// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeros (`FromBytes` -/// is not currently implemented for, e.g., `Option<*const UnsafeCell<_>>`, -/// but it could be one day). -/// -/// [`UnsafeCell`]: core::cell::UnsafeCell /// /// This analysis is subject to change. Unsafe code may *only* rely on the /// documented [safety conditions] of `FromBytes`, and must *not* rely on the @@ -1819,15 +1807,10 @@ pub use zerocopy_derive::FromBytes; /// `FromBytes` manually, and you don't plan on writing unsafe code that /// operates on `FromBytes` types, then you don't need to read this section.* /// -/// If `T: FromBytes`, then unsafe code may assume that: -/// - It is sound to treat any initialized sequence of bytes of length -/// `size_of::()` as a `T`. -/// - Given `b: &[u8]` where `b.len() == size_of::()`, `b` is aligned to -/// `align_of::()` it is sound to construct a `t: &T` at the same address -/// as `b`, and it is sound for both `b` and `t` to be live at the same time. -/// -/// If a type is marked as `FromBytes` which violates this contract, it may -/// cause undefined behavior. +/// If `T: FromBytes`, then unsafe code may assume that it is sound to produce a +/// `T` whose bytes are initialized to any sequence of valid `u8`s (in other +/// words, any byte value which is not uninitialized). If a type is marked as +/// `FromBytes` which violates this contract, it may cause undefined behavior. /// /// `#[derive(FromBytes)]` only permits [types which satisfy these /// requirements][derive-analysis]. @@ -1861,7 +1844,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1883,7 +1866,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn ref_from(bytes: &[u8]) -> Option<&Self> where - Self: Sized, + Self: NoCell + Sized, { Ref::<&[u8], Self>::new(bytes).map(Ref::into_ref) } @@ -1903,7 +1886,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -1925,7 +1908,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn ref_from_prefix(bytes: &[u8]) -> Option<&Self> where - Self: Sized, + Self: Sized + NoCell, { Ref::<&[u8], Self>::new_from_prefix(bytes).map(|(r, _)| r.into_ref()) } @@ -1945,7 +1928,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -1961,7 +1944,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn ref_from_suffix(bytes: &[u8]) -> Option<&Self> where - Self: Sized, + Self: Sized + NoCell, { Ref::<&[u8], Self>::new_from_suffix(bytes).map(|(_, r)| r.into_ref()) } @@ -1977,7 +1960,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2003,7 +1986,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<&mut [u8], Self>::new(bytes).map(Ref::into_mut) } @@ -2024,7 +2007,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2050,7 +2033,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from_prefix(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<&mut [u8], Self>::new_from_prefix(bytes).map(|(r, _)| r.into_mut()) } @@ -2070,7 +2053,7 @@ pub unsafe trait FromBytes: FromZeros { /// use zerocopy::FromBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct PacketTrailer { /// frame_check_sequence: [u8; 4], @@ -2090,7 +2073,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_from_suffix(bytes: &mut [u8]) -> Option<&mut Self> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<&mut [u8], Self>::new_from_suffix(bytes).map(|(_, r)| r.into_mut()) } @@ -2115,7 +2098,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2137,7 +2120,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn slice_from(bytes: &[u8]) -> Option<&[Self]> where - Self: Sized, + Self: Sized + NoCell, { Ref::<_, [Self]>::new_slice(bytes).map(|r| r.into_slice()) } @@ -2164,7 +2147,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2188,7 +2171,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn slice_from_prefix(bytes: &[u8], count: usize) -> Option<(&[Self], &[u8])> where - Self: Sized, + Self: Sized + NoCell, { Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, b)| (r.into_slice(), b)) } @@ -2215,7 +2198,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2239,7 +2222,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn slice_from_suffix(bytes: &[u8], count: usize) -> Option<(&[u8], &[Self])> where - Self: Sized, + Self: Sized + NoCell, { Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(b, r)| (b, r.into_slice())) } @@ -2264,7 +2247,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2290,7 +2273,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from(bytes: &mut [u8]) -> Option<&mut [Self]> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<_, [Self]>::new_slice(bytes).map(|r| r.into_mut_slice()) } @@ -2317,7 +2300,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2345,7 +2328,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from_prefix(bytes: &mut [u8], count: usize) -> Option<(&mut [Self], &mut [u8])> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, b)| (r.into_mut_slice(), b)) } @@ -2372,7 +2355,7 @@ pub unsafe trait FromBytes: FromZeros { /// # use zerocopy_derive::*; /// /// # #[derive(Debug, PartialEq, Eq)] - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct Pixel { /// r: u8, @@ -2400,7 +2383,7 @@ pub unsafe trait FromBytes: FromZeros { #[inline] fn mut_slice_from_suffix(bytes: &mut [u8], count: usize) -> Option<(&mut [u8], &mut [Self])> where - Self: Sized + AsBytes, + Self: Sized + AsBytes + NoCell, { Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(b, r)| (b, r.into_mut_slice())) } @@ -2601,14 +2584,6 @@ pub unsafe trait FromBytes: FromZeros { /// - It must be a C-like enum (meaning that all variants have no fields). /// - It must have a defined representation (`repr`s `C`, `u8`, `u16`, `u32`, /// `u64`, `usize`, `i8`, `i16`, `i32`, `i64`, or `isize`). -/// - The type must not contain any [`UnsafeCell`]s (this is required in order -/// for it to be sound to construct a `&[u8]` and a `&T` to the same region of -/// memory). The type may contain references or pointers to `UnsafeCell`s so -/// long as those values can themselves be initialized from zeros (`AsBytes` -/// is not currently implemented for, e.g., `Option<&UnsafeCell<_>>`, but it -/// could be one day). -/// -/// [`UnsafeCell`]: core::cell::UnsafeCell /// /// This analysis is subject to change. Unsafe code may *only* rely on the /// documented [safety conditions] of `FromBytes`, and must *not* rely on the @@ -2671,15 +2646,10 @@ pub use zerocopy_derive::AsBytes; /// `AsBytes` manually, and you don't plan on writing unsafe code that /// operates on `AsBytes` types, then you don't need to read this section.* /// -/// If `T: AsBytes`, then unsafe code may assume that: -/// - It is sound to treat any `t: T` as an immutable `[u8]` of length -/// `size_of_val(t)`. -/// - Given `t: &T`, it is sound to construct a `b: &[u8]` where `b.len() == -/// size_of_val(t)` at the same address as `t`, and it is sound for both `b` -/// and `t` to be live at the same time. -/// -/// If a type is marked as `AsBytes` which violates this contract, it may cause -/// undefined behavior. +/// If `T: AsBytes`, then unsafe code may assume that it is sound to treat any +/// `t: T` as an immutable `[u8]` of length `size_of_val(t)`. If a type is +/// marked as `AsBytes` which violates this contract, it may cause undefined +/// behavior. /// /// `#[derive(AsBytes)]` only permits [types which satisfy these /// requirements][derive-analysis]. @@ -2717,7 +2687,7 @@ pub unsafe trait AsBytes { /// use zerocopy::AsBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes)] + /// #[derive(AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2738,7 +2708,10 @@ pub unsafe trait AsBytes { /// assert_eq!(bytes, [0, 1, 2, 3, 4, 5, 6, 7]); /// ``` #[inline(always)] - fn as_bytes(&self) -> &[u8] { + fn as_bytes(&self) -> &[u8] + where + Self: NoCell, + { // Note that this method does not have a `Self: Sized` bound; // `size_of_val` works for unsized values too. let len = mem::size_of_val(self); @@ -2758,8 +2731,9 @@ pub unsafe trait AsBytes { // - Since `slf` is derived from `self`, and `self` is an immutable // reference, the only other references to this memory region that // could exist are other immutable references, and those don't allow - // mutation. `AsBytes` prohibits types which contain `UnsafeCell`s, - // which are the only types for which this rule wouldn't be sufficient. + // mutation. `Self: NoCell` prohibits types which contain + // `UnsafeCell`s, which are the only types for which this rule + // wouldn't be sufficient. // - The total size of the resulting slice is no larger than // `isize::MAX` because no allocation produced by safe code can be // larger than `isize::MAX`. @@ -2780,7 +2754,7 @@ pub unsafe trait AsBytes { /// # use zerocopy_derive::*; /// /// # #[derive(Eq, PartialEq, Debug)] - /// #[derive(AsBytes, FromZeros, FromBytes)] + /// #[derive(FromZeros, FromBytes, AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2812,7 +2786,7 @@ pub unsafe trait AsBytes { #[inline(always)] fn as_bytes_mut(&mut self) -> &mut [u8] where - Self: FromBytes, + Self: FromBytes + NoCell, { // Note that this method does not have a `Self: Sized` bound; // `size_of_val` works for unsized values too. @@ -2852,7 +2826,7 @@ pub unsafe trait AsBytes { /// use zerocopy::AsBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes)] + /// #[derive(AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2889,7 +2863,10 @@ pub unsafe trait AsBytes { /// assert_eq!(excessive_bytes, [0u8; 128]); /// ``` #[inline] - fn write_to(&self, bytes: &mut [u8]) -> Option<()> { + fn write_to(&self, bytes: &mut [u8]) -> Option<()> + where + Self: NoCell, + { if bytes.len() != mem::size_of_val(self) { return None; } @@ -2909,7 +2886,7 @@ pub unsafe trait AsBytes { /// use zerocopy::AsBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes)] + /// #[derive(AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -2946,7 +2923,10 @@ pub unsafe trait AsBytes { /// assert_eq!(insufficent_bytes, [0, 0]); /// ``` #[inline] - fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()> { + fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()> + where + Self: NoCell, + { let size = mem::size_of_val(self); bytes.get_mut(..size)?.copy_from_slice(self.as_bytes()); Some(()) @@ -2963,7 +2943,7 @@ pub unsafe trait AsBytes { /// use zerocopy::AsBytes; /// # use zerocopy_derive::*; /// - /// #[derive(AsBytes)] + /// #[derive(AsBytes, NoCell)] /// #[repr(C)] /// struct PacketHeader { /// src_port: [u8; 2], @@ -3007,7 +2987,10 @@ pub unsafe trait AsBytes { /// assert_eq!(insufficent_bytes, [0, 0]); /// ``` #[inline] - fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()> { + fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()> + where + Self: NoCell, + { let start = bytes.len().checked_sub(mem::size_of_val(self))?; bytes .get_mut(start..) @@ -3378,11 +3361,8 @@ safety_comment! { safety_comment! { /// SAFETY: /// The following types can be transmuted from `[0u8; size_of::()]`. [1] - /// None of them contain `UnsafeCell`s, and so they all soundly implement - /// `FromZeros`. /// - /// [1] Per - /// https://doc.rust-lang.org/nightly/core/option/index.html#representation: + /// [1] Per https://doc.rust-lang.org/nightly/core/option/index.html#representation: /// /// Rust guarantees to optimize the following types `T` such that /// [`Option`] has the same size and alignment as `T`. In some of these @@ -3412,6 +3392,13 @@ safety_comment! { unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => FromZeros for opt_extern_c_fn!(...)); } +safety_comment! { + /// SAFETY: + /// TODO + unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => NoCell for opt_fn!(...)); + unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => NoCell for opt_extern_c_fn!(...)); +} + safety_comment! { /// SAFETY: /// Per reference [1]: @@ -3459,14 +3446,12 @@ safety_comment! { /// its argument contains a valid `Wrapping`. /// - `FromBytes`: Since `Wrapping` has the same bit validity as `T`, if /// `T: FromBytes`, then all initialized byte sequences are valid - /// instances of `Wrapping`. Similarly, if `T: FromBytes`, then - /// `Wrapping` doesn't contain any `UnsafeCell`s. Thus, `impl FromBytes - /// for Wrapping where T: FromBytes` is a sound impl. + /// instances of `Wrapping`. Thus, `impl FromBytes for Wrapping + /// where T: FromBytes` is a sound impl. /// - `AsBytes`: Since `Wrapping` has the same bit validity as `T`, if /// `T: AsBytes`, then all valid instances of `Wrapping` have all of - /// their bytes initialized. Similarly, if `T: AsBytes`, then - /// `Wrapping` doesn't contain any `UnsafeCell`s. Thus, `impl AsBytes - /// for Wrapping where T: AsBytes` is a valid impl. + /// their bytes initialized. Thus, `impl AsBytes for Wrapping where T: + /// AsBytes` is a valid impl. /// - `Unaligned`: Since `Wrapping` has the same layout as `T`, /// `Wrapping` has alignment 1 exactly when `T` does. /// @@ -3508,25 +3493,15 @@ safety_comment! { /// - `NoCell`: `MaybeUninit` has `UnsafeCell`s exactly when `T` does, so /// `T: NoCell` guarantees that `MaybeUninit` has no `UnsafeCell`s. /// - `TryFromBytes` (with no validator), `FromZeros`, `FromBytes`: - /// `MaybeUninit` has no restrictions on its contents. Unfortunately, - /// in addition to bit validity, `TryFromBytes`, `FromZeros` and - /// `FromBytes` also require that implementers contain no `UnsafeCell`s. - /// Thus, we require `T: Trait` in order to ensure that `T` - and thus - /// `MaybeUninit` - contains to `UnsafeCell`s. Thus, requiring that `T` - /// implement each of these traits is sufficient. + /// `MaybeUninit` has no restrictions on its contents. /// - `Unaligned`: "MaybeUninit is guaranteed to have the same size, /// alignment, and ABI as T" [1] /// /// [1] https://doc.rust-lang.org/stable/core/mem/union.MaybeUninit.html#layout-1 - /// - /// TODO(https://github.com/google/zerocopy/issues/251): If we split - /// `FromBytes` and `RefFromBytes`, or if we introduce a separate - /// `NoCell`/`Freeze` trait, we can relax the trait bounds for `FromZeros` - /// and `FromBytes`. unsafe_impl!(T: NoCell => NoCell for MaybeUninit); - unsafe_impl!(T: TryFromBytes => TryFromBytes for MaybeUninit); - unsafe_impl!(T: FromZeros => FromZeros for MaybeUninit); - unsafe_impl!(T: FromBytes => FromBytes for MaybeUninit); + unsafe_impl!(T => TryFromBytes for MaybeUninit); + unsafe_impl!(T => FromZeros for MaybeUninit); + unsafe_impl!(T => FromBytes for MaybeUninit); unsafe_impl!(T: Unaligned => Unaligned for MaybeUninit); assert_unaligned!(MaybeUninit<()>, MaybeUninit); } @@ -3568,6 +3543,26 @@ safety_comment! { unsafe_impl!(T: ?Sized + Unaligned => Unaligned for ManuallyDrop); assert_unaligned!(ManuallyDrop<()>, ManuallyDrop); } +safety_comment! { + /// SAFETY: + /// - `FromZeros`, `FromBytes`, `AsBytes`: `UnsafeCell` has the same bit + /// validity as `T` [1], and so implements these traits exactly when `T` + /// does. + /// - `Unaligned`: `UnsafeCell` has the same representation as `T`, and + /// so has alignment 1 exactly when `T` does. [2] + /// + /// [1] TODO(#429): Justify this claim. + /// + /// [2] Per https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html#memory-layout: + /// + /// `UnsafeCell`` has the same in-memory representation as its inner + /// type `T`. + unsafe_impl!(T: ?Sized + FromZeros => FromZeros for UnsafeCell); + unsafe_impl!(T: ?Sized + FromBytes => FromBytes for UnsafeCell); + unsafe_impl!(T: ?Sized + AsBytes => AsBytes for UnsafeCell); + unsafe_impl!(T: ?Sized + Unaligned => Unaligned for UnsafeCell); + assert_unaligned!(UnsafeCell<()>, UnsafeCell); +} safety_comment! { /// SAFETY: /// Per the reference [1]: @@ -3949,17 +3944,34 @@ macro_rules! transmute_ref { #[allow(unused, clippy::diverging_sub_expression)] if false { // This branch, though never taken, ensures that the type of `e` is - // `&T` where `T: 't + Sized + AsBytes`, that the type of this macro - // expression is `&U` where `U: 'u + Sized + FromBytes`, and that - // `'t` outlives `'u`. + // `&T` where `T: 't + Sized + AsBytes + NoCell`, that the type of + // this macro expression is `&U` where `U: 'u + Sized + FromBytes + + // NoCell`, and that `'t` outlives `'u`. - struct AssertIsAsBytes<'a, T: ::core::marker::Sized + $crate::AsBytes>(&'a T); - let _ = AssertIsAsBytes(e); + struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); + struct AssertSrcIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertSrcIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); + struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); + struct AssertDstIsFromBytes<'a, U: ?::core::marker::Sized + $crate::FromBytes>(&'a U); + struct AssertDstIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); - struct AssertIsFromBytes<'a, U: ::core::marker::Sized + $crate::FromBytes>(&'a U); - #[allow(unused, unreachable_code)] - let u = AssertIsFromBytes(loop {}); - u.0 + let _ = AssertSrcIsSized(e); + let _ = AssertSrcIsAsBytes(e); + let _ = AssertSrcIsNoCell(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 + } else { + #[allow(unused, unreachable_code)] + let u = AssertDstIsNoCell(loop {}); + u.0 + } } else if false { // This branch, though never taken, ensures that `size_of::() == // size_of::()` and that that `align_of::() >= @@ -3980,8 +3992,10 @@ macro_rules! transmute_ref { &u } else { // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `Src: AsBytes` and `Dst: FromBytes` thanks to the - // uses of `AssertIsAsBytes` and `AssertIsFromBytes` above. + // - We know that `Src: AsBytes + NoCell` and `Dst: FromBytes + + // NoCell` thanks to the uses of `AssertSrcIsAsBytes`, + // `AssertSrcIsNoCell`, `AssertDstIsFromBytes`, and + // `AssertDstIsNoCell`` above. // - We know that `size_of::() == size_of::()` thanks to // the use of `assert_size_eq!` above. // - We know that `align_of::() >= align_of::()` thanks to @@ -4058,34 +4072,50 @@ macro_rules! transmute_mut { #[allow(unused, clippy::diverging_sub_expression)] if false { // This branch, though never taken, ensures that the type of `e` is - // `&mut T` where `T: 't + Sized + FromBytes + AsBytes`, that the - // type of this macro expression is `&mut U` where `U: 'u + Sized + - // FromBytes + AsBytes`. + // `&mut T` where `T: 't + Sized + FromBytes + AsBytes + NoCell` and + // that the type of this macro expression is `&mut U` where `U: 'u + + // Sized + FromBytes + AsBytes + NoCell`. // 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 AssertSrcIsFromBytes<'a, T: ::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertSrcIsAsBytes<'a, T: ::core::marker::Sized + $crate::AsBytes>(&'a T); - struct AssertDstIsFromBytes<'a, T: ::core::marker::Sized + $crate::FromBytes>(&'a T); - struct AssertDstIsAsBytes<'a, T: ::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertSrcIsSized<'a, T: ::core::marker::Sized>(&'a T); + struct AssertSrcIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); + struct AssertSrcIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertSrcIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); + struct AssertDstIsSized<'a, T: ::core::marker::Sized>(&'a T); + struct AssertDstIsFromBytes<'a, T: ?::core::marker::Sized + $crate::FromBytes>(&'a T); + struct AssertDstIsAsBytes<'a, T: ?::core::marker::Sized + $crate::AsBytes>(&'a T); + struct AssertDstIsNoCell<'a, T: ?::core::marker::Sized + $crate::NoCell>(&'a T); if true { + let _ = AssertSrcIsSized(&*e); + } else if true { let _ = AssertSrcIsFromBytes(&*e); - } else { + } else if true { let _ = AssertSrcIsAsBytes(&*e); + } else { + let _ = AssertSrcIsNoCell(&*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 { + } else if true { #[allow(unused, unreachable_code)] let u = AssertDstIsAsBytes(loop {}); &mut *u.0 + } else { + #[allow(unused, unreachable_code)] + let u = AssertDstIsNoCell(loop {}); + &mut *u.0 } } else if false { // This branch, though never taken, ensures that `size_of::() == @@ -4107,10 +4137,11 @@ macro_rules! transmute_mut { &mut u } else { // SAFETY: For source type `Src` and destination type `Dst`: - // - We know that `Src: FromBytes + AsBytes` and `Dst: FromBytes + - // AsBytes` thanks to the uses of `AssertSrcIsFromBytes`, - // `AssertSrcIsAsBytes`, `AssertDstIsFromBytes`, and - // `AssertDstIsAsBytes` above. + // - We know that `Src: FromBytes + AsBytes + NoCell` and `Dst: + // FromBytes + AsBytes + NoCell` thanks to the uses of + // `AssertSrcIsFromBytes`, `AssertSrcIsAsBytes`, + // `AssertSrcIsNoCell`, `AssertDstIsFromBytes`, + // `AssertDstIsAsBytes`, and `AssertDstIsNoCell` above. // - We know that `size_of::() == size_of::()` thanks to // the use of `assert_size_eq!` above. // - We know that `align_of::() >= align_of::()` thanks to @@ -4182,9 +4213,9 @@ macro_rules! include_value { /// /// ```rust /// # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them -/// use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeros, Ref, Unaligned}; +/// use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeros, NoCell, Ref, Unaligned}; /// -/// #[derive(FromZeros, FromBytes, AsBytes, Unaligned)] +/// #[derive(FromZeros, FromBytes, AsBytes, NoCell, Unaligned)] /// #[repr(C)] /// struct UdpHeader { /// src_port: [u8; 2], @@ -4756,7 +4787,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { /// Converts this `Ref` into a reference. /// @@ -4776,7 +4807,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { /// Converts this `Ref` into a mutable reference. /// @@ -4796,7 +4827,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { /// Converts this `Ref` into a slice reference. /// @@ -4816,7 +4847,7 @@ where impl<'a, B, T> Ref where B: 'a + ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { /// Converts this `Ref` into a mutable slice reference. /// @@ -4893,7 +4924,7 @@ where impl Ref where B: ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { /// Creates an immutable reference to `T` with a specific lifetime. /// @@ -4918,7 +4949,7 @@ where impl Ref where B: ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { /// Creates a mutable reference to `T` with a specific lifetime. /// @@ -4943,7 +4974,7 @@ where impl Ref where B: ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { /// Creates an immutable reference to `[T]` with a specific lifetime. /// @@ -4972,7 +5003,7 @@ where impl Ref where B: ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { /// Creates a mutable reference to `[T]` with a specific lifetime. /// @@ -5059,7 +5090,7 @@ where impl Deref for Ref where B: ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { type Target = T; #[inline] @@ -5077,7 +5108,7 @@ where impl DerefMut for Ref where B: ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { #[inline] fn deref_mut(&mut self) -> &mut T { @@ -5094,7 +5125,7 @@ where impl Deref for Ref where B: ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, { type Target = [T]; #[inline] @@ -5112,7 +5143,7 @@ where impl DerefMut for Ref where B: ByteSliceMut, - T: FromBytes + AsBytes, + T: FromBytes + AsBytes + NoCell, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -5129,7 +5160,7 @@ where impl Display for Ref where B: ByteSlice, - T: FromBytes + Display, + T: FromBytes + Display + NoCell, { #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { @@ -5141,7 +5172,7 @@ where impl Display for Ref where B: ByteSlice, - T: FromBytes, + T: FromBytes + NoCell, [T]: Display, { #[inline] @@ -5154,7 +5185,7 @@ where impl Debug for Ref where B: ByteSlice, - T: FromBytes + Debug, + T: FromBytes + Debug + NoCell, { #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { @@ -5166,7 +5197,7 @@ where impl Debug for Ref where B: ByteSlice, - T: FromBytes + Debug, + T: FromBytes + Debug + NoCell, { #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { @@ -5178,21 +5209,21 @@ where impl Eq for Ref where B: ByteSlice, - T: FromBytes + Eq, + T: FromBytes + Eq + NoCell, { } impl Eq for Ref where B: ByteSlice, - T: FromBytes + Eq, + T: FromBytes + Eq + NoCell, { } impl PartialEq for Ref where B: ByteSlice, - T: FromBytes + PartialEq, + T: FromBytes + PartialEq + NoCell, { #[inline] fn eq(&self, other: &Self) -> bool { @@ -5203,7 +5234,7 @@ where impl PartialEq for Ref where B: ByteSlice, - T: FromBytes + PartialEq, + T: FromBytes + PartialEq + NoCell, { #[inline] fn eq(&self, other: &Self) -> bool { @@ -5214,7 +5245,7 @@ where impl Ord for Ref where B: ByteSlice, - T: FromBytes + Ord, + T: FromBytes + Ord + NoCell, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -5227,7 +5258,7 @@ where impl Ord for Ref where B: ByteSlice, - T: FromBytes + Ord, + T: FromBytes + Ord + NoCell, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -5240,7 +5271,7 @@ where impl PartialOrd for Ref where B: ByteSlice, - T: FromBytes + PartialOrd, + T: FromBytes + PartialOrd + NoCell, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -5253,7 +5284,7 @@ where impl PartialOrd for Ref where B: ByteSlice, - T: FromBytes + PartialOrd, + T: FromBytes + PartialOrd + NoCell, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -5616,7 +5647,7 @@ mod tests { // // This is used to test the custom derives of our traits. The `[u8]` type // gets a hand-rolled impl, so it doesn't exercise our custom derives. - #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes, Unaligned)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes, Unaligned, NoCell)] #[repr(transparent)] struct Unsized([u8]); @@ -6952,6 +6983,14 @@ mod tests { const ARRAY_OF_ARRAYS: [[u8; 2]; 4] = [[0, 1], [2, 3], [4, 5], [6, 7]]; const X: [[u8; 2]; 4] = transmute!(ARRAY_OF_U8S); assert_eq!(X, ARRAY_OF_ARRAYS); + + // Test that `transmute!` works with `!NoCell` types. + let x: usize = transmute!(UnsafeCell::new(1usize)); + assert_eq!(x, 1); + let x: UnsafeCell = transmute!(1usize); + assert_eq!(x.into_inner(), 1); + let x: UnsafeCell = transmute!(UnsafeCell::new(1usize)); + assert_eq!(x.into_inner(), 1); } #[test] @@ -7626,7 +7665,7 @@ mod tests { /// has had its bits flipped (by applying `^= 0xFF`). /// /// `N` is the size of `t` in bytes. - fn test( + fn test( t: &mut T, bytes: &[u8], post_mutation: &T, @@ -7683,7 +7722,7 @@ mod tests { assert_eq!(too_many_bytes[0], 123); } - #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes)] + #[derive(Debug, Eq, PartialEq, FromZeros, FromBytes, AsBytes, NoCell)] #[repr(C)] struct Foo { a: u32, @@ -7712,7 +7751,7 @@ mod tests { #[test] fn test_array() { - #[derive(FromZeros, FromBytes, AsBytes)] + #[derive(FromZeros, FromBytes, AsBytes, NoCell)] #[repr(C)] struct Foo { a: [u16; 33], @@ -8039,10 +8078,10 @@ mod tests { assert_impls!(Option<&'static mut [UnsafeCell]>: KnownLayout, NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); assert_impls!(Option>>: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); assert_impls!(Option]>>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Option: KnownLayout, FromZeros, !NoCell, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Option: KnownLayout, NoCell, FromZeros, !TryFromBytes, !FromBytes, !AsBytes, !Unaligned); assert_impls!(PhantomData: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); assert_impls!(PhantomData>: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); @@ -8052,16 +8091,16 @@ mod tests { assert_impls!(ManuallyDrop<[u8]>: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); assert_impls!(ManuallyDrop: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); assert_impls!(ManuallyDrop<[NotZerocopy]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(ManuallyDrop>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: !NoCell, !TryFromBytes, !KnownLayout, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(ManuallyDrop>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); + assert_impls!(ManuallyDrop<[UnsafeCell<()>]>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); assert_impls!(MaybeUninit: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, Unaligned, !AsBytes); - assert_impls!(MaybeUninit: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(MaybeUninit>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(MaybeUninit: KnownLayout, TryFromBytes, FromZeros, FromBytes, !NoCell, !AsBytes, !Unaligned); + assert_impls!(MaybeUninit>: KnownLayout, TryFromBytes, FromZeros, FromBytes, Unaligned, !NoCell, !AsBytes); assert_impls!(Wrapping: KnownLayout, NoCell, TryFromBytes, FromZeros, FromBytes, AsBytes, Unaligned); assert_impls!(Wrapping: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); - assert_impls!(Wrapping>: KnownLayout, !NoCell, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes, !Unaligned); + assert_impls!(Wrapping>: KnownLayout, FromZeros, FromBytes, AsBytes, Unaligned, !NoCell, !TryFromBytes); assert_impls!(Unalign: KnownLayout, NoCell, FromZeros, FromBytes, AsBytes, Unaligned, !TryFromBytes); assert_impls!(Unalign: Unaligned, !NoCell, !KnownLayout, !TryFromBytes, !FromZeros, !FromBytes, !AsBytes); diff --git a/src/macro_util.rs b/src/macro_util.rs index 24fec4f015..7bedae2fa8 100644 --- a/src/macro_util.rs +++ b/src/macro_util.rs @@ -342,8 +342,8 @@ macro_rules! assert_size_eq { /// # Safety /// /// The caller must guarantee that: -/// - `Src: AsBytes` -/// - `Dst: FromBytes` +/// - `Src: AsBytes + NoCell` +/// - `Dst: FromBytes + NoCell` /// - `size_of::() == size_of::()` /// - `align_of::() >= align_of::()` #[inline(always)] @@ -358,8 +358,8 @@ pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( // caller has guaranteed that `Src: AsBytes`, `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: AsBytes` and `Dst: - // FromBytes` both forbid `UnsafeCell`s. + // worry about `UnsafeCell` overlap, because `Src: NoCell` and `Dst: + // NoCell`. // - 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. @@ -372,10 +372,11 @@ pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( /// # Safety /// /// The caller must guarantee that: -/// - `Src: FromBytes + AsBytes` -/// - `Dst: FromBytes + AsBytes` +/// - `Src: FromBytes + AsBytes + NoCell` +/// - `Dst: FromBytes + AsBytes + NoCell` /// - `size_of::() == size_of::()` /// - `align_of::() >= align_of::()` +// TODO(#686): Consider removing the `NoCell` requirement. #[inline(always)] pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( src: &'src mut Src, @@ -389,8 +390,8 @@ pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>( // AsBytes`, `Dst: FromBytes + AsBytes`, 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: FromBytes + AsBytes` - // and `Dst: FromBytes + AsBytes` forbid `UnsafeCell`s. + // worry about `UnsafeCell` overlap, because `Src: NoCell` + // and `Dst: NoCell`. // - 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. diff --git a/tests/ui-msrv/include_value_not_from_bytes.stderr b/tests/ui-msrv/include_value_not_from_bytes.stderr index 21f6443bbf..1a46599bbd 100644 --- a/tests/ui-msrv/include_value_not_from_bytes.stderr +++ b/tests/ui-msrv/include_value_not_from_bytes.stderr @@ -1,12 +1,12 @@ -error[E0277]: the trait bound `UnsafeCell: FromBytes` is not satisfied - --> tests/ui-msrv/include_value_not_from_bytes.rs:12:5 +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-msrv/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `UnsafeCell` +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `AssertIsFromBytes` - --> tests/ui-msrv/include_value_not_from_bytes.rs:12:5 + --> tests/ui-msrv/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` = note: this error originates in the macro `$crate::transmute` (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 8f0ea801ef..cb4e4568c0 100644 --- a/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr @@ -37,3 +37,23 @@ 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) diff --git a/tests/ui-msrv/transmute-mut-dst-not-nocell.rs b/tests/ui-msrv/transmute-mut-dst-not-nocell.rs new file mode 120000 index 0000000000..a1c5d17685 --- /dev/null +++ b/tests/ui-msrv/transmute-mut-dst-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-dst-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-dst-not-nocell.stderr b/tests/ui-msrv/transmute-mut-dst-not-nocell.stderr new file mode 100644 index 0000000000..46d22db875 --- /dev/null +++ b/tests/ui-msrv/transmute-mut-dst-not-nocell.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-msrv/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Dst` + | +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-msrv/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 cb60a82a78..b3c94f1b3e 100644 --- a/tests/ui-msrv/transmute-mut-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-mut-dst-unsized.stderr @@ -5,25 +5,11 @@ 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 a bound in `AssertDstIsFromBytes` +note: required by a bound in `AssertDstIsSized` --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 | 17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the 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 `AssertDstIsAsBytes` - --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 - | -17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-msrv/transmute-mut-src-dst-generic.stderr b/tests/ui-msrv/transmute-mut-src-dst-generic.stderr index 1162f21f9c..f41be15ad3 100644 --- a/tests/ui-msrv/transmute-mut-src-dst-generic.stderr +++ b/tests/ui-msrv/transmute-mut-src-dst-generic.stderr @@ -1,7 +1,7 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:18:5 + --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `T` (this type does not have a fixed size) @@ -9,9 +9,9 @@ error[E0512]: cannot transmute between types of different sizes, or dependently- = 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:18:5 + --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `AlignOf` (size can vary because of T) diff --git a/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr b/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr index 00201a6b68..e5692abab2 100644 --- a/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr @@ -5,11 +5,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -19,11 +19,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -33,53 +33,11 @@ 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 a bound in `AssertSrcIsAsBytes` +note: required by a bound in `AssertDstIsSized` --> 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 `AssertSrcIsAsBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` - = 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 `AssertDstIsFromBytes` - --> 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 `AssertDstIsFromBytes` - = 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 `AssertDstIsAsBytes` - --> 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 `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-msrv/transmute-mut-src-generic.stderr b/tests/ui-msrv/transmute-mut-src-generic.stderr index 8a9296ca66..ff55eb1286 100644 --- a/tests/ui-msrv/transmute-mut-src-generic.stderr +++ b/tests/ui-msrv/transmute-mut-src-generic.stderr @@ -1,7 +1,7 @@ error[E0405]: cannot find trait `FromBytes` in this scope --> tests/ui-msrv/transmute-mut-src-generic.rs:15:31 | -15 | fn transmute_mut(t: &mut T) -> &mut u8 { +15 | fn transmute_mut(t: &mut T) -> &mut u8 { | ^^^^^^^^^ not found in this scope | help: consider importing this trait diff --git a/tests/ui-msrv/transmute-mut-src-not-nocell.rs b/tests/ui-msrv/transmute-mut-src-not-nocell.rs new file mode 120000 index 0000000000..e3c21b3763 --- /dev/null +++ b/tests/ui-msrv/transmute-mut-src-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-src-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-mut-src-not-nocell.stderr b/tests/ui-msrv/transmute-mut-src-not-nocell.stderr new file mode 100644 index 0000000000..5aae55d6ac --- /dev/null +++ b/tests/ui-msrv/transmute-mut-src-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-msrv/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-msrv/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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: NoCell` is not satisfied + --> tests/ui-msrv/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-msrv/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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 6b18695e66..1d8b1504e8 100644 --- a/tests/ui-msrv/transmute-mut-src-unsized.stderr +++ b/tests/ui-msrv/transmute-mut-src-unsized.stderr @@ -5,11 +5,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -19,39 +19,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-msrv/transmute-ref-dst-mutable.stderr b/tests/ui-msrv/transmute-ref-dst-mutable.stderr index 5ccf2cd20d..3189cd0d4b 100644 --- a/tests/ui-msrv/transmute-ref-dst-mutable.stderr +++ b/tests/ui-msrv/transmute-ref-dst-mutable.stderr @@ -27,3 +27,23 @@ 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 9a61c4c7ce..60a79caeba 100644 --- a/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr @@ -27,3 +27,23 @@ 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-not-frombytes.stderr b/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr index d317675446..4d37f5d56b 100644 --- a/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr +++ b/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr @@ -1,12 +1,12 @@ -error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied - --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:18:42 +error[E0277]: the trait bound `Dst: FromBytes` is not satisfied + --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` | -note: required by a bound in `AssertIsFromBytes` - --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:18:42 +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` = 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-nocell.rs b/tests/ui-msrv/transmute-ref-dst-not-nocell.rs new file mode 120000 index 0000000000..6623ce25e4 --- /dev/null +++ b/tests/ui-msrv/transmute-ref-dst-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-dst-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-dst-not-nocell.stderr b/tests/ui-msrv/transmute-ref-dst-not-nocell.stderr new file mode 100644 index 0000000000..b2af111f8e --- /dev/null +++ b/tests/ui-msrv/transmute-ref-dst-not-nocell.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Dst` + | +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 78135de876..79dd8b20e9 100644 --- a/tests/ui-msrv/transmute-ref-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-ref-dst-unsized.stderr @@ -5,11 +5,11 @@ 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 a bound in `AssertIsFromBytes` +note: required by a bound in `AssertDstIsSized` --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 | 17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 2c5e23b6dd..1826e28a52 100644 --- a/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr @@ -40,3 +40,23 @@ 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.stderr b/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr index adfd59792a..297683c063 100644 --- a/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr +++ b/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr @@ -5,11 +5,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -19,11 +19,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -33,11 +33,11 @@ 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 a bound in `AssertIsFromBytes` +note: required by a bound in `AssertDstIsSized` --> 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 `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr b/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr index 6b80d4f494..a49128cea0 100644 --- a/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr @@ -1,25 +1,25 @@ -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = 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-not-nocell.rs b/tests/ui-msrv/transmute-ref-src-not-nocell.rs new file mode 120000 index 0000000000..04204b9522 --- /dev/null +++ b/tests/ui-msrv/transmute-ref-src-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-src-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ref-src-not-nocell.stderr b/tests/ui-msrv/transmute-ref-src-not-nocell.stderr new file mode 100644 index 0000000000..d1fe73496a --- /dev/null +++ b/tests/ui-msrv/transmute-ref-src-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-msrv/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-msrv/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-msrv/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-msrv/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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-unsized.stderr b/tests/ui-msrv/transmute-ref-src-unsized.stderr index 43bac53595..09f81af672 100644 --- a/tests/ui-msrv/transmute-ref-src-unsized.stderr +++ b/tests/ui-msrv/transmute-ref-src-unsized.stderr @@ -5,11 +5,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -19,11 +19,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/include_value_not_from_bytes.rs b/tests/ui-nightly/include_value_not_from_bytes.rs index 45b6138f47..9f0bb6f1d1 100644 --- a/tests/ui-nightly/include_value_not_from_bytes.rs +++ b/tests/ui-nightly/include_value_not_from_bytes.rs @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +include!("../../zerocopy-derive/tests/util.rs"); + #[macro_use] extern crate zerocopy; fn main() {} -// Should fail because `UnsafeCell: !FromBytes`. -const NOT_FROM_BYTES: core::cell::UnsafeCell = - include_value!("../../testdata/include_value/data"); +// Should fail because `NotZerocopy: !FromBytes`. +const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); diff --git a/tests/ui-nightly/include_value_not_from_bytes.stderr b/tests/ui-nightly/include_value_not_from_bytes.stderr index d948a0db81..544c3916a0 100644 --- a/tests/ui-nightly/include_value_not_from_bytes.stderr +++ b/tests/ui-nightly/include_value_not_from_bytes.stderr @@ -1,11 +1,11 @@ -error[E0277]: the trait bound `UnsafeCell: FromBytes` is not satisfied - --> tests/ui-nightly/include_value_not_from_bytes.rs:12:5 +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-nightly/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `FromBytes` is not implemented for `UnsafeCell` - | required by a bound introduced by this call +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `NotZerocopy` + | required by a bound introduced by this call | = help: the following other types implement trait `FromBytes`: isize @@ -18,8 +18,8 @@ error[E0277]: the trait bound `UnsafeCell: FromBytes` is not satisfied u8 and $N others note: required by a bound in `AssertIsFromBytes` - --> tests/ui-nightly/include_value_not_from_bytes.rs:12:5 + --> tests/ui-nightly/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` = note: this error originates in the macro `$crate::transmute` which comes from the expansion of the macro `include_value` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-mut-dst-generic.rs b/tests/ui-nightly/transmute-mut-dst-generic.rs index 7068f1026d..fc5eacf99d 100644 --- a/tests/ui-nightly/transmute-mut-dst-generic.rs +++ b/tests/ui-nightly/transmute-mut-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes, FromBytes}; +use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell}; fn main() {} -fn transmute_mut(u: &mut u8) -> &mut T { +fn transmute_mut(u: &mut u8) -> &mut T { // `transmute_mut!` requires the destination type to be concrete. transmute_mut!(u) } diff --git a/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr index a84547bd03..90cdfe1c94 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr @@ -37,3 +37,23 @@ 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) diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs index 3714db7c4f..16ea706dec 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs index 1c0121fcac..72f97d86d1 100644 --- a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::AsBytes)] +#[derive(zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-dst-not-nocell.rs b/tests/ui-nightly/transmute-mut-dst-not-nocell.rs new file mode 100644 index 0000000000..3a8eb7b361 --- /dev/null +++ b/tests/ui-nightly/transmute-mut-dst-not-nocell.rs @@ -0,0 +1,24 @@ +// 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() {} + +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[repr(C)] +struct Src; + +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[repr(C)] +struct Dst; + +// `transmute_mut` requires that the destination type implements `NoCell` +const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); diff --git a/tests/ui-nightly/transmute-mut-dst-not-nocell.stderr b/tests/ui-nightly/transmute-mut-dst-not-nocell.stderr new file mode 100644 index 0000000000..6f8cfe5627 --- /dev/null +++ b/tests/ui-nightly/transmute-mut-dst-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-nightly/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-nightly/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 a670e25013..3e18c98b52 100644 --- a/tests/ui-nightly/transmute-mut-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-mut-dst-unsized.stderr @@ -8,28 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsFromBytes` +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 `AssertDstIsFromBytes` - = 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 - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsAsBytes` - --> 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 `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.rs b/tests/ui-nightly/transmute-mut-src-dst-generic.rs index aed7ded96f..76bc520f52 100644 --- a/tests/ui-nightly/transmute-mut-src-dst-generic.rs +++ b/tests/ui-nightly/transmute-mut-src-dst-generic.rs @@ -8,11 +8,13 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes, FromBytes}; +use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell}; fn main() {} -fn transmute_mut(t: &mut T) -> &mut U { +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 index e3f3a3fd79..eb5c498cec 100644 --- a/tests/ui-nightly/transmute-mut-src-dst-generic.stderr +++ b/tests/ui-nightly/transmute-mut-src-dst-generic.stderr @@ -1,7 +1,7 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:18:5 + --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `T` (this type does not have a fixed size) @@ -9,9 +9,9 @@ error[E0512]: cannot transmute between types of different sizes, or dependently- = 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:18:5 + --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `AlignOf` (size can vary because of T) diff --git a/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr b/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr index 0f41a420eb..4eccaaf339 100644 --- a/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -39,59 +39,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsAsBytes` +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 `AssertSrcIsAsBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` - = 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 `AssertDstIsFromBytes` - --> 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 `AssertDstIsFromBytes` - = 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 `AssertDstIsAsBytes` - --> 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 `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/transmute-mut-src-generic.rs b/tests/ui-nightly/transmute-mut-src-generic.rs index a3ef397876..3f26a374cd 100644 --- a/tests/ui-nightly/transmute-mut-src-generic.rs +++ b/tests/ui-nightly/transmute-mut-src-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_mut, AsBytes}; +use zerocopy::{transmute_mut, AsBytes, NoCell}; fn main() {} -fn transmute_mut(t: &mut T) -> &mut u8 { +fn transmute_mut(t: &mut T) -> &mut u8 { // `transmute_mut!` requires the source type to be concrete. transmute_mut!(t) } diff --git a/tests/ui-nightly/transmute-mut-src-generic.stderr b/tests/ui-nightly/transmute-mut-src-generic.stderr index c06d775072..67ef7d4fcc 100644 --- a/tests/ui-nightly/transmute-mut-src-generic.stderr +++ b/tests/ui-nightly/transmute-mut-src-generic.stderr @@ -1,7 +1,7 @@ error[E0405]: cannot find trait `FromBytes` in this scope --> tests/ui-nightly/transmute-mut-src-generic.rs:15:31 | -15 | fn transmute_mut(t: &mut T) -> &mut u8 { +15 | fn transmute_mut(t: &mut T) -> &mut u8 { | ^^^^^^^^^ not found in this scope | help: consider importing this trait diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs index 4eaadece17..c24328e9a4 100644 --- a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::FromZeros, zerocopy::FromBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs index 09baa1022b..ffff1a198c 100644 --- a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs +++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs @@ -12,11 +12,11 @@ use zerocopy::transmute_mut; fn main() {} -#[derive(zerocopy::AsBytes)] +#[derive(zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Src; -#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] #[repr(C)] struct Dst; diff --git a/tests/ui-nightly/transmute-mut-src-not-nocell.rs b/tests/ui-nightly/transmute-mut-src-not-nocell.rs new file mode 100644 index 0000000000..7ef96e7ad1 --- /dev/null +++ b/tests/ui-nightly/transmute-mut-src-not-nocell.rs @@ -0,0 +1,24 @@ +// 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() {} + +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes)] +#[repr(C)] +struct Src; + +#[derive(zerocopy::FromZeros, zerocopy::FromBytes, zerocopy::AsBytes, zerocopy::NoCell)] +#[repr(C)] +struct Dst; + +// `transmute_mut` requires that the source type implements `NoCell` +const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); diff --git a/tests/ui-nightly/transmute-mut-src-not-nocell.stderr b/tests/ui-nightly/transmute-mut-src-not-nocell.stderr new file mode 100644 index 0000000000..8e3424ca5e --- /dev/null +++ b/tests/ui-nightly/transmute-mut-src-not-nocell.stderr @@ -0,0 +1,48 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-nightly/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Src` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-nightly/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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: NoCell` is not satisfied + --> tests/ui-nightly/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-nightly/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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.stderr b/tests/ui-nightly/transmute-mut-src-unsized.stderr index 99475adee0..bc07d97628 100644 --- a/tests/ui-nightly/transmute-mut-src-unsized.stderr +++ b/tests/ui-nightly/transmute-mut-src-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,42 +22,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` - = 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 - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/transmute-ref-dst-generic.rs b/tests/ui-nightly/transmute-ref-dst-generic.rs index bf4a0f9adf..6c73e6447f 100644 --- a/tests/ui-nightly/transmute-ref-dst-generic.rs +++ b/tests/ui-nightly/transmute-ref-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_ref, FromBytes}; +use zerocopy::{transmute_ref, FromBytes, NoCell}; fn main() {} -fn transmute_ref(u: &u8) -> &T { +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-mutable.stderr b/tests/ui-nightly/transmute-ref-dst-mutable.stderr index 0cbdd176b8..7df1d0ed73 100644 --- a/tests/ui-nightly/transmute-ref-dst-mutable.stderr +++ b/tests/ui-nightly/transmute-ref-dst-mutable.stderr @@ -27,3 +27,23 @@ 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 + | + = 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-nightly/transmute-ref-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr index 847d54732e..f52f9d43ae 100644 --- a/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr @@ -27,3 +27,23 @@ 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 `&_` + | + = 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-nightly/transmute-ref-dst-not-frombytes.rs b/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs index d81f64d21b..6251323b2a 100644 --- a/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs +++ b/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs @@ -14,5 +14,9 @@ use zerocopy::transmute_ref; fn main() {} +#[derive(zerocopy::NoCell)] +#[repr(transparent)] +struct Dst(AU16); + // `transmute_ref` requires that the destination type implements `FromBytes` -const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); +const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); diff --git a/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr index e4791d76b0..83f69bcc02 100644 --- a/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr +++ b/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr @@ -1,11 +1,11 @@ -error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied - --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:18:42 +error[E0277]: the trait bound `Dst: FromBytes` is not satisfied + --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `FromBytes` is not implemented for `NotZerocopy` - | required by a bound introduced by this call +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call | = help: the following other types implement trait `FromBytes`: isize @@ -17,9 +17,9 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied usize u8 and $N others -note: required by a bound in `AssertIsFromBytes` - --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:18:42 +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` = 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-nocell.rs b/tests/ui-nightly/transmute-ref-dst-not-nocell.rs new file mode 100644 index 0000000000..014bd86271 --- /dev/null +++ b/tests/ui-nightly/transmute-ref-dst-not-nocell.rs @@ -0,0 +1,22 @@ +// 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/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute_ref; + +fn main() {} + +#[derive(zerocopy::FromZeros, zerocopy::FromBytes)] +#[repr(transparent)] +struct Dst(AU16); + +// `transmute_ref` requires that the destination type implements `NoCell` +const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); diff --git a/tests/ui-nightly/transmute-ref-dst-not-nocell.stderr b/tests/ui-nightly/transmute-ref-dst-not-nocell.stderr new file mode 100644 index 0000000000..b11951242a --- /dev/null +++ b/tests/ui-nightly/transmute-ref-dst-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-nightly/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-nightly/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 3d0f6d0300..359fcdc45d 100644 --- a/tests/ui-nightly/transmute-ref-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-ref-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsFromBytes` +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 `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.rs b/tests/ui-nightly/transmute-ref-src-dst-generic.rs index 409d785b20..384e8e011a 100644 --- a/tests/ui-nightly/transmute-ref-src-dst-generic.rs +++ b/tests/ui-nightly/transmute-ref-src-dst-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_ref, AsBytes, FromBytes}; +use zerocopy::{transmute_ref, AsBytes, FromBytes, NoCell}; fn main() {} -fn transmute_ref(t: &T) -> &U { +fn transmute_ref(t: &T) -> &U { // `transmute_ref!` requires the source and destination types to be // concrete. transmute_ref!(t) diff --git a/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr index 0f1f7fc7b3..8b06ee56a8 100644 --- a/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr @@ -43,3 +43,23 @@ 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 `&_` + | + = 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-nightly/transmute-ref-src-dst-unsized.stderr b/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr index 02e62bce0b..62ff449361 100644 --- a/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr +++ b/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -39,11 +39,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsFromBytes` +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 `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-nightly/transmute-ref-src-generic.rs b/tests/ui-nightly/transmute-ref-src-generic.rs index 010281c32e..836c884ad6 100644 --- a/tests/ui-nightly/transmute-ref-src-generic.rs +++ b/tests/ui-nightly/transmute-ref-src-generic.rs @@ -8,11 +8,11 @@ extern crate zerocopy; -use zerocopy::{transmute_ref, AsBytes}; +use zerocopy::{transmute_ref, AsBytes, NoCell}; fn main() {} -fn transmute_ref(t: &T) -> &u8 { +fn transmute_ref(t: &T) -> &u8 { // `transmute_ref!` requires the source type to be concrete. transmute_ref!(t) } diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.rs b/tests/ui-nightly/transmute-ref-src-not-asbytes.rs index 6ab19f3c82..4a9018b5e3 100644 --- a/tests/ui-nightly/transmute-ref-src-not-asbytes.rs +++ b/tests/ui-nightly/transmute-ref-src-not-asbytes.rs @@ -14,5 +14,9 @@ use zerocopy::transmute_ref; fn main() {} +#[derive(zerocopy::NoCell)] +#[repr(transparent)] +struct Src(AU16); + // `transmute_ref` requires that the source type implements `AsBytes` -const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); +const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr b/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr index eb28ccf7c8..57cc76fa51 100644 --- a/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr @@ -1,10 +1,10 @@ -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the trait `AsBytes` is not implemented for `NotZerocopy` + | the trait `AsBytes` is not implemented for `Src` | required by a bound introduced by this call | = help: the following other types implement trait `AsBytes`: @@ -17,18 +17,18 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | = help: the following other types implement trait `AsBytes`: bool @@ -40,9 +40,9 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-ref-src-not-nocell.rs b/tests/ui-nightly/transmute-ref-src-not-nocell.rs new file mode 100644 index 0000000000..b78c5fe940 --- /dev/null +++ b/tests/ui-nightly/transmute-ref-src-not-nocell.rs @@ -0,0 +1,22 @@ +// 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/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute_ref; + +fn main() {} + +#[derive(zerocopy::AsBytes)] +#[repr(transparent)] +struct Src(AU16); + +// `transmute_ref` requires that the source type implements `NoCell` +const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); diff --git a/tests/ui-nightly/transmute-ref-src-not-nocell.stderr b/tests/ui-nightly/transmute-ref-src-not-nocell.stderr new file mode 100644 index 0000000000..4a2f1d8c43 --- /dev/null +++ b/tests/ui-nightly/transmute-ref-src-not-nocell.stderr @@ -0,0 +1,48 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-nightly/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Src` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-nightly/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-nightly/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-nightly/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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-unsized.stderr b/tests/ui-nightly/transmute-ref-src-unsized.stderr index b280429b03..67a9ee1c51 100644 --- a/tests/ui-nightly/transmute-ref-src-unsized.stderr +++ b/tests/ui-nightly/transmute-ref-src-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-stable/include_value_not_from_bytes.stderr b/tests/ui-stable/include_value_not_from_bytes.stderr index 7e9a035dc3..40f9439185 100644 --- a/tests/ui-stable/include_value_not_from_bytes.stderr +++ b/tests/ui-stable/include_value_not_from_bytes.stderr @@ -1,11 +1,11 @@ -error[E0277]: the trait bound `UnsafeCell: FromBytes` is not satisfied - --> tests/ui-stable/include_value_not_from_bytes.rs:12:5 +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-stable/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `FromBytes` is not implemented for `UnsafeCell` - | required by a bound introduced by this call +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `NotZerocopy` + | required by a bound introduced by this call | = help: the following other types implement trait `FromBytes`: isize @@ -18,8 +18,8 @@ error[E0277]: the trait bound `UnsafeCell: FromBytes` is not satisfied u8 and $N others note: required by a bound in `AssertIsFromBytes` - --> tests/ui-stable/include_value_not_from_bytes.rs:12:5 + --> tests/ui-stable/include_value_not_from_bytes.rs:13:42 | -12 | include_value!("../../testdata/include_value/data"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +13 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` = note: this error originates in the macro `$crate::transmute` which comes from the expansion of the macro `include_value` (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 14ee444cc5..9a05f9eb82 100644 --- a/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr +++ b/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr @@ -37,3 +37,23 @@ 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) diff --git a/tests/ui-stable/transmute-mut-dst-not-nocell.rs b/tests/ui-stable/transmute-mut-dst-not-nocell.rs new file mode 120000 index 0000000000..a1c5d17685 --- /dev/null +++ b/tests/ui-stable/transmute-mut-dst-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-dst-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-dst-not-nocell.stderr b/tests/ui-stable/transmute-mut-dst-not-nocell.stderr new file mode 100644 index 0000000000..27a12a0607 --- /dev/null +++ b/tests/ui-stable/transmute-mut-dst-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-stable/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-stable/transmute-mut-dst-not-nocell.rs:24:35 + | +24 | const DST_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 07727850cd..39aba0b8d2 100644 --- a/tests/ui-stable/transmute-mut-dst-unsized.stderr +++ b/tests/ui-stable/transmute-mut-dst-unsized.stderr @@ -8,28 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsFromBytes` +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 `AssertDstIsFromBytes` - = 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 - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertDstIsAsBytes` - --> 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 `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-stable/transmute-mut-src-dst-generic.stderr b/tests/ui-stable/transmute-mut-src-dst-generic.stderr index ddb8bb6fe7..2fd87ed86b 100644 --- a/tests/ui-stable/transmute-mut-src-dst-generic.stderr +++ b/tests/ui-stable/transmute-mut-src-dst-generic.stderr @@ -1,7 +1,7 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> tests/ui-stable/transmute-mut-src-dst-generic.rs:18:5 + --> tests/ui-stable/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `T` (this type does not have a fixed size) @@ -9,9 +9,9 @@ error[E0512]: cannot transmute between types of different sizes, or dependently- = 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:18:5 + --> tests/ui-stable/transmute-mut-src-dst-generic.rs:20:5 | -18 | transmute_mut!(t) +20 | transmute_mut!(t) | ^^^^^^^^^^^^^^^^^ | = note: source type: `AlignOf` (size can vary because of T) diff --git a/tests/ui-stable/transmute-mut-src-dst-unsized.stderr b/tests/ui-stable/transmute-mut-src-dst-unsized.stderr index 8cf76649eb..3521e93613 100644 --- a/tests/ui-stable/transmute-mut-src-dst-unsized.stderr +++ b/tests/ui-stable/transmute-mut-src-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsFromBytes` +note: required by a bound in `AssertSrcIsSized` --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 | 17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertSrcIsFromBytes` +note: required by a bound in `AssertSrcIsSized` --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 | 17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -39,59 +39,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsAsBytes` +note: required by a bound in `AssertDstIsSized` --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 | 17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` - = 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-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 `AssertSrcIsAsBytes` - --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` - = 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-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 `AssertDstIsFromBytes` - --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` - = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui-stable/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 `AssertDstIsAsBytes` - --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36 - | -17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-stable/transmute-mut-src-generic.stderr b/tests/ui-stable/transmute-mut-src-generic.stderr index fc4809e418..e40eec29ca 100644 --- a/tests/ui-stable/transmute-mut-src-generic.stderr +++ b/tests/ui-stable/transmute-mut-src-generic.stderr @@ -1,7 +1,7 @@ error[E0405]: cannot find trait `FromBytes` in this scope --> tests/ui-stable/transmute-mut-src-generic.rs:15:31 | -15 | fn transmute_mut(t: &mut T) -> &mut u8 { +15 | fn transmute_mut(t: &mut T) -> &mut u8 { | ^^^^^^^^^ not found in this scope | help: consider importing this trait diff --git a/tests/ui-stable/transmute-mut-src-not-nocell.rs b/tests/ui-stable/transmute-mut-src-not-nocell.rs new file mode 120000 index 0000000000..e3c21b3763 --- /dev/null +++ b/tests/ui-stable/transmute-mut-src-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-mut-src-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-mut-src-not-nocell.stderr b/tests/ui-stable/transmute-mut-src-not-nocell.stderr new file mode 100644 index 0000000000..80b0126fa7 --- /dev/null +++ b/tests/ui-stable/transmute-mut-src-not-nocell.stderr @@ -0,0 +1,48 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-stable/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Src` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-stable/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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: NoCell` is not satisfied + --> tests/ui-stable/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-stable/transmute-mut-src-not-nocell.rs:24:35 + | +24 | const SRC_NOT_NO_CELL: &mut Dst = transmute_mut!(&mut Src); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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 7f6def929d..0fe91c360a 100644 --- a/tests/ui-stable/transmute-mut-src-unsized.stderr +++ b/tests/ui-stable/transmute-mut-src-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,42 +22,11 @@ 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 a bound in `AssertSrcIsFromBytes` +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 `AssertSrcIsFromBytes` - = 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 - | required by a bound introduced by this call - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` - = 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 `AssertSrcIsAsBytes` - --> 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 `AssertSrcIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-stable/transmute-ref-dst-mutable.stderr b/tests/ui-stable/transmute-ref-dst-mutable.stderr index c70f6ea618..2f880ec3c1 100644 --- a/tests/ui-stable/transmute-ref-dst-mutable.stderr +++ b/tests/ui-stable/transmute-ref-dst-mutable.stderr @@ -27,3 +27,23 @@ 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 + | + = 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-stable/transmute-ref-dst-not-a-reference.stderr b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr index ab3f90c2fd..afdb0f1563 100644 --- a/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr +++ b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr @@ -27,3 +27,23 @@ 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 `&_` + | + = 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-stable/transmute-ref-dst-not-frombytes.stderr b/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr index 76d18c5e45..5f292d286b 100644 --- a/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr +++ b/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr @@ -1,11 +1,11 @@ -error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied - --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:18:42 +error[E0277]: the trait bound `Dst: FromBytes` is not satisfied + --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | the trait `FromBytes` is not implemented for `NotZerocopy` - | required by a bound introduced by this call +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `FromBytes` is not implemented for `Dst` + | required by a bound introduced by this call | = help: the following other types implement trait `FromBytes`: isize @@ -17,9 +17,9 @@ error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied usize u8 and $N others -note: required by a bound in `AssertIsFromBytes` - --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:18:42 +note: required by a bound in `AssertDstIsFromBytes` + --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:22:34 | -18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` +22 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` = 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-nocell.rs b/tests/ui-stable/transmute-ref-dst-not-nocell.rs new file mode 120000 index 0000000000..6623ce25e4 --- /dev/null +++ b/tests/ui-stable/transmute-ref-dst-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-dst-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-dst-not-nocell.stderr b/tests/ui-stable/transmute-ref-dst-not-nocell.stderr new file mode 100644 index 0000000000..09f6a9609d --- /dev/null +++ b/tests/ui-stable/transmute-ref-dst-not-nocell.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `Dst: NoCell` is not satisfied + --> tests/ui-stable/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Dst` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertDstIsNoCell` + --> tests/ui-stable/transmute-ref-dst-not-nocell.rs:22:31 + | +22 | const DST_NOT_NO_CELL: &Dst = transmute_ref!(&AU16(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsNoCell` + = 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 8a0c761466..f29b8f527f 100644 --- a/tests/ui-stable/transmute-ref-dst-unsized.stderr +++ b/tests/ui-stable/transmute-ref-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsFromBytes` +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 `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 8a80e991e6..4d1701e2d9 100644 --- a/tests/ui-stable/transmute-ref-src-dst-not-references.stderr +++ b/tests/ui-stable/transmute-ref-src-dst-not-references.stderr @@ -43,3 +43,23 @@ 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 `&_` + | + = 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-stable/transmute-ref-src-dst-unsized.stderr b/tests/ui-stable/transmute-ref-src-dst-unsized.stderr index ca62fcf7db..ef430a0799 100644 --- a/tests/ui-stable/transmute-ref-src-dst-unsized.stderr +++ b/tests/ui-stable/transmute-ref-src-dst-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsAsBytes` +note: required by a bound in `AssertSrcIsSized` --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32 | 17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertIsAsBytes` +note: required by a bound in `AssertSrcIsSized` --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32 | 17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -39,11 +39,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsFromBytes` +note: required by a bound in `AssertDstIsSized` --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32 | 17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui-stable/transmute-ref-src-not-asbytes.stderr b/tests/ui-stable/transmute-ref-src-not-asbytes.stderr index 2ded6baa03..7303d38108 100644 --- a/tests/ui-stable/transmute-ref-src-not-asbytes.stderr +++ b/tests/ui-stable/transmute-ref-src-not-asbytes.stderr @@ -1,10 +1,10 @@ -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the trait `AsBytes` is not implemented for `NotZerocopy` + | the trait `AsBytes` is not implemented for `Src` | required by a bound introduced by this call | = help: the following other types implement trait `AsBytes`: @@ -17,18 +17,18 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33 +error[E0277]: the trait bound `Src: AsBytes` is not satisfied + --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src` | = help: the following other types implement trait `AsBytes`: bool @@ -40,9 +40,9 @@ error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied i64 i128 and $N others -note: required by a bound in `AssertIsAsBytes` - --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33 +note: required by a bound in `AssertSrcIsAsBytes` + --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:22:33 | -18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes` +22 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes` = 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-src-not-nocell.rs b/tests/ui-stable/transmute-ref-src-not-nocell.rs new file mode 120000 index 0000000000..04204b9522 --- /dev/null +++ b/tests/ui-stable/transmute-ref-src-not-nocell.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ref-src-not-nocell.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ref-src-not-nocell.stderr b/tests/ui-stable/transmute-ref-src-not-nocell.stderr new file mode 100644 index 0000000000..115a32cc9d --- /dev/null +++ b/tests/ui-stable/transmute-ref-src-not-nocell.stderr @@ -0,0 +1,48 @@ +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-stable/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `NoCell` is not implemented for `Src` + | required by a bound introduced by this call + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-stable/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Src: NoCell` is not satisfied + --> tests/ui-stable/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NoCell` is not implemented for `Src` + | + = help: the following other types implement trait `NoCell`: + bool + char + isize + i8 + i16 + i32 + i64 + i128 + and $N others +note: required by a bound in `AssertSrcIsNoCell` + --> tests/ui-stable/transmute-ref-src-not-nocell.rs:22:32 + | +22 | const SRC_NOT_NO_CELL: &AU16 = transmute_ref!(&Src(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsNoCell` + = 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-src-unsized.stderr b/tests/ui-stable/transmute-ref-src-unsized.stderr index b194d67473..c0b6a8aaf8 100644 --- a/tests/ui-stable/transmute-ref-src-unsized.stderr +++ b/tests/ui-stable/transmute-ref-src-unsized.stderr @@ -8,11 +8,11 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ -22,11 +22,11 @@ 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 a bound in `AssertIsAsBytes` +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 `AssertIsAsBytes` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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