Skip to content

Commit 45988ee

Browse files
committed
Constify mem::replace and ptr::replace
1 parent 64e2248 commit 45988ee

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

library/core/src/mem/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
813813
#[inline]
814814
#[stable(feature = "rust1", since = "1.0.0")]
815815
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
816-
pub fn replace<T>(dest: &mut T, src: T) -> T {
816+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
817+
pub const fn replace<T>(dest: &mut T, src: T) -> T {
817818
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
818819
// such that the old value is not duplicated. Nothing is dropped and
819820
// nothing here can panic.

library/core/src/ptr/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
584584
/// ```
585585
#[inline]
586586
#[stable(feature = "rust1", since = "1.0.0")]
587-
pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
587+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
588+
pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
588589
// SAFETY: the caller must guarantee that `dst` is valid to be
589590
// cast to a mutable reference (valid for writes, aligned, initialized),
590591
// and cannot overlap `src` since `dst` must point to a distinct

0 commit comments

Comments
 (0)