Convert more usages over

This commit is contained in:
Chris Gregory 2019-06-30 11:30:01 -07:00
parent 8a3797b736
commit 636f5e6d11
30 changed files with 44 additions and 48 deletions

View File

@ -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(),

View File

@ -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();
}

View File

@ -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) }
}

View File

@ -1278,8 +1278,8 @@ impl<'a> LoweringContext<'a> {
let was_in_loop_condition = self.is_in_loop_condition;
self.is_in_loop_condition = false;
let catch_scopes = mem::replace(&mut self.catch_scopes, Vec::new());
let loop_scopes = mem::replace(&mut self.loop_scopes, Vec::new());
let catch_scopes = mem::take(&mut self.catch_scopes);
let loop_scopes = mem::take(&mut self.loop_scopes);
let ret = f(self);
self.catch_scopes = catch_scopes;
self.loop_scopes = loop_scopes;

View File

@ -364,7 +364,7 @@ where
// been fully instantiated and hence the set of scopes we have
// doesn't matter -- just to be sure, put an empty vector
// in there.
let old_a_scopes = ::std::mem::replace(pair.vid_scopes(self), vec![]);
let old_a_scopes = ::std::mem::take(pair.vid_scopes(self));
// Relate the generalized kind to the original one.
let result = pair.relate_generalized_ty(self, generalized_ty);

View File

@ -112,7 +112,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// Trait queries just want to pass back type obligations "as is"
pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
::std::mem::take(&mut *self.region_obligations.borrow_mut())
}
/// Process the region obligations that must be proven (during

View File

@ -410,7 +410,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
*any_unifications = false;
}
mem::replace(data, RegionConstraintData::default())
mem::take(data)
}
pub fn data(&self) -> &RegionConstraintData<'tcx> {

View File

