59
59
//! method argument, but is a very common return type, and hence implements
60
60
//! [`Encode`].
61
61
62
+ use core:: cell:: { Cell , UnsafeCell } ;
62
63
use core:: ffi:: c_void;
63
64
use core:: mem:: { self , ManuallyDrop , MaybeUninit } ;
64
65
use core:: num:: {
@@ -484,11 +485,15 @@ encode_impls_transparent! {
484
485
// TODO: With specialization: `impl Encode for ManuallyDrop<Box<T>>`
485
486
ManuallyDrop <T : ?Sized >,
486
487
488
+ // SAFETY: Guaranteed to have the same in-memory representation `T`.
489
+ //
487
490
// The fact that this has `repr(no_niche)` has no effect on us, since we
488
491
// don't unconditionally implement `Encode` generically over `Option`.
489
492
// (e.g. an `Option<UnsafeCell<&u8>>` impl is not available).
490
- // The inner field is not public, so may not be stable.
491
- // TODO: UnsafeCell<T>,
493
+ UnsafeCell <T : ?Sized >,
494
+
495
+ // SAFETY: Guaranteed to have the same layout as `UnsafeCell<T>`.
496
+ Cell <T : ?Sized >,
492
497
493
498
// The inner field is not public, so may not be safe.
494
499
// TODO: Pin<T>,
@@ -499,9 +504,6 @@ encode_impls_transparent! {
499
504
// SAFETY: Guaranteed to have the same layout and ABI as `T`.
500
505
Wrapping <T >,
501
506
502
- // It might have requirements that would disourage this impl?
503
- // TODO: Cell<T>
504
-
505
507
// TODO: Types that need to be made repr(transparent) first:
506
508
// - core::cell::Ref?
507
509
// - core::cell::RefCell?
@@ -702,13 +704,13 @@ mod tests {
702
704
assert_eq ! ( <ManuallyDrop <Option <& u8 >>>:: ENCODING , u8 :: ENCODING_REF ) ;
703
705
assert_eq ! ( <& ManuallyDrop <Option <& u8 >>>:: ENCODING , <&&u8 >:: ENCODING ) ;
704
706
705
- // assert_eq!(<UnsafeCell<u8>>::ENCODING, u8::ENCODING);
707
+ assert_eq ! ( <UnsafeCell <u8 >>:: ENCODING , u8 :: ENCODING ) ;
708
+ assert_eq ! ( <UnsafeCell <& u8 >>:: ENCODING , <& u8 >:: ENCODING ) ;
709
+ assert_eq ! ( <Cell <u8 >>:: ENCODING , u8 :: ENCODING ) ;
710
+ assert_eq ! ( <Cell <& u8 >>:: ENCODING , <& u8 >:: ENCODING ) ;
706
711
// assert_eq!(<Pin<u8>>::ENCODING, u8::ENCODING);
707
712
assert_eq ! ( <MaybeUninit <u8 >>:: ENCODING , u8 :: ENCODING ) ;
708
713
assert_eq ! ( <Wrapping <u8 >>:: ENCODING , u8 :: ENCODING ) ;
709
-
710
- // Shouldn't compile
711
- // assert_eq!(<Option<UnsafeCell<&u8>>>::ENCODING, <&u8>::ENCODING);
712
714
}
713
715
714
716
#[ test]
0 commit comments