@@ -674,8 +674,9 @@ impl<T> [T] {
674674 /// assert!(v == [3, 2, 1]);
675675 /// ```
676676 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
677+ #[ rustc_const_unstable( feature = "const_reverse" , issue = "100784" ) ]
677678 #[ inline]
678- pub fn reverse ( & mut self ) {
679+ pub const fn reverse ( & mut self ) {
679680 let half_len = self . len ( ) / 2 ;
680681 let Range { start, end } = self . as_mut_ptr_range ( ) ;
681682
@@ -698,18 +699,20 @@ impl<T> [T] {
698699 revswap ( front_half, back_half, half_len) ;
699700
700701 #[ inline]
701- fn revswap < T > ( a : & mut [ T ] , b : & mut [ T ] , n : usize ) {
702- debug_assert_eq ! ( a. len( ) , n) ;
703- debug_assert_eq ! ( b. len( ) , n) ;
702+ const fn revswap < T > ( a : & mut [ T ] , b : & mut [ T ] , n : usize ) {
703+ debug_assert ! ( a. len( ) == n) ;
704+ debug_assert ! ( b. len( ) == n) ;
704705
705706 // Because this function is first compiled in isolation,
706707 // this check tells LLVM that the indexing below is
707708 // in-bounds. Then after inlining -- once the actual
708709 // lengths of the slices are known -- it's removed.
709710 let ( a, b) = ( & mut a[ ..n] , & mut b[ ..n] ) ;
710711
711- for i in 0 ..n {
712+ let mut i = 0 ;
713+ while i < n {
712714 mem:: swap ( & mut a[ i] , & mut b[ n - 1 - i] ) ;
715+ i += 1 ;
713716 }
714717 }
715718 }
0 commit comments