Skip to content

Commit e8b3e46

Browse files
committed
Revert "Use ManuallyDrop<T> instead of mem::forget in scopeguard"
This reverts commit ca6cd09.
1 parent a54ecb4 commit e8b3e46

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/scopeguard.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Extracted from the scopeguard crate
22
use core::{
3-
mem::ManuallyDrop,
3+
mem,
44
ops::{Deref, DerefMut},
55
ptr,
66
};
@@ -28,16 +28,15 @@ where
2828
#[inline]
2929
pub fn into_inner(guard: Self) -> T {
3030
// Cannot move out of Drop-implementing types, so
31-
// ptr::read the value out of a ManuallyDrop<Self>
32-
// Don't use mem::forget as that might invalidate value
33-
let guard = ManuallyDrop::new(guard);
31+
// ptr::read the value and forget the guard.
3432
unsafe {
3533
let value = ptr::read(&guard.value);
3634
// read the closure so that it is dropped, and assign it to a local
3735
// variable to ensure that it is only dropped after the guard has
3836
// been forgotten. (In case the Drop impl of the closure, or that
3937
// of any consumed captured variable, panics).
4038
let _dropfn = ptr::read(&guard.dropfn);
39+
mem::forget(guard);
4140
value
4241
}
4342
}

0 commit comments

Comments
 (0)