Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5529ee

Browse files
committedOct 9, 2024
Clean up is_aligned_and_not_null
1 parent db5a9a7 commit a5529ee

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎core/src/ub_checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ pub(crate) const fn check_language_ub() -> bool {
109109
intrinsics::ub_checks() && const_eval_select((), comptime, runtime)
110110
}
111111

112-
/// Checks whether `ptr` is properly aligned with respect to
113-
/// `align_of::<T>()`.
112+
/// Checks whether `ptr` is properly aligned with respect to the given alignment, and
113+
/// if `is_zst == false`, that `ptr` is not null.
114114
///
115115
/// In `const` this is approximate and can fail spuriously. It is primarily intended
116116
/// for `assert_unsafe_precondition!` with `check_language_ub`, in which case the
117117
/// check is anyway not executed in `const`.
118118
#[inline]
119119
pub(crate) const fn is_aligned_and_not_null(ptr: *const (), align: usize, is_zst: bool) -> bool {
120-
if is_zst { ptr.is_aligned_to(align) } else { !ptr.is_null() && ptr.is_aligned_to(align) }
120+
ptr.is_aligned_to(align) && (is_zst || !ptr.is_null())
121121
}
122122

123123
#[inline]

0 commit comments

Comments
 (0)
Please sign in to comment.