From: Ralf Jung Date: Wed, 15 May 2019 15:52:08 +0000 (+0200) Subject: this also fixed our 2-phase woes X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b9517ca9f3c1d54dba369dca811ed30b291c2e17;p=rust.git this also fixed our 2-phase woes --- diff --git a/tests/run-pass/stacked-borrows/interior_mutability.rs b/tests/run-pass/stacked-borrows/interior_mutability.rs index 33f44d0093e..d27519df48a 100644 --- a/tests/run-pass/stacked-borrows/interior_mutability.rs +++ b/tests/run-pass/stacked-borrows/interior_mutability.rs @@ -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); +} }