diff --git a/src/lib.rs b/src/lib.rs index 880a14b98c80..c34b90877d9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,5 +62,5 @@ pub use crate::stacked_borrows::{ /// Insert rustc arguments at the beginning of the argument list that Miri wants to be /// set per default, for maximal validation power. pub fn miri_default_args() -> &'static [&'static str] { - &["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri"] + &["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri", "-Cdebug-assertions=on"] } diff --git a/tests/compile-fail/copy_null.rs b/tests/compile-fail/copy_null.rs index 08391b12ae1b..ce2fbe170e45 100644 --- a/tests/compile-fail/copy_null.rs +++ b/tests/compile-fail/copy_null.rs @@ -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(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); } } diff --git a/tests/compile-fail/copy_overlapping.rs b/tests/compile-fail/copy_overlapping.rs index 748bccff5d3a..76e1e20d2177 100644 --- a/tests/compile-fail/copy_overlapping.rs +++ b/tests/compile-fail/copy_overlapping.rs @@ -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(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); } } diff --git a/tests/compile-fail/copy_unaligned.rs b/tests/compile-fail/copy_unaligned.rs index e1f243210ade..1a2692978f79 100644 --- a/tests/compile-fail/copy_unaligned.rs +++ b/tests/compile-fail/copy_unaligned.rs @@ -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(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); } } diff --git a/tests/run-pass/panic/catch_panic.rs b/tests/run-pass/panic/catch_panic.rs index 722da68b70b2..4d4206923a5e 100644 --- a/tests/run-pass/panic/catch_panic.rs +++ b/tests/run-pass/panic/catch_panic.rs @@ -1,4 +1,5 @@ // ignore-windows: Unwind panicking does not currently work on Windows +// normalize-stderr-test "[^ ]*libcore/macros/mod.rs[0-9:]*" -> "$$LOC" #![feature(never_type)] #![allow(const_err)] use std::panic::{catch_unwind, AssertUnwindSafe}; @@ -11,7 +12,6 @@ thread_local! { } struct DropTester; - impl Drop for DropTester { fn drop(&mut self) { DROPPED.with(|c| { @@ -61,6 +61,11 @@ fn main() { test(|_old_val| { let _val = [0, 1, 2][4]; loop {} }); test(|_old_val| { let _val = 1/0; loop {} }); + // Assertion and debug assertion + test(|_old_val| { assert!(false); loop {} }); + test(|_old_val| { debug_assert!(false); loop {} }); + test(|_old_val| { unsafe { (1 as *const i32).read() }; loop {} }); // trigger debug-assertion in libstd + // Cleanup: reset to default hook. drop(std::panic::take_hook()); diff --git a/tests/run-pass/panic/catch_panic.stderr b/tests/run-pass/panic/catch_panic.stderr index fd9a2f14ec3b..636179beeade 100644 --- a/tests/run-pass/panic/catch_panic.stderr +++ b/tests/run-pass/panic/catch_panic.stderr @@ -16,4 +16,10 @@ thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4' Caught panic message (String): index out of bounds: the len is 3 but the index is 4 thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:62:34 Caught panic message (String): attempt to divide by zero +thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:65:23 +Caught panic message (&str): assertion failed: false +thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:66:23 +Caught panic message (&str): assertion failed: false +thread 'main' panicked at 'attempt to copy from unaligned or null pointer', $LOC +Caught panic message (String): attempt to copy from unaligned or null pointer Success!