From 1e2f893da2f33deef7fb7c6dc62b265f454c4456 Mon Sep 17 00:00:00 2001 From: Nylonicious <50183564+nylonicious@users.noreply.github.com> Date: Thu, 22 Apr 2021 13:33:42 +0200 Subject: [PATCH] chore: fix some clippy lints (#3720) --- tokio/src/io/util/lines.rs | 2 +- tokio/src/io/util/read_line.rs | 4 ++-- tokio/src/io/util/read_to_string.rs | 2 +- tokio/src/io/util/split.rs | 2 +- tokio/src/runtime/blocking/pool.rs | 2 +- tokio/src/sync/watch.rs | 2 +- tokio/src/util/slab.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tokio/src/io/util/lines.rs b/tokio/src/io/util/lines.rs index ed6a94440..d02a4538a 100644 --- a/tokio/src/io/util/lines.rs +++ b/tokio/src/io/util/lines.rs @@ -128,7 +128,7 @@ where } } - Poll::Ready(Ok(Some(mem::replace(me.buf, String::new())))) + Poll::Ready(Ok(Some(mem::take(me.buf)))) } } diff --git a/tokio/src/io/util/read_line.rs b/tokio/src/io/util/read_line.rs index d38ffaf2c..e641f5153 100644 --- a/tokio/src/io/util/read_line.rs +++ b/tokio/src/io/util/read_line.rs @@ -36,7 +36,7 @@ where { ReadLine { reader, - buf: mem::replace(string, String::new()).into_bytes(), + buf: mem::take(string).into_bytes(), output: string, read: 0, _pin: PhantomPinned, @@ -99,7 +99,7 @@ pub(super) fn read_line_internal( read: &mut usize, ) -> Poll> { let io_res = ready!(read_until_internal(reader, cx, b'\n', buf, read)); - let utf8_res = String::from_utf8(mem::replace(buf, Vec::new())); + let utf8_res = String::from_utf8(mem::take(buf)); // At this point both buf and output are empty. The allocation is in utf8_res. diff --git a/tokio/src/io/util/read_to_string.rs b/tokio/src/io/util/read_to_string.rs index 2c17383c6..b3d82a26b 100644 --- a/tokio/src/io/util/read_to_string.rs +++ b/tokio/src/io/util/read_to_string.rs @@ -37,7 +37,7 @@ pub(crate) fn read_to_string<'a, R>( where R: AsyncRead + ?Sized + Unpin, { - let buf = mem::replace(string, String::new()).into_bytes(); + let buf = mem::take(string).into_bytes(); ReadToString { reader, buf: VecWithInitialized::new(buf), diff --git a/tokio/src/io/util/split.rs b/tokio/src/io/util/split.rs index 4f3ce4eff..9c2bb0589 100644 --- a/tokio/src/io/util/split.rs +++ b/tokio/src/io/util/split.rs @@ -106,7 +106,7 @@ where me.buf.pop(); } - Poll::Ready(Ok(Some(mem::replace(me.buf, Vec::new())))) + Poll::Ready(Ok(Some(mem::take(me.buf)))) } } diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index 791e4050d..3e9364db6 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -151,7 +151,7 @@ impl BlockingPool { self.spawner.inner.condvar.notify_all(); let last_exited_thread = std::mem::take(&mut shared.last_exiting_thread); - let workers = std::mem::replace(&mut shared.worker_threads, HashMap::new()); + let workers = std::mem::take(&mut shared.worker_threads); drop(shared); diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs index bf6f0ac86..db65e5a5e 100644 --- a/tokio/src/sync/watch.rs +++ b/tokio/src/sync/watch.rs @@ -205,7 +205,7 @@ impl Receiver { // not memory access. shared.ref_count_rx.fetch_add(1, Relaxed); - Self { version, shared } + Self { shared, version } } /// Returns a reference to the most recently sent value diff --git a/tokio/src/util/slab.rs b/tokio/src/util/slab.rs index efc72e133..2ddaa6c74 100644 --- a/tokio/src/util/slab.rs +++ b/tokio/src/util/slab.rs @@ -296,7 +296,7 @@ impl Slab { // Remove the slots vector from the page. This is done so that the // freeing process is done outside of the lock's critical section. - let vec = mem::replace(&mut slots.slots, vec![]); + let vec = mem::take(&mut slots.slots); slots.head = 0; // Drop the lock so we can drop the vector outside the lock below.