about summary refs log tree commit diff
path: root/library/core/src
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
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')
-rw-r--r--library/core/src/ptr/mut_ptr.rs3
-rw-r--r--library/core/src/slice/mod.rs6
2 files changed, 6 insertions, 3 deletions
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
index adc64cb2bd3..5d5527dc8b4 100644
--- a/library/core/src/ptr/mut_ptr.rs
+++ b/library/core/src/ptr/mut_ptr.rs
@@ -1092,8 +1092,9 @@ impl<T: ?Sized> *mut T {
     ///
     /// [`ptr::swap`]: crate::ptr::swap()
     #[stable(feature = "pointer_methods", since = "1.26.0")]
+    #[rustc_const_unstable(feature = "const_swap", issue = "83163")]
     #[inline(always)]
-    pub unsafe fn swap(self, with: *mut T)
+    pub const unsafe fn swap(self, with: *mut T)
     where
         T: Sized,
     {
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];