Skip to content

Commit a7ada04

Browse files
authored
Rollup merge of rust-lang#136750 - kornelski:ub-bug, r=saethlin
Make ub_check message clear that it's not an assert I've seen a user assume that their unsound code was *safe*, because ub_check prevented the program from performing the unsafe operation. This PR makes the panic message clearer that ub_check is a bug detector, not run-time safety protection.
2 parents 866d147 + ca28827 commit a7ada04

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

library/core/src/ub_checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ macro_rules! assert_unsafe_precondition {
6565
#[rustc_nounwind]
6666
const fn precondition_check($($name:$ty),*) {
6767
if !$e {
68-
::core::panicking::panic_nounwind(
69-
concat!("unsafe precondition(s) violated: ", $message)
70-
);
68+
::core::panicking::panic_nounwind(concat!("unsafe precondition(s) violated: ", $message,
69+
"\n\nThis indicates a bug in the program. \
70+
This Undefined Behavior check is optional, and cannot be relied on for safety."));
7171
}
7272
}
7373

src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
33
unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
4+
5+
This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
46
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
57
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
68
thread caused non-unwinding panic. aborting.

0 commit comments

Comments
 (0)