diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index da2ee2660cf..542bc8c985d 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -119,10 +119,7 @@ fn calc_deps_of_std( deps_of_roots(roots, &mut state)?; } state.is_std = false; - Ok(Some(std::mem::replace( - &mut state.unit_dependencies, - HashMap::new(), - ))) + Ok(Some(std::mem::take(&mut state.unit_dependencies))) } /// Add the standard library units to the `unit_dependencies`. diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 14e2a8c28ab..8acb87097de 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -735,7 +735,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> { .pending .remove(&token) .expect("got a token for a non-in-progress transfer"); - let data = mem::replace(&mut *dl.data.borrow_mut(), Vec::new()); + let data = mem::take(&mut *dl.data.borrow_mut()); let mut handle = self.set.multi.remove(handle)?; self.pending_ids.remove(&dl.id); diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index d502467e2fe..0efdc477fe2 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -115,8 +115,7 @@ impl Summary { { { let slot = &mut Rc::make_mut(&mut self.inner).dependencies; - let deps = mem::replace(slot, Vec::new()); - *slot = deps.into_iter().map(f).collect(); + *slot = mem::take(slot).into_iter().map(f).collect(); } self } diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index bcc776d6c91..28755d05060 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1452,12 +1452,10 @@ impl ConfigValue { fn merge(&mut self, from: ConfigValue, force: bool) -> CargoResult<()> { match (self, from) { (&mut CV::List(ref mut old, _), CV::List(ref mut new, _)) => { - let new = mem::replace(new, Vec::new()); - old.extend(new.into_iter()); + old.extend(mem::take(new).into_iter()); } (&mut CV::Table(ref mut old, _), CV::Table(ref mut new, _)) => { - let new = mem::replace(new, HashMap::new()); - for (key, value) in new { + for (key, value) in mem::take(new) { match old.entry(key.clone()) { Occupied(mut entry) => { let new_def = value.definition().clone(); diff --git a/src/cargo/util/profile.rs b/src/cargo/util/profile.rs index b450d12058e..f172a296525 100644 --- a/src/cargo/util/profile.rs +++ b/src/cargo/util/profile.rs @@ -48,11 +48,7 @@ impl Drop for Profiler { let duration = start.elapsed(); let duration_ms = duration.as_secs() * 1000 + u64::from(duration.subsec_millis()); - let msg = ( - stack_len, - duration_ms, - mem::replace(&mut self.desc, String::new()), - ); + let msg = (stack_len, duration_ms, mem::take(&mut self.desc)); MESSAGES.with(|msgs| msgs.borrow_mut().push(msg)); if stack_len == 0 {