@@ -417,10 +417,12 @@ mod atomics {
417417    use  super :: * ; 
418418
419419    macro_rules!  impl_traits_for_atomics { 
420-         ( $( $atomics: ident) ,*  $( , ) ?)  => { 
420+         ( $( $atomics: ident  [ $primitives : ident ] ) ,*  $( , ) ?)  => { 
421421            $( 
422+                 impl_size_eq!( $atomics,  $primitives) ; 
422423                impl_known_layout!( $atomics) ; 
423-                 impl_for_transparent_wrapper!( => TryFromBytes  for  $atomics) ; 
424+                 impl_for_transmute_from!( => TryFromBytes  for  $atomics [ UnsafeCell <$primitives>] ) ; 
425+                 // impl_for_transparent_wrapper!(=> TryFromBytes for $atomics); 
424426                impl_for_transparent_wrapper!( => FromZeros  for  $atomics) ; 
425427                impl_for_transparent_wrapper!( => FromBytes  for  $atomics) ; 
426428                impl_for_transparent_wrapper!( => IntoBytes  for  $atomics) ; 
@@ -435,11 +437,13 @@ mod atomics {
435437
436438        use  super :: * ; 
437439
438-         impl_traits_for_atomics ! ( AtomicU8 ,  AtomicI8 ) ; 
440+         impl_traits_for_atomics ! ( AtomicU8 [ u8 ] ,  AtomicI8 [ i8 ] ) ; 
439441
442+         impl_size_eq ! ( AtomicBool ,  bool ) ; 
440443        impl_known_layout ! ( AtomicBool ) ; 
441444
442-         impl_for_transparent_wrapper ! ( => TryFromBytes  for  AtomicBool ) ; 
445+         // impl_for_transparent_wrapper!(=> TryFromBytes for AtomicBool); 
446+         impl_for_transmute_from ! ( => TryFromBytes  for  AtomicBool  [ UnsafeCell <bool >] ) ; 
443447        impl_for_transparent_wrapper ! ( => FromZeros  for  AtomicBool ) ; 
444448        impl_for_transparent_wrapper ! ( => IntoBytes  for  AtomicBool ) ; 
445449
@@ -472,6 +476,7 @@ mod atomics {
472476             /// All of these pass an atomic type and that type's native equivalent, as 
473477             /// required by the macro safety preconditions. 
474478             unsafe_impl_transparent_wrapper_for_atomic!( AtomicU8  [ u8 ] ,  AtomicI8  [ i8 ] ,  AtomicBool  [ bool ] ) ; 
479+             unsafe_impl_transmute_from_for_atomic!( AtomicU8  [ u8 ] ,  AtomicI8  [ i8 ] ,  AtomicBool  [ bool ] ) ; 
475480        } 
476481    } 
477482
@@ -482,13 +487,14 @@ mod atomics {
482487
483488        use  super :: * ; 
484489
485-         impl_traits_for_atomics ! ( AtomicU16 ,  AtomicI16 ) ; 
490+         impl_traits_for_atomics ! ( AtomicU16 [ u16 ] ,  AtomicI16 [ i16 ] ) ; 
486491
487492        safety_comment !  { 
488493            /// SAFETY: 
489494             /// All of these pass an atomic type and that type's native equivalent, as 
490495             /// required by the macro safety preconditions. 
491496             unsafe_impl_transparent_wrapper_for_atomic!( AtomicU16  [ u16 ] ,  AtomicI16  [ i16 ] ) ; 
497+             unsafe_impl_transmute_from_for_atomic!( AtomicU16  [ u16 ] ,  AtomicI16  [ i16 ] ) ; 
492498        } 
493499    } 
494500
@@ -499,13 +505,14 @@ mod atomics {
499505
500506        use  super :: * ; 
501507
502-         impl_traits_for_atomics ! ( AtomicU32 ,  AtomicI32 ) ; 
508+         impl_traits_for_atomics ! ( AtomicU32 [ u32 ] ,  AtomicI32 [ i32 ] ) ; 
503509
504510        safety_comment !  { 
505511            /// SAFETY: 
506512             /// All of these pass an atomic type and that type's native equivalent, as 
507513             /// required by the macro safety preconditions. 
508514             unsafe_impl_transparent_wrapper_for_atomic!( AtomicU32  [ u32 ] ,  AtomicI32  [ i32 ] ) ; 
515+             unsafe_impl_transmute_from_for_atomic!( AtomicU32  [ u32 ] ,  AtomicI32  [ i32 ] ) ; 
509516        } 
510517    } 
511518
@@ -516,13 +523,14 @@ mod atomics {
516523
517524        use  super :: * ; 
518525
519-         impl_traits_for_atomics ! ( AtomicU64 ,  AtomicI64 ) ; 
526+         impl_traits_for_atomics ! ( AtomicU64 [ u64 ] ,  AtomicI64 [ i64 ] ) ; 
520527
521528        safety_comment !  { 
522529            /// SAFETY: 
523530             /// All of these pass an atomic type and that type's native equivalent, as 
524531             /// required by the macro safety preconditions. 
525532             unsafe_impl_transparent_wrapper_for_atomic!( AtomicU64  [ u64 ] ,  AtomicI64  [ i64 ] ) ; 
533+             unsafe_impl_transmute_from_for_atomic!( AtomicU64  [ u64 ] ,  AtomicI64  [ i64 ] ) ; 
526534        } 
527535    } 
528536
@@ -533,13 +541,23 @@ mod atomics {
533541
534542        use  super :: * ; 
535543
536-         impl_traits_for_atomics ! ( AtomicUsize ,  AtomicIsize ) ; 
544+         impl_traits_for_atomics ! ( AtomicUsize [ usize ] ,  AtomicIsize [ isize ] ) ; 
537545
538546        impl_known_layout ! ( T  => AtomicPtr <T >) ; 
539547
548+         // SAFETY: `AtomicPtr<T>` and `*mut T` have the same size [1]. 
549+         // 
550+         // [1] Per https://doc.rust-lang.org/1.85.0/std/sync/atomic/struct.AtomicPtr.html: 
551+         // 
552+         //   This type has the same size and bit validity as a `*mut T`. 
553+         unsafe  impl < T >  crate :: pointer:: SizeEq < * mut  T >  for  AtomicPtr < T >  { } 
554+         // SAFETY: See previous safety comment. 
555+         unsafe  impl < T >  crate :: pointer:: SizeEq < AtomicPtr < T > >  for  * mut  T  { } 
556+ 
540557        // TODO(#170): Implement `FromBytes` and `IntoBytes` once we implement 
541558        // those traits for `*mut T`. 
542-         impl_for_transparent_wrapper ! ( T  => TryFromBytes  for  AtomicPtr <T >) ; 
559+         // impl_for_transparent_wrapper!(T => TryFromBytes for AtomicPtr<T>); 
560+         impl_for_transmute_from ! ( T  => TryFromBytes  for  AtomicPtr <T > [ UnsafeCell <* mut  T >] ) ; 
543561        impl_for_transparent_wrapper ! ( T  => FromZeros  for  AtomicPtr <T >) ; 
544562
545563        safety_comment !  { 
@@ -548,6 +566,9 @@ mod atomics {
548566             /// required by the macro safety preconditions. 
549567             unsafe_impl_transparent_wrapper_for_atomic!( AtomicUsize  [ usize ] ,  AtomicIsize  [ isize ] ) ; 
550568            unsafe_impl_transparent_wrapper_for_atomic!( T  => AtomicPtr <T > [ * mut  T ] ) ; 
569+ 
570+             unsafe_impl_transmute_from_for_atomic!( AtomicUsize  [ usize ] ,  AtomicIsize  [ isize ] ) ; 
571+             unsafe_impl_transmute_from_for_atomic!( T  => AtomicPtr <T > [ * mut  T ] ) ; 
551572        } 
552573    } 
553574} 
@@ -578,7 +599,7 @@ safety_comment! {
578599} 
579600
580601impl_for_transparent_wrapper ! ( T :  Immutable  => Immutable  for  Wrapping <T >) ; 
581- impl_for_transparent_wrapper ! ( T :  TryFromBytes  => TryFromBytes  for  Wrapping <T >) ; 
602+ impl_for_transmute_from ! ( T :  TryFromBytes  => TryFromBytes  for  Wrapping <T >[ T ] ) ; 
582603impl_for_transparent_wrapper ! ( T :  FromZeros  => FromZeros  for  Wrapping <T >) ; 
583604impl_for_transparent_wrapper ! ( T :  FromBytes  => FromBytes  for  Wrapping <T >) ; 
584605impl_for_transparent_wrapper ! ( T :  IntoBytes  => IntoBytes  for  Wrapping <T >) ; 
@@ -599,7 +620,35 @@ impl_for_transparent_wrapper!(T: Unaligned => Unaligned for CoreMaybeUninit<T>);
599620assert_unaligned ! ( CoreMaybeUninit <( ) >,  CoreMaybeUninit <u8 >) ; 
600621
601622impl_for_transparent_wrapper ! ( T :  ?Sized  + Immutable  => Immutable  for  ManuallyDrop <T >) ; 
602- impl_for_transparent_wrapper ! ( T :  ?Sized  + TryFromBytes  => TryFromBytes  for  ManuallyDrop <T >) ; 
623+ 
624+ unsafe  impl < T :  ?Sized  + TryFromBytes >  TryFromBytes  for  ManuallyDrop < T >  { 
625+     #[ allow( clippy:: missing_inline_in_public_items) ]  
626+     fn  only_derive_is_allowed_to_implement_this_trait ( )  { } 
627+ 
628+     #[ inline( always) ]  
629+     fn  is_bit_valid < A :  crate :: pointer:: invariant:: Reference > ( 
630+         candidate :  Maybe < ' _ ,  Self ,  A > , 
631+     )  -> bool  { 
632+         // SAFETY: `ManuallyDrop<T>` and `T` have the same size [1], so this 
633+         // cast preserves size. It also preserves provenance. 
634+         // 
635+         // [1] Per https://doc.rust-lang.org/1.85.0/std/mem/struct.ManuallyDrop.html: 
636+         // 
637+         //   `ManuallyDrop<T>` is guaranteed to have the same layout and bit 
638+         //   validity as `T` 
639+         let  c:  Maybe < ' _ ,  T ,  A >  = unsafe  {  candidate. cast_unsized ( |p| cast ! ( p => NonNull <_>) )  } ; 
640+ 
641+         // SAFETY: `ManuallyDrop<T>` and `T` have the same bit validity [1], so 
642+         // this is a sound implementation of `ManuallyDrop::is_bit_valid`. 
643+         // 
644+         // [1] Per https://doc.rust-lang.org/1.85.0/std/mem/struct.ManuallyDrop.html: 
645+         // 
646+         //   `ManuallyDrop<T>` is guaranteed to have the same layout and bit 
647+         //   validity as `T` 
648+         <T  as  TryFromBytes >:: is_bit_valid ( c) 
649+     } 
650+ } 
651+ 
603652impl_for_transparent_wrapper ! ( T :  ?Sized  + FromZeros  => FromZeros  for  ManuallyDrop <T >) ; 
604653impl_for_transparent_wrapper ! ( T :  ?Sized  + FromBytes  => FromBytes  for  ManuallyDrop <T >) ; 
605654impl_for_transparent_wrapper ! ( T :  ?Sized  + IntoBytes  => IntoBytes  for  ManuallyDrop <T >) ; 
0 commit comments