about summary refs log tree commit diff
path: root/library/core/src/slice
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2021-11-06 05:56:09 +0100
committerest31 <MTest31@outlook.com>2021-11-09 20:09:56 +0100
commiteeaa2f16aa4487d3e5fdaef7097b488d45b986d2 (patch)
tree24b426920a2a453d8184fd82bba64e1226c08615 /library/core/src/slice
parentd32993afe81a49701edd6f2b8f018020ca50da1a (diff)
downloadrust-eeaa2f16aa4487d3e5fdaef7097b488d45b986d2.tar.gz
rust-eeaa2f16aa4487d3e5fdaef7097b488d45b986d2.zip
Extend the const_swap feature
This makes the inherent method ptr::swap unstably
const, as well as slice::swap{,_unchecked}.
Diffstat (limited to 'library/core/src/slice')
-rw-r--r--library/core/src/slice/mod.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index 65ed72cb0cd..d876d944e7f 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -558,8 +558,9 @@ impl<T> [T] {
     /// assert!(v == ["a", "b", "e", "d", "c"]);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[rustc_const_unstable(feature = "const_swap", issue = "83163")]
     #[inline]
-    pub fn swap(&mut self, a: usize, b: usize) {
+    pub const fn swap(&mut self, a: usize, b: usize) {
         let _ = &self[a];
         let _ = &self[b];
 
@@ -595,7 +596,8 @@ impl<T> [T] {
     /// [`swap`]: slice::swap
     /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
     #[unstable(feature = "slice_swap_unchecked", issue = "88539")]
-    pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
+    #[rustc_const_unstable(feature = "const_swap", issue = "83163")]
+    pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
         #[cfg(debug_assertions)]
         {
             let _ = &self[a];