File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -321,13 +321,15 @@ impl<T> SyncOnceCell<T> {
321321 /// It is an error to reentrantly initialize the cell from `f`. The exact
322322 /// outcome is unspecified. Current implementation deadlocks, but this may
323323 /// be changed to a panic in the future.
324- pub ( crate ) fn get_or_init_pin < F , G > ( self : Pin < & Self > , f : F , g : G ) -> & T
324+ pub ( crate ) fn get_or_init_pin < F , G > ( self : Pin < & Self > , f : F , g : G ) -> Pin < & T >
325325 where
326326 F : FnOnce ( ) -> T ,
327327 G : FnOnce ( Pin < & mut T > ) ,
328328 {
329329 if let Some ( value) = self . get_ref ( ) . get ( ) {
330- return value;
330+ // SAFETY: The inner value was already initialized, and will not be
331+ // moved anymore.
332+ return unsafe { Pin :: new_unchecked ( value) } ;
331333 }
332334
333335 let slot = & self . value ;
@@ -345,8 +347,9 @@ impl<T> SyncOnceCell<T> {
345347 g ( unsafe { Pin :: new_unchecked ( value) } ) ;
346348 } ) ;
347349
348- // SAFETY: The inner value has been initialized.
349- unsafe { self . get_ref ( ) . get_unchecked ( ) }
350+ // SAFETY: The inner value has been initialized, and will not be moved
351+ // anymore.
352+ unsafe { Pin :: new_unchecked ( self . get_ref ( ) . get_unchecked ( ) ) }
350353 }
351354
352355 /// Consumes the `SyncOnceCell`, returning the wrapped value. Returns
You can’t perform that action at this time.
0 commit comments