about summary refs log tree commit diff
path: root/src/liballoc
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/liballoc
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/liballoc')
-rw-r--r--src/liballoc/collections/btree/map.rs4
-rw-r--r--src/liballoc/collections/linked_list.rs2
-rw-r--r--src/liballoc/lib.rs1
-rw-r--r--src/liballoc/str.rs2
4 files changed, 5 insertions, 4 deletions
diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs
index 6b079fc87cc..d9ebc40aa2c 100644
--- a/src/liballoc/collections/btree/map.rs
+++ b/src/liballoc/collections/btree/map.rs
@@ -770,8 +770,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
         }
 
         // First, we merge `self` and `other` into a sorted sequence in linear time.
-        let self_iter = mem::replace(self, BTreeMap::new()).into_iter();
-        let other_iter = mem::replace(other, BTreeMap::new()).into_iter();
+        let self_iter = mem::take(self).into_iter();
+        let other_iter = mem::take(other).into_iter();
         let iter = MergeIter {
             left: self_iter.peekable(),
             right: other_iter.peekable(),
diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs
index 40a82d6feaa..ca9e78bb459 100644
--- a/src/liballoc/collections/linked_list.rs
+++ b/src/liballoc/collections/linked_list.rs
@@ -708,7 +708,7 @@ impl<T> LinkedList<T> {
         let len = self.len();
         assert!(at <= len, "Cannot split off at a nonexistent index");
         if at == 0 {
-            return mem::replace(self, Self::new());
+            return mem::take(self);
         } else if at == len {
             return Self::new();
         }
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 5fc58c8ab5a..bfe7d12d9d0 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -112,6 +112,7 @@
 #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
 #![feature(alloc_layout_extra)]
 #![feature(try_trait)]
+#![feature(mem_take)]
 
 // Allow testing this library
 
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index 40104554fe5..70a93157c9e 100644
--- a/src/liballoc/str.rs
+++ b/src/liballoc/str.rs
@@ -203,7 +203,7 @@ impl ToOwned for str {
     }
 
     fn clone_into(&self, target: &mut String) {
-        let mut b = mem::replace(target, String::new()).into_bytes();
+        let mut b = mem::take(target).into_bytes();
         self.as_bytes().clone_into(&mut b);
         *target = unsafe { String::from_utf8_unchecked(b) }
     }