Skip to content

Commit 0f9f91c

Browse files
authored
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`
2 parents af9293f + 03c2ac2 commit 0f9f91c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

library/core/src/slice/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,9 @@ impl<T> [T] {
987987
/// assert!(v == [3, 2, 1]);
988988
/// ```
989989
#[stable(feature = "rust1", since = "1.0.0")]
990+
#[rustc_const_unstable(feature = "const_slice_reverse", issue = "135120")]
990991
#[inline]
991-
pub fn reverse(&mut self) {
992+
pub const fn reverse(&mut self) {
992993
let half_len = self.len() / 2;
993994
let Range { start, end } = self.as_mut_ptr_range();
994995

@@ -1011,15 +1012,16 @@ impl<T> [T] {
10111012
revswap(front_half, back_half, half_len);
10121013

10131014
#[inline]
1014-
fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
1015+
const fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
10151016
debug_assert!(a.len() == n);
10161017
debug_assert!(b.len() == n);
10171018

10181019
// Because this function is first compiled in isolation,
10191020
// this check tells LLVM that the indexing below is
10201021
// in-bounds. Then after inlining -- once the actual
10211022
// lengths of the slices are known -- it's removed.
1022-
let (a, b) = (&mut a[..n], &mut b[..n]);
1023+
let (a, _) = a.split_at_mut(n);
1024+
let (b, _) = b.split_at_mut(n);
10231025

10241026
let mut i = 0;
10251027
while i < n {

0 commit comments

Comments
 (0)