This repository was archived by the owner on May 28, 2025. It is now read-only.
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> {
321
321
/// It is an error to reentrantly initialize the cell from `f`. The exact
322
322
/// outcome is unspecified. Current implementation deadlocks, but this may
323
323
/// 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 >
325
325
where
326
326
F : FnOnce ( ) -> T ,
327
327
G : FnOnce ( Pin < & mut T > ) ,
328
328
{
329
329
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) } ;
331
333
}
332
334
333
335
let slot = & self . value ;
@@ -345,8 +347,9 @@ impl<T> SyncOnceCell<T> {
345
347
g ( unsafe { Pin :: new_unchecked ( value) } ) ;
346
348
} ) ;
347
349
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 ( ) ) }
350
353
}
351
354
352
355
/// Consumes the `SyncOnceCell`, returning the wrapped value. Returns
You can’t perform that action at this time.
0 commit comments