Skip to content

Commit eeaa2f1

Browse files
committed
Extend the const_swap feature
This makes the inherent method ptr::swap unstably const, as well as slice::swap{,_unchecked}.
1 parent d32993a commit eeaa2f1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

library/core/src/ptr/mut_ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,9 @@ impl<T: ?Sized> *mut T {
10921092
///
10931093
/// [`ptr::swap`]: crate::ptr::swap()
10941094
#[stable(feature = "pointer_methods", since = "1.26.0")]
1095+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
10951096
#[inline(always)]
1096-
pub unsafe fn swap(self, with: *mut T)
1097+
pub const unsafe fn swap(self, with: *mut T)
10971098
where
10981099
T: Sized,
10991100
{

library/core/src/slice/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ impl<T> [T] {
558558
/// assert!(v == ["a", "b", "e", "d", "c"]);
559559
/// ```
560560
#[stable(feature = "rust1", since = "1.0.0")]
561+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
561562
#[inline]
562-
pub fn swap(&mut self, a: usize, b: usize) {
563+
pub const fn swap(&mut self, a: usize, b: usize) {
563564
let _ = &self[a];
564565
let _ = &self[b];
565566

@@ -595,7 +596,8 @@ impl<T> [T] {
595596
/// [`swap`]: slice::swap
596597
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
597598
#[unstable(feature = "slice_swap_unchecked", issue = "88539")]
598-
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
599+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
600+
pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
599601
#[cfg(debug_assertions)]
600602
{
601603
let _ = &self[a];

0 commit comments

Comments
 (0)