Skip to content

Commit

Permalink
Make ub_check message clear that it's not an assert
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Feb 16, 2025
1 parent 9cd60bd commit ca28827
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/core/src/ub_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ macro_rules! assert_unsafe_precondition {
#[rustc_nounwind]
const fn precondition_check($($name:$ty),*) {
if !$e {
::core::panicking::panic_nounwind(
concat!("unsafe precondition(s) violated: ", $message)
);
::core::panicking::panic_nounwind(concat!("unsafe precondition(s) violated: ", $message,
"\n\nThis indicates a bug in the program. \
This Undefined Behavior check is optional, and cannot be relied on for safety."));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
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

This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
thread caused non-unwinding panic. aborting.
Expand Down

0 comments on commit ca28827

Please sign in to comment.