@@ -576,33 +576,24 @@ impl<Fut> Drop for FuturesUnordered<Fut> {
576576 // Before the strong reference to the queue is dropped we need all
577577 // futures to be dropped. See note at the bottom of this method.
578578 //
579- // This ensures we drop all futures even in the case of one drop
580- // panicking and unwinding.
581- //
582- // If a second future panics, that will trigger an abort from panicking
583- // while panicking.
584- struct DropGuard < ' a , Fut > ( & ' a mut FuturesUnordered < Fut > ) ;
585- impl < Fut > DropGuard < ' _ , Fut > {
586- fn drop_futures ( & mut self ) {
587- // When a `FuturesUnordered` is dropped we want to drop all futures
588- // associated with it. At the same time though there may be tons of
589- // wakers flying around which contain `Task<Fut>` references
590- // inside them. We'll let those naturally get deallocated.
591- while !self . 0 . head_all . get_mut ( ) . is_null ( ) {
592- let head = * self . 0 . head_all . get_mut ( ) ;
593- let task = unsafe { self . 0 . unlink ( head) } ;
594- self . 0 . release_task ( task) ;
595- }
596- }
597- }
598- impl < Fut > Drop for DropGuard < ' _ , Fut > {
579+ // If there is a panic before this completes, we leak the queue.
580+ struct LeakQueueOnDrop < ' a , Fut > ( & ' a mut FuturesUnordered < Fut > ) ;
581+ impl < Fut > Drop for LeakQueueOnDrop < ' _ , Fut > {
599582 fn drop ( & mut self ) {
600- self . drop_futures ( ) ;
583+ mem :: forget ( Arc :: clone ( & self . 0 . ready_to_run_queue ) ) ;
601584 }
602585 }
603- let mut guard = DropGuard ( self ) ;
604- guard. drop_futures ( ) ;
605- mem:: forget ( guard) ; // no need to check head_all again
586+ let guard = LeakQueueOnDrop ( self ) ;
587+ // When a `FuturesUnordered` is dropped we want to drop all futures
588+ // associated with it. At the same time though there may be tons of
589+ // wakers flying around which contain `Task<Fut>` references
590+ // inside them. We'll let those naturally get deallocated.
591+ while !guard. 0 . head_all . get_mut ( ) . is_null ( ) {
592+ let head = * guard. 0 . head_all . get_mut ( ) ;
593+ let task = unsafe { guard. 0 . unlink ( head) } ;
594+ guard. 0 . release_task ( task) ;
595+ }
596+ mem:: forget ( guard) ; // safe to release strong reference to queue
606597
607598 // Note that at this point we could still have a bunch of tasks in the
608599 // ready to run queue. None of those tasks, however, have futures
0 commit comments