Skip to content

Commit 0bd4adf

Browse files
authored
refactor(lib): reduce clippy warnings (#3805)
1 parent 12717d1 commit 0bd4adf

File tree

21 files changed

+78
-101
lines changed

21 files changed

+78
-101
lines changed

benches/end_to_end.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn http1_parallel_x10_req_10kb_100_chunks(b: &mut test::Bencher) {
8282
#[bench]
8383
#[ignore]
8484
fn http1_parallel_x10_res_1mb(b: &mut test::Bencher) {
85-
let body = &[b'x'; 1024 * 1024 * 1];
85+
let body = &[b'x'; 1024 * 1024];
8686
opts().parallel(10).response_body(body).bench(b)
8787
}
8888

@@ -177,7 +177,7 @@ fn http2_parallel_x10_req_10kb_100_chunks_max_window(b: &mut test::Bencher) {
177177

178178
#[bench]
179179
fn http2_parallel_x10_res_1mb(b: &mut test::Bencher) {
180-
let body = &[b'x'; 1024 * 1024 * 1];
180+
let body = &[b'x'; 1024 * 1024];
181181
opts()
182182
.http2()
183183
.parallel(10)

benches/support/tokiort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Timer for TokioTimer {
4444

4545
fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
4646
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
47-
sleep.reset(new_deadline.into())
47+
sleep.reset(new_deadline)
4848
}
4949
}
5050
}

examples/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
7171
while let Some(next) = res.frame().await {
7272
let frame = next?;
7373
if let Some(chunk) = frame.data_ref() {
74-
io::stdout().write_all(&chunk).await?;
74+
io::stdout().write_all(chunk).await?;
7575
}
7676
}
7777

examples/gateway.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1515
let in_addr: SocketAddr = ([127, 0, 0, 1], 3001).into();
1616
let out_addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
1717

18-
let out_addr_clone = out_addr.clone();
18+
let out_addr_clone = out_addr;
1919

2020
let listener = TcpListener::bind(in_addr).await?;
2121

examples/http_proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn proxy(
111111
}
112112

113113
fn host_addr(uri: &http::Uri) -> Option<String> {
114-
uri.authority().and_then(|auth| Some(auth.to_string()))
114+
uri.authority().map(|auth| auth.to_string())
115115
}
116116

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

examples/single_threaded.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
207207
while let Some(next) = res.frame().await {
208208
let frame = next?;
209209
if let Some(chunk) = frame.data_ref() {
210-
stdout.write_all(&chunk).await.unwrap();
210+
stdout.write_all(chunk).await.unwrap();
211211
}
212212
}
213213
stdout.write_all(b"\n-----------------\n").await.unwrap();
@@ -308,7 +308,7 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
308308
while let Some(next) = res.frame().await {
309309
let frame = next?;
310310
if let Some(chunk) = frame.data_ref() {
311-
stdout.write_all(&chunk).await.unwrap();
311+
stdout.write_all(chunk).await.unwrap();
312312
}
313313
}
314314
stdout.write_all(b"\n-----------------\n").await.unwrap();

examples/upgrades.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ async fn main() {
169169
res = &mut conn => {
170170
if let Err(err) = res {
171171
println!("Error serving connection: {:?}", err);
172-
return;
173172
}
174173
}
175174
// Continue polling the connection after enabling graceful shutdown.
@@ -187,7 +186,7 @@ async fn main() {
187186
});
188187

189188
// Client requests a HTTP connection upgrade.
190-
let request = client_upgrade_request(addr.clone());
189+
let request = client_upgrade_request(addr);
191190
if let Err(e) = request.await {
192191
eprintln!("client error: {}", e);
193192
}

examples/web_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async fn main() -> Result<()> {
117117
let io = TokioIo::new(stream);
118118

119119
tokio::task::spawn(async move {
120-
let service = service_fn(move |req| response_examples(req));
120+
let service = service_fn(response_examples);
121121

122122
if let Err(err) = http1::Builder::new().serve_connection(io, service).await {
123123
println!("Failed to serve connection: {:?}", err);

src/ext/h1_reason_phrase.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,26 +174,26 @@ mod tests {
174174

175175
#[test]
176176
fn basic_valid() {
177-
const PHRASE: &'static [u8] = b"OK";
177+
const PHRASE: &[u8] = b"OK";
178178
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
179179
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
180180
}
181181

182182
#[test]
183183
fn empty_valid() {
184-
const PHRASE: &'static [u8] = b"";
184+
const PHRASE: &[u8] = b"";
185185
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
186186
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
187187
}
188188

189189
#[test]
190190
fn obs_text_valid() {
191-
const PHRASE: &'static [u8] = b"hyp\xe9r";
191+
const PHRASE: &[u8] = b"hyp\xe9r";
192192
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
193193
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
194194
}
195195

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

198198
#[test]
199199
#[should_panic]
@@ -206,7 +206,7 @@ mod tests {
206206
assert!(ReasonPhrase::try_from(NEWLINE_PHRASE).is_err());
207207
}
208208

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

211211
#[test]
212212
#[should_panic]

src/proto/h1/decode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ mod tests {
693693
use std::pin::Pin;
694694
use std::time::Duration;
695695

696-
impl<'a> MemRead for &'a [u8] {
696+
impl MemRead for &[u8] {
697697
fn read_mem(&mut self, _: &mut Context<'_>, len: usize) -> Poll<io::Result<Bytes>> {
698698
let n = std::cmp::min(len, self.len());
699699
if n > 0 {
@@ -707,12 +707,12 @@ mod tests {
707707
}
708708
}
709709

710-
impl<'a> MemRead for &'a mut (dyn Read + Unpin) {
710+
impl MemRead for &mut (dyn Read + Unpin) {
711711
fn read_mem(&mut self, cx: &mut Context<'_>, len: usize) -> Poll<io::Result<Bytes>> {
712712
let mut v = vec![0; len];
713713
let mut buf = ReadBuf::new(&mut v);
714714
ready!(Pin::new(self).poll_read(cx, buf.unfilled())?);
715-
Poll::Ready(Ok(Bytes::copy_from_slice(&buf.filled())))
715+
Poll::Ready(Ok(Bytes::copy_from_slice(buf.filled())))
716716
}
717717
}
718718

@@ -761,7 +761,7 @@ mod tests {
761761
})
762762
.await;
763763
let desc = format!("read_size failed for {:?}", s);
764-
state = result.expect(desc.as_str());
764+
state = result.expect(&desc);
765765
if state == ChunkedState::Body || state == ChunkedState::EndCr {
766766
break;
767767
}

0 commit comments

Comments
 (0)