From 06137bc861a35707f1b1ac29549dd73c907093af Mon Sep 17 00:00:00 2001 From: tottoto Date: Mon, 6 Nov 2023 21:01:57 +0900 Subject: [PATCH] style(lib): cargo fmt cfg workaround (#3384) --- .github/workflows/CI.yml | 9 +++++---- src/client/client.rs | 15 ++++++++------- src/client/conn.rs | 5 +---- src/client/conn/http1.rs | 31 ++++++++++--------------------- src/client/conn/http2.rs | 26 +++++++++----------------- src/client/connect/dns.rs | 2 +- src/client/connect/http.rs | 9 +++++++-- src/client/connect/mod.rs | 9 +++++++-- src/headers.rs | 8 ++++---- src/proto/h1/decode.rs | 5 ++++- src/proto/h1/dispatch.rs | 25 +++++++++++++------------ src/proto/h2/mod.rs | 6 ++---- src/proto/h2/ping.rs | 4 ++-- src/proto/h2/server.rs | 3 +-- src/server/tcp.rs | 8 ++++---- 15 files changed, 78 insertions(+), 87 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 392d366305..415e59ed57 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 }} diff --git a/src/client/client.rs b/src/client/client.rs index 8163f54a23..10a0ed4b77 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -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()), )); } @@ -606,7 +607,7 @@ impl ResponseFuture { F: Future>> + Send + 'static, { Self { - inner: SyncWrapper::new(Box::pin(value)) + inner: SyncWrapper::new(Box::pin(value)), } } @@ -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 { @@ -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 diff --git a/src/client/conn.rs b/src/client/conn.rs index 88e2c413a7..7410ec6d09 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -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 diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index d8936d8655..6ad215aa10 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -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; @@ -44,7 +42,6 @@ pub struct Parts { _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 @@ -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> { - self.inner.as_mut().expect("algready upgraded").poll_without_shutdown(cx) + self.inner + .as_mut() + .expect("algready upgraded") + .poll_without_shutdown(cx) } } @@ -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( - io: T, -) -> crate::Result<(SendRequest, Connection)> +pub async fn handshake(io: T) -> crate::Result<(SendRequest, Connection)> where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, B: Body + 'static, @@ -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 @@ -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 @@ -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 diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index fd0adf897b..5c93889b89 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -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, @@ -25,7 +25,9 @@ pub struct SendRequest { impl Clone for SendRequest { fn clone(&self) -> SendRequest { - SendRequest { dispatch: self.dispatch.clone() } + SendRequest { + dispatch: self.dispatch.clone(), + } } } @@ -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( - exec: E, - io: T, -) -> crate::Result<(SendRequest, Connection)> +pub async fn handshake(exec: E, io: T) -> crate::Result<(SendRequest, Connection)> where E: Executor + Send + Sync + 'static, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, @@ -244,7 +243,7 @@ where impl Builder { /// Creates a new connection builder. #[inline] - pub fn new(exec: E) -> Builder + pub fn new(exec: E) -> Builder where E: Executor + Send + Sync + 'static, { @@ -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>, - ) -> &mut Self { + pub fn initial_connection_window_size(&mut self, sz: impl Into>) -> &mut Self { if let Some(sz) = sz.into() { self.h2_builder.adaptive_window = false; self.h2_builder.initial_conn_window_size = sz; @@ -331,10 +327,7 @@ impl Builder { /// /// Default is currently disabled. #[cfg(feature = "runtime")] - pub fn keep_alive_interval( - &mut self, - interval: impl Into>, - ) -> &mut Self { + pub fn keep_alive_interval(&mut self, interval: impl Into>) -> &mut Self { self.h2_builder.keep_alive_interval = interval.into(); self } @@ -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(), diff --git a/src/client/connect/dns.rs b/src/client/connect/dns.rs index e4465078b3..b0d9c4741b 100644 --- a/src/client/connect/dns.rs +++ b/src/client/connect/dns.rs @@ -318,7 +318,7 @@ impl Future for TokioThreadpoolGaiFuture { */ mod sealed { - use super::{SocketAddr, Name}; + use super::{Name, SocketAddr}; use crate::common::{task, Future, Poll}; use tower_service::Service; diff --git a/src/client/connect/http.rs b/src/client/connect/http.rs index a3acca8082..ee09afe9a3 100644 --- a/src/client/connect/http.rs +++ b/src/client/connect/http.rs @@ -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 } @@ -521,7 +524,9 @@ struct ConnectingTcpRemote { impl ConnectingTcpRemote { fn new(addrs: dns::SocketAddrs, connect_timeout: Option) -> 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, diff --git a/src/client/connect/mod.rs b/src/client/connect/mod.rs index 6b4a04acf7..1f24de1f7e 100644 --- a/src/client/connect/mod.rs +++ b/src/client/connect/mod.rs @@ -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; @@ -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) + ) } } diff --git a/src/headers.rs b/src/headers.rs index 8407be185f..2e5e5db0f2 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -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 { @@ -80,7 +80,7 @@ fn from_digits(bytes: &[u8]) -> Option { 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; diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index 1e3a38effc..a04dca84c1 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -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( diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index fddf639d9e..f663210546 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -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 { @@ -60,10 +58,10 @@ cfg_client! { impl Dispatcher where D: Dispatch< - PollItem = MessageHead, - PollBody = Bs, - RecvItem = MessageHead, - > + Unpin, + PollItem = MessageHead, + PollBody = Bs, + RecvItem = MessageHead, + > + Unpin, D::PollError: Into>, I: AsyncRead + AsyncWrite + Unpin, T: Http1Transaction + Unpin, @@ -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::().is_none(), "OnUpgrade already set"); + debug_assert!( + head.extensions.get::().is_none(), + "OnUpgrade already set" + ); head.extensions.insert(upgrade); } self.dispatch.recv_msg(Ok((head, body)))?; @@ -416,10 +417,10 @@ where impl Future for Dispatcher where D: Dispatch< - PollItem = MessageHead, - PollBody = Bs, - RecvItem = MessageHead, - > + Unpin, + PollItem = MessageHead, + PollBody = Bs, + RecvItem = MessageHead, + > + Unpin, D::PollError: Into>, I: AsyncRead + AsyncWrite + Unpin, T: Http1Transaction + Unpin, diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index 5857c919d1..216aa2dac4 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -383,14 +383,12 @@ where cx: &mut Context<'_>, ) -> Poll> { 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())) } diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index 1e8386497c..d830c93eda 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -328,7 +328,7 @@ impl Ponger { } } - if let Some(ref mut bdp) = self.bdp { + if let Some(ref mut bdp) = self.bdp { let bytes = locked.bytes.expect("bdp enabled implies bytes"); locked.bytes = Some(0); // reset trace!("received BDP ack; bytes = {}, rtt = {:?}", bytes, rtt); @@ -336,7 +336,7 @@ impl Ponger { let update = bdp.calculate(bytes, rtt); locked.next_bdp_at = Some(now + bdp.ping_delay); if let Some(update) = update { - return Poll::Ready(Ponged::SizeUpdate(update)) + return Poll::Ready(Ponged::SizeUpdate(update)); } } } diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 4127387e71..f4c0a848be 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -35,8 +35,7 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb -// 16 MB "sane default" taken from golang http2 -const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20; +const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20; // 16 MB "sane default" taken from golang http2 #[derive(Clone, Debug)] pub(crate) struct Config { diff --git a/src/server/tcp.rs b/src/server/tcp.rs index 3f937154be..31fcdfa343 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -1,8 +1,8 @@ +use socket2::TcpKeepalive; use std::fmt; use std::io; use std::net::{SocketAddr, TcpListener as StdTcpListener}; use std::time::Duration; -use socket2::TcpKeepalive; use tokio::net::TcpListener; use tokio::time::Sleep; @@ -71,7 +71,7 @@ impl TcpKeepaliveConfig { windows, )))] fn ka_with_interval(ka: TcpKeepalive, _: Duration, _: &mut bool) -> TcpKeepalive { - ka // no-op as keepalive interval is not supported on this platform + ka // no-op as keepalive interval is not supported on this platform } #[cfg(any( @@ -100,7 +100,7 @@ impl TcpKeepaliveConfig { target_vendor = "apple", )))] fn ka_with_retries(ka: TcpKeepalive, _: u32, _: &mut bool) -> TcpKeepalive { - ka // no-op as keepalive retries is not supported on this platform + ka // no-op as keepalive retries is not supported on this platform } } @@ -420,8 +420,8 @@ mod addr_stream { #[cfg(test)] mod tests { - use std::time::Duration; use crate::server::tcp::TcpKeepaliveConfig; + use std::time::Duration; #[test] fn no_tcp_keepalive_config() {