@@ -196,7 +196,7 @@ use crate::cmp::Ordering;
196
196
use crate :: fmt:: { self , Debug , Display } ;
197
197
use crate :: marker:: { PhantomData , Unsize } ;
198
198
use crate :: mem;
199
- use crate :: ops:: { CoerceUnsized , Deref , DerefMut } ;
199
+ use crate :: ops:: { CoerceUnsized , Deref , DerefMut , DispatchFromDyn } ;
200
200
use crate :: ptr:: { self , NonNull } ;
201
201
202
202
mod lazy;
@@ -571,6 +571,16 @@ impl<T: Default> Cell<T> {
571
571
#[ unstable( feature = "coerce_unsized" , issue = "18598" ) ]
572
572
impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
573
573
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
+
574
584
impl < T > Cell < [ T ] > {
575
585
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
576
586
///
@@ -2078,6 +2088,16 @@ impl<T> const From<T> for UnsafeCell<T> {
2078
2088
#[ unstable( feature = "coerce_unsized" , issue = "18598" ) ]
2079
2089
impl < T : CoerceUnsized < U > , U > CoerceUnsized < UnsafeCell < U > > for UnsafeCell < T > { }
2080
2090
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
+
2081
2101
/// [`UnsafeCell`], but [`Sync`].
2082
2102
///
2083
2103
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2169,6 +2189,17 @@ impl<T> const From<T> for SyncUnsafeCell<T> {
2169
2189
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2170
2190
impl < T : CoerceUnsized < U > , U > CoerceUnsized < SyncUnsafeCell < U > > for SyncUnsafeCell < T > { }
2171
2191
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
+
2172
2203
#[ allow( unused) ]
2173
2204
fn assert_coerce_unsized (
2174
2205
a : UnsafeCell < & i32 > ,
0 commit comments