@@ -196,7 +196,7 @@ use crate::cmp::Ordering;
196196use crate :: fmt:: { self , Debug , Display } ;
197197use crate :: marker:: { PhantomData , Unsize } ;
198198use crate :: mem;
199- use crate :: ops:: { CoerceUnsized , Deref , DerefMut } ;
199+ use crate :: ops:: { CoerceUnsized , Deref , DerefMut , DispatchFromDyn } ;
200200use crate :: ptr:: { self , NonNull } ;
201201
202202mod lazy;
@@ -571,6 +571,16 @@ impl<T: Default> Cell<T> {
571571#[ unstable( feature = "coerce_unsized" , issue = "18598" ) ]
572572impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
573573
574+ // Allow types that wrap `Cell` to also implement `DispatchFromDyn`
575+ // and become object safe method receivers.
576+ // Note that currently `Cell` itself cannot be a method receiver
577+ // because it does not implement Deref.
578+ // In other words:
579+ // `self: Cell<&Self>` won't work
580+ // `self: CellWrapper<Self>` becomes possible
581+ #[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
582+ impl < T : DispatchFromDyn < U > , U > DispatchFromDyn < Cell < U > > for Cell < T > { }
583+
574584impl < T > Cell < [ T ] > {
575585 /// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
576586 ///
@@ -2078,6 +2088,16 @@ impl<T> const From<T> for UnsafeCell<T> {
20782088#[ unstable( feature = "coerce_unsized" , issue = "18598" ) ]
20792089impl < T : CoerceUnsized < U > , U > CoerceUnsized < UnsafeCell < U > > for UnsafeCell < T > { }
20802090
2091+ // Allow types that wrap `UnsafeCell` to also implement `DispatchFromDyn`
2092+ // and become object safe method receivers.
2093+ // Note that currently `UnsafeCell` itself cannot be a method receiver
2094+ // because it does not implement Deref.
2095+ // In other words:
2096+ // `self: UnsafeCell<&Self>` won't work
2097+ // `self: UnsafeCellWrapper<Self>` becomes possible
2098+ #[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
2099+ impl < T : DispatchFromDyn < U > , U > DispatchFromDyn < UnsafeCell < U > > for UnsafeCell < T > { }
2100+
20812101/// [`UnsafeCell`], but [`Sync`].
20822102///
20832103/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2169,6 +2189,17 @@ impl<T> const From<T> for SyncUnsafeCell<T> {
21692189//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
21702190impl < T : CoerceUnsized < U > , U > CoerceUnsized < SyncUnsafeCell < U > > for SyncUnsafeCell < T > { }
21712191
2192+ // Allow types that wrap `SyncUnsafeCell` to also implement `DispatchFromDyn`
2193+ // and become object safe method receivers.
2194+ // Note that currently `SyncUnsafeCell` itself cannot be a method receiver
2195+ // because it does not implement Deref.
2196+ // In other words:
2197+ // `self: SyncUnsafeCell<&Self>` won't work
2198+ // `self: SyncUnsafeCellWrapper<Self>` becomes possible
2199+ #[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
2200+ //#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2201+ impl < T : DispatchFromDyn < U > , U > DispatchFromDyn < SyncUnsafeCell < U > > for SyncUnsafeCell < T > { }
2202+
21722203#[ allow( unused) ]
21732204fn assert_coerce_unsized (
21742205 a : UnsafeCell < & i32 > ,
0 commit comments