Constify mem::replace and ptr::replace
This commit is contained in:
parent
64e2248794
commit
45988ee438
2 changed files with 4 additions and 2 deletions
|
@ -813,7 +813,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
||||||
pub fn replace<T>(dest: &mut T, src: T) -> T {
|
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
|
||||||
|
pub const fn replace<T>(dest: &mut T, src: T) -> T {
|
||||||
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
|
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
|
||||||
// such that the old value is not duplicated. Nothing is dropped and
|
// such that the old value is not duplicated. Nothing is dropped and
|
||||||
// nothing here can panic.
|
// nothing here can panic.
|
||||||
|
|
|
@ -584,7 +584,8 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
|
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
|
||||||
|
pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
|
||||||
// SAFETY: the caller must guarantee that `dst` is valid to be
|
// SAFETY: the caller must guarantee that `dst` is valid to be
|
||||||
// cast to a mutable reference (valid for writes, aligned, initialized),
|
// cast to a mutable reference (valid for writes, aligned, initialized),
|
||||||
// and cannot overlap `src` since `dst` must point to a distinct
|
// and cannot overlap `src` since `dst` must point to a distinct
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue