about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2024-10-09 18:34:33 -0400
committerBen Kimock <kimockb@gmail.com>2024-10-09 19:34:27 -0400
commitaec09a43efed613ed12e32cef5d1bd94750e04eb (patch)
treefd51a00ff6f46f3392d978dbcc101f420e4bcda7
parent84dacc18829e24ec5d61087a233de68ef57dfabc (diff)
downloadrust-aec09a43efed613ed12e32cef5d1bd94750e04eb.tar.gz
rust-aec09a43efed613ed12e32cef5d1bd94750e04eb.zip
Clean up is_aligned_and_not_null
-rw-r--r--library/core/src/ub_checks.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs
index 2ea30e77609..daaaf5a7195 100644
--- a/library/core/src/ub_checks.rs
+++ b/library/core/src/ub_checks.rs
@@ -109,15 +109,15 @@ pub(crate) const fn check_language_ub() -> bool {
     intrinsics::ub_checks() && const_eval_select((), comptime, runtime)
 }
 
-/// Checks whether `ptr` is properly aligned with respect to
-/// `align_of::<T>()`.
+/// Checks whether `ptr` is properly aligned with respect to the given alignment, and
+/// if `is_zst == false`, that `ptr` is not null.
 ///
 /// In `const` this is approximate and can fail spuriously. It is primarily intended
 /// for `assert_unsafe_precondition!` with `check_language_ub`, in which case the
 /// check is anyway not executed in `const`.
 #[inline]
 pub(crate) const fn is_aligned_and_not_null(ptr: *const (), align: usize, is_zst: bool) -> bool {
-    if is_zst { ptr.is_aligned_to(align) } else { !ptr.is_null() && ptr.is_aligned_to(align) }
+    ptr.is_aligned_to(align) && (is_zst || !ptr.is_null())
 }
 
 #[inline]