@@ -193,7 +193,7 @@ extern crate core as std;
193
193
194
194
use std:: fmt;
195
195
use std:: marker:: PhantomData ;
196
- use std:: mem:: { self , ManuallyDrop } ;
196
+ use std:: mem:: ManuallyDrop ;
197
197
use std:: ops:: { Deref , DerefMut } ;
198
198
use std:: ptr;
199
199
@@ -346,16 +346,15 @@ impl<T, F, S> ScopeGuard<T, F, S>
346
346
/// ```
347
347
#[ inline]
348
348
pub fn into_inner ( guard : Self ) -> T {
349
- // Cannot move out of Drop-implementing types, so
350
- // ptr::read the value and forget the guard.
349
+ // Cannot move out of Drop-implementing types, so ptr::read the value
350
+ // and forget the guard.
351
+ let guard = ManuallyDrop :: new ( guard) ;
351
352
unsafe {
352
353
let value = ptr:: read ( & * guard. value ) ;
353
- // read the closure so that it is dropped, and assign it to a local
354
- // variable to ensure that it is only dropped after the guard has
355
- // been forgotten. (In case the Drop impl of the closure, or that
356
- // of any consumed captured variable, panics).
357
- let _dropfn = ptr:: read ( & * guard. dropfn ) ;
358
- mem:: forget ( guard) ;
354
+ // Read the closure so that it gets dropped. Do this after value has
355
+ // also been read so that, if the closure's drop function panics,
356
+ // unwinding still tries to drop value.
357
+ ptr:: read ( & * guard. dropfn )
359
358
value
360
359
}
361
360
}
0 commit comments