Skip to content

Commit 28a8da8

Browse files
authored
Rollup merge of rust-lang#62249 - czipperz:use-mem-take-instead-of-replace-default, r=dtolnay,Centril
Use mem::take instead of mem::replace with default
2 parents ea3bee0 + eddfad3 commit 28a8da8

File tree

43 files changed

+57
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+57
-49
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/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
113113
#![feature(alloc_layout_extra)]
114114
#![feature(try_trait)]
115+
#![feature(mem_take)]
115116

116117
// Allow testing this library
117118

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/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
#![feature(adx_target_feature)]
127127
#![feature(maybe_uninit_slice, maybe_uninit_array)]
128128
#![feature(external_doc)]
129+
#![feature(mem_take)]
129130

130131
#[prelude_import]
131132
#[allow(unused)]

src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ impl<T> Option<T> {
845845
#[inline]
846846
#[stable(feature = "rust1", since = "1.0.0")]
847847
pub fn take(&mut self) -> Option<T> {
848-
mem::replace(self, None)
848+
mem::take(self)
849849
}
850850

851851
/// Replaces the actual value in the option by the value given in parameter,

src/libproc_macro/bridge/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<T: Copy> Buffer<T> {
7878
}
7979

8080
pub(super) fn take(&mut self) -> Self {
81-
mem::replace(self, Self::default())
81+
mem::take(self)
8282
}
8383

8484
pub(super) fn extend_from_slice(&mut self, xs: &[T]) {

src/libproc_macro/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(extern_types)]
2626
#![feature(in_band_lifetimes)]
2727
#![feature(optin_builtin_traits)]
28+
#![feature(mem_take)]
2829
#![feature(non_exhaustive)]
2930
#![feature(specialization)]
3031

src/librustc/hir/lowering.rs

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

1283-
let catch_scopes = mem::replace(&mut self.catch_scopes, Vec::new());
1284-
let loop_scopes = mem::replace(&mut self.loop_scopes, Vec::new());
1283+
let catch_scopes = mem::take(&mut self.catch_scopes);
1284+
let loop_scopes = mem::take(&mut self.loop_scopes);
12851285
let ret = f(self);
12861286
self.catch_scopes = catch_scopes;
12871287
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);

0 commit comments

Comments
 (0)