From 551453363eb65d76fda4b0bc3d11bfdfa9ae731a Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 17 Jun 2024 18:38:46 -0400 Subject: [PATCH] Allow map_in_place to be called then the callee is already panicking. (#300) - Forget the abort on panic once we know the closure did not panic. Update util.rs --- src/util.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); } }