@@ -327,7 +327,7 @@ impl<'a, 'stream, T: BorrowMut<C::Completed>, C: Completion<T>> Async<'a, 'strea
327327 (
328328 this. stream ,
329329 std:: ptr:: read ( & this. value ) ,
330- ( std:: ptr:: read ( & this. status ) ) ,
330+ std:: ptr:: read ( & this. status ) ,
331331 )
332332 }
333333 }
@@ -481,6 +481,13 @@ pub struct AsyncProj<'a, 'stream, T: 'a> {
481481 use_callback : Option < Box < dyn FnMut ( ) -> CudaResult < ( ) > + ' a > > ,
482482}
483483
484+ #[ cfg( feature = "host" ) ]
485+ unsafe impl < #[ may_dangle] ' a , ' stream , T : ' a > Drop for AsyncProj < ' a , ' stream , T > {
486+ fn drop ( & mut self ) {
487+ // no-op
488+ }
489+ }
490+
484491#[ cfg( feature = "host" ) ]
485492impl < ' a , ' stream , T : ' a > AsyncProj < ' a , ' stream , T > {
486493 #[ must_use]
@@ -511,7 +518,8 @@ impl<'a, 'stream, T: 'a> AsyncProj<'a, 'stream, T> {
511518 /// computation out of smaller ones that have all been submitted to the
512519 /// same [`Stream`].
513520 pub ( crate ) unsafe fn unwrap_unchecked ( self ) -> T {
514- self . value
521+ let ( value, _use_callback) = self . unwrap_unchecked_with_use ( ) ;
522+ value
515523 }
516524
517525 #[ allow( clippy:: type_complexity) ]
@@ -527,7 +535,16 @@ impl<'a, 'stream, T: 'a> AsyncProj<'a, 'stream, T> {
527535 pub ( crate ) unsafe fn unwrap_unchecked_with_use (
528536 self ,
529537 ) -> ( T , Option < Box < dyn FnMut ( ) -> CudaResult < ( ) > + ' a > > ) {
530- ( self . value , self . use_callback )
538+ let this = std:: mem:: ManuallyDrop :: new ( self ) ;
539+
540+ // Safety: we destructure self into its droppable components,
541+ // value and use_callback, without dropping self itself
542+ unsafe {
543+ (
544+ std:: ptr:: read ( & this. value ) ,
545+ std:: ptr:: read ( & this. use_callback ) ,
546+ )
547+ }
531548 }
532549}
533550
0 commit comments