Skip to content

Commit 702e53c

Browse files
committed
Apply clippy fixes, except in #[test] code
1 parent 0888623 commit 702e53c

31 files changed

+102
-95
lines changed

.github/workflows/CI.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
uses: actions-rs/toolchain@v1
8383
with:
8484
profile: minimal
85+
components: clippy
8586
toolchain: ${{ matrix.rust }}
8687
override: true
8788

@@ -91,6 +92,12 @@ jobs:
9192
command: test
9293
args: ${{ matrix.features }}
9394

95+
- name: Clippy
96+
uses: actions-rs/cargo@v1
97+
with:
98+
command: clippy
99+
args: ${{ matrix.features }} --lib --examples --benches
100+
94101
- name: Test all benches
95102
if: matrix.benches
96103
uses: actions-rs/cargo@v1

benches/body.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "nightly")]
12
#![feature(test)]
23
#![deny(warnings)]
34

benches/connect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#![cfg(feature = "nightly")]
12
#![feature(test)]
23
#![deny(warnings)]
34

4-
extern crate test;
5-
65
// TODO: Reimplement http_connector bench using hyper::client::conn
76
// (instead of removed HttpConnector).
87

benches/end_to_end.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#![cfg(feature = "nightly")]
12
#![feature(test)]
23
#![deny(warnings)]
34

4-
extern crate test;
5-
65
// TODO: Reimplement Opts::bench using hyper::server::conn and hyper::client::conn
76
// (instead of Server and HttpClient).
87

benches/pipeline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "nightly")]
12
#![feature(test)]
23
#![deny(warnings)]
34

benches/server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "nightly")]
12
#![feature(test)]
23
#![deny(warnings)]
34

@@ -149,7 +150,7 @@ fn raw_tcp_throughput_small_payload(b: &mut test::Bencher) {
149150

150151
let mut buf = [0u8; 8192];
151152
while rx.try_recv().is_err() {
152-
sock.read(&mut buf).unwrap();
153+
let _ = sock.read(&mut buf).unwrap();
153154
sock.write_all(
154155
b"\
155156
HTTP/1.1 200 OK\r\n\
@@ -196,7 +197,7 @@ fn raw_tcp_throughput_large_payload(b: &mut test::Bencher) {
196197
let mut buf = [0u8; 8192];
197198
while rx.try_recv().is_err() {
198199
let r = sock.read(&mut buf).unwrap();
199-
extern crate test;
200+
200201
if r == 0 {
201202
break;
202203
}

benches/support/tokiort.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ impl Timer for TokioTimer {
3232
fn sleep(&self, duration: Duration) -> Box<dyn Sleep + Unpin> {
3333
let s = tokio::time::sleep(duration);
3434
let hs = TokioSleep { inner: Box::pin(s) };
35-
return Box::new(hs);
35+
Box::new(hs)
3636
}
3737

3838
fn sleep_until(&self, deadline: Instant) -> Box<dyn Sleep + Unpin> {
39-
return Box::new(TokioSleep {
39+
Box::new(TokioSleep {
4040
inner: Box::pin(tokio::time::sleep_until(deadline.into())),
41-
});
41+
})
4242
}
4343
}
4444

examples/gateway.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
let in_addr: SocketAddr = ([127, 0, 0, 1], 3001).into();
1212
let out_addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
1313

14-
let out_addr_clone = out_addr.clone();
15-
1614
let listener = TcpListener::bind(in_addr).await?;
1715

1816
println!("Listening on http://{}", in_addr);
@@ -27,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2725
let service = service_fn(move |mut req| {
2826
let uri_string = format!(
2927
"http://{}{}",
30-
out_addr_clone,
28+
out_addr,
3129
req.uri()
3230
.path_and_query()
3331
.map(|x| x.as_str())

examples/http_proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async fn proxy(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Erro
104104
}
105105

106106
fn host_addr(uri: &http::Uri) -> Option<String> {
107-
uri.authority().and_then(|auth| Some(auth.to_string()))
107+
uri.authority().map(|auth| auth.to_string())
108108
}
109109

110110
fn empty() -> BoxBody<Bytes, hyper::Error> {

examples/upgrades.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ async fn main() {
160160
res = &mut conn => {
161161
if let Err(err) = res {
162162
println!("Error serving connection: {:?}", err);
163-
return;
164163
}
165164
}
166165
// Continue polling the connection after enabling graceful shutdown.
@@ -178,7 +177,7 @@ async fn main() {
178177
});
179178

180179
// Client requests a HTTP connection upgrade.
181-
let request = client_upgrade_request(addr.clone());
180+
let request = client_upgrade_request(addr);
182181
if let Err(e) = request.await {
183182
eprintln!("client error: {}", e);
184183
}

examples/web_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn main() -> Result<()> {
111111
let (stream, _) = listener.accept().await?;
112112

113113
tokio::task::spawn(async move {
114-
let service = service_fn(move |req| response_examples(req));
114+
let service = service_fn(response_examples);
115115

116116
if let Err(err) = http1::Builder::new()
117117
.serve_connection(stream, service)

src/body/body.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ impl Recv {
125125
if !content_length.is_exact() && recv.is_end_stream() {
126126
content_length = DecodedLength::ZERO;
127127
}
128-
let body = Recv::new(Kind::H2 {
128+
Recv::new(Kind::H2 {
129129
data_done: false,
130130
ping,
131131
content_length,
132132
recv,
133-
});
134-
135-
body
133+
})
136134
}
137135

138136
#[cfg(feature = "ffi")]
@@ -339,6 +337,7 @@ impl Sender {
339337

340338
/// Aborts the body in an abnormal fashion.
341339
#[allow(unused)]
340+
#[allow(clippy::redundant_clone)]
342341
pub(crate) fn abort(self) {
343342
let _ = self
344343
.data_tx

src/client/conn/http1.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct SendRequest<B> {
3333
/// This allows taking apart a `Connection` at a later time, in order to
3434
/// reclaim the IO object, and additional related pieces.
3535
#[derive(Debug)]
36+
#[non_exhaustive]
3637
pub struct Parts<T> {
3738
/// The original IO object used in the handshake.
3839
pub io: T,
@@ -45,7 +46,6 @@ pub struct Parts<T> {
4546
/// You will want to check for any existing bytes if you plan to continue
4647
/// communicating on the IO object.
4748
pub read_buf: Bytes,
48-
_inner: (),
4949
}
5050

5151

@@ -76,7 +76,6 @@ where
7676
Parts {
7777
io,
7878
read_buf,
79-
_inner: (),
8079
}
8180
}
8281

@@ -546,3 +545,9 @@ impl Builder {
546545
}
547546
}
548547
}
548+
549+
impl std::default::Default for Builder {
550+
fn default() -> Self {
551+
Self::new()
552+
}
553+
}

src/client/conn/http2.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,9 @@ impl Builder {
441441
}
442442
}
443443
}
444+
445+
impl std::default::Default for Builder {
446+
fn default() -> Self {
447+
Self::new()
448+
}
449+
}

src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub(super) enum Parse {
6767
Header(Header),
6868
TooLarge,
6969
Status,
70+
#[cfg(feature = "http1")]
7071
#[cfg_attr(debug_assertions, allow(unused))]
7172
Internal,
7273
}
@@ -193,7 +194,7 @@ impl Error {
193194
pub(crate) fn find_source<E: StdError + 'static>(&self) -> Option<&E> {
194195
let mut cause = self.source();
195196
while let Some(err) = cause {
196-
if let Some(ref typed) = err.downcast_ref() {
197+
if let Some(typed) = err.downcast_ref() {
197198
return Some(typed);
198199
}
199200
cause = err.source();
@@ -351,6 +352,7 @@ impl Error {
351352
}
352353
Kind::Parse(Parse::TooLarge) => "message head is too large",
353354
Kind::Parse(Parse::Status) => "invalid HTTP status-code parsed",
355+
#[cfg(feature = "http1")]
354356
Kind::Parse(Parse::Internal) => {
355357
"internal error inside Hyper and/or its dependencies, please report"
356358
}

src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl HeaderCaseMap {
104104
&'a self,
105105
name: &HeaderName,
106106
) -> impl Iterator<Item = impl AsRef<[u8]> + 'a> + 'a {
107-
self.get_all_internal(name).into_iter()
107+
self.get_all_internal(name)
108108
}
109109

110110
/// Returns a view of all spellings associated with that header name,

src/ext/h1_reason_phrase.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ impl ReasonPhrase {
5252

5353
/// Converts a `Bytes` directly into a `ReasonPhrase` without validating.
5454
///
55+
/// # Safety
56+
///
5557
/// Use with care; invalid bytes in a reason phrase can cause serious security problems if
5658
/// emitted in a response.
5759
pub unsafe fn from_bytes_unchecked(reason: Bytes) -> Self {
@@ -107,9 +109,9 @@ impl TryFrom<Bytes> for ReasonPhrase {
107109
}
108110
}
109111

110-
impl Into<Bytes> for ReasonPhrase {
111-
fn into(self) -> Bytes {
112-
self.0
112+
impl From<ReasonPhrase> for Bytes {
113+
fn from(rp: ReasonPhrase) -> Self {
114+
rp.0
113115
}
114116
}
115117

@@ -144,12 +146,9 @@ const fn is_valid_byte(b: u8) -> bool {
144146
}
145147

146148
// See https://httpwg.org/http-core/draft-ietf-httpbis-semantics-latest.html#fields.values
147-
//
148-
// The 0xFF comparison is technically redundant, but it matches the text of the spec more
149-
// clearly and will be optimized away.
150149
#[allow(unused_comparisons)]
151150
const fn is_obs_text(b: u8) -> bool {
152-
0x80 <= b && b <= 0xFF
151+
0x80 <= b /* && b <= 0xFF */
153152
}
154153

155154
// See https://httpwg.org/http-core/draft-ietf-httpbis-messaging-latest.html#rfc.section.4.p.7
@@ -174,26 +173,26 @@ mod tests {
174173

175174
#[test]
176175
fn basic_valid() {
177-
const PHRASE: &'static [u8] = b"OK";
176+
const PHRASE: &[u8] = b"OK";
178177
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
179178
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
180179
}
181180

182181
#[test]
183182
fn empty_valid() {
184-
const PHRASE: &'static [u8] = b"";
183+
const PHRASE: &[u8] = b"";
185184
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
186185
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
187186
}
188187

189188
#[test]
190189
fn obs_text_valid() {
191-
const PHRASE: &'static [u8] = b"hyp\xe9r";
190+
const PHRASE: &[u8] = b"hyp\xe9r";
192191
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
193192
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
194193
}
195194

196-
const NEWLINE_PHRASE: &'static [u8] = b"hyp\ner";
195+
const NEWLINE_PHRASE: &[u8] = b"hyp\ner";
197196

198197
#[test]
199198
#[should_panic]
@@ -206,7 +205,7 @@ mod tests {
206205
assert!(ReasonPhrase::try_from(NEWLINE_PHRASE).is_err());
207206
}
208207

209-
const CR_PHRASE: &'static [u8] = b"hyp\rer";
208+
const CR_PHRASE: &[u8] = b"hyp\rer";
210209

211210
#[test]
212211
#[should_panic]

src/headers.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
6161
}
6262
}
6363

64-
return content_length
64+
content_length
6565
}
6666

6767
fn from_digits(bytes: &[u8]) -> Option<u64> {
@@ -93,10 +93,7 @@ fn from_digits(bytes: &[u8]) -> Option<u64> {
9393

9494
#[cfg(all(feature = "http2", feature = "client"))]
9595
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
96-
match *method {
97-
Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false,
98-
_ => true,
99-
}
96+
!matches!(*method, Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT)
10097
}
10198

10299
#[cfg(feature = "http2")]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![deny(missing_docs)]
22
#![deny(missing_debug_implementations)]
3+
#![allow(clippy::module_inception)]
34
#![cfg_attr(test, deny(rust_2018_idioms))]
45
#![cfg_attr(all(test, feature = "full"), deny(unreachable_pub))]
56
#![cfg_attr(all(test, feature = "full"), deny(warnings))]

src/proto/h1/conn.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ where
169169
}
170170

171171
pub(crate) fn can_read_body(&self) -> bool {
172-
match self.state.reading {
173-
Reading::Body(..) | Reading::Continue(..) => true,
174-
_ => false,
175-
}
172+
matches!(self.state.reading, Reading::Body(..) | Reading::Continue(..))
176173
}
177174

178175
fn should_error_on_eof(&self) -> bool {
@@ -185,6 +182,7 @@ where
185182
read_buf.len() >= 24 && read_buf[..24] == *H2_PREFACE
186183
}
187184

185+
#[allow(clippy::type_complexity)] // The return type is complex due to task-semantics
188186
pub(super) fn poll_read_head(
189187
&mut self,
190188
cx: &mut task::Context<'_>,
@@ -943,11 +941,7 @@ impl State {
943941
}
944942

945943
fn wants_keep_alive(&self) -> bool {
946-
if let KA::Disabled = self.keep_alive.status() {
947-
false
948-
} else {
949-
true
950-
}
944+
!matches!(self.keep_alive.status(), KA::Disabled)
951945
}
952946

953947
fn try_keep_alive<T: Http1Transaction>(&mut self) {

0 commit comments

Comments
 (0)