From 9f48b3029ca51997945ae4170f1e2b0ebb23a7a2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 May 2019 19:26:50 +0200 Subject: [PATCH] test that we cannot access unescaped static memory with a raw ptr --- tests/compile-fail/stacked_borrows/unescaped_static.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/compile-fail/stacked_borrows/unescaped_static.rs diff --git a/tests/compile-fail/stacked_borrows/unescaped_static.rs b/tests/compile-fail/stacked_borrows/unescaped_static.rs new file mode 100644 index 00000000000..0f0467fc5cb --- /dev/null +++ b/tests/compile-fail/stacked_borrows/unescaped_static.rs @@ -0,0 +1,7 @@ +static ARRAY: [u8; 2] = [0, 1]; + +fn main() { + let ptr_to_first = &ARRAY[0] as *const u8; + // Illegally use this to access the 2nd element. + let _val = unsafe { *ptr_to_first.add(1) }; //~ ERROR borrow stack +}