Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling, clippy #7032

Closed
wants to merge 13 commits into from
4 changes: 3 additions & 1 deletion examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl Shared {
async fn broadcast(&mut self, sender: SocketAddr, message: &str) {
for peer in self.peers.iter_mut() {
if *peer.0 != sender {
let _ = peer.1.send(message.into());
if let Err(e) = peer.1.send(message.into()) {
tracing::error!("Failed to send message to {}: {:?}", peer.0, e);
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions tokio-util/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ impl<T: tokio::io::AsyncSeek> futures_io::AsyncSeek for Compat<T> {
*self.as_mut().project().seek_pos = Some(pos);
}
let res = ready!(self.as_mut().project().inner.poll_complete(cx));
*self.as_mut().project().seek_pos = None;
if res.is_ok() {
*self.as_mut().project().seek_pos = None;
}
Comment on lines -235 to +237
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being changed? Is there a use-case where this behaves incorrectly? Can you add that use-case as a test?

Poll::Ready(res)
}
}
Expand All @@ -255,7 +257,9 @@ impl<T: futures_io::AsyncSeek> tokio::io::AsyncSeek for Compat<T> {
Some(pos) => pos,
};
let res = ready!(self.as_mut().project().inner.poll_seek(cx, pos));
*self.as_mut().project().seek_pos = None;
if res.is_ok() {
*self.as_mut().project().seek_pos = None;
}
Poll::Ready(res)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/time/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl TimerEntry {
*self.inner.get() = Some(TimerShared::new(shard_id));
}
}
return inner.as_ref().unwrap();
inner.as_ref().unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here seems to be wrong.

}

pub(crate) fn deadline(&self) -> Instant {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ impl<T> From<T> for RwLock<T> {
}
}

impl<T: ?Sized> Default for RwLock<T>
impl<T> Default for RwLock<T>
where
T: Default,
{
Expand Down
4 changes: 1 addition & 3 deletions tokio/tests/io_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ fn method_delegation() {
assert_eq!(1, w.write(&[b'x']).await.unwrap());
assert_eq!(
2,
w.write_vectored(&[io::IoSlice::new(&[b'x'])])
.await
.unwrap()
w.write_vectored(&[io::IoSlice::new(b"x")]).await.unwrap()
);
assert!(w.is_write_vectored());

Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/tcp_accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct TrackPolls<'a> {
listener: &'a mut TcpListener,
}

impl<'a> Stream for TrackPolls<'a> {
impl Stream for TrackPolls<'_> {
type Item = io::Result<(TcpStream, SocketAddr)>;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
Loading