]> git.lizzy.rs Git - rust.git/commitdiff
adjust some const_eval_select safety comments
authorRalf Jung <post@ralfj.de>
Sun, 28 Nov 2021 19:00:58 +0000 (14:00 -0500)
committerRalf Jung <post@ralfj.de>
Sun, 28 Nov 2021 19:00:58 +0000 (14:00 -0500)
library/core/src/intrinsics.rs
library/core/src/slice/raw.rs

index 3814c4237f11466f746fba4d20b80d680ef2d834..975dc593b5181a13a4a715cdfe10bfd20d6b1222 100644 (file)
@@ -2068,8 +2068,8 @@ fn runtime_check<T>(src: *const T, dst: *mut T, count: usize) {
     #[cfg(debug_assertions)]
     const fn compiletime_check<T>(_src: *const T, _dst: *mut T, _count: usize) {}
     #[cfg(debug_assertions)]
-    // SAFETY: runtime debug-assertions are a best-effort basis; it's fine to
-    // not do them during compile time
+    // SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached.
+    // Therefore, compiletime_check and runtime_check are observably equivalent.
     unsafe {
         const_eval_select((src, dst, count), compiletime_check, runtime_check);
     }
@@ -2159,8 +2159,8 @@ fn runtime_check<T>(src: *const T, dst: *mut T) {
     #[cfg(debug_assertions)]
     const fn compiletime_check<T>(_src: *const T, _dst: *mut T) {}
     #[cfg(debug_assertions)]
-    // SAFETY: runtime debug-assertions are a best-effort basis; it's fine to
-    // not do them during compile time
+    // SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached.
+    // Therefore, compiletime_check and runtime_check are observably equivalent.
     unsafe {
         const_eval_select((src, dst), compiletime_check, runtime_check);
     }
index 81bb16d54015e9551266e41068e1bb6ec63cd5a5..a8667c3a8caf4e73582be4da4cf574e112dca62e 100644 (file)
@@ -149,8 +149,8 @@ const fn noop<T>(_: *const T) {}
     // it is not required for safety (the safety must be guatanteed by
     // the `from_raw_parts[_mut]` caller).
     //
-    // Since the checks are not required, we ignore them in CTFE as they can't
-    // be done there (alignment does not make much sense there).
+    // As per our safety precondition, we may assume that assertion above never fails.
+    // Therefore, noop and rt_check are observably equivalent.
     unsafe {
         crate::intrinsics::const_eval_select((data,), noop, rt_check);
     }