From 122da00a932db83f6ab618df3423f2b0c32f46f6 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Thu, 4 Dec 2025 22:47:55 +0000 Subject: [PATCH] Add `HasField::project`; simplify `is_bit_valid` This method projects from `PtrInner<_, Self>` to a `PtrInner` of a field of `Self`. In this commit, we use `HasField::project` to considerably simplify `is_bit_valid` implementations. gherrit-pr-id: G9e7039c715e1ec53e6d860909bb0d618898fd46b --- Cargo.toml | 2 + src/impls.rs | 48 + src/lib.rs | 5 + src/pointer/inner.rs | 12 +- zerocopy-derive/src/enum.rs | 103 +- zerocopy-derive/src/lib.rs | 80 +- zerocopy-derive/src/output_tests.rs | 1916 ++++++++++++++++++++++----- 7 files changed, 1760 insertions(+), 406 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5cf7f9d74e..05e8f9f2bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,6 +130,8 @@ glob = "=0.3.2" itertools = "0.11" rand = { version = "0.8.5", default-features = false, features = ["small_rng"] } rustversion = "1.0" +# More recent versions of `ryu` have an MSRV higher than ours. +ryu = "=1.0.20" static_assertions = "1.1" testutil = { path = "testutil" } # Pinned to a specific version so that the version used for local development diff --git a/src/impls.rs b/src/impls.rs index 462fa45cc7..1d46a29632 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -794,6 +794,54 @@ impl_for_transmute_from!(T: ?Sized + IntoBytes => IntoBytes for ManuallyDrop[ const _: () = unsafe { unsafe_impl!(T: ?Sized + Unaligned => Unaligned for ManuallyDrop) }; assert_unaligned!(ManuallyDrop<()>, ManuallyDrop); +const _: () = { + #[allow( + non_camel_case_types, + missing_copy_implementations, + missing_debug_implementations, + missing_docs + )] + pub enum value {} + + // SAFETY: `ManuallyDrop` has a field of type `T` at offset `0` without + // any safety invariants beyond those of `T`. Its existence is not + // explicitly documented, but it can be inferred; per [1] `ManuallyDrop` + // has the same size and bit validity as `T`. This field is not literally + // public, but is effectively so; the field can be transparently: + // + // - initialized via `ManuallyDrop::new` + // - moved via `ManuallyDrop::into_inner` + // - referenced via `ManuallyDrop::deref` + // - exclusively referenced via `ManuallyDrop::deref_mut` + // + // We call this field `value`, both because that is both the name of this + // private field, and because it is the name it is referred to in the public + // documentation of `ManuallyDrop::new`, `ManuallyDrop::into_inner`, + // `ManuallyDrop::take` and `ManuallyDrop::drop`. + unsafe impl HasField for ManuallyDrop { + type Type = T; + + #[inline] + fn only_derive_is_allowed_to_implement_this_trait() + where + Self: Sized, + { + } + + #[inline(always)] + fn project(slf: PtrInner<'_, Self>) -> PtrInner<'_, T> { + // SAFETY: `ManuallyDrop` has the same layout and bit validity as + // `T` [1]. + // + // [1] Per https://doc.rust-lang.org/1.85.0/std/mem/struct.ManuallyDrop.html: + // + // `ManuallyDrop` is guaranteed to have the same layout and bit + // validity as `T` + unsafe { slf.cast() } + } + } +}; + impl_for_transmute_from!(T: ?Sized + TryFromBytes => TryFromBytes for Cell[UnsafeCell]); impl_for_transmute_from!(T: ?Sized + FromZeros => FromZeros for Cell[UnsafeCell]); impl_for_transmute_from!(T: ?Sized + FromBytes => FromBytes for Cell[UnsafeCell]); diff --git a/src/lib.rs b/src/lib.rs index b99ded47e1..020cdf5a91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -372,6 +372,8 @@ use core::{ use std::io; use crate::pointer::invariant::{self, BecauseExclusive}; +#[doc(hidden)] +pub use crate::pointer::PtrInner; pub use crate::{ byte_slice::*, byteorder::*, @@ -1109,6 +1111,9 @@ pub unsafe trait HasField { /// The type of the field. type Type: ?Sized; + + /// Projects from `slf` to the field. + fn project(slf: PtrInner<'_, Self>) -> PtrInner<'_, Self::Type>; } /// Analyzes whether a type is [`FromZeros`]. diff --git a/src/pointer/inner.rs b/src/pointer/inner.rs index a9134e347c..a11ba180b8 100644 --- a/src/pointer/inner.rs +++ b/src/pointer/inner.rs @@ -15,7 +15,7 @@ use crate::util::polyfills::NumExt as _; use crate::{ layout::{CastType, MetadataCastError}, util::AsAddress, - AlignmentError, CastError, KnownLayout, MetadataOf, SizeError, SplitAt, + AlignmentError, CastError, HasField, KnownLayout, MetadataOf, SizeError, SplitAt, }; mod _def { @@ -196,6 +196,16 @@ impl<'a, T: ?Sized> PtrInner<'a, T> { // then `A` is guaranteed to live for at least `'a`. unsafe { PtrInner::new(ptr) } } + + /// Projects a field. + #[must_use] + #[inline(always)] + pub fn project(self) -> PtrInner<'a, T::Type> + where + T: HasField, + { + >::project(self) + } } #[allow(clippy::needless_lifetimes)] diff --git a/zerocopy-derive/src/enum.rs b/zerocopy-derive/src/enum.rs index 8fd58a81c8..5898ef61c4 100644 --- a/zerocopy-derive/src/enum.rs +++ b/zerocopy-derive/src/enum.rs @@ -9,11 +9,13 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{ - parse_quote, spanned::Spanned as _, DataEnum, DeriveInput, Error, Fields, Generics, Ident, Path, + parse_quote, spanned::Spanned as _, DataEnum, DeriveInput, Error, Fields, Generics, Ident, + Index, Path, }; use crate::{ - derive_try_from_bytes_inner, repr::EnumRepr, DataExt, FieldBounds, ImplBlockBuilder, Trait, + derive_has_field_struct_union, derive_try_from_bytes_inner, repr::EnumRepr, DataExt, + FieldBounds, ImplBlockBuilder, Trait, }; /// Generates a tag enum for the given enum. This generates an enum with the @@ -162,7 +164,18 @@ fn generate_variant_structs( } } -fn generate_variants_union(generics: &Generics, data: &DataEnum) -> TokenStream { +fn variants_union_field_ident(ident: &Ident) -> Ident { + let variant_ident_str = crate::ext::to_ident_str(ident); + // Field names are prefixed with `__field_` to prevent name collision + // with the `__nonempty` field. + Ident::new(&format!("__field_{}", variant_ident_str), ident.span()) +} + +fn generate_variants_union( + generics: &Generics, + data: &DataEnum, + zerocopy_crate: &Path, +) -> TokenStream { let (_, ty_generics, _) = generics.split_for_impl(); let fields = data.variants.iter().filter_map(|variant| { @@ -172,10 +185,7 @@ fn generate_variants_union(generics: &Generics, data: &DataEnum) -> TokenStream return None; } - // Field names are prefixed with `__field_` to prevent name collision - // with the `__nonempty` field. - let field_name_str = crate::ext::to_ident_str(&variant.ident); - let field_name = Ident::new(&format!("__field_{}", field_name_str), variant.ident.span()); + let field_name = variants_union_field_ident(&variant.ident); let variant_struct_ident = variant_struct_ident(&variant.ident); Some(quote! { @@ -185,7 +195,7 @@ fn generate_variants_union(generics: &Generics, data: &DataEnum) -> TokenStream }) }); - quote! { + let variants_union = parse_quote! { #[repr(C)] #[allow(non_snake_case)] union ___ZerocopyVariants #generics { @@ -197,6 +207,14 @@ fn generate_variants_union(generics: &Generics, data: &DataEnum) -> TokenStream // affect the layout. __nonempty: (), } + }; + + let has_field = + derive_has_field_struct_union(&variants_union, &variants_union.data, zerocopy_crate); + + quote! { + #variants_union + #has_field } } @@ -246,18 +264,20 @@ pub(crate) fn derive_is_bit_valid( }; let variant_structs = generate_variant_structs(enum_ident, generics, data, zerocopy_crate); - let variants_union = generate_variants_union(generics, data); + let variants_union = generate_variants_union(generics, data, zerocopy_crate); - let (_, ty_generics, _) = generics.split_for_impl(); + let (_, ref ty_generics, _) = generics.split_for_impl(); let has_fields = data.variants().into_iter().flat_map(|(variant, fields)| { let variant_ident = &variant.unwrap().ident; + let variants_union_field_ident = variants_union_field_ident(variant_ident); let field: Box = parse_quote!(()); - fields.into_iter().map(move |(vis, ident, ty)| { + fields.into_iter().enumerate().map(move |(idx, (vis, ident, ty))| { // Rust does not presently support explicit visibility modifiers on // enum fields, but we guard against the possibility to ensure this // derive remains sound. assert!(matches!(vis, syn::Visibility::Inherited)); + let variant_struct_field_index = Index::from(idx + 1); ImplBlockBuilder::new( ast, data, @@ -274,6 +294,18 @@ pub(crate) fn derive_is_bit_valid( ) .inner_extras(quote! { type Type = #ty; + + #[inline(always)] + fn project(slf: #zerocopy_crate::PtrInner<'_, Self>) -> #zerocopy_crate::PtrInner<'_, Self::Type> { + // SAFETY: By invariant on `___ZerocopyRawEnum`, + // `___ZerocopyRawEnum` has the same layout as `Self`. + let slf = unsafe { slf.cast::<___ZerocopyRawEnum #ty_generics>() }; + + slf.project::<_, 0, { #zerocopy_crate::ident_id!(variants) }>() + .project::<_, 0, { #zerocopy_crate::ident_id!(#variants_union_field_ident) }>() + .project::<_, 0, { #zerocopy_crate::ident_id!(value) }>() + .project::<_, 0, { #zerocopy_crate::ident_id!(#variant_struct_field_index) }>() + } }) .build() }) @@ -323,6 +355,22 @@ pub(crate) fn derive_is_bit_valid( } }); + let raw_enum = parse_quote! { + #[repr(C)] + struct ___ZerocopyRawEnum #generics { + tag: ___ZerocopyOuterTag, + variants: ___ZerocopyVariants #ty_generics, + } + }; + + let raw_enum_projections = + derive_has_field_struct_union(&raw_enum, &raw_enum.data, zerocopy_crate); + + let raw_enum = quote! { + #raw_enum + #raw_enum_projections + }; + Ok(quote! { // SAFETY: We use `is_bit_valid` to validate that the bit pattern of the // enum's tag corresponds to one of the enum's discriminants. Then, we @@ -351,11 +399,7 @@ pub(crate) fn derive_is_bit_valid( #variants_union - #[repr(C)] - struct ___ZerocopyRawEnum #generics { - tag: ___ZerocopyOuterTag, - variants: ___ZerocopyVariants #ty_generics, - } + #raw_enum #(#has_fields)* @@ -399,26 +443,23 @@ pub(crate) fn derive_is_bit_valid( // invariant from `p`, so we re-assert that all of the bytes are // initialized. let raw_enum = unsafe { raw_enum.assume_initialized() }; + // SAFETY: - // - This projection returns a subfield of `this` using - // `addr_of_mut!`. - // - Because the subfield pointer is derived from `this`, it has the - // same provenance. + // - This projection returns a subfield of `raw_enum` using + // `project`. + // - Because the subfield pointer is derived from `raw_enum`, it has + // the same provenance. // - The locations of `UnsafeCell`s in the subfield match the - // locations of `UnsafeCell`s in `this`. This is because the + // locations of `UnsafeCell`s in `raw_enum`. This is because the // subfield pointer just points to a smaller portion of the // overall struct. + let project = #zerocopy_crate::pointer::PtrInner::project::< + _, + 0, + { #zerocopy_crate::ident_id!(variants) } + >; let variants = unsafe { - use #zerocopy_crate::pointer::PtrInner; - raw_enum.cast_unsized_unchecked(|p: PtrInner<'_, ___ZerocopyRawEnum #ty_generics>| { - let p = p.as_non_null().as_ptr(); - let ptr = core_reexport::ptr::addr_of_mut!((*p).variants); - // SAFETY: `ptr` is a projection into `p`, which is - // `NonNull`, and guaranteed not to wrap around the address - // space. Thus, `ptr` cannot be null. - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) }; - unsafe { PtrInner::new(ptr) } - }) + raw_enum.cast_unsized_unchecked(project) }; #[allow(non_upper_case_globals)] diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 6f0c5f2f92..7274fa0fa8 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -774,6 +774,34 @@ fn derive_has_field_struct_union( ) .inner_extras(quote! { type Type = #ty; + + #[inline(always)] + fn project(slf: #zerocopy_crate::PtrInner<'_, Self>) -> #zerocopy_crate::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + // SAFETY: `PtrInner` promises it references either a zero-sized + // byte range, or else will reference a byte range that is + // entirely contained within an allocated object. In either + // case, this guarantees that `(*slf).#ident` is in-bounds of + // `slf`. + let field = unsafe { #zerocopy_crate::util::macro_util::core_reexport::ptr::addr_of_mut!((*slf).#ident) }; + // SAFETY: `PtrInner` promises it references either a zero-sized + // byte range, or else will reference a byte range that is + // entirely contained within an allocated object. In either + // case, this guarantees that field projection will not wrap + // around the address space, and so `field` will be non-null. + let ptr = unsafe { #zerocopy_crate::util::macro_util::core_reexport::ptr::NonNull::new_unchecked(field) }; + // SAFETY: + // 0. `ptr` addresses a subset of the bytes of + // `slf`, so by invariant on `slf: PtrInner`, + // if `ptr`'s referent is not zero sized, + // then `ptr` has valid provenance for its + // referent, which is entirely contained in + // some Rust allocation, `A`. + // 1. By invariant on `slf: PtrInner`, if + // `ptr`'s referent is not zero sized, `A` is + // guaranteed to live for at least `'a`. + unsafe { #zerocopy_crate::PtrInner::new(ptr) } + } }) .build() }); @@ -816,6 +844,7 @@ fn derive_try_from_bytes_struct( use #zerocopy_crate::pointer::PtrInner; true #(&& { + let project = >::project; // SAFETY: // - `project` is a field projection, and so it // addresses a subset of the bytes addressed by `slf` @@ -824,31 +853,6 @@ fn derive_try_from_bytes_struct( // at the same byte ranges in the returned pointer's // referent as they do in `*slf` let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((*slf).#field_names); - // SAFETY: `cast_unsized_unchecked` promises - // that `slf` will either reference a zero-sized - // byte range, or else will reference a byte - // range that is entirely contained within an - // allocated object. In either case, this - // guarantees that field projection will not - // wrap around the address space, and so `field` - // will be non-null. - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(field) }; - // SAFETY: - // 0. `ptr` addresses a subset of the bytes of - // `slf`, so by invariant on `slf: PtrInner`, - // if `ptr`'s referent is not zero sized, - // then `ptr` has valid provenance for its - // referent, which is entirely contained in - // some Rust allocation, `A`. - // 1. By invariant on `slf: PtrInner`, if - // `ptr`'s referent is not zero sized, `A` is - // guaranteed to live for at least `'a`. - unsafe { PtrInner::new(ptr) } - }; - candidate.reborrow().cast_unsized_unchecked(project) }; @@ -901,6 +905,7 @@ fn derive_try_from_bytes_union( use #zerocopy_crate::pointer::PtrInner; false #(|| { + let project = >::project; // SAFETY: // - `project` is a field projection, and so it // addresses a subset of the bytes addressed by `slf` @@ -910,31 +915,6 @@ fn derive_try_from_bytes_union( // returned pointer's referent contain any // `UnsafeCell`s let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((*slf).#field_names); - // SAFETY: `cast_unsized_unchecked` promises - // that `slf` will either reference a zero-sized - // byte range, or else will reference a byte - // range that is entirely contained within an - // allocated object. In either case, this - // guarantees that field projection will not - // wrap around the address space, and so `field` - // will be non-null. - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(field) }; - // SAFETY: - // 0. `ptr` addresses a subset of the bytes of - // `slf`, so by invariant on `slf: PtrInner`, - // if `ptr`'s referent is not zero sized, - // then `ptr` has valid provenance for its - // referent, which is entirely contained in - // some Rust allocation, `A`. - // 1. By invariant on `slf: PtrInner`, if - // `ptr`'s referent is not zero sized, `A` is - // guaranteed to live for at least `'a`. - unsafe { PtrInner::new(ptr) } - }; - candidate.reborrow().cast_unsized_unchecked(project) }; diff --git a/zerocopy-derive/src/output_tests.rs b/zerocopy-derive/src/output_tests.rs index 259ba2ef7f..1baa85637d 100644 --- a/zerocopy-derive/src/output_tests.rs +++ b/zerocopy-derive/src/output_tests.rs @@ -436,6 +436,23 @@ fn test_from_bytes_union() { > for Foo { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).a + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -708,15 +725,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -740,15 +751,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -756,15 +764,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -772,15 +777,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -788,15 +790,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).5); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; <[( @@ -807,15 +806,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).6); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -868,6 +881,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -886,6 +916,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -904,6 +951,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -922,6 +986,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -940,6 +1021,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).5 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -960,6 +1058,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).6 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -1012,15 +1127,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1044,15 +1153,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1060,15 +1166,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1135,6 +1252,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1153,6 +1287,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1171,6 +1322,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1191,6 +1359,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -1205,11 +1390,186 @@ fn test_try_from_bytes_enum() { >, __nonempty: (), } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕ__field_StructLike {} + enum ẕ__field_TupleLike {} + enum ẕ__nonempty {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_StructLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_StructLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_StructLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_StructLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_TupleLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_TupleLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_TupleLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__nonempty, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__nonempty) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = (); + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__nonempty + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[repr(C)] struct ___ZerocopyRawEnum<'a: 'static, const N: usize, X, Y: Deref> { tag: ___ZerocopyOuterTag, variants: ___ZerocopyVariants<'a, N, X, Y>, } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕtag {} + enum ẕvariants {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕtag, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyOuterTag; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).tag + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕvariants, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyVariants<'a, N, X, Y>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).variants + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[allow(deprecated, non_local_definitions)] #[automatically_derived] unsafe impl< @@ -1227,6 +1587,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1245,6 +1615,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1263,6 +1643,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1281,6 +1671,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(4) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1299,6 +1699,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(5) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1317,6 +1727,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1335,6 +1755,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1353,6 +1783,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } let tag = { let tag_ptr = unsafe { @@ -1374,18 +1814,12 @@ fn test_try_from_bytes_enum() { }) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; - let variants = unsafe { - use ::zerocopy::pointer::PtrInner; - raw_enum - .cast_unsized_unchecked(| - p: PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| - { - let p = p.as_non_null().as_ptr(); - let ptr = core_reexport::ptr::addr_of_mut!((* p).variants); - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) }; - unsafe { PtrInner::new(ptr) } - }) - }; + let project = ::zerocopy::pointer::PtrInner::project::< + _, + 0, + { ::zerocopy::ident_id!(variants) }, + >; + let variants = unsafe { raw_enum.cast_unsized_unchecked(project) }; #[allow(non_upper_case_globals)] match tag { ___ZEROCOPY_TAG_UnitLike => true, @@ -1549,15 +1983,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1581,15 +2009,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1597,15 +2022,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1613,15 +2035,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1629,15 +2048,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).5); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; <[( @@ -1648,15 +2064,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).6); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1709,6 +2139,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1727,6 +2174,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1745,6 +2209,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1763,6 +2244,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1781,6 +2279,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).5 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1801,6 +2316,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).6 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -1853,15 +2385,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1885,15 +2411,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -1901,15 +2424,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1976,6 +2510,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -1994,6 +2545,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2012,6 +2580,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2032,6 +2617,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -2046,11 +2648,186 @@ fn test_try_from_bytes_enum() { >, __nonempty: (), } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕ__field_StructLike {} + enum ẕ__field_TupleLike {} + enum ẕ__nonempty {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_StructLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_StructLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_StructLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_StructLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_TupleLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_TupleLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_TupleLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__nonempty, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__nonempty) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = (); + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__nonempty + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[repr(C)] struct ___ZerocopyRawEnum<'a: 'static, const N: usize, X, Y: Deref> { tag: ___ZerocopyOuterTag, variants: ___ZerocopyVariants<'a, N, X, Y>, } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕtag {} + enum ẕvariants {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕtag, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyOuterTag; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).tag + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕvariants, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyVariants<'a, N, X, Y>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).variants + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[allow(deprecated, non_local_definitions)] #[automatically_derived] unsafe impl< @@ -2068,6 +2845,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2086,6 +2873,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2104,6 +2901,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2122,6 +2929,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(4) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2140,6 +2957,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(5) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2158,6 +2985,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2176,6 +3013,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2194,6 +3041,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } let tag = { let tag_ptr = unsafe { @@ -2215,18 +3072,12 @@ fn test_try_from_bytes_enum() { }) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; - let variants = unsafe { - use ::zerocopy::pointer::PtrInner; - raw_enum - .cast_unsized_unchecked(| - p: PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| - { - let p = p.as_non_null().as_ptr(); - let ptr = core_reexport::ptr::addr_of_mut!((* p).variants); - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) }; - unsafe { PtrInner::new(ptr) } - }) - }; + let project = ::zerocopy::pointer::PtrInner::project::< + _, + 0, + { ::zerocopy::ident_id!(variants) }, + >; + let variants = unsafe { raw_enum.cast_unsized_unchecked(project) }; #[allow(non_upper_case_globals)] match tag { ___ZEROCOPY_TAG_UnitLike => true, @@ -2390,15 +3241,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2422,15 +3267,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2438,15 +3280,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2454,15 +3293,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2470,15 +3306,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).5); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; <[( @@ -2489,15 +3322,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).6); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2550,6 +3397,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2568,6 +3432,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2586,6 +3467,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2604,6 +3502,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2622,6 +3537,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).5 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2642,6 +3574,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).6 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -2694,15 +3643,12 @@ fn test_try_from_bytes_enum() { use ::zerocopy::pointer::PtrInner; true && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).0); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).1); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2726,15 +3669,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).2); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ::is_bit_valid( @@ -2742,15 +3682,12 @@ fn test_try_from_bytes_enum() { ) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).3); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate) } && { + let project = >::project; let field_candidate = unsafe { - let project = |slf: PtrInner<'_, Self>| { - let slf = slf.as_non_null().as_ptr(); - let field = core_reexport::ptr::addr_of_mut!((* slf).4); - let ptr = unsafe { - core_reexport::ptr::NonNull::new_unchecked(field) - }; - unsafe { PtrInner::new(ptr) } - }; candidate.reborrow().cast_unsized_unchecked(project) }; ; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).0 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2817,6 +3768,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).1 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2835,6 +3803,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).2 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2853,6 +3838,23 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).3 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2873,6 +3875,23 @@ fn test_try_from_bytes_enum() { type Type = core_reexport::marker::PhantomData< ComplexWithGenerics<'a, N, X, Y>, >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).4 + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } } }; }; @@ -2887,11 +3906,186 @@ fn test_try_from_bytes_enum() { >, __nonempty: (), } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕ__field_StructLike {} + enum ẕ__field_TupleLike {} + enum ẕ__nonempty {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_StructLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_StructLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_StructLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_StructLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__field_TupleLike, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__field_TupleLike) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = core_reexport::mem::ManuallyDrop< + ___ZerocopyVariantStruct_TupleLike<'a, N, X, Y>, + >; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__field_TupleLike + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕ__nonempty, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(__nonempty) }, + > for ___ZerocopyVariants<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = (); + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).__nonempty + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[repr(C)] struct ___ZerocopyRawEnum<'a: 'static, const N: usize, X, Y: Deref> { tag: ___ZerocopyOuterTag, variants: ___ZerocopyVariants<'a, N, X, Y>, } + #[allow(non_camel_case_types)] + const _: () = { + enum ẕtag {} + enum ẕvariants {} + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕtag, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(tag) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyOuterTag; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).tag + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + #[allow(deprecated, non_local_definitions)] + #[automatically_derived] + unsafe impl< + 'a: 'static, + const N: usize, + X, + Y: Deref, + > ::zerocopy::HasField< + ẕvariants, + { ::zerocopy::ident_id!(0) }, + { ::zerocopy::ident_id!(variants) }, + > for ___ZerocopyRawEnum<'a, { N }, X, Y> { + fn only_derive_is_allowed_to_implement_this_trait() {} + type Type = ___ZerocopyVariants<'a, N, X, Y>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = slf.as_non_null().as_ptr(); + let field = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!( + (* slf).variants + ) + }; + let ptr = unsafe { + ::zerocopy::util::macro_util::core_reexport::ptr::NonNull::new_unchecked( + field, + ) + }; + unsafe { ::zerocopy::PtrInner::new(ptr) } + } + } + }; #[allow(deprecated, non_local_definitions)] #[automatically_derived] unsafe impl< @@ -2909,6 +4103,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = u8; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2927,6 +4131,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2945,6 +4159,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = X::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2963,6 +4187,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y::Target; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(4) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2981,6 +4215,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = [(X, Y); N]; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_StructLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(5) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -2999,6 +4243,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = bool; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(1) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -3017,6 +4271,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = Y; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(2) }>() + } } #[allow(deprecated, non_local_definitions)] #[automatically_derived] @@ -3035,6 +4299,16 @@ fn test_try_from_bytes_enum() { { fn only_derive_is_allowed_to_implement_this_trait() {} type Type = PhantomData<&'a [(X, Y); N]>; + #[inline(always)] + fn project( + slf: ::zerocopy::PtrInner<'_, Self>, + ) -> ::zerocopy::PtrInner<'_, Self::Type> { + let slf = unsafe { slf.cast::<___ZerocopyRawEnum<'a, N, X, Y>>() }; + slf.project::<_, 0, { ::zerocopy::ident_id!(variants) }>() + .project::<_, 0, { ::zerocopy::ident_id!(__field_TupleLike) }>() + .project::<_, 0, { ::zerocopy::ident_id!(value) }>() + .project::<_, 0, { ::zerocopy::ident_id!(3) }>() + } } let tag = { let tag_ptr = unsafe { @@ -3056,18 +4330,12 @@ fn test_try_from_bytes_enum() { }) }; let raw_enum = unsafe { raw_enum.assume_initialized() }; - let variants = unsafe { - use ::zerocopy::pointer::PtrInner; - raw_enum - .cast_unsized_unchecked(| - p: PtrInner<'_, ___ZerocopyRawEnum<'a, N, X, Y>>| - { - let p = p.as_non_null().as_ptr(); - let ptr = core_reexport::ptr::addr_of_mut!((* p).variants); - let ptr = unsafe { core_reexport::ptr::NonNull::new_unchecked(ptr) }; - unsafe { PtrInner::new(ptr) } - }) - }; + let project = ::zerocopy::pointer::PtrInner::project::< + _, + 0, + { ::zerocopy::ident_id!(variants) }, + >; + let variants = unsafe { raw_enum.cast_unsized_unchecked(project) }; #[allow(non_upper_case_globals)] match tag { ___ZEROCOPY_TAG_UnitLike => true,