5959//! method argument, but is a very common return type, and hence implements
6060//! [`Encode`].
6161
62+ use core:: cell:: { Cell , UnsafeCell } ;
6263use core:: ffi:: c_void;
6364use core:: mem:: { self , ManuallyDrop , MaybeUninit } ;
6465use core:: num:: {
@@ -484,11 +485,15 @@ encode_impls_transparent! {
484485 // TODO: With specialization: `impl Encode for ManuallyDrop<Box<T>>`
485486 ManuallyDrop <T : ?Sized >,
486487
488+ // SAFETY: Guaranteed to have the same in-memory representation `T`.
489+ //
487490 // The fact that this has `repr(no_niche)` has no effect on us, since we
488491 // don't unconditionally implement `Encode` generically over `Option`.
489492 // (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 >,
492497
493498 // The inner field is not public, so may not be safe.
494499 // TODO: Pin<T>,
@@ -499,9 +504,6 @@ encode_impls_transparent! {
499504 // SAFETY: Guaranteed to have the same layout and ABI as `T`.
500505 Wrapping <T >,
501506
502- // It might have requirements that would disourage this impl?
503- // TODO: Cell<T>
504-
505507 // TODO: Types that need to be made repr(transparent) first:
506508 // - core::cell::Ref?
507509 // - core::cell::RefCell?
@@ -702,13 +704,13 @@ mod tests {
702704 assert_eq ! ( <ManuallyDrop <Option <& u8 >>>:: ENCODING , u8 :: ENCODING_REF ) ;
703705 assert_eq ! ( <& ManuallyDrop <Option <& u8 >>>:: ENCODING , <&&u8 >:: ENCODING ) ;
704706
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 ) ;
706711 // assert_eq!(<Pin<u8>>::ENCODING, u8::ENCODING);
707712 assert_eq ! ( <MaybeUninit <u8 >>:: ENCODING , u8 :: ENCODING ) ;
708713 assert_eq ! ( <Wrapping <u8 >>:: ENCODING , u8 :: ENCODING ) ;
709-
710- // Shouldn't compile
711- // assert_eq!(<Option<UnsafeCell<&u8>>>::ENCODING, <&u8>::ENCODING);
712714 }
713715
714716 #[ test]
0 commit comments