Skip to content

Commit b55ae00

Browse files
committed
Auto merge of #901 - RalfJung:protected, r=RalfJung
test that even &Cell must be dereferencable Behavior here changed (deliberately) with Stacked Borrows 2; just making sure we notice when/if it ever changes again.
2 parents c1cb249 + b936292 commit b55ae00

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)