]> git.lizzy.rs Git - rust.git/commitdiff
fix compile-fail tests to avoid libstd debug assertions
authorRalf Jung <post@ralfj.de>
Sun, 16 Feb 2020 13:01:00 +0000 (14:01 +0100)
committerRalf Jung <post@ralfj.de>
Sun, 16 Feb 2020 13:01:00 +0000 (14:01 +0100)
tests/compile-fail/copy_null.rs
tests/compile-fail/copy_overlapping.rs
tests/compile-fail/copy_unaligned.rs

index 08391b12ae1bc620ae724a718f76c8855f5571a2..ce2fbe170e45da50966ec4dc3729cdb36f17ef6d 100644 (file)
@@ -1,8 +1,14 @@
 //error-pattern: invalid use of NULL pointer
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
+}
 
 fn main() {
     let mut data = [0u16; 4];
     let ptr = &mut data[0] as *mut u16;
     // Even copying 0 elements from NULL should error.
-    unsafe { ptr.copy_from(std::ptr::null(), 0); }
+    unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); }
 }
index 748bccff5d3aca3e5d852fba8e47b2d1e3a7b687..76e1e20d2177fba97529d4f467fe8dd8cab3146f 100644 (file)
@@ -1,12 +1,16 @@
-#![feature(core_intrinsics)]
-
 //error-pattern: copy_nonoverlapping called on overlapping ranges
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
+}
 
 fn main() {
     let mut data = [0u8; 16];
     unsafe {
         let a = data.as_mut_ptr();
         let b = a.wrapping_offset(1) as *mut _;
-        std::ptr::copy_nonoverlapping(a, b, 2);
+        copy_nonoverlapping(a, b, 2);
     }
 }
index e1f243210ade068fa1a7cc90a026f397b610dc80..1a2692978f7974d7a16ad6448a373cbf9941ca7f 100644 (file)
@@ -1,8 +1,14 @@
 //error-pattern: tried to access memory with alignment 1, but alignment 2 is required
+#![feature(intrinsics)]
+
+// Directly call intrinsic to avoid debug assertions in libstd
+extern "rust-intrinsic" {
+    fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
+}
 
 fn main() {
     let mut data = [0u16; 8];
     let ptr = (&mut data[0] as *mut u16 as *mut u8).wrapping_add(1) as *mut u16;
     // Even copying 0 elements to something unaligned should error
-    unsafe { ptr.copy_from(&data[5], 0); }
+    unsafe { copy_nonoverlapping(&data[5], ptr, 0); }
 }