Skip to content

Commit 2203ec3

Browse files
committed
Use opt.take() instead of mem::replace(opt, None)
1 parent 4e88b73 commit 2203ec3

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/librustc/ty/steal.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::sync::{RwLock, ReadGuard, MappedReadGuard};
12-
use std::mem;
1312

1413
/// The `Steal` struct is intended to used as the value for a query.
1514
/// Specifically, we sometimes have queries (*cough* MIR *cough*)
@@ -51,7 +50,7 @@ impl<T> Steal<T> {
5150

5251
pub fn steal(&self) -> T {
5352
let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
54-
let value = mem::replace(value_ref, None);
53+
let value = value_ref.take();
5554
value.expect("attempt to read from stolen value")
5655
}
5756
}

src/librustc_data_structures/tiny_list.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
//! If you expect to store more than 1 element in the common case, steer clear
2323
//! and use a `Vec<T>`, `Box<[T]>`, or a `SmallVec<T>`.
2424
25-
use std::mem;
26-
2725
#[derive(Clone, Hash, Debug, PartialEq)]
2826
pub struct TinyList<T: PartialEq> {
2927
head: Option<Element<T>>
@@ -52,15 +50,15 @@ impl<T: PartialEq> TinyList<T> {
5250
pub fn insert(&mut self, data: T) {
5351
self.head = Some(Element {
5452
data,
55-
next: mem::replace(&mut self.head, None).map(Box::new),
53+
next: self.head.take().map(Box::new)
5654
});
5755
}
5856

5957
#[inline]
6058
pub fn remove(&mut self, data: &T) -> bool {
6159
self.head = match self.head {
6260
Some(ref mut head) if head.data == *data => {
63-
mem::replace(&mut head.next, None).map(|x| *x)
61+
head.next.take().map(|x| *x)
6462
}
6563
Some(ref mut head) => return head.remove_next(data),
6664
None => return false,
@@ -100,7 +98,7 @@ impl<T: PartialEq> Element<T> {
10098
if next.data != *data {
10199
return next.remove_next(data)
102100
} else {
103-
mem::replace(&mut next.next, None)
101+
next.next.take()
104102
}
105103
} else {
106104
return false

src/librustc_typeck/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
831831
}
832832

833833
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
834-
let private_candidate = mem::replace(&mut self.private_candidate, None);
834+
let private_candidate = self.private_candidate.take();
835835
let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
836836

837837
// things failed, so lets look at all traits, for diagnostic purposes now:

0 commit comments

Comments
 (0)