Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ 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 = AbortOnDrop;

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.
// If we made it here, the operation has already completed, so no need to panic.
std::mem::forget(promote_panic_to_abort);
}
}

struct AbortOnPanic;
struct AbortOnDrop;

impl Drop for AbortOnPanic {
impl Drop for AbortOnDrop {
fn drop(&mut self) {
if std::thread::panicking() {
std::process::abort()
}
std::process::abort()
}
}

Expand Down