1 // error-pattern: deallocating while item is protected
2 
3 use std::cell::Cell;
4 
5 // Check that even `&Cell` are dereferenceable.
6 // Also see <https://github.com/rust-lang/rust/issues/55005>.
inner(x: &Cell<i32>, f: fn(&Cell<i32>))7 fn inner(x: &Cell<i32>, f: fn(&Cell<i32>)) {
8     // `f` may mutate, but it may not deallocate!
9     f(x)
10 }
11 
main()12 fn main() {
13     inner(Box::leak(Box::new(Cell::new(0))), |x| {
14         let raw = x as *const _ as *mut Cell<i32>;
15         drop(unsafe { Box::from_raw(raw) });
16     });
17 }
18