diff --git a/zerocopy/src/impls.rs b/zerocopy/src/impls.rs index 5ecd54c9d9..12284fb6ce 100644 --- a/zerocopy/src/impls.rs +++ b/zerocopy/src/impls.rs @@ -796,8 +796,8 @@ const _: () = { // private field, and because it is the name it is referred to in the public // documentation of `ManuallyDrop::new`, `ManuallyDrop::into_inner`, // `ManuallyDrop::take` and `ManuallyDrop::drop`. - unsafe impl - HasField + unsafe impl + HasField for ManuallyDrop { #[inline] @@ -1015,8 +1015,8 @@ mod tuples { // SAFETY: If all fields in `c` are `is_bit_valid`, so too is `c`. unsafe_impl!($($head_T: TryFromBytes,)* $next_T: TryFromBytes => TryFromBytes for ($($head_T,)* $next_T,); |c| { let mut c = c; - $(TryFromBytes::is_bit_valid(into_inner!(c.reborrow().project::<_, { crate::STRUCT_VARIANT_ID }, { crate::ident_id!($head_I) }>())) &&)* - TryFromBytes::is_bit_valid(into_inner!(c.reborrow().project::<_, { crate::STRUCT_VARIANT_ID }, { crate::ident_id!($next_I) }>())) + $(TryFromBytes::is_bit_valid(into_inner!(c.reborrow().project::())) &&)* + TryFromBytes::is_bit_valid(into_inner!(c.reborrow().project::())) }); // SAFETY: If all fields in `Self` are `FromZeros`, so too is `Self`. @@ -1077,7 +1077,8 @@ mod tuples { // - `()` has the same visibility as the `.$CurrI` field (ie, `.0`, // `.1`, etc) // - `Type` has the same type as `$CurrI`; i.e., `$CurrT`. - unsafe impl<$($AllT),+> crate::HasField< + unsafe impl crate::HasField< + Client, (), { crate::STRUCT_VARIANT_ID }, { crate::ident_id!($CurrI)} @@ -1103,7 +1104,8 @@ mod tuples { } // SAFETY: See comments on items. - unsafe impl crate::ProjectField< + unsafe impl crate::ProjectField< + Client, (), (Aliasing, Alignment, crate::invariant::Uninit), { crate::STRUCT_VARIANT_ID }, @@ -1129,7 +1131,8 @@ mod tuples { } // SAFETY: See comments on items. - unsafe impl crate::ProjectField< + unsafe impl crate::ProjectField< + Client, (), (Aliasing, Alignment, crate::invariant::Initialized), { crate::STRUCT_VARIANT_ID }, @@ -1155,7 +1158,8 @@ mod tuples { } // SAFETY: See comments on items. - unsafe impl crate::ProjectField< + unsafe impl crate::ProjectField< + Client, (), (Aliasing, Alignment, crate::invariant::Valid), { crate::STRUCT_VARIANT_ID }, diff --git a/zerocopy/src/lib.rs b/zerocopy/src/lib.rs index 38c35fd783..6957131e31 100644 --- a/zerocopy/src/lib.rs +++ b/zerocopy/src/lib.rs @@ -1181,6 +1181,9 @@ pub const STRUCT_VARIANT_ID: i128 = -1; pub const UNION_VARIANT_ID: i128 = -2; #[doc(hidden)] pub const REPR_C_UNION_VARIANT_ID: i128 = -3; +#[doc(hidden)] +#[derive(Copy, Clone, Debug)] +pub enum TryFromBytesDerive {} /// # Safety /// @@ -1209,6 +1212,9 @@ pub unsafe trait HasTag { /// should use the same `Field` type; this ensures that `Field` is inferable /// given an explicit `VARIANT_ID` and `FIELD_ID`. /// +/// The `Client` parameter exists solely to disambiguate between implementations +/// of `HasField` that would otherwise conflict. +/// /// # Safety /// /// A field `f` is `HasField` for `Self` if and only if: @@ -1232,7 +1238,7 @@ pub unsafe trait HasTag { /// /// The implementation of `project` must satisfy its safety post-condition. #[doc(hidden)] -pub unsafe trait HasField: +pub unsafe trait HasField: HasTag { fn only_derive_is_allowed_to_implement_this_trait() @@ -1263,15 +1269,18 @@ pub unsafe trait HasField: /// other words, it is a type-level function over invariants; `I` goes in, /// `Self::Invariants` comes out. /// +/// The `Client` parameter exists solely to disambiguate between implementations +/// of `HasField` that would otherwise conflict. +/// /// # Safety /// -/// `T: ProjectField` if, for a +/// `T: ProjectField` if, for a /// `ptr: Ptr<'_, T, I>` such that `T::is_projectable(ptr).is_ok()`, -/// `>::project(ptr.as_inner())` +/// `>::project(ptr.as_inner())` /// conforms to `T::Invariants`. #[doc(hidden)] -pub unsafe trait ProjectField: - HasField +pub unsafe trait ProjectField: + HasField where I: invariant::Invariants, { @@ -1302,17 +1311,17 @@ where const IS_INFALLIBLE: bool; } - struct Projection( - PhantomData<(Field, I, T)>, + struct Projection( + PhantomData<(Client, Field, I, T)>, ) where - T: ?Sized + HasField, + T: ?Sized + HasField, I: invariant::Invariants; - impl IsInfallible - for Projection + impl IsInfallible + for Projection where - T: ?Sized + HasField, + T: ?Sized + HasField, I: invariant::Invariants, { const IS_INFALLIBLE: bool = { @@ -1348,7 +1357,7 @@ where } const_assert!( - as IsInfallible>::IS_INFALLIBLE + as IsInfallible>::IS_INFALLIBLE ); Ok(()) diff --git a/zerocopy/src/pointer/mod.rs b/zerocopy/src/pointer/mod.rs index bdb283fdac..d0cfe7fd44 100644 --- a/zerocopy/src/pointer/mod.rs +++ b/zerocopy/src/pointer/mod.rs @@ -240,18 +240,22 @@ pub mod cast { /// /// A `Projection` is a [`Project`] which implements projection by /// delegating to an implementation of [`HasField::project`]. + /// + /// The `Client` parameter exists to select between implementations of + /// [`HasField`] that would otherwise conflict. #[allow(missing_debug_implementations, missing_copy_implementations)] - pub struct Projection { + pub struct Projection { _never: core::convert::Infallible, + _client: PhantomData, _phantom: PhantomData, } // SAFETY: `HasField::project` has the same safety post-conditions as // `Project::project`. - unsafe impl Project - for Projection + unsafe impl + Project for Projection where - T: HasField, + T: HasField, { #[inline(always)] fn project(src: PtrInner<'_, T>) -> *mut T::Type { @@ -292,10 +296,10 @@ pub mod cast { // // FIXME(https://github.com/rust-lang/unsafe-code-guidelines/issues/595): // Cite the documentation once it's updated. - unsafe impl Cast - for Projection + unsafe impl Cast + for Projection where - T: HasField, + T: HasField, { } diff --git a/zerocopy/src/pointer/ptr.rs b/zerocopy/src/pointer/ptr.rs index 487f01fa36..e440985556 100644 --- a/zerocopy/src/pointer/ptr.rs +++ b/zerocopy/src/pointer/ptr.rs @@ -875,19 +875,20 @@ mod _casts { } #[inline(always)] - pub fn project( + pub fn project( mut self, ) -> Result, T::Error> where - T: ProjectField, + T: ProjectField, I::Aliasing: Reference, { use crate::pointer::cast::Projection; match T::is_projectable(self.reborrow().project_tag()) { Ok(()) => { let inner = self.as_inner(); - let projected = inner.project::<_, Projection>(); - // SAFETY: By `T: ProjectField`, + let projected = + inner.project::<_, Projection>(); + // SAFETY: By `T: ProjectField`, // for `self: Ptr<'_, T, I>` such that `T::is_projectable` // (which we've verified in this match arm), // `T::project(self.as_inner())` conforms to diff --git a/zerocopy/src/wrappers.rs b/zerocopy/src/wrappers.rs index 8b52996108..d26bd246d9 100644 --- a/zerocopy/src/wrappers.rs +++ b/zerocopy/src/wrappers.rs @@ -775,14 +775,14 @@ unsafe impl HasTag for ReadOnly { // SAFETY: `ReadOnly` is a `#[repr(transparent)]` wrapper around `T`, and so // has the same fields at the same offsets. Thus, it satisfies the safety -// invariants of `HasField` for field `f` exactly +// invariants of `HasField` for field `f` exactly // when `T` does, as guaranteed by the `T: HasField` bound: // - If `VARIANT_ID` is `STRUCT_VARIANT_ID` or `UNION_VARIANT_ID`, then `T` has // the layout of a struct or union type. Since `ReadOnly` is a transparent // wrapper around `T`, it does too. Otherwise, if `VARIANT_ID` is an enum // variant index, then `T` has the layout of an enum type, and `ReadOnly` // does too. -// - By `T: HasField<_, _, FIELD_ID>`: +// - By `T: HasField<_, _, _, FIELD_ID>`: // - `T` has a field `f` with name `n` such that // `FIELD_ID = zerocopy::ident_id!(n)` or at index `i` such that // `FIELD_ID = zerocopy::ident_id!(i)`. @@ -794,10 +794,10 @@ unsafe impl HasTag for ReadOnly { // refers to a non-strict subset of the bytes of `slf`'s referent, and has the // same provenance as `slf` – because all intermediate operations satisfy those // same conditions. -unsafe impl - HasField for ReadOnly +unsafe impl + HasField for ReadOnly where - T: HasField + ?Sized, + T: HasField + ?Sized, { #[allow(clippy::missing_inline_in_public_items)] fn only_derive_is_allowed_to_implement_this_trait() @@ -811,7 +811,7 @@ where #[inline(always)] fn project(slf: PtrInner<'_, Self>) -> *mut ReadOnly { slf.project::<_, >>::CastFrom>() - .project::<_, crate::pointer::cast::Projection>() + .project::<_, crate::pointer::cast::Projection>() .project::<_, as SizeEq>::CastFrom>() .as_non_null() .as_ptr() @@ -822,10 +822,10 @@ where // has the same fields at the same offsets. `is_projectable` simply delegates to // `T::is_projectable`, which is sound because a `Ptr<'_, ReadOnly, I>` will // be projectable exactly when a `Ptr<'_, T, I>` referent is. -unsafe impl - ProjectField for ReadOnly +unsafe impl + ProjectField for ReadOnly where - T: ProjectField + ?Sized, + T: ProjectField + ?Sized, I: invariant::Invariants, { #[allow(clippy::missing_inline_in_public_items)] diff --git a/zerocopy/zerocopy-derive/src/derive/try_from_bytes.rs b/zerocopy/zerocopy-derive/src/derive/try_from_bytes.rs index 8a7741f397..5777a763a1 100644 --- a/zerocopy/zerocopy-derive/src/derive/try_from_bytes.rs +++ b/zerocopy/zerocopy-derive/src/derive/try_from_bytes.rs @@ -10,7 +10,7 @@ use syn::{ use crate::{ repr::{EnumRepr, StructUnionRepr}, util::{ - const_block, enum_size_from_repr, generate_tag_enum, Ctx, DataExt, FieldBounds, + const_block, enum_size_from_repr, generate_tag_enum, Client, Ctx, DataExt, FieldBounds, ImplBlockBuilder, Trait, TraitBound, }, }; @@ -238,6 +238,7 @@ pub(crate) fn derive_is_bit_valid( let variant_struct_field_index = Index::from(idx + 1); let (_, ty_generics, _) = ctx.ast.generics.split_for_impl(); let has_field_trait = Trait::HasField { + client: Client::TryFromBytesDerive, variant_id: parse_quote!({ #zerocopy_crate::ident_id!(#variant_ident) }), // Since Rust does not presently support explicit visibility // modifiers on enum fields, any public type is suitable here; @@ -260,10 +261,10 @@ pub(crate) fn derive_is_bit_valid( use #zerocopy_crate::pointer::cast::{CastSized, Projection}; slf.project::<___ZerocopyRawEnum #ty_generics, CastSized>() - .project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(variants) }>>() - .project::<_, Projection<_, { #zerocopy_crate::REPR_C_UNION_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variants_union_field_ident) }>>() - .project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(value) }>>() - .project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variant_struct_field_index) }>>() + .project::<_, Projection<#zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(variants) }>>() + .project::<_, Projection<#zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::REPR_C_UNION_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variants_union_field_ident) }>>() + .project::<_, Projection<#zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(value) }>>() + .project::<_, Projection<#zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variant_struct_field_index) }>>() .as_ptr() } }) @@ -273,6 +274,7 @@ pub(crate) fn derive_is_bit_valid( ctx, data, Trait::ProjectField { + client: Client::TryFromBytesDerive, variant_id: parse_quote!({ #zerocopy_crate::ident_id!(#variant_ident) }), // Since Rust does not presently support explicit visibility // modifiers on enum fields, any public type is suitable @@ -321,6 +323,7 @@ pub(crate) fn derive_is_bit_valid( let variant_md = variants.cast::< _, #zerocopy_crate::pointer::cast::Projection< + #zerocopy_crate::TryFromBytesDerive, // #zerocopy_crate::ReadOnly<_>, _, { #zerocopy_crate::REPR_C_UNION_VARIANT_ID }, @@ -431,6 +434,7 @@ pub(crate) fn derive_is_bit_valid( >(); let variants = #zerocopy_crate::into_inner!(raw_enum.project::< + #zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(variants) } @@ -491,6 +495,7 @@ fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream { let field: Box = parse_quote!(#field_token); let field_id: Box = parse_quote!({ #zerocopy_crate::ident_id!(#ident) }); let has_field_trait = Trait::HasField { + client: Client::TryFromBytesDerive, variant_id: variant_id.clone(), field: field.clone(), field_id: field_id.clone(), @@ -530,6 +535,7 @@ fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream { ctx, data, Trait::ProjectField { + client: Client::TryFromBytesDerive, variant_id: variant_id.clone(), field, field_id, @@ -585,6 +591,7 @@ fn derive_try_from_bytes_struct( { true #(&& { let field_candidate = #zerocopy_crate::into_inner!(candidate.reborrow().project::< + #zerocopy_crate::TryFromBytesDerive, _, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(#field_names) } @@ -644,6 +651,7 @@ fn derive_try_from_bytes_union(ctx: &Ctx, unn: &DataUnion, top_level: Trait) -> _, _, #zerocopy_crate::pointer::cast::Projection< + #zerocopy_crate::TryFromBytesDerive, _, #variant_id, { #zerocopy_crate::ident_id!(#field_names) } diff --git a/zerocopy/zerocopy-derive/src/output_tests/expected/from_bytes_union.expected.rs b/zerocopy/zerocopy-derive/src/output_tests/expected/from_bytes_union.expected.rs index 3f10d5743a..43b3862d64 100644 --- a/zerocopy/zerocopy-derive/src/output_tests/expected/from_bytes_union.expected.rs +++ b/zerocopy/zerocopy-derive/src/output_tests/expected/from_bytes_union.expected.rs @@ -81,6 +81,7 @@ const _: () = { #[automatically_derived] const _: () = { unsafe impl ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕa, { ::zerocopy::UNION_VARIANT_ID }, { ::zerocopy::ident_id!(a) }, @@ -91,6 +92,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut () ); @@ -135,7 +136,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -145,7 +147,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -155,7 +158,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -165,7 +169,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -175,7 +180,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) } > () ); @@ -188,7 +194,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) } > () ); @@ -267,6 +274,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -282,6 +290,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -352,6 +362,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -365,6 +376,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -435,6 +448,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -448,6 +462,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -518,6 +534,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -531,6 +548,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -601,6 +620,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -614,6 +634,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -684,6 +706,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) }, @@ -697,6 +720,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ5, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -767,6 +792,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) }, @@ -782,6 +808,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ6, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -897,7 +925,8 @@ const _: () = { true && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) } > () ); @@ -909,7 +938,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -919,7 +949,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -929,7 +960,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -941,7 +973,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -1018,6 +1051,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -1033,6 +1067,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1103,6 +1139,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -1116,6 +1153,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1186,6 +1225,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -1199,6 +1239,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1269,6 +1311,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -1282,6 +1325,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1352,6 +1397,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -1367,6 +1413,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1489,6 +1537,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_StructLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -1501,6 +1550,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_TupleLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, @@ -1545,6 +1596,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__nonempty, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__nonempty) }, @@ -1587,6 +1640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(tag) }, @@ -1684,6 +1739,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕtag, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1751,6 +1808,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) }, @@ -1761,6 +1819,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕvariants, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1852,6 +1912,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(a) }, @@ -1865,6 +1926,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -1964,6 +2031,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(b) }, @@ -1977,6 +2045,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2076,6 +2150,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(c) }, @@ -2089,6 +2164,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2188,6 +2269,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(d) }, @@ -2201,6 +2283,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2300,6 +2388,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(e) }, @@ -2313,6 +2402,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2412,6 +2507,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(0) }, @@ -2425,6 +2521,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2524,6 +2626,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(1) }, @@ -2537,6 +2640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2636,6 +2745,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(2) }, @@ -2649,6 +2759,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2750,8 +2866,8 @@ const _: () = { (::zerocopy::pointer::BecauseRead, _), >(); let variants = ::zerocopy::into_inner!( - raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { - ::zerocopy::ident_id!(variants) } > () + raw_enum.project:: < ::zerocopy::TryFromBytesDerive, _, { + ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) } > () ); match tag { ___ZEROCOPY_TAG_UnitLike => true, @@ -2760,6 +2876,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -2786,6 +2903,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, diff --git a/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs b/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs index 90cb2a815f..3b04367aa9 100644 --- a/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs +++ b/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs @@ -123,7 +123,8 @@ const _: () = { true && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) } > () ); @@ -135,7 +136,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -145,7 +147,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -155,7 +158,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -165,7 +169,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -175,7 +180,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) } > () ); @@ -188,7 +194,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) } > () ); @@ -267,6 +274,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -282,6 +290,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -352,6 +362,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -365,6 +376,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -435,6 +448,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -448,6 +462,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -518,6 +534,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -531,6 +548,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -601,6 +620,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -614,6 +634,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -684,6 +706,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) }, @@ -697,6 +720,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ5, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -767,6 +792,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) }, @@ -782,6 +808,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ6, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -897,7 +925,8 @@ const _: () = { true && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) } > () ); @@ -909,7 +938,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -919,7 +949,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -929,7 +960,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -941,7 +973,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -1018,6 +1051,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -1033,6 +1067,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1103,6 +1139,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -1116,6 +1153,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1186,6 +1225,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -1199,6 +1239,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1269,6 +1311,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -1282,6 +1325,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1352,6 +1397,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -1367,6 +1413,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1489,6 +1537,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_StructLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -1501,6 +1550,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_TupleLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, @@ -1545,6 +1596,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__nonempty, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__nonempty) }, @@ -1587,6 +1640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(tag) }, @@ -1684,6 +1739,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕtag, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1751,6 +1808,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) }, @@ -1761,6 +1819,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕvariants, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1852,6 +1912,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(a) }, @@ -1865,6 +1926,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -1964,6 +2031,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(b) }, @@ -1977,6 +2045,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2076,6 +2150,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(c) }, @@ -2089,6 +2164,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2188,6 +2269,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(d) }, @@ -2201,6 +2283,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2300,6 +2388,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(e) }, @@ -2313,6 +2402,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2412,6 +2507,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(0) }, @@ -2425,6 +2521,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2524,6 +2626,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(1) }, @@ -2537,6 +2640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2636,6 +2745,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(2) }, @@ -2649,6 +2759,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2750,8 +2866,8 @@ const _: () = { (::zerocopy::pointer::BecauseRead, _), >(); let variants = ::zerocopy::into_inner!( - raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { - ::zerocopy::ident_id!(variants) } > () + raw_enum.project:: < ::zerocopy::TryFromBytesDerive, _, { + ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) } > () ); match tag { ___ZEROCOPY_TAG_UnitLike => true, @@ -2760,6 +2876,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -2786,6 +2903,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, diff --git a/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs b/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs index 78238e3c2d..cb7f3d803b 100644 --- a/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs +++ b/zerocopy/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs @@ -123,7 +123,8 @@ const _: () = { true && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) } > () ); @@ -135,7 +136,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -145,7 +147,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -155,7 +158,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -165,7 +169,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -175,7 +180,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) } > () ); @@ -188,7 +194,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) } > () ); @@ -267,6 +274,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -282,6 +290,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -352,6 +362,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -365,6 +376,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -435,6 +448,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -448,6 +462,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -518,6 +534,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -531,6 +548,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -601,6 +620,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -614,6 +634,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -684,6 +706,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(5) }, @@ -697,6 +720,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ5, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -767,6 +792,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(6) }, @@ -782,6 +808,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ6, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -897,7 +925,8 @@ const _: () = { true && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) } > () ); @@ -909,7 +938,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) } > () ); @@ -919,7 +949,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) } > () ); @@ -929,7 +960,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) } > () ); @@ -941,7 +973,8 @@ const _: () = { } && { let field_candidate = ::zerocopy::into_inner!( - candidate.reborrow().project:: < _, { + candidate.reborrow().project:: < + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) } > () ); @@ -1018,6 +1051,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(0) }, @@ -1033,6 +1067,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ0, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1103,6 +1139,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(1) }, @@ -1116,6 +1153,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ1, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1186,6 +1225,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(2) }, @@ -1199,6 +1239,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ2, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1269,6 +1311,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(3) }, @@ -1282,6 +1325,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ3, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1352,6 +1397,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(4) }, @@ -1367,6 +1413,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕ4, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1489,6 +1537,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_StructLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -1501,6 +1550,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__field_TupleLike, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, @@ -1545,6 +1596,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕ__nonempty, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__nonempty) }, @@ -1587,6 +1640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(tag) }, @@ -1684,6 +1739,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕtag, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1751,6 +1808,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) }, @@ -1761,6 +1819,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, ẕvariants, (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1852,6 +1912,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(a) }, @@ -1865,6 +1926,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -1964,6 +2031,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(b) }, @@ -1977,6 +2045,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2076,6 +2150,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(c) }, @@ -2089,6 +2164,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2188,6 +2269,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(d) }, @@ -2201,6 +2283,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2300,6 +2388,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(StructLike) }, { ::zerocopy::ident_id!(e) }, @@ -2313,6 +2402,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(StructLike) }, @@ -2412,6 +2507,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(0) }, @@ -2425,6 +2521,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2524,6 +2626,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(1) }, @@ -2537,6 +2640,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2636,6 +2745,7 @@ const _: () = { Y: Deref, const N: usize, > ::zerocopy::HasField< + ::zerocopy::TryFromBytesDerive, (), { ::zerocopy::ident_id!(TupleLike) }, { ::zerocopy::ident_id!(2) }, @@ -2649,6 +2759,7 @@ const _: () = { fn project( slf: ::zerocopy::pointer::PtrInner<'_, Self>, ) -> *mut ::zerocopy::ProjectField< + ::zerocopy::TryFromBytesDerive, (), (Aliasing, Alignment, ::zerocopy::invariant::Initialized), { ::zerocopy::ident_id!(TupleLike) }, @@ -2750,8 +2866,8 @@ const _: () = { (::zerocopy::pointer::BecauseRead, _), >(); let variants = ::zerocopy::into_inner!( - raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { - ::zerocopy::ident_id!(variants) } > () + raw_enum.project:: < ::zerocopy::TryFromBytesDerive, _, { + ::zerocopy::STRUCT_VARIANT_ID }, { ::zerocopy::ident_id!(variants) } > () ); match tag { ___ZEROCOPY_TAG_UnitLike => true, @@ -2760,6 +2876,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_StructLike) }, @@ -2786,6 +2903,7 @@ const _: () = { .cast::< _, ::zerocopy::pointer::cast::Projection< + ::zerocopy::TryFromBytesDerive, _, { ::zerocopy::REPR_C_UNION_VARIANT_ID }, { ::zerocopy::ident_id!(__field_TupleLike) }, diff --git a/zerocopy/zerocopy-derive/src/util.rs b/zerocopy/zerocopy-derive/src/util.rs index 933b7b3e67..6f18f3e5d9 100644 --- a/zerocopy/zerocopy-derive/src/util.rs +++ b/zerocopy/zerocopy-derive/src/util.rs @@ -298,16 +298,40 @@ impl PaddingCheck { } } +#[derive(Clone)] +pub(crate) enum Client { + TryFromBytesDerive, +} + +impl ToTokens for Client { + fn to_tokens(&self, tokens: &mut TokenStream) { + let s = match self { + Client::TryFromBytesDerive => "TryFromBytesDerive", + }; + let ident = Ident::new(s, Span::call_site()); + tokens.extend(quote!(#ident)); + } +} + +impl Client { + pub(crate) fn crate_path(&self, ctx: &Ctx) -> Path { + let zerocopy_crate = &ctx.zerocopy_crate; + parse_quote!(#zerocopy_crate::#self) + } +} + #[derive(Clone)] pub(crate) enum Trait { KnownLayout, HasTag, HasField { + client: Client, variant_id: Box, field: Box, field_id: Box, }, ProjectField { + client: Client, variant_id: Box, field: Box, field_id: Box, @@ -354,11 +378,11 @@ impl ToTokens for Trait { }; let ident = Ident::new(s, Span::call_site()); let arguments: Option = match self { - Trait::HasField { variant_id, field, field_id } => { - Some(parse_quote!(<#field, #variant_id, #field_id>)) + Trait::HasField { client, variant_id, field, field_id } => { + Some(parse_quote!(<#client, #field, #variant_id, #field_id>)) } - Trait::ProjectField { variant_id, field, field_id, invariants } => { - Some(parse_quote!(<#field, #invariants, #variant_id, #field_id>)) + Trait::ProjectField { client, variant_id, field, field_id, invariants } => { + Some(parse_quote!(<#client, #field, #invariants, #variant_id, #field_id>)) } Trait::KnownLayout | Trait::HasTag @@ -383,6 +407,22 @@ impl Trait { let core = ctx.core_path(); match self { Self::Sized => parse_quote!(#core::marker::#self), + Self::HasField { client, variant_id, field, field_id } => { + let client = client.crate_path(ctx); + parse_quote!(#zerocopy_crate::HasField<#client, #field, #variant_id, #field_id>) + } + Self::ProjectField { client, variant_id, field, field_id, invariants } => { + let client = client.crate_path(ctx); + parse_quote!( + #zerocopy_crate::ProjectField< + #client, + #field, + #invariants, + #variant_id, + #field_id + > + ) + } _ => parse_quote!(#zerocopy_crate::#self), } } diff --git a/zerocopy/zerocopy-derive/tests/ui/privacy.msrv.stderr b/zerocopy/zerocopy-derive/tests/ui/privacy.msrv.stderr index b0ece5da3b..e10a5cdf72 100644 --- a/zerocopy/zerocopy-derive/tests/ui/privacy.msrv.stderr +++ b/zerocopy/zerocopy-derive/tests/ui/privacy.msrv.stderr @@ -31,42 +31,42 @@ error[E0747]: type provided when a constant was expected = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:135:52 + --> $DIR/privacy.rs:135:90 | -135 | let _: >::Type = - | ^ +135 | let _: >::Type = + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:138:52 + --> $DIR/privacy.rs:138:90 | -138 | let _: >::Type = - | ^ +138 | let _: >::Type = + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:145:51 + --> $DIR/privacy.rs:145:89 | -145 | let _: >::Type = - | ^ +145 | let _: >::Type = + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:148:51 + --> $DIR/privacy.rs:148:89 | -148 | let _: >::Type = - | ^ +148 | let _: >::Type = + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:152:51 + --> $DIR/privacy.rs:152:89 | -152 | let _: >::Type = - | ^ +152 | let _: >::Type = + | ^ | = help: const arguments cannot yet be inferred with `_` @@ -103,42 +103,42 @@ error[E0747]: type provided when a constant was expected = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:70:56 + --> $DIR/privacy.rs:70:94 | -70 | let _: >::Type = 0u8; - | ^ +70 | ... let _: >::Type ... + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:72:56 + --> $DIR/privacy.rs:72:94 | -72 | let _: >::Type = 0u16; - | ^ +72 | ... let _: >::Type ... + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:85:55 + --> $DIR/privacy.rs:85:93 | -85 | let _: >::Type = 0u8; - | ^ +85 | ... let _: >::Type =... + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:87:55 + --> $DIR/privacy.rs:87:93 | -87 | let _: >::Type = 0u16; - | ^ +87 | ... let _: >::Type =... + | ^ | = help: const arguments cannot yet be inferred with `_` error[E0747]: type provided when a constant was expected - --> $DIR/privacy.rs:90:55 + --> $DIR/privacy.rs:90:93 | -90 | let _: >::Type = 0u8; - | ^ +90 | ... let _: >::Type =... + | ^ | = help: const arguments cannot yet be inferred with `_` diff --git a/zerocopy/zerocopy-derive/tests/ui/privacy.nightly.stderr b/zerocopy/zerocopy-derive/tests/ui/privacy.nightly.stderr index fece5130c2..71ece92ea9 100644 --- a/zerocopy/zerocopy-derive/tests/ui/privacy.nightly.stderr +++ b/zerocopy/zerocopy-derive/tests/ui/privacy.nightly.stderr @@ -23,10 +23,10 @@ error: type `private::_::_::_::ẕ1` is private | ^ private type error: type `private::_::_::_::ẕb` is private - --> $DIR/privacy.rs:138:49 + --> $DIR/privacy.rs:138:87 | -138 | let _: >:... - | ^ private type +138 | ...erocopy_renamed::TryFromBytesDerive, _, _, { zerocopy_renamed::ident_id!(b) }>>::Type = + | ^ private type error: aborting due to 3 previous errors; 1 warning emitted diff --git a/zerocopy/zerocopy-derive/tests/ui/privacy.rs b/zerocopy/zerocopy-derive/tests/ui/privacy.rs index 58db7467d5..8ec654c617 100644 --- a/zerocopy/zerocopy-derive/tests/ui/privacy.rs +++ b/zerocopy/zerocopy-derive/tests/ui/privacy.rs @@ -27,12 +27,14 @@ mod private { const _: () = { let _: >::Type = 0u8; let _: >::Type = 0u8; let _: >::Type = 0u8; + let _: >::Type = 0u8; //~[msrv]^ ERROR: type provided when a constant was expected - let _: >::Type = 0u16; + let _: >::Type = 0u16; //~[msrv]^ ERROR: type provided when a constant was expected }; @@ -82,14 +96,30 @@ mod private { } const _: () = { - let _: >::Type = 0u8; + let _: >::Type = 0u8; //~[msrv]^ ERROR: type provided when a constant was expected - let _: >::Type = 0u16; + let _: >::Type = 0u16; //~[msrv]^ ERROR: type provided when a constant was expected - let _: >::Type = 0u8; + let _: >::Type = 0u8; //~[msrv]^ ERROR: type provided when a constant was expected let _: >::Type = 0u8; let _: >::Type = 0u8; let _: >::Type = + let _: >::Type = //~[msrv]^ ERROR: type provided when a constant was expected 0u8; - let _: >::Type = + let _: >::Type = //~[msrv]^ ERROR: type provided when a constant was expected //~[stable, nightly]^^ ERROR: type `private::_::_::_::ẕb` is private 0u16; }; const _: () = { - let _: >::Type = + let _: >::Type = //~[msrv]^ ERROR: type provided when a constant was expected 0u8; - let _: >::Type = + let _: >::Type = //~[msrv]^ ERROR: type provided when a constant was expected 0u16; - let _: >::Type = + let _: >::Type = //~[msrv]^ ERROR: type provided when a constant was expected 0u8; let _: $DIR/privacy.rs:138:49 + --> $DIR/privacy.rs:138:87 | -138 | let _: >:... - | ^ private type +138 | ...erocopy_renamed::TryFromBytesDerive, _, _, { zerocopy_renamed::ident_id!(b) }>>::Type = + | ^ private type error: aborting due to 3 previous errors; 1 warning emitted