@ -1375,7 +1375,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
let outer_ec = mem::replace(&mut self.expr_and_pat_count, 0);
let outer_cx = self.cx;
let outer_ts = mem::replace(&mut self.terminating_scopes, FxHashSet::default());
let outer_ts = mem::take(&mut self.terminating_scopes);
self.terminating_scopes.insert(body.value.hir_id.local_id);
if let Some(root_id) = self.cx.root_id {

View File

@ -18,7 +18,7 @@ use errors::{Applicability, DiagnosticBuilder};
use rustc_macros::HashStable;
use std::borrow::Cow;
use std::cell::Cell;
use std::mem::replace;
use std::mem::{replace, take};
use syntax::ast;
use syntax::attr;
use syntax::ptr::P;
@ -441,7 +441,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
// Each body has their own set of labels, save labels.
let saved = replace(&mut self.labels_in_fn, vec![]);
let saved = take(&mut self.labels_in_fn);
let body = self.tcx.hir().body(body);
extract_labels(self, body);
self.with(
@ -1405,9 +1405,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
lifetime_uses,
..
} = self;
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
let xcrate_object_lifetime_defaults =
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap::default());
let labels_in_fn = take(&mut self.labels_in_fn);
let xcrate_object_lifetime_defaults = take(&mut self.xcrate_object_lifetime_defaults);
let mut this = LifetimeContext {
tcx: *tcx,
map: map,

View File

@ -205,8 +205,8 @@ impl<'a> LlvmArchiveBuilder<'a> {
}
fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
let removals = mem::replace(&mut self.removals, Vec::new());
let mut additions = mem::replace(&mut self.additions, Vec::new());
let removals = mem::take(&mut self.removals);
let mut additions = mem::take(&mut self.additions);
let mut strings = Vec::new();
let mut members = Vec::new();

View File

@ -110,7 +110,7 @@ impl Command {
}
pub fn take_args(&mut self) -> Vec<OsString> {
mem::replace(&mut self.args, Vec::new())
mem::take(&mut self.args)
}
/// Returns a `true` if we're pretty sure that this'll blow OS spawn limits,

View File

@ -1345,12 +1345,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
assert!(!started_lto);
started_lto = true;
let needs_fat_lto =
mem::replace(&mut needs_fat_lto, Vec::new());
let needs_thin_lto =
mem::replace(&mut needs_thin_lto, Vec::new());
let import_only_modules =
mem::replace(&mut lto_import_only_modules, Vec::new());
let needs_fat_lto = mem::take(&mut needs_fat_lto);
let needs_thin_lto = mem::take(&mut needs_thin_lto);
let import_only_modules = mem::take(&mut lto_import_only_modules);
for (work, cost) in generate_lto_work(&cgcx, needs_fat_lto,
needs_thin_lto, import_only_modules) {

View File

@ -275,7 +275,7 @@ fn do_mir_borrowck<'a, 'tcx>(
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
// Convert any reservation warnings into lints.
let reservation_warnings = mem::replace(&mut mbcx.reservation_warnings, Default::default());
let reservation_warnings = mem::take(&mut mbcx.reservation_warnings);
for (_, (place, span, location, bk, borrow)) in reservation_warnings {
let mut initial_diag =
mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow);

View File

@ -28,7 +28,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
candidate: &mut Candidate<'pat, 'tcx>) {
// repeatedly simplify match pairs until fixed point is reached
loop {
let match_pairs = mem::replace(&mut candidate.match_pairs, vec![]);
let match_pairs = mem::take(&mut candidate.match_pairs);
let mut changed = false;
for match_pair in match_pairs {
match self.simplify_match_pair(match_pair, candidate) {

View File

@ -31,7 +31,7 @@ impl DefUseAnalysis {
self.clear();
let mut finder = DefUseFinder {
info: mem::replace(&mut self.info, IndexVec::new()),
info: mem::take(&mut self.info),
};
finder.visit_body(body);
self.info = finder.info

View File

@ -946,7 +946,7 @@ impl<'a> Resolver<'a> {
};
let macro_resolutions =
mem::replace(&mut *module.multi_segment_macro_resolutions.borrow_mut(), Vec::new());
mem::take(&mut *module.multi_segment_macro_resolutions.borrow_mut());
for (mut path, path_span, kind, parent_scope, initial_res) in macro_resolutions {
// FIXME: Path resolution will ICE if segment IDs present.
for seg in &mut path { seg.id = None; }
@ -973,7 +973,7 @@ impl<'a> Resolver<'a> {
}
let macro_resolutions =
mem::replace(&mut *module.single_segment_macro_resolutions.borrow_mut(), Vec::new());
mem::take(&mut *module.single_segment_macro_resolutions.borrow_mut());
for (ident, kind, parent_scope, initial_binding) in macro_resolutions {
match self.early_resolve_ident_in_lexical_scope(ident, ScopeSet::Macro(kind),
&parent_scope, true, true, ident.span) {
@ -998,7 +998,7 @@ impl<'a> Resolver<'a> {
}
}
let builtin_attrs = mem::replace(&mut *module.builtin_attrs.borrow_mut(), Vec::new());
let builtin_attrs = mem::take(&mut *module.builtin_attrs.borrow_mut());
for (ident, parent_scope) in builtin_attrs {
let _ = self.early_resolve_ident_in_lexical_scope(
ident, ScopeSet::Macro(MacroKind::Attr), &parent_scope, true, true, ident.span

View File

@ -682,7 +682,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let mut prev_num_indeterminates = self.indeterminate_imports.len() + 1;
while self.indeterminate_imports.len() < prev_num_indeterminates {
prev_num_indeterminates = self.indeterminate_imports.len();
for import in mem::replace(&mut self.indeterminate_imports, Vec::new()) {
for import in mem::take(&mut self.indeterminate_imports) {
match self.resolve_import(&import) {
true => self.determined_imports.push(import),
false => self.indeterminate_imports.push(import),

View File

@ -970,9 +970,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
debug!("pick: actual search failed, assemble diagnotics");
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
let static_candidates = mem::take(&mut self.static_candidates);
let private_candidate = self.private_candidate.take();
let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
let unsatisfied_predicates = mem::take(&mut self.unsatisfied_predicates);
// things failed, so lets look at all traits, for diagnostic purposes now:
self.reset();

View File

@ -4408,7 +4408,7 @@ pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
where
F: FnOnce() -> R,
{
let old_bounds = mem::replace(&mut *cx.impl_trait_bounds.borrow_mut(), Default::default());
let old_bounds = mem::take(&mut *cx.impl_trait_bounds.borrow_mut());
let r = f();
assert!(cx.impl_trait_bounds.borrow().is_empty());
*cx.impl_trait_bounds.borrow_mut() = old_bounds;

View File

@ -131,7 +131,7 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP
for param in &mut params {
match param.kind {
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
*bounds = ty_bounds(mem::replace(bounds, Vec::new()));
*bounds = ty_bounds(mem::take(bounds));
}
_ => panic!("expected only type parameters"),
}

View File

@ -660,7 +660,7 @@ pub fn run(mut krate: clean::Crate,
deref_trait_did,
deref_mut_trait_did,
owned_box_did,
masked_crates: mem::replace(&mut krate.masked_crates, Default::default()),
masked_crates: mem::take(&mut krate.masked_crates),
param_names: external_param_names,
aliases: Default::default(),
};

View File

@ -46,7 +46,7 @@ fn collapse(doc_strings: &mut Vec<DocFragment>) {
let mut docs = vec![];
let mut last_frag: Option<DocFragment> = None;
for frag in replace(doc_strings, vec![]) {
for frag in take(doc_strings) {
if let Some(mut curr_frag) = last_frag.take() {
let curr_kind = curr_frag.kind();
let new_kind = frag.kind();

View File

@ -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))
}

View File

@ -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()
};

View File

@ -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));

View File

@ -307,7 +307,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
} else {
self.resolve_imports();
if undetermined_invocations.is_empty() { break }
invocations = mem::replace(&mut undetermined_invocations, Vec::new());
invocations = mem::take(&mut undetermined_invocations);
force = !mem::replace(&mut progress, false);
continue
};

View File

@ -249,7 +249,7 @@ pub fn transcribe(
quoted::TokenTree::Delimited(mut span, delimited) => {
span = span.apply_mark(cx.current_expansion.mark);
stack.push(Frame::Delimited { forest: delimited, idx: 0, span });
result_stack.push(mem::replace(&mut result, Vec::new()));
result_stack.push(mem::take(&mut result));
}
// Nothing much to do here. Just push the token to the result, being careful to

View File

@ -7699,7 +7699,7 @@ impl<'a> Parser<'a> {
let mut tokens = Vec::new();
let prev_collecting = match self.token_cursor.frame.last_token {
LastToken::Collecting(ref mut list) => {
Some(mem::replace(list, Vec::new()))
Some(mem::take(list))
}
LastToken::Was(ref mut last) => {
tokens.extend(last.take());
@ -7717,7 +7717,7 @@ impl<'a> Parser<'a> {
// Pull out the tokens that we've collected from the call to `f` above.
let mut collected_tokens = match *last_token {
LastToken::Collecting(ref mut v) => mem::replace(v, Vec::new()),
LastToken::Collecting(ref mut v) => mem::take(v),
LastToken::Was(_) => panic!("our vector went away?"),
};

View File

@ -120,8 +120,8 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
// We don't want to recurse into anything other than mods, since
// mods or tests inside of functions will break things
if let ast::ItemKind::Mod(mut module) = item.node {
let tests = mem::replace(&mut self.tests, Vec::new());
let tested_submods = mem::replace(&mut self.tested_submods, Vec::new());
let tests = mem::take(&mut self.tests);
let tested_submods = mem::take(&mut self.tested_submods);
noop_visit_mod(&mut module, self);
let tests = mem::replace(&mut self.tests, tests);
let tested_submods = mem::replace(&mut self.tested_submods, tested_submods);

View File

@ -3608,7 +3608,7 @@ fn nocomment_mir_line(line: &str) -> &str {
fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
use crate::read2::read2;
use std::mem::replace;
use std::mem::take;
const HEAD_LEN: usize = 160 * 1024;
const TAIL_LEN: usize = 256 * 1024;
@ -3632,7 +3632,7 @@ fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
return;
}
let tail = bytes.split_off(new_len - TAIL_LEN).into_boxed_slice();
let head = replace(bytes, Vec::new());
let head = take(bytes);
let skipped = new_len - HEAD_LEN - TAIL_LEN;
ProcOutput::Abbreviated {
head,