Skip to content

Commit

Permalink
Clean up is_aligned_and_not_null
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 9, 2024
1 parent db5a9a7 commit a5529ee
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/ub_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a5529ee

Please sign in to comment.