@@ -135,15 +135,15 @@ macro_rules! unsafe_impl {
135135 fn only_derive_is_allowed_to_implement_this_trait( ) { }
136136
137137 #[ inline]
138- fn is_bit_valid< AA : crate :: pointer :: invariant :: Reference > ( $candidate: Maybe <' _, Self , AA >) -> bool {
138+ fn is_bit_valid( $candidate: Maybe <' _, Self >) -> bool {
139139 $is_bit_valid
140140 }
141141 } ;
142142 ( @method TryFromBytes ) => {
143143 #[ allow( clippy:: missing_inline_in_public_items) ]
144144 #[ cfg_attr( all( coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS) , coverage( off) ) ]
145145 fn only_derive_is_allowed_to_implement_this_trait( ) { }
146- #[ inline( always) ] fn is_bit_valid< AA : crate :: pointer :: invariant :: Reference > ( _: Maybe <' _, Self , AA >) -> bool { true }
146+ #[ inline( always) ] fn is_bit_valid( _: Maybe <' _, Self >) -> bool { true }
147147 } ;
148148 ( @method $trait: ident) => {
149149 #[ allow( clippy:: missing_inline_in_public_items, dead_code) ]
@@ -166,6 +166,13 @@ macro_rules! impl_for_transmute_from {
166166 $( $tyvar: ident $( : $( ? $optbound: ident $( +) ?) * $( $bound: ident $( +) ?) * ) ?) ?
167167 => $trait: ident for $ty: ty [ $( $unsafe_cell: ident) ? <$repr: ty>]
168168 ) => {
169+ // SAFETY: TODO
170+ const _: ( ) = unsafe {
171+ impl_size_eq!(
172+ @inner [ $( $tyvar $( : $( ? $optbound +) * $( $bound +) * ) ?) ?] ReadOnly <$ty>, ReadOnly <$repr>
173+ ) ;
174+ } ;
175+
169176 const _: ( ) = {
170177 $( #[ $attr] ) *
171178 #[ allow( non_local_definitions) ]
@@ -218,9 +225,9 @@ macro_rules! impl_for_transmute_from {
218225 TryFromBytes for $ty: ty [ UnsafeCell <$repr: ty>]
219226 ) => {
220227 #[ inline]
221- fn is_bit_valid< A : crate :: pointer :: invariant :: Reference > ( candidate: Maybe <' _, Self , A >) -> bool {
222- let c: Maybe <' _, Self , crate :: pointer:: invariant:: Exclusive > = candidate. into_exclusive_or_pme( ) ;
223- let c: Maybe <' _, $repr, _> = c . transmute:: <_, _, ( _, ( _, ( BecauseExclusive , BecauseExclusive ) ) ) >( ) ;
228+ fn is_bit_valid( candidate: Maybe <' _, Self >) -> bool {
229+ // let c: Maybe<'_, Self, crate::pointer::invariant::Exclusive> = candidate.into_exclusive_or_pme();
230+ let c: Maybe <' _, $repr, _> = candidate . transmute:: <_, _, ( _, ( _, ( BecauseImmutable , BecauseImmutable ) ) ) >( ) ;
224231 // SAFETY: This macro ensures that `$repr` and `Self` have the same
225232 // size and bit validity. Thus, a bit-valid instance of `$repr` is
226233 // also a bit-valid instance of `Self`.
@@ -233,11 +240,11 @@ macro_rules! impl_for_transmute_from {
233240 TryFromBytes for $ty: ty [ <$repr: ty>]
234241 ) => {
235242 #[ inline]
236- fn is_bit_valid< A : crate :: pointer :: invariant :: Reference > ( candidate: $crate:: Maybe <' _, Self , A >) -> bool {
243+ fn is_bit_valid( candidate: $crate:: Maybe <' _, Self >) -> bool {
237244 // SAFETY: This macro ensures that `$repr` and `Self` have the same
238245 // size and bit validity. Thus, a bit-valid instance of `$repr` is
239246 // also a bit-valid instance of `Self`.
240- <$repr as TryFromBytes >:: is_bit_valid( candidate. transmute( ) )
247+ <$repr as TryFromBytes >:: is_bit_valid( candidate. transmute:: <_ , _ , BecauseImmutable > ( ) )
241248 }
242249 } ;
243250 (
@@ -788,44 +795,56 @@ macro_rules! impl_transitive_transmute_from {
788795
789796#[ rustfmt:: skip]
790797macro_rules! impl_size_eq {
791- ( $t: ty, $u: ty) => {
792- const _: ( ) = {
793- use crate :: { KnownLayout , pointer:: { PtrInner , SizeEq } } ;
794-
795- static_assert!( => {
796- let t = <$t as KnownLayout >:: LAYOUT ;
797- let u = <$u as KnownLayout >:: LAYOUT ;
798- t. align. get( ) >= u. align. get( ) && match ( t. size_info, u. size_info) {
799- ( SizeInfo :: Sized { size: t } , SizeInfo :: Sized { size: u } ) => t == u,
800- (
801- SizeInfo :: SliceDst ( TrailingSliceLayout { offset: t_offset, elem_size: t_elem_size } ) ,
802- SizeInfo :: SliceDst ( TrailingSliceLayout { offset: u_offset, elem_size: u_elem_size } )
803- ) => t_offset == u_offset && t_elem_size == u_elem_size,
804- _ => false ,
805- }
806- } ) ;
798+ ( $t: ty, $u: ty) => {
799+ const _: ( ) = { static_assert!( => {
800+ let t = <$t as KnownLayout >:: LAYOUT ;
801+ let u = <$u as KnownLayout >:: LAYOUT ;
802+ t. align. get( ) >= u. align. get( ) && match ( t. size_info, u. size_info) {
803+ ( SizeInfo :: Sized { size: t } , SizeInfo :: Sized { size: u } ) => t == u,
804+ (
805+ SizeInfo :: SliceDst ( TrailingSliceLayout { offset: t_offset, elem_size: t_elem_size } ) ,
806+ SizeInfo :: SliceDst ( TrailingSliceLayout { offset: u_offset, elem_size: u_elem_size } )
807+ ) => t_offset == u_offset && t_elem_size == u_elem_size,
808+ _ => false ,
809+ }
810+ } ) } ;
807811
808- // SAFETY: See inline.
809- unsafe impl SizeEq <$t> for $u {
810- #[ inline( always) ]
811- fn cast_from_raw( t: PtrInner <' _, $t>) -> PtrInner <' _, $u> {
812- // SAFETY: We've asserted that their
813- // `KnownLayout::LAYOUT.size_info`s are equal, and so this
814- // cast is guaranteed to preserve address and referent size.
815- // It trivially preserves provenance.
816- unsafe { cast!( t) }
817- }
812+ const _: ( ) = unsafe { impl_size_eq!( @inner [ ] $t, $u) ; } ;
813+ } ;
814+ (
815+ $tyvar: ident $( : $( ? $optbound: ident $( +) ?) * $( $bound: ident $( +) ?) * ) ? =>
816+ $t: ty, $u: ty
817+ ) => {
818+ impl_size_eq!( @inner [ $tyvar $( : $( ? $optbound) * $( $bound) * ) ?] $t, $u) ;
819+ } ;
820+ (
821+ @inner [ $( $tyvar: ident $( : $( ? $optbound: ident $( +) ?) * $( $bound: ident $( +) ?) * ) ?) ?]
822+ $t: ty, $u: ty
823+ ) => { {
824+ $crate:: util:: macros:: __unsafe( ) ;
825+
826+ use crate :: { KnownLayout , pointer:: { PtrInner , SizeEq } , layout:: { SizeInfo , TrailingSliceLayout } } ;
827+
828+ // SAFETY: See inline.
829+ unsafe impl <$( $tyvar $( : $( ? $optbound +) * $( $bound +) * ) ?) ?> SizeEq <$t> for $u {
830+ #[ inline( always) ]
831+ fn cast_from_raw( t: PtrInner <' _, $t>) -> PtrInner <' _, $u> {
832+ // SAFETY: We've asserted that their
833+ // `KnownLayout::LAYOUT.size_info`s are equal, and so this
834+ // cast is guaranteed to preserve address and referent size.
835+ // It trivially preserves provenance.
836+ unsafe { cast!( t) }
818837 }
819- // SAFETY: See previous safety comment.
820- unsafe impl SizeEq <$u> for $t {
821- # [ inline ( always ) ]
822- fn cast_from_raw ( u : PtrInner < ' _ , $u> ) -> PtrInner < ' _ , $t> {
823- // SAFETY: See previous safety comment.
824- unsafe { cast! ( u ) }
825- }
838+ }
839+ // SAFETY: See previous safety comment.
840+ unsafe impl <$ ( $tyvar $ ( : $ ( ? $optbound + ) * $ ( $bound + ) * ) ? ) ?> SizeEq <$u> for $t {
841+ # [ inline ( always ) ]
842+ fn cast_from_raw ( u : PtrInner < ' _ , $u> ) -> PtrInner < ' _ , $t> {
843+ // SAFETY: See previous safety comment.
844+ unsafe { cast! ( u ) }
826845 }
827- } ;
828- } ;
846+ }
847+ } } ;
829848}
830849
831850/// Invokes `$blk` in a context in which `$src<$t>` and `$dst<$u>` implement
0 commit comments