Skip to content

Commit

Permalink
chore: clippy and doc fixes (#6081)
Browse files Browse the repository at this point in the history
  • Loading branch information
barafael authored Oct 16, 2023
1 parent 1b8ebfc commit 6871084
Show file tree
Hide file tree
Showing 87 changed files with 220 additions and 235 deletions.
2 changes: 1 addition & 1 deletion tokio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,6 @@ impl ToTokens for Body<'_> {
for stmt in self.stmts {
stmt.to_tokens(tokens);
}
})
});
}
}
10 changes: 5 additions & 5 deletions tokio-macros/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ fn clean_pattern(pat: &mut syn::Pat) {
}
}
syn::Pat::Or(or) => {
for case in or.cases.iter_mut() {
for case in &mut or.cases {
clean_pattern(case);
}
}
syn::Pat::Slice(slice) => {
for elem in slice.elems.iter_mut() {
for elem in &mut slice.elems {
clean_pattern(elem);
}
}
syn::Pat::Struct(struct_pat) => {
for field in struct_pat.fields.iter_mut() {
for field in &mut struct_pat.fields {
clean_pattern(&mut field.pat);
}
}
syn::Pat::Tuple(tuple) => {
for elem in tuple.elems.iter_mut() {
for elem in &mut tuple.elems {
clean_pattern(elem);
}
}
syn::Pat::TupleStruct(tuple) => {
for elem in tuple.elems.iter_mut() {
for elem in &mut tuple.elems {
clean_pattern(elem);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-stream/src/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<I> Unpin for Once<I> {}
/// ```
pub fn once<T>(value: T) -> Once<T> {
Once {
iter: crate::iter(Some(value).into_iter()),
iter: crate::iter(Some(value)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokio-stream/src/wrappers/mpsc_bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T> ReceiverStream<T> {
///
/// [`Permit`]: struct@tokio::sync::mpsc::Permit
pub fn close(&mut self) {
self.inner.close()
self.inner.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokio-stream/src/wrappers/mpsc_unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T> UnboundedReceiverStream<T> {
/// This prevents any further messages from being sent on the channel while
/// still enabling the receiver to drain messages that are buffered.
pub fn close(&mut self) {
self.inner.close()
self.inner.close();
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio-test/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct Inner {
}

impl Builder {
/// Return a new, empty `Builder.
/// Return a new, empty `Builder`.
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -478,7 +478,7 @@ impl Drop for Mock {
Action::Read(data) => assert!(data.is_empty(), "There is still data left to read."),
Action::Write(data) => assert!(data.is_empty(), "There is still data left to write."),
_ => (),
})
});
}
}
/*
Expand Down
2 changes: 1 addition & 1 deletion tokio-test/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<T: Future> Spawn<T> {
}

impl<T: Stream> Spawn<T> {
/// If `T` is a [`Stream`] then poll_next it. This will handle pinning and the context
/// If `T` is a [`Stream`] then `poll_next` it. This will handle pinning and the context
/// type for the stream.
pub fn poll_next(&mut self) -> Poll<Option<T::Item>> {
let stream = self.future.as_mut();
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
}

fn consume(self: Pin<&mut Self>, amt: usize) {
delegate_call!(self.consume(amt))
delegate_call!(self.consume(amt));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/sync/cancellation_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Default for CancellationToken {
}

impl CancellationToken {
/// Creates a new CancellationToken in the non-cancelled state.
/// Creates a new `CancellationToken` in the non-cancelled state.
pub fn new() -> CancellationToken {
CancellationToken {
inner: Arc::new(tree_node::TreeNode::new()),
Expand Down
8 changes: 4 additions & 4 deletions tokio-util/src/sync/cancellation_token/tree_node.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! This mod provides the logic for the inner tree structure of the CancellationToken.
//!
//! CancellationTokens are only light handles with references to TreeNode.
//! All the logic is actually implemented in the TreeNode.
//! CancellationTokens are only light handles with references to [`TreeNode`].
//! All the logic is actually implemented in the [`TreeNode`].
//!
//! A TreeNode is part of the cancellation tree and may have one parent and an arbitrary number of
//! A [`TreeNode`] is part of the cancellation tree and may have one parent and an arbitrary number of
//! children.
//!
//! A TreeNode can receive the request to perform a cancellation through a CancellationToken.
//! A [`TreeNode`] can receive the request to perform a cancellation through a CancellationToken.
//! This cancellation request will cancel the node and all of its descendants.
//!
//! As soon as a node cannot get cancelled any more (because it was already cancelled or it has no
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/sync/poll_semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl PollSemaphore {

/// Closes the semaphore.
pub fn close(&self) {
self.semaphore.close()
self.semaphore.close();
}

/// Obtain a clone of the inner semaphore.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/dir_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl DirBuilder {
/// let builder = DirBuilder::new();
/// ```
pub fn new() -> Self {
Default::default()
DirBuilder::default()
}

/// Indicates whether to create directories recursively (including all parent directories).
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl File {
///
/// This function will return an error if called from outside of the Tokio
/// runtime or if path does not already exist. Other errors may also be
/// returned according to OpenOptions::open.
/// returned according to `OpenOptions::open`.
///
/// # Examples
///
Expand Down Expand Up @@ -367,7 +367,7 @@ impl File {
} else {
std.set_len(size)
}
.map(|_| 0); // the value is discarded later
.map(|()| 0); // the value is discarded later

// Return the result as a seek
(Operation::Seek(res), buf)
Expand Down Expand Up @@ -562,7 +562,7 @@ impl AsyncRead for File {
inner.state = State::Idle(Some(buf));
return Poll::Ready(Err(e));
}
Operation::Write(Ok(_)) => {
Operation::Write(Ok(())) => {
assert!(buf.is_empty());
inner.state = State::Idle(Some(buf));
continue;
Expand Down Expand Up @@ -877,7 +877,7 @@ impl Inner {
async fn complete_inflight(&mut self) {
use crate::future::poll_fn;

poll_fn(|cx| self.poll_complete_inflight(cx)).await
poll_fn(|cx| self.poll_complete_inflight(cx)).await;
}

fn poll_complete_inflight(&mut self, cx: &mut Context<'_>) -> Poll<()> {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/future/maybe_done.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Definition of the MaybeDone combinator.
//! Definition of the [`MaybeDone`] combinator.
use std::future::Future;
use std::mem;
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/async_buf_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
}

fn consume(self: Pin<&mut Self>, amt: usize) {
self.get_mut().as_mut().consume(amt)
self.get_mut().as_mut().consume(amt);
}
}

Expand All @@ -112,6 +112,6 @@ impl<T: AsRef<[u8]> + Unpin> AsyncBufRead for io::Cursor<T> {
}

fn consume(self: Pin<&mut Self>, amt: usize) {
io::BufRead::consume(self.get_mut(), amt)
io::BufRead::consume(self.get_mut(), amt);
}
}
12 changes: 6 additions & 6 deletions tokio/src/io/async_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use std::{task::Context, task::Poll};
/// `kqueue`, etc), such as a network socket or pipe, and the file descriptor
/// must have the nonblocking mode set to true.
///
/// Creating an AsyncFd registers the file descriptor with the current tokio
/// Creating an [`AsyncFd`] registers the file descriptor with the current tokio
/// Reactor, allowing you to directly await the file descriptor being readable
/// or writable. Once registered, the file descriptor remains registered until
/// the AsyncFd is dropped.
/// the [`AsyncFd`] is dropped.
///
/// The AsyncFd takes ownership of an arbitrary object to represent the IO
/// The [`AsyncFd`] takes ownership of an arbitrary object to represent the IO
/// object. It is intended that this object will handle closing the file
/// descriptor when it is dropped, avoiding resource leaks and ensuring that the
/// AsyncFd can clean up the registration before closing the file descriptor.
/// [`AsyncFd`] can clean up the registration before closing the file descriptor.
/// The [`AsyncFd::into_inner`] function can be used to extract the inner object
/// to retake control from the tokio IO reactor.
///
Expand Down Expand Up @@ -204,7 +204,7 @@ pub struct AsyncFdReadyMutGuard<'a, T: AsRawFd> {
}

impl<T: AsRawFd> AsyncFd<T> {
/// Creates an AsyncFd backed by (and taking ownership of) an object
/// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
/// implementing [`AsRawFd`]. The backing file descriptor is cached at the
/// time of creation.
///
Expand All @@ -226,7 +226,7 @@ impl<T: AsRawFd> AsyncFd<T> {
Self::with_interest(inner, Interest::READABLE | Interest::WRITABLE)
}

/// Creates an AsyncFd backed by (and taking ownership of) an object
/// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
/// implementing [`AsRawFd`], with a specific [`Interest`]. The backing
/// file descriptor is cached at the time of creation.
///
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where

self.state = State::Busy(sys::run(move || {
let n = buf.len();
let res = buf.write_to(&mut inner).map(|_| n);
let res = buf.write_to(&mut inner).map(|()| n);

(res, buf, inner)
}));
Expand Down Expand Up @@ -147,7 +147,7 @@ where
let mut inner = self.inner.take().unwrap();

self.state = State::Busy(sys::run(move || {
let res = inner.flush().map(|_| 0);
let res = inner.flush().map(|()| 0);
(res, buf, inner)
}));

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl ops::BitOr for Interest {
impl ops::BitOrAssign for Interest {
#[inline]
fn bitor_assign(&mut self, other: Self) {
*self = *self | other
*self = *self | other;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/stdio_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::io::AsyncWrite;
use std::pin::Pin;
use std::task::{Context, Poll};
/// # Windows
/// AsyncWrite adapter that finds last char boundary in given buffer and does not write the rest,
/// if buffer contents seems to be utf8. Otherwise it only trims buffer down to MAX_BUF.
/// [`AsyncWrite`] adapter that finds last char boundary in given buffer and does not write the rest,
/// if buffer contents seems to be utf8. Otherwise it only trims buffer down to `MAX_BUF`.
/// That's why, wrapped writer will always receive well-formed utf-8 bytes.
/// # Other platforms
/// Passes data to `inner` as is.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/async_buf_read_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ cfg_io_util! {
where
Self: Unpin,
{
std::pin::Pin::new(self).consume(amt)
std::pin::Pin::new(self).consume(amt);
}

/// Returns a stream over the lines of this reader.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/buf_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<RW: AsyncRead + AsyncWrite> AsyncBufRead for BufStream<RW> {
}

fn consume(self: Pin<&mut Self>, amt: usize) {
self.project().inner.consume(amt)
self.project().inner.consume(amt);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/buf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<W: AsyncWrite + AsyncBufRead> AsyncBufRead for BufWriter<W> {
}

fn consume(self: Pin<&mut Self>, amt: usize) {
self.get_pin_mut().consume(amt)
self.get_pin_mut().consume(amt);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/util/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CopyBuffer {
buf.set_filled(me.cap);

let res = reader.poll_read(cx, &mut buf);
if let Poll::Ready(Ok(_)) = res {
if let Poll::Ready(Ok(())) = res {
let filled_len = buf.filled().len();
me.read_done = me.cap == filled_len;
me.cap = filled_len;
Expand Down Expand Up @@ -90,7 +90,7 @@ impl CopyBuffer {
self.cap = 0;

match self.poll_fill_buf(cx, reader.as_mut()) {
Poll::Ready(Ok(_)) => (),
Poll::Ready(Ok(())) => (),
Poll::Ready(Err(err)) => return Poll::Ready(Err(err)),
Poll::Pending => {
// Try flushing when the reader has no progress to avoid deadlock
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/read_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(super) fn read_to_end_internal<V: VecU8, R: AsyncRead + ?Sized>(
}
}

/// Tries to read from the provided AsyncRead.
/// Tries to read from the provided [`AsyncRead`].
///
/// The length of the buffer is increased by the number of bytes read.
fn poll_read_to_end<V: VecU8, R: AsyncRead + ?Sized>(
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<R: AsyncRead> Take<R> {
/// the amount of bytes read and the previous limit value don't matter when
/// calling this method.
pub fn set_limit(&mut self, limit: u64) {
self.limit_ = limit
self.limit_ = limit;
}

/// Gets a reference to the underlying reader.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl TcpListener {
use std::os::unix::io::{FromRawFd, IntoRawFd};
self.io
.into_inner()
.map(|io| io.into_raw_fd())
.map(IntoRawFd::into_raw_fd)
.map(|raw_fd| unsafe { std::net::TcpListener::from_raw_fd(raw_fd) })
}

Expand Down
6 changes: 3 additions & 3 deletions tokio/src/net/tcp/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ impl TcpSocket {
self.inner.recv_buffer_size().map(|n| n as u32)
}

/// Sets the linger duration of this socket by setting the SO_LINGER option.
/// Sets the linger duration of this socket by setting the `SO_LINGER` option.
///
/// This option controls the action taken when a stream has unsent messages and the stream is
/// closed. If SO_LINGER is set, the system shall block the process until it can transmit the
/// closed. If `SO_LINGER` is set, the system shall block the process until it can transmit the
/// data or until the time expires.
///
/// If SO_LINGER is not specified, and the socket is closed, the system handles the call in a
/// If `SO_LINGER` is not specified, and the socket is closed, the system handles the call in a
/// way that allows the process to continue as quickly as possible.
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
self.inner.set_linger(dur)
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl TcpStream {
use std::os::unix::io::{FromRawFd, IntoRawFd};
self.io
.into_inner()
.map(|io| io.into_raw_fd())
.map(IntoRawFd::into_raw_fd)
.map(|raw_fd| unsafe { std::net::TcpStream::from_raw_fd(raw_fd) })
}

Expand Down
Loading

0 comments on commit 6871084

Please sign in to comment.