Skip to content

Commit

Permalink
lint: assortment of clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
barafael committed Aug 17, 2024
1 parent 965e209 commit d0ce8ae
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 32 deletions.
4 changes: 2 additions & 2 deletions examples/tinyhttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ impl Decoder for Http {
ret = ret.header(&data[k.0..k.1], value);
}

let req = ret
let request = ret
.body(())
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
Ok(Some(req))
Ok(Some(request))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/sync_cancellation_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn cancel_child_token_without_parent() {

#[test]
fn create_child_token_after_parent_was_cancelled() {
for drop_child_first in [true, false].iter().cloned() {
for drop_child_first in [true, false].iter().copied() {
let (waker, wake_counter) = new_count_waker();
let token = CancellationToken::new();
token.cancel();
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/fs/create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use std::path::Path;
/// limited to just these cases:
///
/// * If any directory in the path specified by `path` does not already exist
/// and it could not be created otherwise. The specific error conditions for
/// when a directory is being created (after it is determined to not exist) are
/// outlined by [`fs::create_dir`].
/// and it could not be created otherwise. The specific error conditions for
/// when a directory is being created (after it is determined to not exist) are
/// outlined by [`fs::create_dir`].
///
/// Notable exception is made for situations where any of the directories
/// specified in the `path` could not be created as it was being created concurrently.
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/fs/mocks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Mock version of std::fs::File;
//! Mock version of [`std::fs::File`].
use mockall::mock;

use crate::sync::oneshot;
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
//! * [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP
//! * [`UdpSocket`] provides functionality for communication over UDP
//! * [`UnixListener`] and [`UnixStream`] provide functionality for communication over a
//! Unix Domain Stream Socket **(available on Unix only)**
//! Unix Domain Stream Socket **(available on Unix only)**
//! * [`UnixDatagram`] provides functionality for communication
//! over Unix Domain Datagram Socket **(available on Unix only)**
//! over Unix Domain Datagram Socket **(available on Unix only)**
//! * [`tokio::net::unix::pipe`] for FIFO pipes **(available on Unix only)**
//! * [`tokio::net::windows::named_pipe`] for Named Pipes **(available on Windows only)**
//!
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/process/unix/pidfd_reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ where
if let Some(pidfd) = Pidfd::open(inner.id()) {
match PollEvented::new_with_interest(pidfd, Interest::READABLE) {
Ok(pidfd) => Ok(Self {
inner: Some(PidfdReaperInner { pidfd, inner }),
inner: Some(PidfdReaperInner { inner, pidfd }),
orphan_queue,
}),
Err(io_error) => Err((Some(io_error), inner)),
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
10 changes: 5 additions & 5 deletions tokio/src/time/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ cfg_not_test_util! {
}

cfg_test_util! {
use crate::time::{Duration, Instant};
use crate::loom::sync::Mutex;
use crate::loom::sync::atomic::Ordering;
use crate::loom::sync::Mutex;
use crate::time::{Duration, Instant};
use std::sync::atomic::AtomicBool as StdAtomicBool;

cfg_rt! {
#[track_caller]
fn with_clock<R>(f: impl FnOnce(Option<&Clock>) -> Result<R, &'static str>) -> R {
use crate::runtime::Handle;

let res = match Handle::try_current() {
let result = match Handle::try_current() {
Ok(handle) => f(Some(handle.inner.driver().clock())),
Err(ref e) if e.is_missing_context() => f(None),
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
};

match res {
match result {
Ok(ret) => ret,
Err(msg) => panic!("{}", msg),
}
Expand Down Expand Up @@ -257,7 +257,7 @@ cfg_test_util! {

let elapsed = match inner.unfrozen.as_ref() {
Some(v) => v.elapsed(),
None => return Err("time is already frozen")
None => return Err("time is already frozen"),
};
inner.base += elapsed;
inner.unfrozen = None;
Expand Down
8 changes: 3 additions & 5 deletions tokio/tests/io_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl AsyncRead for R {
_cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buf.put_slice(&[b'z']);
buf.put_slice(b"z");
Poll::Ready(Ok(()))
}
}
Expand Down Expand Up @@ -68,12 +68,10 @@ fn method_delegation() {
assert_eq!(1, rw.read(&mut buf).await.unwrap());
assert_eq!(b'z', buf[0]);

assert_eq!(1, rw.write(&[b'x']).await.unwrap());
assert_eq!(1, rw.write(b"x").await.unwrap());
assert_eq!(
2,
rw.write_vectored(&[io::IoSlice::new(&[b'x'])])
.await
.unwrap()
rw.write_vectored(&[io::IoSlice::new(b"x")]).await.unwrap()
);
assert!(rw.is_write_vectored());

Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/io_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl AsyncRead for RW {
_cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buf.put_slice(&[b'z']);
buf.put_slice(b"z");
Poll::Ready(Ok(()))
}
}
Expand Down
8 changes: 3 additions & 5 deletions tokio/tests/io_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl AsyncRead for RW {
_cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buf.put_slice(&[b'z']);
buf.put_slice(b"z");
Poll::Ready(Ok(()))
}
}
Expand Down Expand Up @@ -101,12 +101,10 @@ fn method_delegation() {
assert_eq!(1, r.read(&mut buf).await.unwrap());
assert_eq!(b'z', buf[0]);

assert_eq!(1, w.write(&[b'x']).await.unwrap());
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/time_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}

/// Helper struct to test the [tokio::time::Interval::poll_tick()] method.
/// Helper struct to test the [`tokio::time::Interval::poll_tick()`] method.
///
/// `poll_tick()` should register the waker in the context only if it returns
/// `Poll::Pending`, not when returning `Poll::Ready`. This struct contains an
Expand Down
8 changes: 4 additions & 4 deletions tokio/tests/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,25 +372,25 @@ async fn try_send_spawn() {
.unwrap();
assert_eq!(sent, &MSG_LEN);
let mut buf = [0u8; 32];
let mut received = receiver.recv(&mut buf[..]).await.unwrap();
let mut bytes_received = receiver.recv(&mut buf[..]).await.unwrap();

sender
.connect(receiver.local_addr().unwrap())
.await
.unwrap();
let sent = &sender.try_send(MSG2).unwrap();
assert_eq!(sent, &MSG2_LEN);
received += receiver.recv(&mut buf[..]).await.unwrap();
bytes_received += receiver.recv(&mut buf[..]).await.unwrap();

std::thread::spawn(move || {
let sent = &sender.try_send(MSG).unwrap();
assert_eq!(sent, &MSG_LEN);
})
.join()
.unwrap();
received += receiver.recv(&mut buf[..]).await.unwrap();
bytes_received += receiver.recv(&mut buf[..]).await.unwrap();

assert_eq!(received, MSG_LEN * 2 + MSG2_LEN);
assert_eq!(bytes_received, MSG_LEN * 2 + MSG2_LEN);
}

#[tokio::test]
Expand Down

0 comments on commit d0ce8ae

Please sign in to comment.