Skip to content

Commit

Permalink
Allow map_in_place to be called then the callee is already panicking. (
Browse files Browse the repository at this point in the history
…#300)

- Forget the abort on panic once we know the closure did not panic.

Update util.rs
  • Loading branch information
dtzxporter authored Jun 17, 2024
1 parent 4be6f57 commit 5514533
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ pub fn map_in_place_2<T, U, F: FnOnce(U, T) -> 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);
}
}

Expand Down

0 comments on commit 5514533

Please sign in to comment.