about summary refs log tree commit diff
path: root/library/core/src/slice
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-01-05 18:35:05 -0500
committerGitHub <noreply@github.com>2025-01-05 18:35:05 -0500
commit0f9f91cccf05ea643878d7f1bf3c7fddddc42e6b (patch)
tree9d96c1f8fecf78f0ddfb7856aed70271ce463994 /library/core/src/slice
parentaf9293f507dec2eaac544a98175e00692b1c4770 (diff)
parent03c2ac248fee1e66ab081011f13e28354ea0f992 (diff)
downloadrust-0f9f91cccf05ea643878d7f1bf3c7fddddc42e6b.tar.gz
rust-0f9f91cccf05ea643878d7f1bf3c7fddddc42e6b.zip
Rollup merge of #135121 - okaneco:const_slice_reverse, r=jhpratt
Mark `slice::reverse` unstably const

Tracking issue #135120

This is unblocked by the stabilization of `const_swap`
Diffstat (limited to 'library/core/src/slice')
-rw-r--r--library/core/src/slice/mod.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index 073cca7daef..f800e0d391c 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -987,8 +987,9 @@ impl<T> [T] {
     /// assert!(v == [3, 2, 1]);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[rustc_const_unstable(feature = "const_slice_reverse", issue = "135120")]
     #[inline]
-    pub fn reverse(&mut self) {
+    pub const fn reverse(&mut self) {
         let half_len = self.len() / 2;
         let Range { start, end } = self.as_mut_ptr_range();
 
@@ -1011,7 +1012,7 @@ impl<T> [T] {
         revswap(front_half, back_half, half_len);
 
         #[inline]
-        fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
+        const fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
             debug_assert!(a.len() == n);
             debug_assert!(b.len() == n);
 
@@ -1019,7 +1020,8 @@ impl<T> [T] {
             // this check tells LLVM that the indexing below is
             // in-bounds. Then after inlining -- once the actual
             // lengths of the slices are known -- it's removed.
-            let (a, b) = (&mut a[..n], &mut b[..n]);
+            let (a, _) = a.split_at_mut(n);
+            let (b, _) = b.split_at_mut(n);
 
             let mut i = 0;
             while i < n {