From e0adfe4d459482240d0614990fcb0ea112d48cf4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 30 Jan 2020 12:21:37 +0100 Subject: [PATCH] new compile-fail test involving non-reborrowing-cast-to-raw --- tests/compile-fail/stacked_borrows/illegal_read8.rs | 13 +++++++++++++ tests/run-pass/stacked-borrows/stacked-borrows.rs | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/compile-fail/stacked_borrows/illegal_read8.rs diff --git a/tests/compile-fail/stacked_borrows/illegal_read8.rs b/tests/compile-fail/stacked_borrows/illegal_read8.rs new file mode 100644 index 000000000000..72fca84ba19b --- /dev/null +++ b/tests/compile-fail/stacked_borrows/illegal_read8.rs @@ -0,0 +1,13 @@ +// Make sure that creating a raw ptr next to a shared ref works +// but the shared ref still gets invalidated when the raw ptr is used for writing. + +fn main() { unsafe { + use std::mem; + let x = &mut 0; + let y1: &i32 = mem::transmute(&*x); // launder lifetimes + let y2 = x as *mut _; + let _val = *y2; + let _val = *y1; + *y2 += 1; + let _fail = *y1; //~ ERROR borrow stack +} } diff --git a/tests/run-pass/stacked-borrows/stacked-borrows.rs b/tests/run-pass/stacked-borrows/stacked-borrows.rs index 208cb7e15e03..824437f4f1bf 100644 --- a/tests/run-pass/stacked-borrows/stacked-borrows.rs +++ b/tests/run-pass/stacked-borrows/stacked-borrows.rs @@ -136,7 +136,6 @@ fn shr_and_raw() { unsafe { let y2 = x as *mut _; let _val = *y1; *y2 += 1; - // TODO: Once this works, add compile-fail test that tries to read from y1 again. } } fn disjoint_mutable_subborrows() {