mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
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); }
This commit is contained in:
@@ -1092,8 +1092,9 @@ pub unsafe fn replace(self, src: T) -> 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,
|
||||
{
|
||||
|
||||
@@ -558,8 +558,9 @@ pub const fn as_mut_ptr_range(&mut self) -> Range<*mut 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 @@ pub fn swap(&mut self, a: usize, b: usize) {
|
||||
/// [`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];
|
||||
|
||||
Reference in New Issue
Block a user