Skip to content

Commit 636f5e6

Browse files
committed
Convert more usages over
1 parent 8a3797b commit 636f5e6

File tree

30 files changed

+44
-48
lines changed

30 files changed

+44
-48
lines changed

src/liballoc/collections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
770770
}
771771

772772
// First, we merge `self` and `other` into a sorted sequence in linear time.
773-
let self_iter = mem::replace(self, BTreeMap::new()).into_iter();
774-
let other_iter = mem::replace(other, BTreeMap::new()).into_iter();
773+
let self_iter = mem::take(self).into_iter();
774+
let other_iter = mem::take(other).into_iter();
775775
let iter = MergeIter {
776776
left: self_iter.peekable(),
777777
right: other_iter.peekable(),

src/liballoc/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ impl<T> LinkedList<T> {
708708
let len = self.len();
709709
assert!(at <= len, "Cannot split off at a nonexistent index");
710710
if at == 0 {
711-
return mem::replace(self, Self::new());
711+
return mem::take(self);
712712
} else if at == len {
713713
return Self::new();
714714
}

src/liballoc/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl ToOwned for str {
203203
}
204204

205205
fn clone_into(&self, target: &mut String) {
206-
let mut b = mem::replace(target, String::new()).into_bytes();
206+
let mut b = mem::take(target).into_bytes();
207207
self.as_bytes().clone_into(&mut b);
208208
*target = unsafe { String::from_utf8_unchecked(b) }
209209
}

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,8 @@ impl<'a> LoweringContext<'a> {
12781278
let was_in_loop_condition = self.is_in_loop_condition;
12791279
self.is_in_loop_condition = false;
12801280

1281-
let catch_scopes = mem::replace(&mut self.catch_scopes, Vec::new());
1282-
let loop_scopes = mem::replace(&mut self.loop_scopes, Vec::new());
1281+
let catch_scopes = mem::take(&mut self.catch_scopes);
1282+
let loop_scopes = mem::take(&mut self.loop_scopes);
12831283
let ret = f(self);
12841284
self.catch_scopes = catch_scopes;
12851285
self.loop_scopes = loop_scopes;

src/librustc/infer/nll_relate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ where
364364
// been fully instantiated and hence the set of scopes we have
365365
// doesn't matter -- just to be sure, put an empty vector
366366
// in there.
367-
let old_a_scopes = ::std::mem::replace(pair.vid_scopes(self), vec![]);
367+
let old_a_scopes = ::std::mem::take(pair.vid_scopes(self));
368368

369369
// Relate the generalized kind to the original one.
370370
let result = pair.relate_generalized_ty(self, generalized_ty);

src/librustc/infer/outlives/obligations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
112112

113113
/// Trait queries just want to pass back type obligations "as is"
114114
pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
115-
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
115+
::std::mem::take(&mut *self.region_obligations.borrow_mut())
116116
}
117117

118118
/// Process the region obligations that must be proven (during

src/librustc/infer/region_constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
410410
*any_unifications = false;
411411
}
412412

413-
mem::replace(data, RegionConstraintData::default())
413+
mem::take(data)
414414
}
415415

416416
pub fn data(&self) -> &RegionConstraintData<'tcx> {

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
13751375

13761376
let outer_ec = mem::replace(&mut self.expr_and_pat_count, 0);
13771377
let outer_cx = self.cx;
1378-
let outer_ts = mem::replace(&mut self.terminating_scopes, FxHashSet::default());
1378+
let outer_ts = mem::take(&mut self.terminating_scopes);
13791379
self.terminating_scopes.insert(body.value.hir_id.local_id);
13801380

