diff --git a/tests/compile-fail/stacked_borrows/deallocate_against_barrier.rs b/tests/compile-fail/stacked_borrows/deallocate_against_barrier1.rs similarity index 100% rename from tests/compile-fail/stacked_borrows/deallocate_against_barrier.rs rename to tests/compile-fail/stacked_borrows/deallocate_against_barrier1.rs diff --git a/tests/compile-fail/stacked_borrows/deallocate_against_barrier2.rs b/tests/compile-fail/stacked_borrows/deallocate_against_barrier2.rs new file mode 100644 index 000000000000..db4d2d998dbd --- /dev/null +++ b/tests/compile-fail/stacked_borrows/deallocate_against_barrier2.rs @@ -0,0 +1,17 @@ +// error-pattern: deallocating while item is protected + +use std::cell::Cell; + +// Check that even `&Cell` are dereferencable. +// Also see . +fn inner(x: &Cell, f: fn(&Cell)) { + // `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; + drop(unsafe { Box::from_raw(raw) }); + }); +}