about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-04 01:38:46 +0200
committerGitHub <noreply@github.com>2019-07-04 01:38:46 +0200
commit88c007cd0418e92bbacb8a46d9f9b23422da0d56 (patch)
treef0b6b549f2d818d2e12a6b38eebe6c74e026d536 /src/libstd
parent6cfd474e3337934da9606844e6cf571f96d9652b (diff)
parenteddfad31400b9c6cba6eda95cadd96c455504898 (diff)
downloadrust-88c007cd0418e92bbacb8a46d9f9b23422da0d56.tar.gz
rust-88c007cd0418e92bbacb8a46d9f9b23422da0d56.zip
Rollup merge of #62249 - czipperz:use-mem-take-instead-of-replace-default, r=dtolnay,Centril
Use mem::take instead of mem::replace with default
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/lib.rs1
-rw-r--r--src/libstd/panicking.rs2
-rw-r--r--src/libstd/sync/mpsc/sync.rs2
-rw-r--r--src/libstd/sys/windows/pipe.rs2
4 files changed, 4 insertions, 3 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 60e06139eba..fb9a228880e 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -272,6 +272,7 @@
 #![feature(libc)]
 #![feature(link_args)]
 #![feature(linkage)]
+#![feature(mem_take)]
 #![feature(needs_panic_runtime)]
 #![feature(never_type)]
 #![feature(nll)]
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index 797d85e941d..952fd9ebfdf 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -364,7 +364,7 @@ fn continue_panic_fmt(info: &PanicInfo<'_>) -> ! {
 
     unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
         fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
-            let contents = mem::replace(self.fill(), String::new());
+            let contents = mem::take(self.fill());
             Box::into_raw(Box::new(contents))
         }
 
diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs
index 3c4f8e077c9..f8fcd3ff5a5 100644
--- a/src/libstd/sync/mpsc/sync.rs
+++ b/src/libstd/sync/mpsc/sync.rs
@@ -383,7 +383,7 @@ impl<T> Packet<T> {
         // needs to be careful to destroy the data *outside* of the lock to
         // prevent deadlock.
         let _data = if guard.cap != 0 {
-            mem::replace(&mut guard.buf.buf, Vec::new())
+            mem::take(&mut guard.buf.buf)
         } else {
             Vec::new()
         };
diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs
index 493ee8a9a2d..c77f30dfc71 100644
--- a/src/libstd/sys/windows/pipe.rs
+++ b/src/libstd/sys/windows/pipe.rs
@@ -342,7 +342,7 @@ impl<'a> Drop for AsyncPipe<'a> {
         // If anything here fails, there's not really much we can do, so we leak
         // the buffer/OVERLAPPED pointers to ensure we're at least memory safe.
         if self.pipe.cancel_io().is_err() || self.result().is_err() {
-            let buf = mem::replace(self.dst, Vec::new());
+            let buf = mem::take(self.dst);
             let overlapped = Box::new(unsafe { mem::zeroed() });
             let overlapped = mem::replace(&mut self.overlapped, overlapped);
             mem::forget((buf, overlapped));