Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read mut_ref inside of catch_unwind closure #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ pub fn take<T, F>(mut_ref: &mut T, closure: F)
use std::ptr;

unsafe {
let old_t = ptr::read(mut_ref);
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure(old_t)))
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure( ptr::read(mut_ref) )))
.unwrap_or_else(|_| ::std::process::abort());
ptr::write(mut_ref, new_t);
}
Expand Down Expand Up @@ -82,8 +81,7 @@ pub fn take_or_recover<T, F, R>(mut_ref: &mut T, recover: R, closure: F)
where F: FnOnce(T) -> T, R: FnOnce() -> T {
use std::ptr;
unsafe {
let old_t = ptr::read(mut_ref);
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure(old_t)));
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure( ptr::read(mut_ref) )));
match new_t {
Err(err) => {
let r = panic::catch_unwind(panic::AssertUnwindSafe(|| recover()))
Expand Down Expand Up @@ -145,6 +143,3 @@ fn it_works_recover_panic() {
assert!(res.is_err());
assert_eq!(&foo, &Foo::C);
}