@@ -2799,6 +2799,10 @@ pub(crate) use assert_unsafe_precondition;
2799
2799
2800
2800
/// Checks whether `ptr` is properly aligned with respect to
2801
2801
/// `align_of::<T>()`.
2802
+ ///
2803
+ /// In `const` this is approximate and can fail spuriously. It is primarily intended
2804
+ /// for `assert_unsafe_precondition!` with `check_language_ub`, in which case the
2805
+ /// check is anyway not executed in `const`.
2802
2806
#[ inline]
2803
2807
pub ( crate ) const fn is_aligned_and_not_null ( ptr : * const ( ) , align : usize ) -> bool {
2804
2808
!ptr. is_null ( ) && ptr. is_aligned_to ( align)
@@ -2813,10 +2817,10 @@ pub(crate) const fn is_valid_allocation_size(size: usize, len: usize) -> bool {
2813
2817
/// Checks whether the regions of memory starting at `src` and `dst` of size
2814
2818
/// `count * size` do *not* overlap.
2815
2819
///
2816
- /// # Safety
2817
- /// This function must only be called such that if it returns false, we will execute UB .
2820
+ /// Note that in const-eval this function just returns `true` and therefore must
2821
+ /// only be used with `assert_unsafe_precondition!`, similar to `is_aligned_and_not_null` .
2818
2822
#[ inline]
2819
- pub ( crate ) const unsafe fn is_nonoverlapping (
2823
+ pub ( crate ) const fn is_nonoverlapping (
2820
2824
src : * const ( ) ,
2821
2825
dst : * const ( ) ,
2822
2826
size : usize ,
@@ -2842,7 +2846,7 @@ pub(crate) const unsafe fn is_nonoverlapping(
2842
2846
true
2843
2847
}
2844
2848
2845
- #[ cfg_attr( not( bootstrap) , allow( unused_unsafe) ) ]
2849
+ #[ cfg_attr( not( bootstrap) , allow( unused_unsafe) ) ] // on bootstrap bump, remove unsafe block
2846
2850
// SAFETY: This function's precondition is equivalent to that of `const_eval_select`.
2847
2851
// Programs which do not execute UB will only see this function return `true`, which makes the
2848
2852
// const and runtime implementation indistinguishable.
@@ -2962,8 +2966,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
2962
2966
) =>
2963
2967
is_aligned_and_not_null( src, align)
2964
2968
&& is_aligned_and_not_null( dst, align)
2965
- // SAFETY: If this returns false, we're about to execute UB.
2966
- && unsafe { is_nonoverlapping( src, dst, size, count) }
2969
+ && is_nonoverlapping( src, dst, size, count)
2967
2970
) ;
2968
2971
2969
2972
// SAFETY: the safety contract for `copy_nonoverlapping` must be
0 commit comments