Skip to content

Commit 8acf52b

Browse files
committed
fix compile-fail tests to avoid libstd debug assertions
1 parent 6ff5b3f commit 8acf52b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

tests/compile-fail/copy_null.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
//error-pattern: invalid use of NULL pointer
2+
#![feature(intrinsics)]
3+
4+
// Directly call intrinsic to avoid debug assertions in libstd
5+
extern "rust-intrinsic" {
6+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
7+
}
28

39
fn main() {
410
let mut data = [0u16; 4];
511
let ptr = &mut data[0] as *mut u16;
612
// Even copying 0 elements from NULL should error.
7-
unsafe { ptr.copy_from(std::ptr::null(), 0); }
13+
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); }
814
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
#![feature(core_intrinsics)]
2-
31
//error-pattern: copy_nonoverlapping called on overlapping ranges
2+
#![feature(intrinsics)]
3+
4+
// Directly call intrinsic to avoid debug assertions in libstd
5+
extern "rust-intrinsic" {
6+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
7+
}
48

59
fn main() {
610
let mut data = [0u8; 16];
711
unsafe {
812
let a = data.as_mut_ptr();
913
let b = a.wrapping_offset(1) as *mut _;
10-
std::ptr::copy_nonoverlapping(a, b, 2);
14+
copy_nonoverlapping(a, b, 2);
1115
}
1216
}

tests/compile-fail/copy_unaligned.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
//error-pattern: tried to access memory with alignment 1, but alignment 2 is required
2+
#![feature(intrinsics)]
3+
4+
// Directly call intrinsic to avoid debug assertions in libstd
5+
extern "rust-intrinsic" {
6+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
7+
}
28

39
fn main() {
410
let mut data = [0u16; 8];
511
let ptr = (&mut data[0] as *mut u16 as *mut u8).wrapping_add(1) as *mut u16;
612
// Even copying 0 elements to something unaligned should error
7-
unsafe { ptr.copy_from(&data[5], 0); }
13+
unsafe { copy_nonoverlapping(&data[5], ptr, 0); }
814
}

0 commit comments

Comments
 (0)