From bcb95db4e2d4a9a43a3f3f5e129ddb7232599451 Mon Sep 17 00:00:00 2001 From: cssivision Date: Wed, 10 Mar 2021 15:42:24 +0800 Subject: [PATCH] chore: fix clippy warnings in newer versions (#3588) --- tokio-util/src/codec/length_delimited.rs | 8 ++++---- tokio-util/src/sync/mpsc.rs | 5 +---- tokio/src/io/driver/scheduled_io.rs | 4 ++-- tokio/src/runtime/context.rs | 10 ++-------- tokio/src/runtime/thread_pool/worker.rs | 2 +- tokio/src/sync/watch.rs | 2 +- tokio/src/task/local.rs | 2 +- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/tokio-util/src/codec/length_delimited.rs b/tokio-util/src/codec/length_delimited.rs index ef706dfab..c316c145c 100644 --- a/tokio-util/src/codec/length_delimited.rs +++ b/tokio-util/src/codec/length_delimited.rs @@ -535,14 +535,14 @@ impl LengthDelimitedCodec { Ok(Some(n)) } - fn decode_data(&self, n: usize, src: &mut BytesMut) -> io::Result> { + fn decode_data(&self, n: usize, src: &mut BytesMut) -> Option { // At this point, the buffer has already had the required capacity // reserved. All there is to do is read. if src.len() < n { - return Ok(None); + return None; } - Ok(Some(src.split_to(n))) + Some(src.split_to(n)) } } @@ -562,7 +562,7 @@ impl Decoder for LengthDelimitedCodec { DecodeState::Data(n) => n, }; - match self.decode_data(n, src)? { + match self.decode_data(n, src) { Some(data) => { // Update the decode state self.state = DecodeState::Head; diff --git a/tokio-util/src/sync/mpsc.rs b/tokio-util/src/sync/mpsc.rs index b09d76d27..7c79c98e5 100644 --- a/tokio-util/src/sync/mpsc.rs +++ b/tokio-util/src/sync/mpsc.rs @@ -126,10 +126,7 @@ impl PollSender { /// If this method returns `None`, then the channel is closed. (But it is /// not guaranteed to return `None` if the channel is closed.) pub fn clone_inner(&self) -> Option> { - match &self.sender { - Some(sender) => Some((&**sender).clone()), - None => None, - } + self.sender.as_ref().map(|sender| (&**sender).clone()) } /// Access the underlying `Sender`. diff --git a/tokio/src/io/driver/scheduled_io.rs b/tokio/src/io/driver/scheduled_io.rs index 71864b3e6..2626b40a7 100644 --- a/tokio/src/io/driver/scheduled_io.rs +++ b/tokio/src/io/driver/scheduled_io.rs @@ -443,7 +443,7 @@ cfg_io_readiness! { // Currently ready! let tick = TICK.unpack(curr) as u8; *state = State::Done; - return Poll::Ready(ReadyEvent { ready, tick }); + return Poll::Ready(ReadyEvent { tick, ready }); } // Wasn't ready, take the lock (and check again while locked). @@ -462,7 +462,7 @@ cfg_io_readiness! { // Currently ready! let tick = TICK.unpack(curr) as u8; *state = State::Done; - return Poll::Ready(ReadyEvent { ready, tick }); + return Poll::Ready(ReadyEvent { tick, ready }); } // Not ready even after locked, insert into list... diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index 6e4a01696..a727ed497 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -40,20 +40,14 @@ cfg_time! { cfg_test_util! { pub(crate) fn clock() -> Option { - CONTEXT.with(|ctx| match *ctx.borrow() { - Some(ref ctx) => Some(ctx.clock.clone()), - None => None, - }) + CONTEXT.with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.clock.clone())) } } } cfg_rt! { pub(crate) fn spawn_handle() -> Option { - CONTEXT.with(|ctx| match *ctx.borrow() { - Some(ref ctx) => Some(ctx.spawner.clone()), - None => None, - }) + CONTEXT.with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.spawner.clone())) } } diff --git a/tokio/src/runtime/thread_pool/worker.rs b/tokio/src/runtime/thread_pool/worker.rs index dbd1aff6d..86d3f91b5 100644 --- a/tokio/src/runtime/thread_pool/worker.rs +++ b/tokio/src/runtime/thread_pool/worker.rs @@ -827,6 +827,6 @@ impl Shared { } fn ptr_eq(&self, other: &Shared) -> bool { - self as *const _ == other as *const _ + std::ptr::eq(self, other) } } diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs index 5590a754d..1ccb040e0 100644 --- a/tokio/src/sync/watch.rs +++ b/tokio/src/sync/watch.rs @@ -293,7 +293,7 @@ impl Clone for Receiver { // not memory access. shared.ref_count_rx.fetch_add(1, Relaxed); - Receiver { version, shared } + Receiver { shared, version } } } diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index ee1151135..64f1ac57c 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -661,7 +661,7 @@ impl Shared { } fn ptr_eq(&self, other: &Shared) -> bool { - self as *const _ == other as *const _ + std::ptr::eq(self, other) } }