mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 11:13:43 +00:00
Constify mem::replace and ptr::replace
This commit is contained in:
parent
64e2248794
commit
45988ee438
@ -813,7 +813,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
|
||||
#[inline]
|
||||
#[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"]
|
||||
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,
|
||||
// such that the old value is not duplicated. Nothing is dropped and
|
||||
// nothing here can panic.
|
||||
|
@ -584,7 +584,8 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[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
|
||||
// cast to a mutable reference (valid for writes, aligned, initialized),
|
||||
// and cannot overlap `src` since `dst` must point to a distinct
|
||||
|
Loading…
Reference in New Issue
Block a user