diff --git a/src/util.rs b/src/util.rs index d84e37db..09ffc850 100644 --- a/src/util.rs +++ b/src/util.rs @@ -12,9 +12,13 @@ pub fn map_in_place_2 T>((k, v): (U, &mut T), f: F) { // # Safety // // If the closure panics, we must abort otherwise we could double drop `T` - let _promote_panic_to_abort = AbortOnPanic; + let promote_panic_to_abort = AbortOnPanic; ptr::write(v, f(k, ptr::read(v))); + + // If we made it here, the calling thread could have already have panicked, in which case + // We know that the closure did not panic, so don't bother checking. + std::mem::forget(promote_panic_to_abort); } }