2019-08-09 12:21:41 -05:00
|
|
|
// error-pattern: deallocating while item is protected
|
|
|
|
|
|
|
|
use std::cell::Cell;
|
|
|
|
|
2019-11-22 11:12:10 -06:00
|
|
|
// Check that even `&Cell` are dereferenceable.
|
2019-08-09 12:21:41 -05:00
|
|
|
// Also see <https://github.com/rust-lang/rust/issues/55005>.
|
|
|
|
fn inner(x: &Cell<i32>, f: fn(&Cell<i32>)) {
|
|
|
|
// `f` may mutate, but it may not deallocate!
|
|
|
|
f(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
inner(Box::leak(Box::new(Cell::new(0))), |x| {
|
|
|
|
let raw = x as *const _ as *mut Cell<i32>;
|
|
|
|
drop(unsafe { Box::from_raw(raw) });
|
|
|
|
});
|
|
|
|
}
|