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

style(lib): cargo fmt cfg workaround #3384

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ jobs:
components: rustfmt

- name: cargo fmt --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: |
if ! rustfmt --check --edition 2018 $(git ls-files '*.rs'); then
printf "Please run \`rustfmt --edition 2018 \$(git ls-files '*.rs')\` to fix rustfmt errors.\nSee CONTRIBUTING.md for more details.\n" >&2
exit 1
fi
test:
name: Test ${{ matrix.rust }} on ${{ matrix.os }}
Expand Down
15 changes: 8 additions & 7 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ where
if req.version() == Version::HTTP_2 {
warn!("Connection is HTTP/1, but request requires HTTP/2");
return Err(ClientError::Normal(
crate::Error::new_user_unsupported_version().with_client_connect_info(pooled.conn_info.clone()),
crate::Error::new_user_unsupported_version()
.with_client_connect_info(pooled.conn_info.clone()),
));
}

Expand Down Expand Up @@ -606,7 +607,7 @@ impl ResponseFuture {
F: Future<Output = crate::Result<Response<Body>>> + Send + 'static,
{
Self {
inner: SyncWrapper::new(Box::pin(value))
inner: SyncWrapper::new(Box::pin(value)),
}
}

Expand Down Expand Up @@ -711,7 +712,10 @@ where
{
fn is_open(&self) -> bool {
if self.conn_info.poisoned.poisoned() {
trace!("marking {:?} as closed because it was poisoned", self.conn_info);
trace!(
"marking {:?} as closed because it was poisoned",
self.conn_info
);
return false;
}
match self.tx {
Expand Down Expand Up @@ -1114,10 +1118,7 @@ impl Builder {
/// line in the input to resume parsing the rest of the headers. An error
/// will be emitted nonetheless if it finds `\0` or a lone `\r` while
/// looking for the next line.
pub fn http1_ignore_invalid_headers_in_responses(
&mut self,
val: bool,
) -> &mut Builder {
pub fn http1_ignore_invalid_headers_in_responses(&mut self, val: bool) -> &mut Builder {
self.conn_builder
.http1_ignore_invalid_headers_in_responses(val);
self
Expand Down
5 changes: 1 addition & 4 deletions src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,7 @@ impl Builder {
/// Note that this setting does not affect HTTP/2.
///
/// Default is false.
pub fn http1_ignore_invalid_headers_in_responses(
&mut self,
enabled: bool,
) -> &mut Builder {
pub fn http1_ignore_invalid_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.ignore_invalid_headers_in_responses(enabled);
self
Expand Down
31 changes: 10 additions & 21 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use http::{Request, Response};
use httparse::ParserConfig;
use tokio::io::{AsyncRead, AsyncWrite};

use crate::body::{Body as IncomingBody, HttpBody as Body};
use super::super::dispatch;
use crate::common::{
task, Future, Pin, Poll,
};
use crate::body::{Body as IncomingBody, HttpBody as Body};
use crate::common::{task, Future, Pin, Poll};
use crate::proto;
use crate::upgrade::Upgraded;

Expand Down Expand Up @@ -44,7 +42,6 @@ pub struct Parts<T> {
_inner: (),
}


/// A future that processes all HTTP state for the IO object.
///
/// In most cases, this should just be spawned into an executor, so that it
Expand Down Expand Up @@ -88,7 +85,10 @@ where
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
/// to work with this function; or use the `without_shutdown` wrapper.
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
self.inner.as_mut().expect("algready upgraded").poll_without_shutdown(cx)
self.inner
.as_mut()
.expect("algready upgraded")
.poll_without_shutdown(cx)
}
}

Expand All @@ -112,9 +112,7 @@ pub struct Builder {
///
/// This is a shortcut for `Builder::new().handshake(io)`.
/// See [`client::conn`](crate::client::conn) for more.
pub async fn handshake<T, B>(
io: T,
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
pub async fn handshake<T, B>(io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: Body + 'static,
Expand Down Expand Up @@ -324,10 +322,7 @@ impl Builder {
/// Default is false.
///
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
pub fn allow_spaces_after_header_name_in_responses(
&mut self,
enabled: bool,
) -> &mut Builder {
pub fn allow_spaces_after_header_name_in_responses(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.allow_spaces_after_header_name_in_responses(enabled);
self
Expand Down Expand Up @@ -365,10 +360,7 @@ impl Builder {
/// Default is false.
///
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
pub fn allow_obsolete_multiline_headers_in_responses(
&mut self,
enabled: bool,
) -> &mut Builder {
pub fn allow_obsolete_multiline_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.allow_obsolete_multiline_headers_in_responses(enabled);
self
Expand All @@ -381,10 +373,7 @@ impl Builder {
/// and no error will be reported.
///
/// Default is false.
pub fn ignore_invalid_headers_in_responses(
&mut self,
enabled: bool,
) -> &mut Builder {
pub fn ignore_invalid_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.ignore_invalid_headers_in_responses(enabled);
self
Expand Down
26 changes: 9 additions & 17 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use http::{Request, Response};
use tokio::io::{AsyncRead, AsyncWrite};

use super::super::dispatch;
use crate::body::{HttpBody as Body, Body as IncomingBody};
use crate::body::{Body as IncomingBody, HttpBody as Body};
use crate::common::{
exec::{BoxSendFuture, Exec},
task, Future, Pin, Poll,
Expand All @@ -25,7 +25,9 @@ pub struct SendRequest<B> {

impl<B> Clone for SendRequest<B> {
fn clone(&self) -> SendRequest<B> {
SendRequest { dispatch: self.dispatch.clone() }
SendRequest {
dispatch: self.dispatch.clone(),
}
}
}

Expand Down Expand Up @@ -55,10 +57,7 @@ pub struct Builder {
///
/// This is a shortcut for `Builder::new().handshake(io)`.
/// See [`client::conn`](crate::client::conn) for more.
pub async fn handshake<E, T, B>(
exec: E,
io: T,
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
pub async fn handshake<E, T, B>(exec: E, io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
where
E: Executor<BoxSendFuture> + Send + Sync + 'static,
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
Expand Down Expand Up @@ -244,7 +243,7 @@ where
impl Builder {
/// Creates a new connection builder.
#[inline]
pub fn new<E>(exec: E) -> Builder
pub fn new<E>(exec: E) -> Builder
where
E: Executor<BoxSendFuture> + Send + Sync + 'static,
{
Expand Down Expand Up @@ -285,10 +284,7 @@ impl Builder {
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
pub fn initial_connection_window_size(
&mut self,
sz: impl Into<Option<u32>>,
) -> &mut Self {
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.adaptive_window = false;
self.h2_builder.initial_conn_window_size = sz;
Expand Down Expand Up @@ -331,10 +327,7 @@ impl Builder {
///
/// Default is currently disabled.
#[cfg(feature = "runtime")]
pub fn keep_alive_interval(
&mut self,
interval: impl Into<Option<Duration>>,
) -> &mut Self {
pub fn keep_alive_interval(&mut self, interval: impl Into<Option<Duration>>) -> &mut Self {
self.h2_builder.keep_alive_interval = interval.into();
self
}
Expand Down Expand Up @@ -412,8 +405,7 @@ impl Builder {
tracing::trace!("client handshake HTTP/1");

let (tx, rx) = dispatch::channel();
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec)
.await?;
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec).await?;
Ok((
SendRequest {
dispatch: tx.unbound(),
Expand Down
2 changes: 1 addition & 1 deletion src/client/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This module contains:
//!
//! - A [`GaiResolver`](GaiResolver) that is the default resolver for the

Check warning on line 5 in src/client/connect/dns.rs

View workflow job for this annotation

GitHub Actions / Build docs

redundant explicit link target
//! `HttpConnector`.
//! - The `Name` type used as an argument to custom resolvers.
//!
Expand Down Expand Up @@ -318,7 +318,7 @@
*/

mod sealed {
use super::{SocketAddr, Name};
use super::{Name, SocketAddr};
use crate::common::{task, Future, Poll};
use tower_service::Service;

Expand Down
9 changes: 7 additions & 2 deletions src/client/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ impl Connection for TcpStream {
fn connected(&self) -> Connected {
let connected = Connected::new();
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
connected.extra(HttpInfo { remote_addr, local_addr })
connected.extra(HttpInfo {
remote_addr,
local_addr,
})
} else {
connected
}
Expand Down Expand Up @@ -521,7 +524,9 @@ struct ConnectingTcpRemote {

impl ConnectingTcpRemote {
fn new(addrs: dns::SocketAddrs, connect_timeout: Option<Duration>) -> Self {
let connect_timeout = connect_timeout.map(|t| t.checked_div(addrs.len() as u32)).flatten();
let connect_timeout = connect_timeout
.map(|t| t.checked_div(addrs.len() as u32))
.flatten();

Self {
addrs,
Expand Down
9 changes: 7 additions & 2 deletions src/client/connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
//! [`Connection`]: Connection
use std::fmt;
use std::fmt::{Debug, Formatter};
use std::sync::atomic::{AtomicBool, Ordering};
use std::ops::Deref;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use ::http::Extensions;
Expand Down Expand Up @@ -129,7 +129,12 @@ pub(crate) struct PoisonPill {
impl Debug for PoisonPill {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// print the address of the pill—this makes debugging issues much easier
write!(f, "PoisonPill@{:p} {{ poisoned: {} }}", self.poisoned, self.poisoned.load(Ordering::Relaxed))
write!(
f,
"PoisonPill@{:p} {{ poisoned: {} }}",
self.poisoned,
self.poisoned.load(Ordering::Relaxed)
)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
return None;
}
} else {
return None
return None;
}
}
} else {
return None
return None;
}
}

return content_length
content_length
}

fn from_digits(bytes: &[u8]) -> Option<u64> {
Expand All @@ -80,7 +80,7 @@ fn from_digits(bytes: &[u8]) -> Option<u64> {
b'0'..=b'9' => {
result = result.checked_mul(RADIX)?;
result = result.checked_add((b - b'0') as u64)?;
},
}
_ => {
// not a DIGIT, get outta here!
return None;
Expand Down
5 changes: 4 additions & 1 deletion src/proto/h1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ impl Decoder {
// methods

pub(crate) fn is_eof(&self) -> bool {
matches!(self.kind, Length(0) | Chunked(ChunkedState::End, _) | Eof(true))
matches!(
self.kind,
Length(0) | Chunked(ChunkedState::End, _) | Eof(true)
)
}

pub(crate) fn decode<R: MemRead>(
Expand Down
25 changes: 13 additions & 12 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use tracing::{debug, trace};
use super::{Http1Transaction, Wants};
use crate::body::{Body, DecodedLength, HttpBody};
use crate::common::{task, Future, Pin, Poll, Unpin};
use crate::proto::{
BodyLength, Conn, Dispatched, MessageHead, RequestHead,
};
use crate::proto::{BodyLength, Conn, Dispatched, MessageHead, RequestHead};
use crate::upgrade::OnUpgrade;

pub(crate) struct Dispatcher<D, Bs: HttpBody, I, T> {
Expand Down Expand Up @@ -60,10 +58,10 @@ cfg_client! {
impl<D, Bs, I, T> Dispatcher<D, Bs, I, T>
where
D: Dispatch<
PollItem = MessageHead<T::Outgoing>,
PollBody = Bs,
RecvItem = MessageHead<T::Incoming>,
> + Unpin,
PollItem = MessageHead<T::Outgoing>,
PollBody = Bs,
RecvItem = MessageHead<T::Incoming>,
> + Unpin,
D::PollError: Into<Box<dyn StdError + Send + Sync>>,
I: AsyncRead + AsyncWrite + Unpin,
T: Http1Transaction + Unpin,
Expand Down Expand Up @@ -262,7 +260,10 @@ where
if wants.contains(Wants::UPGRADE) {
let upgrade = self.conn.on_upgrade();
debug_assert!(!upgrade.is_none(), "empty upgrade");
debug_assert!(head.extensions.get::<OnUpgrade>().is_none(), "OnUpgrade already set");
debug_assert!(
head.extensions.get::<OnUpgrade>().is_none(),
"OnUpgrade already set"
);
head.extensions.insert(upgrade);
}
self.dispatch.recv_msg(Ok((head, body)))?;
Expand Down Expand Up @@ -416,10 +417,10 @@ where
impl<D, Bs, I, T> Future for Dispatcher<D, Bs, I, T>
where
D: Dispatch<
PollItem = MessageHead<T::Outgoing>,
PollBody = Bs,
RecvItem = MessageHead<T::Incoming>,
> + Unpin,
PollItem = MessageHead<T::Outgoing>,
PollBody = Bs,
RecvItem = MessageHead<T::Incoming>,
> + Unpin,
D::PollError: Into<Box<dyn StdError + Send + Sync>>,
I: AsyncRead + AsyncWrite + Unpin,
T: Http1Transaction + Unpin,
Expand Down
6 changes: 2 additions & 4 deletions src/proto/h2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,12 @@ where
cx: &mut Context<'_>,
) -> Poll<Result<(), io::Error>> {
if self.send_stream.write(&[], true).is_ok() {
return Poll::Ready(Ok(()))
return Poll::Ready(Ok(()));
}

Poll::Ready(Err(h2_to_io_error(
match ready!(self.send_stream.poll_reset(cx)) {
Ok(Reason::NO_ERROR) => {
return Poll::Ready(Ok(()))
}
Ok(Reason::NO_ERROR) => return Poll::Ready(Ok(())),
Ok(Reason::CANCEL) | Ok(Reason::STREAM_CLOSED) => {
return Poll::Ready(Err(io::ErrorKind::BrokenPipe.into()))
}
Expand Down
Loading
Loading