13811381
if let Some(root_id) = self.cx.root_id {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use errors::{Applicability, DiagnosticBuilder};
1818
use rustc_macros::HashStable;
1919
use std::borrow::Cow;
2020
use std::cell::Cell;
21-
use std::mem::replace;
21+
use std::mem::{replace, take};
2222
use syntax::ast;
2323
use syntax::attr;
2424
use syntax::ptr::P;
@@ -441,7 +441,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
441441

442442
fn visit_nested_body(&mut self, body: hir::BodyId) {
443443
// Each body has their own set of labels, save labels.
444-
let saved = replace(&mut self.labels_in_fn, vec![]);
444+
let saved = take(&mut self.labels_in_fn);
445445
let body = self.tcx.hir().body(body);
446446
extract_labels(self, body);
447447
self.with(
@@ -1405,9 +1405,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14051405
lifetime_uses,
14061406
..
14071407
} = self;
1408-
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
1409-
let xcrate_object_lifetime_defaults =
1410-
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap::default());
1408+
let labels_in_fn = take(&mut self.labels_in_fn);
1409+
let xcrate_object_lifetime_defaults = take(&mut self.xcrate_object_lifetime_defaults);
14111410
let mut this = LifetimeContext {
14121411
tcx: *tcx,
14131412
map: map,

src/librustc_codegen_llvm/back/archive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ impl<'a> LlvmArchiveBuilder<'a> {
205205
}
206206

207207
fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
208-
let removals = mem::replace(&mut self.removals, Vec::new());
209-
let mut additions = mem::replace(&mut self.additions, Vec::new());
208+
let removals = mem::take(&mut self.removals);
209+
let mut additions = mem::take(&mut self.additions);
210210
let mut strings = Vec::new();
211211
let mut members = Vec::new();
212212

src/librustc_codegen_ssa/back/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Command {
110110
}
111111

112112
pub fn take_args(&mut self) -> Vec<OsString> {
113-
mem::replace(&mut self.args, Vec::new())
113+
mem::take(&mut self.args)
114114
}
115115

116116
/// Returns a `true` if we're pretty sure that this'll blow OS spawn limits,

src/librustc_codegen_ssa/back/write.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,12 +1345,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
13451345
assert!(!started_lto);
13461346
started_lto = true;
13471347

1348-
let needs_fat_lto =
1349-
mem::replace(&mut needs_fat_lto, Vec::new());
1350-
let needs_thin_lto =
1351-
mem::replace(&mut needs_thin_lto, Vec::new());
1352-
let import_only_modules =
1353-
mem::replace(&mut lto_import_only_modules, Vec::new());
1348+
let needs_fat_lto = mem::take(&mut needs_fat_lto);
1349+
let needs_thin_lto = mem::take(&mut needs_thin_lto);
1350+
let import_only_modules = mem::take(&mut lto_import_only_modules);
13541351

13551352
for (work, cost) in generate_lto_work(&cgcx, needs_fat_lto,
13561353
needs_thin_lto, import_only_modules) {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn do_mir_borrowck<'a, 'tcx>(
275275
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
276276

277277
// Convert any reservation warnings into lints.
278-
let reservation_warnings = mem::replace(&mut mbcx.reservation_warnings, Default::default());
278+
let reservation_warnings = mem::take(&mut mbcx.reservation_warnings);
279279
for (_, (place, span, location, bk, borrow)) in reservation_warnings {
280280
let mut initial_diag =
281281
mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow);

src/librustc_mir/build/matches/simplify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2828
candidate: &mut Candidate<'pat, 'tcx>) {
2929
// repeatedly simplify match pairs until fixed point is reached
3030
loop {
31-
let match_pairs = mem::replace(&mut candidate.match_pairs, vec![]);
31+
let match_pairs = mem::take(&mut candidate.match_pairs);
3232
let mut changed = false;
3333
for match_pair in match_pairs {
3434
match self.simplify_match_pair(match_pair, candidate) {

src/librustc_mir/util/def_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl DefUseAnalysis {
3131
self.clear();
3232

3333
let mut finder = DefUseFinder {
34-
info: mem::replace(&mut self.info, IndexVec::new()),
34+
info: mem::take(&mut self.info),
3535
};
3636
finder.visit_body(body);
3737
self.info = finder.info

src/librustc_resolve/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ impl<'a> Resolver<'a> {
946946
};
947947

948948
let macro_resolutions =
949-
mem::replace(&mut *module.multi_segment_macro_resolutions.borrow_mut(), Vec::new());
949+
mem::take(&mut *module.multi_segment_macro_resolutions.borrow_mut());
950950
for (mut path, path_span, kind, parent_scope, initial_res) in macro_resolutions {
951951
// FIXME: Path resolution will ICE if segment IDs present.
952952
for seg in &mut path { seg.id = None; }
@@ -973,7 +973,7 @@ impl<'a> Resolver<'a> {
973973
}
974974

975975
let macro_resolutions =
976-
mem::replace(&mut *module.single_segment_macro_resolutions.borrow_mut(), Vec::new());
976+
mem::take(&mut *module.single_segment_macro_resolutions.borrow_mut());
977977
for (ident, kind, parent_scope, initial_binding) in macro_resolutions {
978978
match self.early_resolve_ident_in_lexical_scope(ident, ScopeSet::Macro(kind),
979979
&parent_scope, true, true, ident.span) {
@@ -998,7 +998,7 @@ impl<'a> Resolver<'a> {
998998
}
999999
}
10001000

1001-
let builtin_attrs = mem::replace(&mut *module.builtin_attrs.borrow_mut(), Vec::new());
1001+
let builtin_attrs = mem::take(&mut *module.builtin_attrs.borrow_mut());
10021002
for (ident, parent_scope) in builtin_attrs {
10031003
let _ = self.early_resolve_ident_in_lexical_scope(
10041004
ident, ScopeSet::Macro(MacroKind::Attr), &parent_scope, true, true, ident.span

src/librustc_resolve/resolve_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
682682
let mut prev_num_indeterminates = self.indeterminate_imports.len() + 1;
683683
while self.indeterminate_imports.len() < prev_num_indeterminates {
684684
prev_num_indeterminates = self.indeterminate_imports.len();
685-
for import in mem::replace(&mut self.indeterminate_imports, Vec::new()) {
685+
for import in mem::take(&mut self.indeterminate_imports) {
686686
match self.resolve_import(&import) {
687687
true => self.determined_imports.push(import),
688688
false => self.indeterminate_imports.push(import),

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
970970

971971
debug!("pick: actual search failed, assemble diagnotics");
972972

973-
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
973+
let static_candidates = mem::take(&mut self.static_candidates);
974974
let private_candidate = self.private_candidate.take();
975-
let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
975+
let unsatisfied_predicates = mem::take(&mut self.unsatisfied_predicates);
976976

977977
// things failed, so lets look at all traits, for diagnostic purposes now:
978978
self.reset();

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4408,7 +4408,7 @@ pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
44084408
where
44094409
F: FnOnce() -> R,
44104410
{
4411-
let old_bounds = mem::replace(&mut *cx.impl_trait_bounds.borrow_mut(), Default::default());
4411+
let old_bounds = mem::take(&mut *cx.impl_trait_bounds.borrow_mut());
44124412
let r = f();
44134413
assert!(cx.impl_trait_bounds.borrow().is_empty());
44144414
*cx.impl_trait_bounds.borrow_mut() = old_bounds;

src/librustdoc/clean/simplify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP
131131
for param in &mut params {
132132
match param.kind {
133133
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
134-
*bounds = ty_bounds(mem::replace(bounds, Vec::new()));
134+
*bounds = ty_bounds(mem::take(bounds));
135135
}
136136
_ => panic!("expected only type parameters"),
137137
}

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub fn run(mut krate: clean::Crate,
660660
deref_trait_did,
661661
deref_mut_trait_did,
662662
owned_box_did,
663-
masked_crates: mem::replace(&mut krate.masked_crates, Default::default()),
663+
masked_crates: mem::take(&mut krate.masked_crates),
664664
param_names: external_param_names,
665665
aliases: Default::default(),
666666
};

src/librustdoc/passes/collapse_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn collapse(doc_strings: &mut Vec<DocFragment>) {
4646
let mut docs = vec![];
4747
let mut last_frag: Option<DocFragment> = None;
4848

49-
for frag in replace(doc_strings, vec![]) {
49+
for frag in take(doc_strings) {
5050
if let Some(mut curr_frag) = last_frag.take() {
5151
let curr_kind = curr_frag.kind();
5252
let new_kind = frag.kind();

src/libstd/panicking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn continue_panic_fmt(info: &PanicInfo<'_>) -> ! {
364364

365365
unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
366366
fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
367-
let contents = mem::replace(self.fill(), String::new());
367+
let contents = mem::take(self.fill());
368368
Box::into_raw(Box::new(contents))
369369
}
370370

src/libstd/sync/mpsc/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<T> Packet<T> {
383383
// needs to be careful to destroy the data *outside* of the lock to
384384
// prevent deadlock.
385385
let _data = if guard.cap != 0 {
386-
mem::replace(&mut guard.buf.buf, Vec::new())
386+
mem::take(&mut guard.buf.buf)
387387
} else {
388388
Vec::new()
389389
};

src/libstd/sys/windows/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<'a> Drop for AsyncPipe<'a> {
342342
// If anything here fails, there's not really much we can do, so we leak
343343
// the buffer/OVERLAPPED pointers to ensure we're at least memory safe.
344344
if self.pipe.cancel_io().is_err() || self.result().is_err() {
345-
let buf = mem::replace(self.dst, Vec::new());
345+
let buf = mem::take(self.dst);
346346
let overlapped = Box::new(unsafe { mem::zeroed() });
347347
let overlapped = mem::replace(&mut self.overlapped, overlapped);
348348
mem::forget((buf, overlapped));

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
307307
} else {
308308
self.resolve_imports();
309309
if undetermined_invocations.is_empty() { break }
310-
invocations = mem::replace(&mut undetermined_invocations, Vec::new());
310+
invocations = mem::take(&mut undetermined_invocations);
311311
force = !mem::replace(&mut progress, false);
312312
continue
313313
};

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub fn transcribe(
249249
quoted::TokenTree::Delimited(mut span, delimited) => {
250250
span = span.apply_mark(cx.current_expansion.mark);
251251
stack.push(Frame::Delimited { forest: delimited, idx: 0, span });
252-
result_stack.push(mem::replace(&mut result, Vec::new()));
252+
result_stack.push(mem::take(&mut result));
253253
}
254254

255255
// Nothing much to do here. Just push the token to the result, being careful to

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7699,7 +7699,7 @@ impl<'a> Parser<'a> {
76997699
let mut tokens = Vec::new();
77007700
let prev_collecting = match self.token_cursor.frame.last_token {
77017701
LastToken::Collecting(ref mut list) => {
7702-
Some(mem::replace(list, Vec::new()))
7702+
Some(mem::take(list))
77037703
}
77047704
LastToken::Was(ref mut last) => {
77057705
tokens.extend(last.take());
@@ -7717,7 +7717,7 @@ impl<'a> Parser<'a> {
77177717

77187718
// Pull out the tokens that we've collected from the call to `f` above.
77197719
let mut collected_tokens = match *last_token {
7720-
LastToken::Collecting(ref mut v) => mem::replace(v, Vec::new()),
7720+
LastToken::Collecting(ref mut v) => mem::take(v),
77217721
LastToken::Was(_) => panic!("our vector went away?"),
77227722
};
77237723

src/libsyntax/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
120120
// We don't want to recurse into anything other than mods, since
121121
// mods or tests inside of functions will break things
122122
if let ast::ItemKind::Mod(mut module) = item.node {
123-
let tests = mem::replace(&mut self.tests, Vec::new());
124-
let tested_submods = mem::replace(&mut self.tested_submods, Vec::new());
123+
let tests = mem::take(&mut self.tests);
124+
let tested_submods = mem::take(&mut self.tested_submods);
125125
noop_visit_mod(&mut module, self);
126126
let tests = mem::replace(&mut self.tests, tests);
127127
let tested_submods = mem::replace(&mut self.tested_submods, tested_submods);

src/tools/compiletest/src/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,7 +3608,7 @@ fn nocomment_mir_line(line: &str) -> &str {
36083608

36093609
fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
36103610
use crate::read2::read2;
3611-
use std::mem::replace;
3611+
use std::mem::take;
36123612

36133613
const HEAD_LEN: usize = 160 * 1024;
36143614
const TAIL_LEN: usize = 256 * 1024;
@@ -3632,7 +3632,7 @@ fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
36323632
return;
36333633
}
36343634
let tail = bytes.split_off(new_len - TAIL_LEN).into_boxed_slice();
3635-
let head = replace(bytes, Vec::new());
3635+
let head = take(bytes);
36363636
let skipped = new_len - HEAD_LEN - TAIL_LEN;
36373637
ProcOutput::Abbreviated {
36383638
head,

0 commit comments

Comments
 (0)