Constify mem::swap and ptr::swap[_nonoverlapping]

This commit is contained in:
Albin Hedman
2021-03-13 20:33:27 +01:00
parent 62cf244563
commit 64e2248794
4 changed files with 12 additions and 27 deletions

View File

@@ -682,7 +682,8 @@ pub unsafe fn uninitialized<T>() -> T {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap<T>(x: &mut T, y: &mut T) {
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
pub const fn swap<T>(x: &mut T, y: &mut T) {
// SAFETY: the raw pointers have been created from safe mutable references satisfying all the
// constraints on `ptr::swap_nonoverlapping_one`
unsafe {