Closed
Description
Test Case 1: Playground
use std::cell::Cell;
use std::panic::{self, AssertRecoverSafe};
fn main() {
let should_work = AssertRecoverSafe(Cell::new(0));
panic::recover(|| should_work.set(0));
}
Test Case 2: Playground
use std::cell::Cell;
use std::panic::{self, RecoverSafe};
struct MyWrapper(Cell<u32>);
impl RecoverSafe for MyWrapper {}
fn main() {
let should_work = MyWrapper(Cell::new(0));
panic::recover(|| should_work.0.set(0));
}
Both produce errors like this:
<anon>:8:5: 8:19 error: the trait `std::panic::NoUnsafeCell` is not implemented for the type `core::cell::UnsafeCell<i32>` [E0277]
<anon>:8 panic::recover(|| should_work.set(0));
^~~~~~~~~~~~~~
<anon>:8:5: 8:19 help: see the detailed explanation for E0277
<anon>:8:5: 8:19 note: the type core::cell::UnsafeCell<i32> contains interior mutability and a reference may not be safely transferrable across a recover boundary
<anon>:8:5: 8:19 note: required because of the requirements on the impl of `std::panic::NoUnsafeCell` for `core::cell::Cell<i32>`
<anon>:8:5: 8:19 note: required because of the requirements on the impl of `std::panic::NoUnsafeCell` for `std::panic::AssertRecoverSafe<core::cell::Cell<i32>>`
<anon>:8:5: 8:19 note: required because of the requirements on the impl of `std::panic::RecoverSafe` for `[closure@<anon>:8:20: 8:41 should_work:&std::panic::AssertRecoverSafe<core::cell::Cell<i32>>]`
<anon>:8:5: 8:19 note: required by `std::panic::recover`
error: aborting due to previous error
playpen: application terminated with error code 101