Skip to content

Commit

Permalink
chore: format code and enable rustfmt CI task (tokio-rs#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche authored Jun 27, 2019
1 parent 1f47ed3 commit ed4d4a5
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 60 deletions.
9 changes: 5 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ variables:
nightly: nightly-2019-06-10

jobs:
# # Check formatting
# - template: ci/azure-rustfmt.yml
# parameters:
# name: rustfmt
# Check formatting
- template: ci/azure-rustfmt.yml
parameters:
rust: $(nightly)
name: rustfmt

# Test top level crate
- template: ci/azure-test-stable.yml
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-rustfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- template: azure-install-rust.yml
parameters:
rust_version: stable
rust_version: ${{ parameters.rust }}
- script: |
rustup component add rustfmt
cargo fmt --version
Expand Down
11 changes: 6 additions & 5 deletions tokio-io/src/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ pub trait AsyncWrite {
///
/// This function will panic if not called within the context of a future's
/// task.
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>)
-> Poll<Result<(), io::Error>>;
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>>;

/// Write a `Buf` into this value, returning how many bytes were written.
///
Expand Down Expand Up @@ -175,9 +174,11 @@ where
P: DerefMut + Unpin,
P::Target: AsyncWrite,
{
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8])
-> Poll<io::Result<usize>>
{
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.get_mut().as_mut().poll_write(cx, buf)
}

Expand Down
22 changes: 11 additions & 11 deletions tokio-io/tests/async_read.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tokio_io::AsyncRead;
use tokio_test::{assert_ready_ok, assert_ready_err};
use tokio_test::task::MockTask;
use tokio_test::{assert_ready_err, assert_ready_ok};

use bytes::{BufMut, BytesMut};
use pin_utils::pin_mut;
Expand All @@ -22,8 +22,8 @@ fn read_buf_success() {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &mut [u8]) -> Poll<io::Result<usize>>
{
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
buf[0..11].copy_from_slice(b"hello world");
Poll::Ready(Ok(11))
}
Expand Down Expand Up @@ -51,8 +51,8 @@ fn read_buf_error() {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_buf: &mut [u8]) -> Poll<io::Result<usize>>
{
_buf: &mut [u8],
) -> Poll<io::Result<usize>> {
let err = io::ErrorKind::Other.into();
Poll::Ready(Err(err))
}
Expand All @@ -78,8 +78,8 @@ fn read_buf_no_capacity() {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_buf: &mut [u8]) -> Poll<io::Result<usize>>
{
_buf: &mut [u8],
) -> Poll<io::Result<usize>> {
unimplemented!();
}
}
Expand Down Expand Up @@ -107,8 +107,8 @@ fn read_buf_no_uninitialized() {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &mut [u8]) -> Poll<io::Result<usize>>
{
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
for b in buf {
assert_eq!(0, *b);
}
Expand Down Expand Up @@ -141,8 +141,8 @@ fn read_buf_uninitialized_ok() {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &mut [u8]) -> Poll<io::Result<usize>>
{
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
assert_eq!(buf[0..11], b"hello world"[..]);
Poll::Ready(Ok(0))
}
Expand Down
10 changes: 4 additions & 6 deletions tokio-sync/src/mpsc/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ impl<T> async_sink::Sink<T> for Sender<T> {
}

fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
self.as_mut()
.try_send(msg)
.map_err(|err| {
assert!(err.is_full(), "call `poll_ready` before sending");
SendError(())
})
self.as_mut().try_send(msg).map_err(|err| {
assert!(err.is_full(), "call `poll_ready` before sending");
SendError(())
})
}

fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down
10 changes: 8 additions & 2 deletions tokio-tcp/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ impl TcpListener {
/// }
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
pub fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<(TcpStream, SocketAddr)>> {
pub fn poll_accept(
&mut self,
cx: &mut Context<'_>,
) -> Poll<io::Result<(TcpStream, SocketAddr)>> {
let (io, addr) = ready!(self.poll_accept_std(cx))?;

let io = mio::net::TcpStream::from_stream(io)?;
Expand Down Expand Up @@ -143,7 +146,10 @@ impl TcpListener {
/// }
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
pub fn poll_accept_std(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<(net::TcpStream, SocketAddr)>> {
pub fn poll_accept_std(
&mut self,
cx: &mut Context<'_>,
) -> Poll<io::Result<(net::TcpStream, SocketAddr)>> {
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;

match self.io.get_ref().accept_std() {
Expand Down
30 changes: 25 additions & 5 deletions tokio-tcp/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ impl TcpStream {
/// });
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
pub fn poll_read_ready(&self, cx: &mut Context<'_>, mask: mio::Ready) -> Poll<io::Result<mio::Ready>> {
pub fn poll_read_ready(
&self,
cx: &mut Context<'_>,
mask: mio::Ready,
) -> Poll<io::Result<mio::Ready>> {
self.io.poll_read_ready(cx, mask)
}

Expand Down Expand Up @@ -729,11 +733,19 @@ impl AsyncRead for TcpStream {
false
}

fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut self.io).poll_read(cx, buf)
}

fn poll_read_buf<B: BufMut>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<io::Result<usize>> {
fn poll_read_buf<B: BufMut>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<io::Result<usize>> {
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;

let r = unsafe {
Expand Down Expand Up @@ -795,7 +807,11 @@ impl AsyncRead for TcpStream {
}

impl AsyncWrite for TcpStream {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut self.io).poll_write(cx, buf)
}

Expand All @@ -809,7 +825,11 @@ impl AsyncWrite for TcpStream {
Poll::Ready(Ok(()))
}

fn poll_write_buf<B: Buf>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<io::Result<usize>> {
fn poll_write_buf<B: Buf>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<io::Result<usize>> {
ready!(self.io.poll_write_ready(cx))?;

let r = {
Expand Down
2 changes: 1 addition & 1 deletion tokio-test/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg(feature = "broken")]
#![deny(warnings, rust_2018_idioms)]

use tokio_macros::{assert_ready, assert_not_ready, assert_ready_eq};
use futures::{future, Async, Future, Poll};
use tokio_macros::{assert_not_ready, assert_ready, assert_ready_eq};

#[test]
fn assert_ready() {
Expand Down
2 changes: 1 addition & 1 deletion tokio-timer/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::timer::{HandlePriv, Registration};
use std::future::Future;
use std::pin::Pin;
use std::time::{Duration, Instant};
use std::task::{self, Poll};
use std::time::{Duration, Instant};

/// A future that completes at a specified instant in time.
///
Expand Down
4 changes: 2 additions & 2 deletions tokio-timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
//! [`Timer`]: timer/struct.Timer.html
macro_rules! ready {
($e:expr) => (
($e:expr) => {
match $e {
::std::task::Poll::Ready(v) => v,
::std::task::Poll::Pending => return ::std::task::Poll::Pending,
}
)
};
}

pub mod clock;
Expand Down
5 changes: 4 additions & 1 deletion tokio-timer/src/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ impl<T: Stream> Stream for Throttle<T> {
self.as_mut().get_unchecked_mut().has_delayed = true;
}

let value = ready!(self.as_mut().map_unchecked_mut(|me| &mut me.stream).poll_next(cx));
let value = ready!(self
.as_mut()
.map_unchecked_mut(|me| &mut me.stream)
.poll_next(cx));

if value.is_some() {
self.as_mut().get_unchecked_mut().delay.reset_timeout();
Expand Down
3 changes: 1 addition & 2 deletions tokio-timer/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ pub struct Timeout<T> {
delay: Delay,
}


/// Error returned by `Timeout`.
#[derive(Debug)]
pub struct Elapsed(());
Expand Down Expand Up @@ -170,7 +169,7 @@ where
unsafe {
match self.map_unchecked_mut(|me| &mut me.delay).poll(cx) {
Poll::Ready(()) => Poll::Ready(Err(Elapsed(()))),
Poll::Pending => Poll::Pending
Poll::Pending => Poll::Pending,
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tokio-timer/src/timer/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ impl Entry {
}

pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {

let mut curr = self.state.load(SeqCst);

if is_elapsed(curr) {
Expand Down
2 changes: 1 addition & 1 deletion tokio-timer/src/timer/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{Delay, Error, /*Interval,*/ Timeout};
use std::cell::RefCell;
use std::fmt;
use std::sync::{Arc, Weak};
use std::time::{/*Duration,*/ Instant};
use std::time::Instant;
use tokio_executor::Enter;

/// Handle to timer instance.
Expand Down
13 changes: 7 additions & 6 deletions tokio/src/io/async_read_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tokio_io::{AsyncRead, AsyncWrite};

/// An extension trait which adds utility methods to `AsyncRead` types.
pub trait AsyncReadExt: AsyncRead {

/// Copy all data from `self` into the provided `AsyncWrite`.
///
/// The returned future will copy all the bytes read from `reader` into the
Expand All @@ -24,9 +23,9 @@ pub trait AsyncReadExt: AsyncRead {
/// unimplemented!();
/// ```
fn copy<'a, W>(&'a mut self, dst: &'a mut W) -> Copy<'a, Self, W>
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized,
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized,
{
copy(self, dst)
}
Expand All @@ -42,7 +41,8 @@ pub trait AsyncReadExt: AsyncRead {
/// unimplemented!();
/// ```
fn read<'a>(&'a mut self, dst: &'a mut [u8]) -> Read<'a, Self>
where Self: Unpin,
where
Self: Unpin,
{
read(self, dst)
}
Expand All @@ -55,7 +55,8 @@ pub trait AsyncReadExt: AsyncRead {
/// unimplemented!();
/// ```
fn read_exact<'a>(&'a mut self, dst: &'a mut [u8]) -> ReadExact<'a, Self>
where Self: Unpin,
where
Self: Unpin,
{
read_exact(self, dst)
}
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/io/async_write_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub trait AsyncWriteExt: AsyncWrite {
/// unimplemented!();
/// ````
fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>
where Self: Unpin,
where
Self: Unpin,
{
write(self, src)
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ mod async_read_ext;
mod async_write_ext;
mod copy;
mod read;
mod write;
mod read_exact;
mod write;

pub use self::async_read_ext::AsyncReadExt;
pub use self::async_write_ext::AsyncWriteExt;
Expand Down
11 changes: 7 additions & 4 deletions tokio/src/io/read_exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ use tokio_io::AsyncRead;
/// Created by the [`read_exact`] function.
///
/// [`read_exact`]: fn.read_exact.html
pub(crate) fn read_exact<'a, A>(reader: &'a mut A, buf: &'a mut[u8]) -> ReadExact<'a, A>
pub(crate) fn read_exact<'a, A>(reader: &'a mut A, buf: &'a mut [u8]) -> ReadExact<'a, A>
where
A: AsyncRead + Unpin + ?Sized
A: AsyncRead + Unpin + ?Sized,
{
ReadExact { reader, buf, pos: 0 }
ReadExact {
reader,
buf,
pos: 0,
}
}

/// Creates a future which will read exactly enough bytes to fill `buf`,
Expand All @@ -29,7 +33,6 @@ pub struct ReadExact<'a, A: ?Sized> {
pos: usize,
}


fn eof() -> io::Error {
io::Error::new(io::ErrorKind::UnexpectedEof, "early eof")
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub mod udp {
//! [`Send`]: struct.Send.html
//! [`RecvFrom`]: struct.RecvFrom.html
//! [`SendTo`]: struct.SendTo.html
pub use tokio_udp::{UdpSocket, Recv, Send, RecvFrom, SendTo};
pub use tokio_udp::{Recv, RecvFrom, Send, SendTo, UdpSocket};
}
#[cfg(feature = "udp")]
pub use self::udp::UdpSocket;
Expand Down
Loading

0 comments on commit ed4d4a5

Please sign in to comment.