Skip to content

Commit b936292

Browse files
committed
test that even &Cell must be dereferencable
1 parent c1cb249 commit b936292

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// error-pattern: deallocating while item is protected
2+
3+
use std::cell::Cell;
4+
5+
// Check that even `&Cell` are dereferencable.
6+
// Also see <https://github.com/rust-lang/rust/issues/55005>.
7+
fn inner(x: &Cell<i32>, f: fn(&Cell<i32>)) {
8+
// `f` may mutate, but it may not deallocate!
9+
f(x)
10+
}
11+
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+
}

0 commit comments

Comments
 (0)