]> git.lizzy.rs Git - rust.git/commitdiff
this also fixed our 2-phase woes
authorRalf Jung <post@ralfj.de>
Wed, 15 May 2019 15:52:08 +0000 (17:52 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 15 May 2019 16:12:58 +0000 (18:12 +0200)
tests/run-pass/stacked-borrows/interior_mutability.rs

index 33f44d0093ed4d4886961dab416ef15d796d25a4..d27519df48a752132cdf8c16b601f3c99249421e 100644 (file)
@@ -1,12 +1,12 @@
 #![feature(maybe_uninit, maybe_uninit_ref)]
 use std::mem::MaybeUninit;
-use std::cell::Cell;
-use std::cell::RefCell;
+use std::cell::{Cell, RefCell, UnsafeCell};
 
 fn main() {
     aliasing_mut_and_shr();
     aliasing_frz_and_shr();
     into_interior_mutability();
+    unsafe_cell_2phase();
 }
 
 fn aliasing_mut_and_shr() {
@@ -57,3 +57,12 @@ fn into_interior_mutability() {
     let ptr = unsafe { x.get_ref() };
     assert_eq!(ptr.1, 1);
 }
+
+// Two-phase borrows of the pointer returned by UnsafeCell::get() should not
+// invalidate aliases.
+fn unsafe_cell_2phase() { unsafe {
+    let x = &UnsafeCell::new(vec![]);
+    let x2 = &*x;
+    (*x.get()).push(0);
+    let _val = (*x2.get()).get(0);
+} }