From b9517ca9f3c1d54dba369dca811ed30b291c2e17 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 May 2019 17:52:08 +0200 Subject: [PATCH] this also fixed our 2-phase woes --- .../run-pass/stacked-borrows/interior_mutability.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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); +} }