about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUrgau <3616612+Urgau@users.noreply.github.com>2025-02-18 18:34:13 +0100
committerGitHub <noreply@github.com>2025-02-18 18:34:13 +0100
commitd7fe4c0e92de2393f3525ccdf43b689fad81d866 (patch)
tree5a1686bdebb4ed2649fe3f388c215b2252020863
parent3b022d8ceea570db9730be34d964f0cc663a567f (diff)
parentca288273b43d4218f00c15e31e78f89949d8cbba (diff)
downloadrust-d7fe4c0e92de2393f3525ccdf43b689fad81d866.tar.gz
rust-d7fe4c0e92de2393f3525ccdf43b689fad81d866.zip
Rollup merge of #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.
-rw-r--r--library/core/src/ub_checks.rs6
-rw-r--r--src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr2
2 files changed, 5 insertions, 3 deletions
diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs
index b289f6026ff..9eb71922218 100644
--- a/library/core/src/ub_checks.rs
+++ b/library/core/src/ub_checks.rs
@@ -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."));
                 }
             }
 
diff --git a/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr b/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr
index 782303d5f3f..80dd2f39b42 100644
--- a/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr
+++ b/src/tools/miri/tests/fail/ptr_swap_nonoverlapping.stderr
@@ -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.