Skip to content

Commit 06137bc

Browse files
authored
style(lib): cargo fmt cfg workaround (#3384)
1 parent d305503 commit 06137bc

File tree

15 files changed

+78
-87
lines changed

15 files changed

+78
-87
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ jobs:
4141
components: rustfmt
4242

4343
- name: cargo fmt --check
44-
uses: actions-rs/cargo@v1
45-
with:
46-
command: fmt
47-
args: --all -- --check
44+
run: |
45+
if ! rustfmt --check --edition 2018 $(git ls-files '*.rs'); then
46+
printf "Please run \`rustfmt --edition 2018 \$(git ls-files '*.rs')\` to fix rustfmt errors.\nSee CONTRIBUTING.md for more details.\n" >&2
47+
exit 1
48+
fi
4849
4950
test:
5051
name: Test ${{ matrix.rust }} on ${{ matrix.os }}

src/client/client.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ where
253253
if req.version() == Version::HTTP_2 {
254254
warn!("Connection is HTTP/1, but request requires HTTP/2");
255255
return Err(ClientError::Normal(
256-
crate::Error::new_user_unsupported_version().with_client_connect_info(pooled.conn_info.clone()),
256+
crate::Error::new_user_unsupported_version()
257+
.with_client_connect_info(pooled.conn_info.clone()),
257258
));
258259
}
259260

@@ -606,7 +607,7 @@ impl ResponseFuture {
606607
F: Future<Output = crate::Result<Response<Body>>> + Send + 'static,
607608
{
608609
Self {
609-
inner: SyncWrapper::new(Box::pin(value))
610+
inner: SyncWrapper::new(Box::pin(value)),
610611
}
611612
}
612613

@@ -711,7 +712,10 @@ where
711712
{
712713
fn is_open(&self) -> bool {
713714
if self.conn_info.poisoned.poisoned() {
714-
trace!("marking {:?} as closed because it was poisoned", self.conn_info);
715+
trace!(
716+
"marking {:?} as closed because it was poisoned",
717+
self.conn_info
718+
);
715719
return false;
716720
}
717721
match self.tx {
@@ -1114,10 +1118,7 @@ impl Builder {
11141118
/// line in the input to resume parsing the rest of the headers. An error
11151119
/// will be emitted nonetheless if it finds `\0` or a lone `\r` while
11161120
/// looking for the next line.
1117-
pub fn http1_ignore_invalid_headers_in_responses(
1118-
&mut self,
1119-
val: bool,
1120-
) -> &mut Builder {
1121+
pub fn http1_ignore_invalid_headers_in_responses(&mut self, val: bool) -> &mut Builder {
11211122
self.conn_builder
11221123
.http1_ignore_invalid_headers_in_responses(val);
11231124
self

src/client/conn.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,7 @@ impl Builder {
710710
/// Note that this setting does not affect HTTP/2.
711711
///
712712
/// Default is false.
713-
pub fn http1_ignore_invalid_headers_in_responses(
714-
&mut self,
715-
enabled: bool,
716-
) -> &mut Builder {
713+
pub fn http1_ignore_invalid_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
717714
self.h1_parser_config
718715
.ignore_invalid_headers_in_responses(enabled);
719716
self

src/client/conn/http1.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ use http::{Request, Response};
88
use httparse::ParserConfig;
99
use tokio::io::{AsyncRead, AsyncWrite};
1010

11-
use crate::body::{Body as IncomingBody, HttpBody as Body};
1211
use super::super::dispatch;
13-
use crate::common::{
14-
task, Future, Pin, Poll,
15-
};
12+
use crate::body::{Body as IncomingBody, HttpBody as Body};
13+
use crate::common::{task, Future, Pin, Poll};
1614
use crate::proto;
1715
use crate::upgrade::Upgraded;
1816

@@ -44,7 +42,6 @@ pub struct Parts<T> {
4442
_inner: (),
4543
}
4644

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

@@ -112,9 +112,7 @@ pub struct Builder {
112112
///
113113
/// This is a shortcut for `Builder::new().handshake(io)`.
114114
/// See [`client::conn`](crate::client::conn) for more.
115-
pub async fn handshake<T, B>(
116-
io: T,
117-
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
115+
pub async fn handshake<T, B>(io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
118116
where
119117
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
120118
B: Body + 'static,
@@ -324,10 +322,7 @@ impl Builder {
324322
/// Default is false.
325323
///
326324
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
327-
pub fn allow_spaces_after_header_name_in_responses(
328-
&mut self,
329-
enabled: bool,
330-
) -> &mut Builder {
325+
pub fn allow_spaces_after_header_name_in_responses(&mut self, enabled: bool) -> &mut Builder {
331326
self.h1_parser_config
332327
.allow_spaces_after_header_name_in_responses(enabled);
333328
self
@@ -365,10 +360,7 @@ impl Builder {
365360
/// Default is false.
366361
///
367362
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
368-
pub fn allow_obsolete_multiline_headers_in_responses(
369-
&mut self,
370-
enabled: bool,
371-
) -> &mut Builder {
363+
pub fn allow_obsolete_multiline_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
372364
self.h1_parser_config
373365
.allow_obsolete_multiline_headers_in_responses(enabled);
374366
self
@@ -381,10 +373,7 @@ impl Builder {
381373
/// and no error will be reported.
382374
///
383375
/// Default is false.
384-
pub fn ignore_invalid_headers_in_responses(
385-
&mut self,
386-
enabled: bool,
387-
) -> &mut Builder {
376+
pub fn ignore_invalid_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
388377
self.h1_parser_config
389378
.ignore_invalid_headers_in_responses(enabled);
390379
self

src/client/conn/http2.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use http::{Request, Response};
1010
use tokio::io::{AsyncRead, AsyncWrite};
1111

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

2626
impl<B> Clone for SendRequest<B> {
2727
fn clone(&self) -> SendRequest<B> {
28-
SendRequest { dispatch: self.dispatch.clone() }
28+
SendRequest {
29+
dispatch: self.dispatch.clone(),
30+
}
2931
}
3032
}
3133

@@ -55,10 +57,7 @@ pub struct Builder {
5557
///
5658
/// This is a shortcut for `Builder::new().handshake(io)`.
5759
/// See [`client::conn`](crate::client::conn) for more.
58-
pub async fn handshake<E, T, B>(
59-
exec: E,
60-
io: T,
61-
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
60+
pub async fn handshake<E, T, B>(exec: E, io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
6261
where
6362
E: Executor<BoxSendFuture> + Send + Sync + 'static,
6463
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
@@ -244,7 +243,7 @@ where
244243
impl Builder {
245244
/// Creates a new connection builder.
246245
#[inline]
247-
pub fn new<E>(exec: E) -> Builder
246+
pub fn new<E>(exec: E) -> Builder
248247
where
249248
E: Executor<BoxSendFuture> + Send + Sync + 'static,
250249
{
@@ -285,10 +284,7 @@ impl Builder {
285284
/// Passing `None` will do nothing.
286285
///
287286
/// If not set, hyper will use a default.
288-
pub fn initial_connection_window_size(
289-
&mut self,
290-
sz: impl Into<Option<u32>>,
291-
) -> &mut Self {
287+
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
292288
if let Some(sz) = sz.into() {
293289
self.h2_builder.adaptive_window = false;
294290
self.h2_builder.initial_conn_window_size = sz;
@@ -331,10 +327,7 @@ impl Builder {
331327
///
332328
/// Default is currently disabled.
333329
#[cfg(feature = "runtime")]
334-
pub fn keep_alive_interval(
335-
&mut self,
336-
interval: impl Into<Option<Duration>>,
337-
) -> &mut Self {
330+
pub fn keep_alive_interval(&mut self, interval: impl Into<Option<Duration>>) -> &mut Self {
338331
self.h2_builder.keep_alive_interval = interval.into();
339332
self
340333
}
@@ -412,8 +405,7 @@ impl Builder {
412405
tracing::trace!("client handshake HTTP/1");
413406

414407
let (tx, rx) = dispatch::channel();
415-
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec)
416-
.await?;
408+
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec).await?;
417409
Ok((
418410
SendRequest {
419411
dispatch: tx.unbound(),

src/client/connect/dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl Future for TokioThreadpoolGaiFuture {
318318
*/
319319

320320
mod sealed {
321-
use super::{SocketAddr, Name};
321+
use super::{Name, SocketAddr};
322322
use crate::common::{task, Future, Poll};
323323
use tower_service::Service;
324324

src/client/connect/http.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,10 @@ impl Connection for TcpStream {
362362
fn connected(&self) -> Connected {
363363
let connected = Connected::new();
364364
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
365-
connected.extra(HttpInfo { remote_addr, local_addr })
365+
connected.extra(HttpInfo {
366+
remote_addr,
367+
local_addr,
368+
})
366369
} else {
367370
connected
368371
}
@@ -521,7 +524,9 @@ struct ConnectingTcpRemote {
521524

522525
impl ConnectingTcpRemote {
523526
fn new(addrs: dns::SocketAddrs, connect_timeout: Option<Duration>) -> Self {
524-
let connect_timeout = connect_timeout.map(|t| t.checked_div(addrs.len() as u32)).flatten();
527+
let connect_timeout = connect_timeout
528+
.map(|t| t.checked_div(addrs.len() as u32))
529+
.flatten();
525530

526531
Self {
527532
addrs,

src/client/connect/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
//! [`Connection`]: Connection
8282
use std::fmt;
8383
use std::fmt::{Debug, Formatter};
84-
use std::sync::atomic::{AtomicBool, Ordering};
8584
use std::ops::Deref;
85+
use std::sync::atomic::{AtomicBool, Ordering};
8686
use std::sync::Arc;
8787

8888
use ::http::Extensions;
@@ -129,7 +129,12 @@ pub(crate) struct PoisonPill {
129129
impl Debug for PoisonPill {
130130
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
131131
// print the address of the pill—this makes debugging issues much easier
132-
write!(f, "PoisonPill@{:p} {{ poisoned: {} }}", self.poisoned, self.poisoned.load(Ordering::Relaxed))
132+
write!(
133+
f,
134+
"PoisonPill@{:p} {{ poisoned: {} }}",
135+
self.poisoned,
136+
self.poisoned.load(Ordering::Relaxed)
137+
)
133138
}
134139
}
135140

src/headers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
5353
return None;
5454
}
5555
} else {
56-
return None
56+
return None;
5757
}
5858
}
5959
} else {
60-
return None
60+
return None;
6161
}
6262
}
6363

64-
return content_length
64+
content_length
6565
}
6666

6767
fn from_digits(bytes: &[u8]) -> Option<u64> {
@@ -80,7 +80,7 @@ fn from_digits(bytes: &[u8]) -> Option<u64> {
8080
b'0'..=b'9' => {
8181
result = result.checked_mul(RADIX)?;
8282
result = result.checked_add((b - b'0') as u64)?;
83-
},
83+
}
8484
_ => {
8585
// not a DIGIT, get outta here!
8686
return None;

src/proto/h1/decode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ impl Decoder {
9595
// methods
9696

9797
pub(crate) fn is_eof(&self) -> bool {
98-
matches!(self.kind, Length(0) | Chunked(ChunkedState::End, _) | Eof(true))
98+
matches!(
99+
self.kind,
100+
Length(0) | Chunked(ChunkedState::End, _) | Eof(true)
101+
)
99102
}
100103

101104
pub(crate) fn decode<R: MemRead>(

0 commit comments

Comments
 (0)