diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-11-12 19:17:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-12 19:17:30 +0100 |
| commit | 70532c4503c91d308bf0a1b1b2e1a3e2f5635ced (patch) | |
| tree | a4159487415698622b734751d6e90ca40aabdc40 | |
| parent | 1fe15be34c472c32a8cd6f1d789592f096d2f50b (diff) | |
| parent | eeaa2f16aa4487d3e5fdaef7097b488d45b986d2 (diff) | |
| download | rust-70532c4503c91d308bf0a1b1b2e1a3e2f5635ced.tar.gz rust-70532c4503c91d308bf0a1b1b2e1a3e2f5635ced.zip | |
Rollup merge of #90644 - est31:const_swap, r=Mark-Simulacrum
Extend the const swap feature
Adds the `const_swap` feature gate to three more swap functions. cc tracking issue #83163
```Rust
impl<T> [T] {
pub const fn swap(&mut self, a: usize, b: usize);
pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize);
}
impl<T: ?Sized> *mut T {
pub const unsafe fn swap(self, with: *mut T);
}
| -rw-r--r-- | library/core/src/ptr/mut_ptr.rs | 3 | ||||
| -rw-r--r-- | library/core/src/slice/mod.rs | 6 |
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]; |
