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.
This commit is contained in:
commit
b55ae00991
2 changed files with 17 additions and 0 deletions
|
|
@ -0,0 +1,17 @@
|
|||
// error-pattern: deallocating while item is protected
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
// Check that even `&Cell` are dereferencable.
|
||||
// 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) });
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue