From 0af028bb2ecb7dd27cba8972e1681eb07bae4c7a Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:20:04 -0500 Subject: [PATCH] fix: use `cmp::min()` instead of `const_min()` helper in `ptr_rotate()` `cmp::min()` is unstably const, but `ptr_rotate()` is a private function so it's safe to allow. --- library/core/src/slice/rotate.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/library/core/src/slice/rotate.rs b/library/core/src/slice/rotate.rs index b3b64422884d5..50765a03383a4 100644 --- a/library/core/src/slice/rotate.rs +++ b/library/core/src/slice/rotate.rs @@ -1,5 +1,5 @@ use crate::mem::{MaybeUninit, SizedTypeProperties}; -use crate::ptr; +use crate::{cmp, ptr}; type BufType = [usize; 32]; @@ -11,6 +11,7 @@ type BufType = [usize; 32]; /// /// The specified range must be valid for reading and writing. #[inline] +#[rustc_allow_const_fn_unstable(const_trait_impl, const_cmp)] pub(super) const unsafe fn ptr_rotate(left: usize, mid: *mut T, right: usize) { if T::IS_ZST { return; @@ -21,8 +22,7 @@ pub(super) const unsafe fn ptr_rotate(left: usize, mid: *mut T, right: usize) } // `T` is not a zero-sized type, so it's okay to divide by its size. if !cfg!(feature = "optimize_for_size") - // FIXME(const-hack): Use cmp::min when available in const - && const_min(left, right) <= size_of::() / size_of::() + && cmp::min(left, right) <= size_of::() / size_of::() { // SAFETY: guaranteed by the caller unsafe { ptr_rotate_memmove(left, mid, right) }; @@ -270,8 +270,3 @@ const unsafe fn ptr_rotate_swap(mut left: usize, mut mid: *mut T, mut right: } } } - -// FIXME(const-hack): Use cmp::min when available in const -const fn const_min(left: usize, right: usize) -> usize { - if right < left { right } else { left } -}