diff --git a/ci/miri.sh b/ci/miri.sh
index 68d6af61c6..9d845d833b 100644
--- a/ci/miri.sh
+++ b/ci/miri.sh
@@ -9,4 +9,4 @@ rustup toolchain install nightly --component miri
 rustup override set nightly
 cargo miri setup
 
-cargo miri test
+MIRIFLAGS='-Zmiri-retag-fields' cargo miri test
diff --git a/src/scopeguard.rs b/src/scopeguard.rs
index f85e6ab0ed..382d06043e 100644
--- a/src/scopeguard.rs
+++ b/src/scopeguard.rs
@@ -1,6 +1,6 @@
 // Extracted from the scopeguard crate
 use core::{
-    mem,
+    mem::ManuallyDrop,
     ops::{Deref, DerefMut},
     ptr,
 };
@@ -28,15 +28,13 @@ where
     #[inline]
     pub fn into_inner(guard: Self) -> T {
         // Cannot move out of Drop-implementing types, so
-        // ptr::read the value and forget the guard.
+        // ptr::read the value out of a ManuallyDrop<Self>
+        // Don't use mem::forget as that might invalidate value
+        let guard = ManuallyDrop::new(guard);
         unsafe {
             let value = ptr::read(&guard.value);
-            // read the closure so that it is dropped, and assign it to a local
-            // variable to ensure that it is only dropped after the guard has
-            // been forgotten. (In case the Drop impl of the closure, or that
-            // of any consumed captured variable, panics).
-            let _dropfn = ptr::read(&guard.dropfn);
-            mem::forget(guard);
+            // read the closure so that it is dropped
+            let _ = ptr::read(&guard.dropfn);
             value
         }
     }