]> git.lizzy.rs Git - rust.git/blobdiff - tests/run-pass/stacked-borrows/stacked-borrows.rs
more tests -- also one showing why we are not done yet
[rust.git] / tests / run-pass / stacked-borrows / stacked-borrows.rs
index 791e97f0eb1e1a7c0d7ebd25b0f9f2892ea9c99c..7d84e33b3d6b3ff7dafea2f6263bec3bedb0bff1 100644 (file)
@@ -11,6 +11,7 @@ fn main() {
     drop_after_sharing();
     direct_mut_to_const_raw();
     two_raw();
+    shr_and_raw();
 }
 
 // Deref a raw ptr to access a field of a large struct, where the field
@@ -136,3 +137,15 @@ fn two_raw() { unsafe {
     *y1 += 2;
     *y2 += 1;
 } }
+
+// Make sure that creating a *mut does not invalidate existing shared references.
+fn shr_and_raw() { /* unsafe {
+    use std::mem;
+    // FIXME: This is currently disabled because "as *mut _" incurs a reborrow.
+    let x = &mut 0;
+    let y1: &i32 = mem::transmute(&*x); // launder lifetimes
+    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.
+} */ }