From 97c34c266f492ff548ca1584ccb7f1c3c49dcf82 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 17 Apr 2019 08:25:21 +0200 Subject: [PATCH] try to test the problematic cast-to-raw case... unfortunately with the implicit reborrow that's not currently possible --- tests/run-pass/2phase.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/run-pass/2phase.rs b/tests/run-pass/2phase.rs index 78ddf566a9d..87ecb4aef06 100644 --- a/tests/run-pass/2phase.rs +++ b/tests/run-pass/2phase.rs @@ -26,6 +26,21 @@ fn two_phase3(b: bool) { )); } +#[allow(unreachable_code)] +fn two_phase_raw() { + let x: &mut Vec = &mut vec![]; + x.push( + { + // Unfortunately this does not trigger the problem of creating a + // raw ponter from a pointer that had a two-phase borrow derived from + // it because of the implicit &mut reborrow. + let raw = x as *mut _; + unsafe { *raw = vec![1]; } + return + } + ); +} + /* fn two_phase_overlapping1() { let mut x = vec![]; @@ -67,6 +82,7 @@ fn main() { two_phase2(); two_phase3(false); two_phase3(true); + two_phase_raw(); with_interior_mutability(); //FIXME: enable these, or remove them, depending on how https://github.com/rust-lang/rust/issues/56254 gets resolved //two_phase_overlapping1(); -- 2.44.0