From 8cd73e534f3ecc96286c626376a05c1adb48ca64 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 22 Oct 2018 18:51:06 +0200 Subject: [PATCH] use as(_mut)_ptr on slices to entirely escape them to raw --- tests/compile-fail/copy_nonoverlapping.rs | 8 ++------ tests/run-pass/ptr_arith_offset_overflow.rs | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/compile-fail/copy_nonoverlapping.rs b/tests/compile-fail/copy_nonoverlapping.rs index 704711640f7d..8e8912c81fe9 100644 --- a/tests/compile-fail/copy_nonoverlapping.rs +++ b/tests/compile-fail/copy_nonoverlapping.rs @@ -10,17 +10,13 @@ #![feature(core_intrinsics)] -// FIXME: Validation disabled because it doesn't let us escape an entire slice -// to the raw universe. -// compile-flags: -Zmiri-disable-validation - //error-pattern: copy_nonoverlapping called on overlapping ranges fn main() { let mut data = [0u8; 16]; unsafe { - let a = &data[0] as *const _; - let b = &mut data[1] as *mut _; + let a = data.as_mut_ptr(); + let b = a.wrapping_offset(1) as *mut _; std::ptr::copy_nonoverlapping(a, b, 2); } } diff --git a/tests/run-pass/ptr_arith_offset_overflow.rs b/tests/run-pass/ptr_arith_offset_overflow.rs index 9eabc9142604..6b778248be5c 100644 --- a/tests/run-pass/ptr_arith_offset_overflow.rs +++ b/tests/run-pass/ptr_arith_offset_overflow.rs @@ -1,7 +1,6 @@ fn main() { let v = [1i16, 2]; - let x = &v[1] as *const i16; - let _ = &v[0] as *const i16; // we need to leak the 2nd thing too or it cannot be accessed through a raw ptr + let x = v.as_ptr().wrapping_offset(1); // ptr to the 2nd element // Adding 2*isize::max and then 1 is like substracting 1 let x = x.wrapping_offset(isize::max_value()); let x = x.wrapping_offset(isize::max_value());