]> git.lizzy.rs Git - rust.git/commitdiff
Use opt.take() instead of mem::replace(opt, None)
authorljedrz <ljedrz@gmail.com>
Mon, 29 Oct 2018 12:48:26 +0000 (13:48 +0100)
committerljedrz <ljedrz@gmail.com>
Mon, 29 Oct 2018 12:48:26 +0000 (13:48 +0100)
src/librustc/ty/steal.rs
src/librustc_data_structures/tiny_list.rs
src/librustc_typeck/check/method/probe.rs

index 1092e23ec3b1d4b182fd9447a7ab7c4731e15f0d..fc3353e339b4d77a27dbad8f0ce933cc656b44bc 100644 (file)
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use rustc_data_structures::sync::{RwLock, ReadGuard, MappedReadGuard};
-use std::mem;
 
 /// The `Steal` struct is intended to used as the value for a query.
 /// Specifically, we sometimes have queries (*cough* MIR *cough*)
@@ -51,7 +50,7 @@ pub fn borrow(&self) -> MappedReadGuard<'_, T> {
 
     pub fn steal(&self) -> T {
         let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
-        let value = mem::replace(value_ref, None);
+        let value = value_ref.take();
         value.expect("attempt to read from stolen value")
     }
 }
index e1bfdf35b274e0d31ff7be040948e0319cf9d0bb..9dbf0ea9f438cb19b5b5ff4970ddf45b604e73a8 100644 (file)
@@ -22,8 +22,6 @@
 //! If you expect to store more than 1 element in the common case, steer clear
 //! and use a `Vec<T>`, `Box<[T]>`, or a `SmallVec<T>`.
 
-use std::mem;
-
 #[derive(Clone, Hash, Debug, PartialEq)]
 pub struct TinyList<T: PartialEq> {
     head: Option<Element<T>>
@@ -52,7 +50,7 @@ pub fn new_single(data: T) -> TinyList<T> {
     pub fn insert(&mut self, data: T) {
         self.head = Some(Element {
             data,
-            next: mem::replace(&mut self.head, None).map(Box::new),
+            next: self.head.take().map(Box::new)
         });
     }
 
@@ -60,7 +58,7 @@ pub fn insert(&mut self, data: T) {
     pub fn remove(&mut self, data: &T) -> bool {
         self.head = match self.head {
             Some(ref mut head) if head.data == *data => {
-                mem::replace(&mut head.next, None).map(|x| *x)
+                head.next.take().map(|x| *x)
             }
             Some(ref mut head) => return head.remove_next(data),
             None => return false,
@@ -100,7 +98,7 @@ fn remove_next(&mut self, data: &T) -> bool {
             if next.data != *data {
                 return next.remove_next(data)
             } else {
-                mem::replace(&mut next.next, None)
+                next.next.take()
             }
         } else {
             return false
index c506f23078f25fe32a3735103a85a84c4411f577..abbdf6d10057b6e405db6d25a42603749737ab77 100644 (file)
@@ -831,7 +831,7 @@ fn pick(mut self) -> PickResult<'tcx> {
         }
 
         let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
-        let private_candidate = mem::replace(&mut self.private_candidate, None);
+        let private_candidate = self.private_candidate.take();
         let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
 
         // things failed, so lets look at all traits, for diagnostic purposes now: