From b93629262dc66361387fd045e53bd01e9e45311b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 9 Aug 2019 19:21:41 +0200 Subject: [PATCH] test that even &Cell must be dereferencable --- ...arrier.rs => deallocate_against_barrier1.rs} | 0 .../deallocate_against_barrier2.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) rename tests/compile-fail/stacked_borrows/{deallocate_against_barrier.rs => deallocate_against_barrier1.rs} (100%) create mode 100644 tests/compile-fail/stacked_borrows/deallocate_against_barrier2.rs 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 00000000000..db4d2d998db --- /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) }); + }); +}