Skip to content

Commit aacd605

Browse files
committed
Fix clippy::mem_replace_with_default warning
``` warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/future/select_all.rs:62:28 | 62 | let rest = mem::replace(&mut self.inner, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut self.inner)` | = note: `#[warn(clippy::mem_replace_with_default)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/future/select_ok.rs:62:40 | 62 | ... let rest = mem::replace(&mut self.inner, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut self.inner)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/stream/collect.rs:22:9 | 22 | mem::replace(self.project().collection, Default::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(self.project().collection)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/stream/unzip.rs:24:10 | 24 | (mem::replace(this.left, Default::default()), mem::replace(this.right, Default::default())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.left)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/stream/unzip.rs:24:55 | 24 | (mem::replace(this.left, Default::default()), mem::replace(this.right, Default::default())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.right)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/stream/chunks.rs:69:40 | 69 | let full_buf = mem::replace(this.items, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.items)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/stream/ready_chunks.rs:77:40 | 77 | let full_buf = mem::replace(this.items, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.items)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/try_stream/try_collect.rs:48:31 | 48 | None => break mem::replace(this.items, Default::default()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.items)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/stream/try_stream/try_chunks.rs:74:40 | 74 | let full_buf = mem::replace(this.items, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.items)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/io/lines.rs:45:29 | 45 | Poll::Ready(Some(Ok(mem::replace(this.buf, String::new())))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(this.buf)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/io/read_exact.rs:33:33 | 33 | let (_, rest) = mem::replace(&mut this.buf, &mut []).split_at_mut(n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut this.buf)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/io/read_line.rs:25:31 | 25 | Self { reader, bytes: mem::replace(buf, String::new()).into_bytes(), buf, read: 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(buf)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/io/read_to_string.rs:25:31 | 25 | Self { reader, bytes: mem::replace(buf, String::new()).into_bytes(), buf, start_len } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(buf)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures-util/src/io/write_all.rs:33:33 | 33 | let (_, rest) = mem::replace(&mut this.buf, &[]).split_at(n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut this.buf)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> futures/tests/sink.rs:141:9 | 141 | mem::replace(&mut self.data, Vec::new()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut self.data)` | = note: `#[warn(clippy::mem_replace_with_default)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default ```
1 parent 0687c59 commit aacd605

File tree

14 files changed

+14
-14
lines changed

14 files changed

+14
-14
lines changed

futures-util/src/future/select_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<Fut: Future + Unpin> Future for SelectAll<Fut> {
5959
match item {
6060
Some((idx, res)) => {
6161
let _ = self.inner.swap_remove(idx);
62-
let rest = mem::replace(&mut self.inner, Vec::new());
62+
let rest = mem::take(&mut self.inner);
6363
Poll::Ready((res, idx, rest))
6464
}
6565
None => Poll::Pending,

futures-util/src/future/select_ok.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<Fut: TryFuture + Unpin> Future for SelectOk<Fut> {
5959
drop(self.inner.remove(idx));
6060
match res {
6161
Ok(e) => {
62-
let rest = mem::replace(&mut self.inner, Vec::new());
62+
let rest = mem::take(&mut self.inner);
6363
return Poll::Ready(Ok((e, rest)));
6464
}
6565
Err(e) => {

futures-util/src/io/lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ impl<R: AsyncBufRead> Stream for Lines<R> {
4242
this.buf.pop();
4343
}
4444
}
45-
Poll::Ready(Some(Ok(mem::replace(this.buf, String::new()))))
45+
Poll::Ready(Some(Ok(mem::take(this.buf))))
4646
}
4747
}

futures-util/src/io/read_exact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<R: AsyncRead + ?Sized + Unpin> Future for ReadExact<'_, R> {
3030
while !this.buf.is_empty() {
3131
let n = ready!(Pin::new(&mut this.reader).poll_read(cx, this.buf))?;
3232
{
33-
let (_, rest) = mem::replace(&mut this.buf, &mut []).split_at_mut(n);
33+
let (_, rest) = mem::take(&mut this.buf).split_at_mut(n);
3434
this.buf = rest;
3535
}
3636
if n == 0 {

futures-util/src/io/read_line.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<R: ?Sized + Unpin> Unpin for ReadLine<'_, R> {}
2222

2323
impl<'a, R: AsyncBufRead + ?Sized + Unpin> ReadLine<'a, R> {
2424
pub(super) fn new(reader: &'a mut R, buf: &'a mut String) -> Self {
25-
Self { reader, bytes: mem::replace(buf, String::new()).into_bytes(), buf, read: 0 }
25+
Self { reader, bytes: mem::take(buf).into_bytes(), buf, read: 0 }
2626
}
2727
}
2828

futures-util/src/io/read_to_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<R: ?Sized + Unpin> Unpin for ReadToString<'_, R> {}
2222
impl<'a, R: AsyncRead + ?Sized + Unpin> ReadToString<'a, R> {
2323
pub(super) fn new(reader: &'a mut R, buf: &'a mut String) -> Self {
2424
let start_len = buf.len();
25-
Self { reader, bytes: mem::replace(buf, String::new()).into_bytes(), buf, start_len }
25+
Self { reader, bytes: mem::take(buf).into_bytes(), buf, start_len }
2626
}
2727
}
2828

futures-util/src/io/write_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteAll<'_, W> {
3030
while !this.buf.is_empty() {
3131
let n = ready!(Pin::new(&mut this.writer).poll_write(cx, this.buf))?;
3232
{
33-
let (_, rest) = mem::replace(&mut this.buf, &[]).split_at(n);
33+
let (_, rest) = mem::take(&mut this.buf).split_at(n);
3434
this.buf = rest;
3535
}
3636
if n == 0 {

futures-util/src/stream/stream/chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<St: Stream> Stream for Chunks<St> {
6666
let last = if this.items.is_empty() {
6767
None
6868
} else {
69-
let full_buf = mem::replace(this.items, Vec::new());
69+
let full_buf = mem::take(this.items);
7070
Some(full_buf)
7171
};
7272

futures-util/src/stream/stream/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pin_project! {
1919

2020
impl<St: Stream, C: Default> Collect<St, C> {
2121
fn finish(self: Pin<&mut Self>) -> C {
22-
mem::replace(self.project().collection, Default::default())
22+
mem::take(self.project().collection)
2323
}
2424

2525
pub(super) fn new(stream: St) -> Self {

futures-util/src/stream/stream/ready_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<St: Stream> Stream for ReadyChunks<St> {
7474
let last = if this.items.is_empty() {
7575
None
7676
} else {
77-
let full_buf = mem::replace(this.items, Vec::new());
77+
let full_buf = mem::take(this.items);
7878
Some(full_buf)
7979
};
8080

0 commit comments

Comments
 (0)