From 2974513d7af78d650e0b3967caf33525e7bc59e6 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Wed, 14 Jan 2026 19:02:38 +0000 Subject: [PATCH] Introduce `ProjectField` trait This trait powers invariant-respecting projection over `Ptr`s. gherrit-pr-id: Gb6fa34cec5080caffa0980ed1d3e1ae273550f44 --- src/impls.rs | 82 +- src/lib.rs | 101 +- src/pointer/inner.rs | 4 +- src/pointer/invariant.rs | 27 +- src/pointer/ptr.rs | 52 +- src/util/macro_util.rs | 12 + .../ui-nightly/ptr-is-invariant-over-v.stderr | 4 +- .../ui-stable/ptr-is-invariant-over-v.stderr | 4 +- zerocopy-derive/src/derive/try_from_bytes.rs | 132 ++- .../try_from_bytes_enum_1.expected.rs | 1037 +++++++++++++++-- .../try_from_bytes_enum_2.expected.rs | 1037 +++++++++++++++-- .../try_from_bytes_enum_3.expected.rs | 1037 +++++++++++++++-- zerocopy-derive/src/util.rs | 54 +- 13 files changed, 3289 insertions(+), 294 deletions(-) diff --git a/src/impls.rs b/src/impls.rs index 2e6094455f..0263807113 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -1019,8 +1019,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(c.reborrow().project::<_, { crate::ident_id!($head_I) }>()) &&)* - TryFromBytes::is_bit_valid(c.reborrow().project::<_, { crate::ident_id!($next_I) }>()) + $(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) }>())) }); // SAFETY: If all fields in `Self` are `FromZeros`, so too is `Self`. @@ -1083,6 +1083,84 @@ mod tuples { } } + // SAFETY: See comments on items. + unsafe impl crate::ProjectField< + (), + (Aliasing, Alignment, crate::invariant::Uninit), + { crate::STRUCT_VARIANT_ID }, + { crate::ident_id!($CurrI)} + > for ($($AllT,)+) + where + Aliasing: crate::invariant::Aliasing, + Alignment: crate::invariant::Alignment, + { + #[inline] + fn only_derive_is_allowed_to_implement_this_trait() + where + Self: Sized + {} + + // SAFETY: Tuples are product types whose fields are + // well-aligned, so projection preserves both the alignment and + // validity invariants of the outer pointer. + type Invariants = (Aliasing, Alignment, crate::invariant::Uninit); + + // SAFETY: Tuples are product types and so projection is infallible; + type Error = core::convert::Infallible; + } + + // SAFETY: See comments on items. + unsafe impl crate::ProjectField< + (), + (Aliasing, Alignment, crate::invariant::Initialized), + { crate::STRUCT_VARIANT_ID }, + { crate::ident_id!($CurrI)} + > for ($($AllT,)+) + where + Aliasing: crate::invariant::Aliasing, + Alignment: crate::invariant::Alignment, + { + #[inline] + fn only_derive_is_allowed_to_implement_this_trait() + where + Self: Sized + {} + + // SAFETY: Tuples are product types whose fields are + // well-aligned, so projection preserves both the alignment and + // validity invariants of the outer pointer. + type Invariants = (Aliasing, Alignment, crate::invariant::Initialized); + + // SAFETY: Tuples are product types and so projection is infallible; + type Error = core::convert::Infallible; + } + + // SAFETY: See comments on items. + unsafe impl crate::ProjectField< + (), + (Aliasing, Alignment, crate::invariant::Valid), + { crate::STRUCT_VARIANT_ID }, + { crate::ident_id!($CurrI)} + > for ($($AllT,)+) + where + Aliasing: crate::invariant::Aliasing, + Alignment: crate::invariant::Alignment, + { + #[inline] + fn only_derive_is_allowed_to_implement_this_trait() + where + Self: Sized + {} + + // SAFETY: Tuples are product types whose fields are + // well-aligned, so projection preserves both the alignment and + // validity invariants of the outer pointer. + type Invariants = (Aliasing, Alignment, crate::invariant::Valid); + + // SAFETY: Tuples are product types and so projection is infallible; + type Error = core::convert::Infallible; + } + // Recurse to the next index. impl_tuple!(@variants [$($AllT $AllI)+] [$($BeforeT)* $CurrT] [$($AfterT $AfterI)*]); }; diff --git a/src/lib.rs b/src/lib.rs index 6b62bb8c7b..49f60e06c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -375,7 +375,8 @@ use core::{ #[cfg(feature = "std")] use std::io; -use crate::pointer::invariant::{self, BecauseExclusive}; +#[doc(hidden)] +pub use crate::pointer::invariant::{self, BecauseExclusive}; #[doc(hidden)] pub use crate::pointer::PtrInner; pub use crate::{ @@ -1151,6 +1152,104 @@ pub unsafe trait HasField { fn project(slf: PtrInner<'_, Self>) -> *mut Self::Type; } +/// Projects a given field from `Self`. +/// +/// Implementations of this trait encode the conditions under which a field can +/// be projected from a `Ptr<'_, Self, I>`, and how the invariants of that +/// [`Ptr`] (`I`) determine the invariants of pointers projected from it. In +/// other words, it is a type-level function over invariants; `I` goes in, +/// `Self::Invariants` comes out. +/// +/// # Safety +/// +/// `T: ProjectField` if, for a +/// `slf: Ptr<'_, T, I>` such that `if let Ok(ptr) = T::is_projectable(slf)`, +/// `>::project(ptr.as_inner())` +/// conforms to `T::Invariants`. +#[doc(hidden)] +pub unsafe trait ProjectField: + HasField +where + I: invariant::Invariants, +{ + fn only_derive_is_allowed_to_implement_this_trait() + where + Self: Sized; + + /// The invariants of the projected field pointer, with respect to the + /// invariants, `I`, of the containing pointer. The aliasing dimension of + /// the invariants is guaranteed to remain unchanged. + type Invariants: invariant::Invariants; + + /// The failure mode of projection. `()` if the projection is fallible, + /// otherwise [`core::convert::Infallible`]. + type Error; + + /// Is the given field projectable from `ptr`? + /// + /// If a field with [`Self::Invariants`] is projectable from the referent, + /// this function produces an `Ok(ptr)` from which the projection can be + /// made; otherwise `Err`. + /// + /// This method must be overriden if the field's projectability depends on + /// the value of the bytes in `ptr`. + #[inline(always)] + fn is_projectable<'a>(ptr: Ptr<'a, Self, I>) -> Result, Self::Error> { + trait IsInfallible { + const IS_INFALLIBLE: bool; + } + + struct Projection( + PhantomData<(Field, I, T)>, + ) + where + T: ?Sized + HasField, + I: invariant::Invariants; + + impl IsInfallible + for Projection + where + T: ?Sized + HasField, + I: invariant::Invariants, + { + const IS_INFALLIBLE: bool = { + let is_infallible = match VARIANT_ID { + // For nondestructive projections of struct and union + // fields, the projected field's satisfaction of + // `Invariants` does not depend on the value of the + // referent. This default implementation of `is_projectable` + // is non-destructive, as it does not overwrite any part of + // the referent. + crate::STRUCT_VARIANT_ID | crate::UNION_VARIANT_ID => true, + _enum_variant => { + use crate::invariant::{Validity, ValidityKind}; + match I::Validity::KIND { + // The projectability of a field from an `Uninit` or + // `Initialized` union cannot generally depend on + // the referent's value, because the union's + // discriminant is not in a valid state, and thus + // cannot be used to discriminate between variants. + ValidityKind::Uninit | ValidityKind::Initialized => true, + // The projectability of an enum field from an + // `AsInitialized` or `Valid` state is a dynamic + // property of its tag. + ValidityKind::AsInitialized | ValidityKind::Valid => false, + } + } + }; + const_assert!(is_infallible); + is_infallible + }; + } + + const_assert!( + as IsInfallible>::IS_INFALLIBLE + ); + + Ok(ptr) + } +} + /// Analyzes whether a type is [`FromZeros`]. /// /// This derive analyzes, at compile time, whether the annotated type satisfies diff --git a/src/pointer/inner.rs b/src/pointer/inner.rs index 70d60caa0b..3136149dfa 100644 --- a/src/pointer/inner.rs +++ b/src/pointer/inner.rs @@ -178,8 +178,8 @@ impl<'a, T: ?Sized> PtrInner<'a, T> { /// # Safety /// - /// The caller may assume that the resulting `PtrInner` addresses a subset - /// of the bytes of `self`'s referent. + /// The caller may assume that the resulting `PtrInner` addresses the subset + /// of the bytes of `self`'s referent addressed by `C::project(self)`. #[must_use] #[inline(always)] pub fn project>(self) -> PtrInner<'a, U> { diff --git a/src/pointer/invariant.rs b/src/pointer/invariant.rs index 90ab1a8734..804ff984a5 100644 --- a/src/pointer/invariant.rs +++ b/src/pointer/invariant.rs @@ -83,7 +83,16 @@ pub trait Alignment: Sealed {} /// mechanism (e.g. a `&` reference used to derive `src`) to write `x` where /// `x ∈ S(T, V)` but `x ∉ S(U, W)`, which would violate the guarantee that /// `dst`'s referent may only contain values in `S(U, W)`. -pub unsafe trait Validity: Sealed {} +pub unsafe trait Validity: Sealed { + const KIND: ValidityKind; +} + +pub enum ValidityKind { + Uninit, + AsInitialized, + Initialized, + Valid, +} /// An [`Aliasing`] invariant which is either [`Shared`] or [`Exclusive`]. /// @@ -137,7 +146,9 @@ pub enum Uninit {} // function of any property of `T` other than its bit validity (in fact, it's // not even a property of `T`'s bit validity, but this is more than we are // required to uphold). -unsafe impl Validity for Uninit {} +unsafe impl Validity for Uninit { + const KIND: ValidityKind = ValidityKind::Uninit; +} /// The byte ranges initialized in `T` are also initialized in the referent of a /// `Ptr`. @@ -169,7 +180,9 @@ unsafe impl Validity for Uninit {} pub enum AsInitialized {} // SAFETY: `AsInitialized`'s validity is well-defined for all `T: ?Sized`, and // is not a function of any property of `T` other than its bit validity. -unsafe impl Validity for AsInitialized {} +unsafe impl Validity for AsInitialized { + const KIND: ValidityKind = ValidityKind::AsInitialized; +} /// The byte ranges in the referent are fully initialized. In other words, if /// the referent is `N` bytes long, then it contains a bit-valid `[u8; N]`. @@ -178,14 +191,18 @@ pub enum Initialized {} // not a function of any property of `T` other than its bit validity (in fact, // it's not even a property of `T`'s bit validity, but this is more than we are // required to uphold). -unsafe impl Validity for Initialized {} +unsafe impl Validity for Initialized { + const KIND: ValidityKind = ValidityKind::Initialized; +} /// The referent of a `Ptr` is valid for `T`, upholding bit validity and any /// library safety invariants. pub enum Valid {} // SAFETY: `Valid`'s validity is well-defined for all `T: ?Sized`, and is not a // function of any property of `T` other than its bit validity. -unsafe impl Validity for Valid {} +unsafe impl Validity for Valid { + const KIND: ValidityKind = ValidityKind::Valid; +} /// # Safety /// diff --git a/src/pointer/ptr.rs b/src/pointer/ptr.rs index bb068d9171..c1bf7ffda3 100644 --- a/src/pointer/ptr.rs +++ b/src/pointer/ptr.rs @@ -864,7 +864,7 @@ mod _casts { use super::*; use crate::{ pointer::cast::{AsBytesCast, Cast}, - HasField, + ProjectField, }; impl<'a, T, I> Ptr<'a, T, I> @@ -929,35 +929,35 @@ mod _casts { unsafe { self.cast_unchecked::<_, C>() } } - // FIXME(#196): Support all validity invariants (not just those that are - // `CastableFrom`). - #[must_use] #[inline(always)] - pub fn project( + pub fn project( self, - ) -> Ptr<'a, T::Type, (I::Aliasing, Unaligned, I::Validity)> + ) -> Result, T::Error> where - T: HasField, - T::Type: 'a + CastableFrom, + T: ProjectField, { - let ptr = self.as_inner().project::<_, crate::pointer::cast::Projection< - F, - { crate::STRUCT_VARIANT_ID }, - FIELD_ID, - >>(); - - // SAFETY: - // 0. `PtrInner::project` promises that it produces a pointer which - // references a subset of its argument's referent. Since, by - // invariant on `Ptr`, its argument (`self.as_inner()`) satisfies - // the aliasing invariant `I::Aliasing`, so does `ptr`. - // 1. The `Ptr` has alignment `Unaligned`, which is trivially - // satisfied. - // 2. By `CastableFrom`, `I::Validity` - // is `Uninit` or `Initialized`. In either case, if `I::Validity` - // holds of `self`'s referent, then it holds any subset of its - // referent. - unsafe { Ptr::from_inner(ptr) } + use crate::pointer::cast::Projection; + match T::is_projectable(self) { + Ok(ptr) => { + let inner = ptr.as_inner(); + 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 + // `T::Invariants`. The `projected` pointer satisfies these + // invariants because it is produced by way of an + // abstraction that is equivalent to + // `T::project(ptr.as_inner())`: by invariant on + // `PtrInner::project`, `projected` is guaranteed to address + // the subset of the bytes of `inner`'s referent addressed + // by `Projection::project(inner)`, and by invariant on + // `Projection`, `Projection::project` is implemented by + // delegating to an implementation of `HasField::project`. + Ok(unsafe { Ptr::from_inner(projected) }) + } + Err(err) => Err(err), + } } } diff --git a/src/util/macro_util.rs b/src/util/macro_util.rs index ebbaf9e6ae..dce1358087 100644 --- a/src/util/macro_util.rs +++ b/src/util/macro_util.rs @@ -530,6 +530,18 @@ macro_rules! assert_size_eq { }}; } +/// Unwraps an infallible `Result`. +#[doc(hidden)] +#[macro_export] +macro_rules! into_inner { + ($e:expr) => { + match $e { + $crate::util::macro_util::core_reexport::result::Result::Ok(e) => e, + $crate::util::macro_util::core_reexport::result::Result::Err(i) => match i {}, + } + }; +} + /// Translates an identifier or tuple index into a numeric identifier. #[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`. #[macro_export] diff --git a/tests/ui-nightly/ptr-is-invariant-over-v.stderr b/tests/ui-nightly/ptr-is-invariant-over-v.stderr index 80cc65a584..83a7516f30 100644 --- a/tests/ui-nightly/ptr-is-invariant-over-v.stderr +++ b/tests/ui-nightly/ptr-is-invariant-over-v.stderr @@ -10,7 +10,7 @@ error: lifetime may not live long enough | ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big` | = help: consider adding the following bound: `'small: 'big` - = note: requirement occurs because of the type `Ptr<'_, &u32, (invariant::Exclusive, Aligned, Valid)>`, which makes the generic argument `&u32` invariant + = note: requirement occurs because of the type `Ptr<'_, &u32, (zerocopy::invariant::Exclusive, Aligned, zerocopy::invariant::Valid)>`, which makes the generic argument `&u32` invariant = note: the struct `Ptr<'a, T, I>` is invariant over the parameter `T` = help: see for more information about variance @@ -26,6 +26,6 @@ error: lifetime may not live long enough | ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big` | = help: consider adding the following bound: `'small: 'big` - = note: requirement occurs because of the type `Ptr<'_, &u32, (Shared, Aligned, Valid)>`, which makes the generic argument `&u32` invariant + = note: requirement occurs because of the type `Ptr<'_, &u32, (Shared, Aligned, zerocopy::invariant::Valid)>`, which makes the generic argument `&u32` invariant = note: the struct `Ptr<'a, T, I>` is invariant over the parameter `T` = help: see for more information about variance diff --git a/tests/ui-stable/ptr-is-invariant-over-v.stderr b/tests/ui-stable/ptr-is-invariant-over-v.stderr index b3559596f1..ddb8c74032 100644 --- a/tests/ui-stable/ptr-is-invariant-over-v.stderr +++ b/tests/ui-stable/ptr-is-invariant-over-v.stderr @@ -10,7 +10,7 @@ error: lifetime may not live long enough | ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big` | = help: consider adding the following bound: `'small: 'big` - = note: requirement occurs because of the type `Ptr<'_, &u32, (invariant::Exclusive, Aligned, Valid)>`, which makes the generic argument `&u32` invariant + = note: requirement occurs because of the type `Ptr<'_, &u32, (zerocopy::invariant::Exclusive, Aligned, zerocopy::invariant::Valid)>`, which makes the generic argument `&u32` invariant = note: the struct `Ptr<'a, T, I>` is invariant over the parameter `T` = help: see for more information about variance @@ -26,6 +26,6 @@ error: lifetime may not live long enough | ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big` | = help: consider adding the following bound: `'small: 'big` - = note: requirement occurs because of the type `Ptr<'_, &u32, (Shared, Aligned, Valid)>`, which makes the generic argument `&u32` invariant + = note: requirement occurs because of the type `Ptr<'_, &u32, (Shared, Aligned, zerocopy::invariant::Valid)>`, which makes the generic argument `&u32` invariant = note: the struct `Ptr<'a, T, I>` is invariant over the parameter `T` = help: see for more information about variance diff --git a/zerocopy-derive/src/derive/try_from_bytes.rs b/zerocopy-derive/src/derive/try_from_bytes.rs index f47b229fc3..d1ac737397 100644 --- a/zerocopy-derive/src/derive/try_from_bytes.rs +++ b/zerocopy-derive/src/derive/try_from_bytes.rs @@ -238,7 +238,7 @@ pub(crate) fn derive_is_bit_valid( field_id: parse_quote!({ #zerocopy_crate::ident_id!(#ident) }), }; let has_field_path = has_field_trait.crate_path(ctx); - ImplBlockBuilder::new( + let has_field = ImplBlockBuilder::new( ctx, data, has_field_trait, @@ -259,7 +259,36 @@ pub(crate) fn derive_is_bit_valid( .as_ptr() } }) - .build() + .build(); + + let project = ImplBlockBuilder::new( + ctx, + data, + Trait::ProjectField { + 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; we use `()`. + field: field.clone(), + field_id: parse_quote!({ #zerocopy_crate::ident_id!(#ident) }), + invariants: parse_quote!((Aliasing, Alignment, #zerocopy_crate::invariant::Initialized)), + }, + FieldBounds::None, + ) + .param_extras(vec![ + parse_quote!(Aliasing: #zerocopy_crate::invariant::Aliasing), + parse_quote!(Alignment: #zerocopy_crate::invariant::Alignment), + ]) + .inner_extras(quote! { + type Error = #zerocopy_crate::util::macro_util::core_reexport::convert::Infallible; + type Invariants = (Aliasing, Alignment, #zerocopy_crate::invariant::Initialized); + }) + .build(); + + quote! { + #has_field + #project + } }) }); @@ -333,7 +362,7 @@ pub(crate) fn derive_is_bit_valid( // check the bit validity of each field of the corresponding variant. // Thus, this is a sound implementation of `is_bit_valid`. fn is_bit_valid<___ZerocopyAliasing>( - candidate: #zerocopy_crate::Maybe<'_, Self, ___ZerocopyAliasing>, + mut candidate: #zerocopy_crate::Maybe<'_, Self, ___ZerocopyAliasing>, ) -> #core::primitive::bool where ___ZerocopyAliasing: #zerocopy_crate::pointer::invariant::Reference, @@ -349,23 +378,6 @@ pub(crate) fn derive_is_bit_valid( type ___ZerocopyOuterTag = #outer_tag_type; type ___ZerocopyInnerTag = #inner_tag_type; - // SAFETY: `___ZerocopyRawEnum` is designed to match the layout of - // the `Self` enum, which has a `___ZerocopyTag` tag as its first - // field. - // - // `project` is implemented using a cast which preserves or shrinks - // the set of referent bytes and preserves provenance. - unsafe impl #generics #zerocopy_crate::HasField<(), { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(tag) }> for ___ZerocopyRawEnum #ty_generics { - fn only_derive_is_allowed_to_implement_this_trait() {} - - type Type = ___ZerocopyTag; - - #[inline(always)] - fn project(slf: #zerocopy_crate::pointer::PtrInner<'_, Self>) -> *mut >::Type { - slf.as_ptr().cast() - } - } - #variant_structs #variants_union @@ -374,25 +386,42 @@ pub(crate) fn derive_is_bit_valid( #(#has_fields)* + let tag = { + // SAFETY: + // - The provided cast addresses a subset of the bytes addressed + // by `candidate` because it addresses the starting tag of the + // enum. + // - Because the pointer is cast from `candidate`, it has the + // same provenance as it. + // - There are no `UnsafeCell`s in the tag because it is a + // primitive integer. + // - `tag_ptr` is casted from `candidate`, whose referent is + // `Initialized`. Since we have not written uninitialized + // bytes into the referent, `tag_ptr` is also `Initialized`. + // + // FIXME(#2874): Revise this to a `cast` once `candidate` + // references a `ReadOnly`. + let tag_ptr = unsafe { + candidate.reborrow().project_transmute_unchecked::< + _, + #zerocopy_crate::invariant::Initialized, + #zerocopy_crate::pointer::cast::CastSized + >() + }; + tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<#zerocopy_crate::BecauseImmutable>() + }; + let mut raw_enum = candidate.cast::< ___ZerocopyRawEnum #ty_generics, #zerocopy_crate::pointer::cast::CastSized, #zerocopy_crate::pointer::BecauseInvariantsEq >(); - let tag = { - let tag_ptr = raw_enum.reborrow().project::< - (), - { #zerocopy_crate::ident_id!(tag) } - >().cast::< - ___ZerocopyTagPrimitive, - #zerocopy_crate::pointer::cast::CastSized, - _ - >(); - tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<#zerocopy_crate::BecauseImmutable>() - }; - - let variants = raw_enum.project::<_, { #zerocopy_crate::ident_id!(variants) }>(); + let variants = #zerocopy_crate::into_inner!(raw_enum.project::< + _, + { #zerocopy_crate::STRUCT_VARIANT_ID }, + { #zerocopy_crate::ident_id!(variants) } + >()); match tag { #(#match_arms,)* @@ -511,6 +540,41 @@ fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream { { } } + } else if matches!(&ctx.ast.data, Data::Struct(..)) { + let fields_preserve_alignment = StructUnionRepr::from_attrs(&ctx.ast.attrs) + .map(|repr| repr.get_packed().is_none()) + .unwrap(); + let alignment = if fields_preserve_alignment { + quote! { Alignment } + } else { + quote! { #zerocopy_crate::invariant::Unaligned } + }; + // SAFETY: See comments on items. + ImplBlockBuilder::new( + ctx, + data, + Trait::ProjectField { + variant_id: variant_id.clone(), + field: field.clone(), + field_id: field_id.clone(), + invariants: parse_quote!((Aliasing, Alignment, #zerocopy_crate::invariant::Initialized)), + }, + FieldBounds::None, + ) + .param_extras(vec![ + parse_quote!(Aliasing: #zerocopy_crate::invariant::Aliasing), + parse_quote!(Alignment: #zerocopy_crate::invariant::Alignment), + ]) + .inner_extras(quote! { + // SAFETY: Projection into structs is always infallible. + type Error = #zerocopy_crate::util::macro_util::core_reexport::convert::Infallible; + // SAFETY: The alignment of the projected `Ptr` is `Unaligned` + // if the structure is packed; otherwise inherited from the + // outer `Ptr`. If the validity of the outer pointer is + // `Initialized`, so too is the validity of its fields. + type Invariants = (Aliasing, #alignment, #zerocopy_crate::invariant::Initialized); + }) + .build() } else { quote! {} }) @@ -545,8 +609,10 @@ fn derive_try_from_bytes_struct( true #(&& { let field_candidate = candidate.reborrow().project::< _, + { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(#field_names) } >(); + let field_candidate = #zerocopy_crate::into_inner!(field_candidate); <#field_tys as #zerocopy_crate::TryFromBytes>::is_bit_valid(field_candidate) })* } diff --git a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_1.expected.rs b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_1.expected.rs index 432ce87551..a8c73912d1 100644 --- a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_1.expected.rs +++ b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_1.expected.rs @@ -11,7 +11,7 @@ #[deny(ambiguous_associated_items)] #[automatically_derived] const _: () = { - unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes + unsafe impl<'a: 'static, X, Y: Deref, const N: usize> ::zerocopy::TryFromBytes for ComplexWithGenerics<'a, { N }, X, Y> where X: Deref, @@ -26,7 +26,7 @@ const _: () = { { fn only_derive_is_allowed_to_implement_this_trait() {} fn is_bit_valid<___ZerocopyAliasing>( - candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, + mut candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, ) -> ::zerocopy::util::macro_util::core_reexport::primitive::bool where ___ZerocopyAliasing: ::zerocopy::pointer::invariant::Reference, @@ -56,29 +56,6 @@ const _: () = { as ___ZerocopyTagPrimitive; type ___ZerocopyOuterTag = (); type ___ZerocopyInnerTag = ___ZerocopyTag; - unsafe impl< - 'a: 'static, - const N: usize, - X, - Y: Deref, - > ::zerocopy::HasField< - (), - { ::zerocopy::STRUCT_VARIANT_ID }, - { ::zerocopy::ident_id!(tag) }, - > for ___ZerocopyRawEnum<'a, N, X, Y> { - fn only_derive_is_allowed_to_implement_this_trait() {} - type Type = ___ZerocopyTag; - #[inline(always)] - fn project( - slf: ::zerocopy::pointer::PtrInner<'_, Self>, - ) -> *mut >::Type { - slf.as_ptr().cast() - } - } #[repr(C)] struct ___ZerocopyVariantStruct_StructLike< 'a: 'static, @@ -115,9 +92,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> where @@ -145,7 +122,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -155,7 +139,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -163,7 +154,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -171,7 +169,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -179,7 +184,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -187,7 +199,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(5) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <[( X, Y, @@ -198,7 +217,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(6) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -242,9 +268,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -273,6 +299,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -289,9 +353,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -318,6 +382,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -334,9 +436,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -363,6 +465,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -379,9 +519,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -408,6 +548,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -424,9 +602,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -453,6 +631,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -469,9 +685,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -498,6 +714,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ5, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -514,9 +768,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -545,6 +799,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ6, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -582,9 +874,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> where @@ -610,7 +902,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -620,7 +919,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -628,7 +934,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -636,7 +949,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -646,7 +966,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -688,9 +1015,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -719,6 +1046,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -735,9 +1100,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -764,6 +1129,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -780,9 +1183,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -809,6 +1212,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -825,9 +1266,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -854,6 +1295,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -870,9 +1349,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -901,6 +1380,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -945,9 +1462,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_StructLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1005,9 +1522,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_TupleLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1065,9 +1582,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__nonempty, { ::zerocopy::UNION_VARIANT_ID }, @@ -1152,9 +1669,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1178,6 +1695,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕtag, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -1194,9 +1746,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1220,6 +1772,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕvariants, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; #[allow( @@ -1237,9 +1824,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1311,9 +1898,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(a) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1385,9 +2010,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(b) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1459,9 +2122,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(c) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1533,9 +2234,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(d) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1607,9 +2346,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(e) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1681,9 +2458,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(0) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1755,9 +2570,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(1) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1814,26 +2667,68 @@ const _: () = { } } }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(2) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + let tag = { + let tag_ptr = unsafe { + candidate + .reborrow() + .project_transmute_unchecked::< + _, + ::zerocopy::invariant::Initialized, + ::zerocopy::pointer::cast::CastSized, + >() + }; + tag_ptr + .recall_validity::<_, (_, (_, _))>() + .read_unaligned::<::zerocopy::BecauseImmutable>() + }; let mut raw_enum = candidate .cast::< ___ZerocopyRawEnum<'a, N, X, Y>, ::zerocopy::pointer::cast::CastSized, ::zerocopy::pointer::BecauseInvariantsEq, >(); - let tag = { - let tag_ptr = raw_enum - .reborrow() - .project::<(), { ::zerocopy::ident_id!(tag) }>() - .cast::< - ___ZerocopyTagPrimitive, - ::zerocopy::pointer::cast::CastSized, - _, - >(); - tag_ptr - .recall_validity::<_, (_, (_, _))>() - .read_unaligned::<::zerocopy::BecauseImmutable>() - }; - let variants = raw_enum.project::<_, { ::zerocopy::ident_id!(variants) }>(); + let variants = ::zerocopy::into_inner!( + raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { + ::zerocopy::ident_id!(variants) } > () + ); match tag { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { diff --git a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs index 72945ef279..915f871167 100644 --- a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs +++ b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs @@ -11,7 +11,7 @@ #[deny(ambiguous_associated_items)] #[automatically_derived] const _: () = { - unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes + unsafe impl<'a: 'static, X, Y: Deref, const N: usize> ::zerocopy::TryFromBytes for ComplexWithGenerics<'a, { N }, X, Y> where X: Deref, @@ -26,7 +26,7 @@ const _: () = { { fn only_derive_is_allowed_to_implement_this_trait() {} fn is_bit_valid<___ZerocopyAliasing>( - candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, + mut candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, ) -> ::zerocopy::util::macro_util::core_reexport::primitive::bool where ___ZerocopyAliasing: ::zerocopy::pointer::invariant::Reference, @@ -56,29 +56,6 @@ const _: () = { as ___ZerocopyTagPrimitive; type ___ZerocopyOuterTag = (); type ___ZerocopyInnerTag = ___ZerocopyTag; - unsafe impl< - 'a: 'static, - const N: usize, - X, - Y: Deref, - > ::zerocopy::HasField< - (), - { ::zerocopy::STRUCT_VARIANT_ID }, - { ::zerocopy::ident_id!(tag) }, - > for ___ZerocopyRawEnum<'a, N, X, Y> { - fn only_derive_is_allowed_to_implement_this_trait() {} - type Type = ___ZerocopyTag; - #[inline(always)] - fn project( - slf: ::zerocopy::pointer::PtrInner<'_, Self>, - ) -> *mut >::Type { - slf.as_ptr().cast() - } - } #[repr(C)] struct ___ZerocopyVariantStruct_StructLike< 'a: 'static, @@ -115,9 +92,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> where @@ -145,7 +122,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -155,7 +139,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -163,7 +154,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -171,7 +169,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -179,7 +184,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -187,7 +199,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(5) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <[( X, Y, @@ -198,7 +217,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(6) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -242,9 +268,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -273,6 +299,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -289,9 +353,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -318,6 +382,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -334,9 +436,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -363,6 +465,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -379,9 +519,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -408,6 +548,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -424,9 +602,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -453,6 +631,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -469,9 +685,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -498,6 +714,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ5, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -514,9 +768,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -545,6 +799,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ6, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -582,9 +874,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> where @@ -610,7 +902,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -620,7 +919,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -628,7 +934,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -636,7 +949,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -646,7 +966,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -688,9 +1015,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -719,6 +1046,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -735,9 +1100,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -764,6 +1129,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -780,9 +1183,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -809,6 +1212,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -825,9 +1266,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -854,6 +1295,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -870,9 +1349,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -901,6 +1380,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -945,9 +1462,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_StructLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1005,9 +1522,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_TupleLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1065,9 +1582,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__nonempty, { ::zerocopy::UNION_VARIANT_ID }, @@ -1152,9 +1669,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1178,6 +1695,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕtag, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -1194,9 +1746,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1220,6 +1772,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕvariants, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; #[allow( @@ -1237,9 +1824,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1311,9 +1898,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(a) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1385,9 +2010,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(b) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1459,9 +2122,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(c) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1533,9 +2234,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(d) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1607,9 +2346,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(e) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1681,9 +2458,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(0) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1755,9 +2570,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(1) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1814,26 +2667,68 @@ const _: () = { } } }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(2) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + let tag = { + let tag_ptr = unsafe { + candidate + .reborrow() + .project_transmute_unchecked::< + _, + ::zerocopy::invariant::Initialized, + ::zerocopy::pointer::cast::CastSized, + >() + }; + tag_ptr + .recall_validity::<_, (_, (_, _))>() + .read_unaligned::<::zerocopy::BecauseImmutable>() + }; let mut raw_enum = candidate .cast::< ___ZerocopyRawEnum<'a, N, X, Y>, ::zerocopy::pointer::cast::CastSized, ::zerocopy::pointer::BecauseInvariantsEq, >(); - let tag = { - let tag_ptr = raw_enum - .reborrow() - .project::<(), { ::zerocopy::ident_id!(tag) }>() - .cast::< - ___ZerocopyTagPrimitive, - ::zerocopy::pointer::cast::CastSized, - _, - >(); - tag_ptr - .recall_validity::<_, (_, (_, _))>() - .read_unaligned::<::zerocopy::BecauseImmutable>() - }; - let variants = raw_enum.project::<_, { ::zerocopy::ident_id!(variants) }>(); + let variants = ::zerocopy::into_inner!( + raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { + ::zerocopy::ident_id!(variants) } > () + ); match tag { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { diff --git a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs index 8c1797034d..5ce512f180 100644 --- a/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs +++ b/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs @@ -11,7 +11,7 @@ #[deny(ambiguous_associated_items)] #[automatically_derived] const _: () = { - unsafe impl<'a: 'static, const N: usize, X, Y: Deref> ::zerocopy::TryFromBytes + unsafe impl<'a: 'static, X, Y: Deref, const N: usize> ::zerocopy::TryFromBytes for ComplexWithGenerics<'a, { N }, X, Y> where X: Deref, @@ -26,7 +26,7 @@ const _: () = { { fn only_derive_is_allowed_to_implement_this_trait() {} fn is_bit_valid<___ZerocopyAliasing>( - candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, + mut candidate: ::zerocopy::Maybe<'_, Self, ___ZerocopyAliasing>, ) -> ::zerocopy::util::macro_util::core_reexport::primitive::bool where ___ZerocopyAliasing: ::zerocopy::pointer::invariant::Reference, @@ -56,29 +56,6 @@ const _: () = { as ___ZerocopyTagPrimitive; type ___ZerocopyOuterTag = ___ZerocopyTag; type ___ZerocopyInnerTag = (); - unsafe impl< - 'a: 'static, - const N: usize, - X, - Y: Deref, - > ::zerocopy::HasField< - (), - { ::zerocopy::STRUCT_VARIANT_ID }, - { ::zerocopy::ident_id!(tag) }, - > for ___ZerocopyRawEnum<'a, N, X, Y> { - fn only_derive_is_allowed_to_implement_this_trait() {} - type Type = ___ZerocopyTag; - #[inline(always)] - fn project( - slf: ::zerocopy::pointer::PtrInner<'_, Self>, - ) -> *mut >::Type { - slf.as_ptr().cast() - } - } #[repr(C)] struct ___ZerocopyVariantStruct_StructLike< 'a: 'static, @@ -115,9 +92,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> where @@ -145,7 +122,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -155,7 +139,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -163,7 +154,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -171,7 +169,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -179,7 +184,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -187,7 +199,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(5) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <[( X, Y, @@ -198,7 +217,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(6) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -242,9 +268,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -273,6 +299,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -289,9 +353,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -318,6 +382,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -334,9 +436,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -363,6 +465,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -379,9 +519,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -408,6 +548,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -424,9 +602,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -453,6 +631,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -469,9 +685,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ5, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -498,6 +714,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ5, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(5) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -514,9 +768,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ6, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -545,6 +799,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ6, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(6) }, + > for ___ZerocopyVariantStruct_StructLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -582,9 +874,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::TryFromBytes for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> where @@ -610,7 +902,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(0) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::mem::MaybeUninit< ___ZerocopyInnerTag, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -620,7 +919,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(1) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -628,7 +934,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(2) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); ::is_bit_valid( field_candidate, ) @@ -636,7 +949,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(3) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -646,7 +966,14 @@ const _: () = { && { let field_candidate = candidate .reborrow() - .project::<_, { ::zerocopy::ident_id!(4) }>(); + .project::< + _, + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + >(); + let field_candidate = ::zerocopy::into_inner!( + field_candidate + ); <::zerocopy::util::macro_util::core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, > as ::zerocopy::TryFromBytes>::is_bit_valid( @@ -688,9 +1015,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ0, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -719,6 +1046,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ0, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(0) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -735,9 +1100,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ1, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -764,6 +1129,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ1, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(1) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -780,9 +1183,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ2, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -809,6 +1212,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ2, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(2) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -825,9 +1266,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ3, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -854,6 +1295,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ3, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(3) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -870,9 +1349,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ4, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -901,6 +1380,44 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕ4, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(4) }, + > for ___ZerocopyVariantStruct_TupleLike<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; }; @@ -945,9 +1462,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_StructLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1005,9 +1522,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__field_TupleLike, { ::zerocopy::UNION_VARIANT_ID }, @@ -1065,9 +1582,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕ__nonempty, { ::zerocopy::UNION_VARIANT_ID }, @@ -1152,9 +1669,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕtag, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1178,6 +1695,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕtag, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; #[allow( deprecated, @@ -1194,9 +1746,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< ẕvariants, { ::zerocopy::STRUCT_VARIANT_ID }, @@ -1220,6 +1772,41 @@ const _: () = { } } } + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + ẕvariants, + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::STRUCT_VARIANT_ID }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; }; }; #[allow( @@ -1237,9 +1824,9 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, - const N: usize, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1311,9 +1898,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(a) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1385,9 +2010,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(b) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1459,9 +2122,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(c) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1533,9 +2234,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(d) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(StructLike) }, @@ -1607,9 +2346,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(StructLike) }, + { ::zerocopy::ident_id!(e) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1681,9 +2458,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(0) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1755,9 +2570,47 @@ const _: () = { const _: () = { unsafe impl< 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(1) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, X, Y: Deref, + const N: usize, > ::zerocopy::HasField< (), { ::zerocopy::ident_id!(TupleLike) }, @@ -1814,26 +2667,68 @@ const _: () = { } } }; + #[allow( + deprecated, + private_bounds, + non_local_definitions, + non_camel_case_types, + non_upper_case_globals, + non_snake_case, + non_ascii_idents, + clippy::missing_inline_in_public_items, + )] + #[deny(ambiguous_associated_items)] + #[automatically_derived] + const _: () = { + unsafe impl< + 'a: 'static, + X, + Y: Deref, + Aliasing: ::zerocopy::invariant::Aliasing, + Alignment: ::zerocopy::invariant::Alignment, + const N: usize, + > ::zerocopy::ProjectField< + (), + (Aliasing, Alignment, ::zerocopy::invariant::Initialized), + { ::zerocopy::ident_id!(TupleLike) }, + { ::zerocopy::ident_id!(2) }, + > for ComplexWithGenerics<'a, { N }, X, Y> + where + X: Deref, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Error = ::zerocopy::util::macro_util::core_reexport::convert::Infallible; + type Invariants = ( + Aliasing, + Alignment, + ::zerocopy::invariant::Initialized, + ); + } + }; + let tag = { + let tag_ptr = unsafe { + candidate + .reborrow() + .project_transmute_unchecked::< + _, + ::zerocopy::invariant::Initialized, + ::zerocopy::pointer::cast::CastSized, + >() + }; + tag_ptr + .recall_validity::<_, (_, (_, _))>() + .read_unaligned::<::zerocopy::BecauseImmutable>() + }; let mut raw_enum = candidate .cast::< ___ZerocopyRawEnum<'a, N, X, Y>, ::zerocopy::pointer::cast::CastSized, ::zerocopy::pointer::BecauseInvariantsEq, >(); - let tag = { - let tag_ptr = raw_enum - .reborrow() - .project::<(), { ::zerocopy::ident_id!(tag) }>() - .cast::< - ___ZerocopyTagPrimitive, - ::zerocopy::pointer::cast::CastSized, - _, - >(); - tag_ptr - .recall_validity::<_, (_, (_, _))>() - .read_unaligned::<::zerocopy::BecauseImmutable>() - }; - let variants = raw_enum.project::<_, { ::zerocopy::ident_id!(variants) }>(); + let variants = ::zerocopy::into_inner!( + raw_enum.project:: < _, { ::zerocopy::STRUCT_VARIANT_ID }, { + ::zerocopy::ident_id!(variants) } > () + ); match tag { ___ZEROCOPY_TAG_UnitLike => true, ___ZEROCOPY_TAG_StructLike => { diff --git a/zerocopy-derive/src/util.rs b/zerocopy-derive/src/util.rs index 5bbf7269a0..61902f7904 100644 --- a/zerocopy-derive/src/util.rs +++ b/zerocopy-derive/src/util.rs @@ -228,7 +228,17 @@ impl PaddingCheck { #[derive(Clone)] pub(crate) enum Trait { KnownLayout, - HasField { variant_id: Box, field: Box, field_id: Box }, + HasField { + variant_id: Box, + field: Box, + field_id: Box, + }, + ProjectField { + variant_id: Box, + field: Box, + field_id: Box, + invariants: Box, + }, Immutable, TryFromBytes, FromZeros, @@ -254,6 +264,7 @@ impl ToTokens for Trait { // [2] https://doc.rust-lang.org/beta/unstable-book/compiler-flags/fmt-debug.html let s = match self { Trait::HasField { .. } => "HasField", + Trait::ProjectField { .. } => "ProjectField", Trait::KnownLayout => "KnownLayout", Trait::Immutable => "Immutable", Trait::TryFromBytes => "TryFromBytes", @@ -271,6 +282,9 @@ impl ToTokens for Trait { Trait::HasField { variant_id, field, field_id } => { Some(parse_quote!(<#field, #variant_id, #field_id>)) } + Trait::ProjectField { variant_id, field, field_id, invariants } => { + Some(parse_quote!(<#field, #invariants, #variant_id, #field_id>)) + } Trait::KnownLayout | Trait::Immutable | Trait::TryFromBytes @@ -345,6 +359,7 @@ pub(crate) struct ImplBlockBuilder<'a> { field_type_trait_bounds: FieldBounds<'a>, self_type_trait_bounds: SelfBounds<'a>, padding_check: Option, + param_extras: Vec, inner_extras: Option, outer_extras: Option, } @@ -363,6 +378,7 @@ impl<'a> ImplBlockBuilder<'a> { field_type_trait_bounds, self_type_trait_bounds: SelfBounds::None, padding_check: None, + param_extras: Vec::new(), inner_extras: None, outer_extras: None, } @@ -378,6 +394,11 @@ impl<'a> ImplBlockBuilder<'a> { self } + pub(crate) fn param_extras(mut self, param_extras: Vec) -> Self { + self.param_extras.extend(param_extras); + self + } + pub(crate) fn inner_extras(mut self, inner_extras: TokenStream) -> Self { self.inner_extras = Some(inner_extras); self @@ -518,13 +539,30 @@ impl<'a> ImplBlockBuilder<'a> { .chain(self_bounds.iter()); // The parameters with trait bounds, but without type defaults. - let params = self.ctx.ast.generics.params.clone().into_iter().map(|mut param| { - match &mut param { - GenericParam::Type(ty) => ty.default = None, - GenericParam::Const(cnst) => cnst.default = None, - GenericParam::Lifetime(_) => {} - } - quote!(#param) + let mut params: Vec<_> = self + .ctx + .ast + .generics + .params + .clone() + .into_iter() + .map(|mut param| { + match &mut param { + GenericParam::Type(ty) => ty.default = None, + GenericParam::Const(cnst) => cnst.default = None, + GenericParam::Lifetime(_) => {} + } + parse_quote!(#param) + }) + .chain(self.param_extras) + .collect(); + + // For MSRV purposes, ensure that lifetimes precede types precede const + // generics. + params.sort_by_cached_key(|param| match param { + GenericParam::Lifetime(_) => 0, + GenericParam::Type(_) => 1, + GenericParam::Const(_) => 2, }); // The identifiers of the parameters without trait bounds or type