diff options
| author | okaneco <47607823+okaneco@users.noreply.github.com> | 2025-01-04 06:47:31 -0500 |
|---|---|---|
| committer | okaneco <47607823+okaneco@users.noreply.github.com> | 2025-01-05 08:01:50 -0500 |
| commit | 03c2ac248fee1e66ab081011f13e28354ea0f992 (patch) | |
| tree | 687ba9b33528acafb5b7c2ce294e3723c5779f12 | |
| parent | 49761b073c2ca81a3e687183cf2e171cdfd61668 (diff) | |
| download | rust-03c2ac248fee1e66ab081011f13e28354ea0f992.tar.gz rust-03c2ac248fee1e66ab081011f13e28354ea0f992.zip | |
Mark `slice::reverse` unstably const
| -rw-r--r-- | library/core/src/slice/mod.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index df9720698d3..c8f9e23e797 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 { |
