Skip to content

Commit 0eaf304

Browse files
danieleadesseanmonstar
authored andcommitted
style(lib): address most clippy lints
1 parent 0f13719 commit 0eaf304

29 files changed

+162
-200
lines changed

benches/end_to_end.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl Opts {
292292
} else {
293293
self.request_body
294294
.map(Body::from)
295-
.unwrap_or_else(|| Body::empty())
295+
.unwrap_or_else(Body::empty)
296296
};
297297
let mut req = Request::new(body);
298298
*req.method_mut() = self.request_method.clone();
@@ -355,5 +355,5 @@ fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
355355
panic!("server error: {}", err);
356356
}
357357
});
358-
return addr;
358+
addr
359359
}

benches/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn throughput_fixedsize_large_payload(b: &mut test::Bencher) {
105105
#[bench]
106106
fn throughput_fixedsize_many_chunks(b: &mut test::Bencher) {
107107
bench_server!(b, ("content-length", "1000000"), || {
108-
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
108+
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
109109
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
110110
})
111111
}
@@ -127,7 +127,7 @@ fn throughput_chunked_large_payload(b: &mut test::Bencher) {
127127
#[bench]
128128
fn throughput_chunked_many_chunks(b: &mut test::Bencher) {
129129
bench_server!(b, ("transfer-encoding", "chunked"), || {
130-
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
130+
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
131131
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
132132
})
133133
}

examples/multi_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use futures_util::future::join;
55
use hyper::service::{make_service_fn, service_fn};
66
use hyper::{Body, Request, Response, Server};
77

8-
static INDEX1: &'static [u8] = b"The 1st service!";
9-
static INDEX2: &'static [u8] = b"The 2nd service!";
8+
static INDEX1: &[u8] = b"The 1st service!";
9+
static INDEX2: &[u8] = b"The 2nd service!";
1010

1111
async fn index1(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
1212
Ok(Response::new(Body::from(INDEX1)))

examples/send_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ async fn simple_file_send(filename: &str) -> Result<Response<Body>> {
7171
return Ok(internal_server_error());
7272
}
7373

74-
return Ok(not_found());
74+
Ok(not_found())
7575
}

examples/tower_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use futures_util::future;
66
use hyper::service::Service;
77
use hyper::{Body, Request, Response, Server};
88

9-
const ROOT: &'static str = "/";
9+
const ROOT: &str = "/";
1010

1111
#[derive(Debug)]
1212
pub struct Svc;

src/body/body.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ impl Body {
112112
let (tx, rx) = mpsc::channel(0);
113113
let (abort_tx, abort_rx) = oneshot::channel();
114114

115-
let tx = Sender {
116-
abort_tx: abort_tx,
117-
tx: tx,
118-
};
115+
let tx = Sender { abort_tx, tx };
119116
let rx = Body::new(Kind::Chan {
120117
content_length,
121118
abort_rx,
@@ -131,7 +128,6 @@ impl Body {
131128
///
132129
/// ```
133130
/// # use hyper::Body;
134-
/// # fn main() {
135131
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec![
136132
/// Ok("hello"),
137133
/// Ok(" "),
@@ -141,7 +137,6 @@ impl Body {
141137
/// let stream = futures_util::stream::iter(chunks);
142138
///
143139
/// let body = Body::wrap_stream(stream);
144-
/// # }
145140
/// ```
146141
///
147142
/// # Optional
@@ -169,10 +164,7 @@ impl Body {
169164
}
170165

171166
fn new(kind: Kind) -> Body {
172-
Body {
173-
kind: kind,
174-
extra: None,
175-
}
167+
Body { kind, extra: None }
176168
}
177169

178170
pub(crate) fn h2(recv: h2::RecvStream, content_length: Option<u64>) -> Self {
@@ -253,7 +245,7 @@ impl Body {
253245
Some(chunk) => {
254246
if let Some(ref mut len) = *len {
255247
debug_assert!(*len >= chunk.len() as u64);
256-
*len = *len - chunk.len() as u64;
248+
*len -= chunk.len() as u64;
257249
}
258250
Poll::Ready(Some(Ok(chunk)))
259251
}

src/body/payload.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ pub trait Payload: sealed::Sealed + Send + 'static {
3333
/// Note: Trailers aren't currently used for HTTP/1, only for HTTP/2.
3434
fn poll_trailers(
3535
self: Pin<&mut Self>,
36-
cx: &mut task::Context<'_>,
36+
_cx: &mut task::Context<'_>,
3737
) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
38-
drop(cx);
3938
Poll::Ready(Ok(None))
4039
}
4140

src/client/conn.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ where
345345
};
346346

347347
Parts {
348-
io: io,
349-
read_buf: read_buf,
348+
io,
349+
read_buf,
350350
_inner: (),
351351
}
352352
}
@@ -363,9 +363,9 @@ where
363363
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
364364
/// to work with this function; or use the `without_shutdown` wrapper.
365365
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
366-
match self.inner.as_mut().expect("already upgraded") {
367-
&mut ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
368-
&mut ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
366+
match *self.inner.as_mut().expect("already upgraded") {
367+
ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
368+
ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
369369
}
370370
}
371371

src/client/connect/http.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl ConnectingTcpRemote {
542542
}
543543
}
544544

545-
return Err(err.take().expect("missing connect error"));
545+
Err(err.take().expect("missing connect error"))
546546
}
547547
}
548548

@@ -552,9 +552,9 @@ fn connect(
552552
reuse_address: bool,
553553
connect_timeout: Option<Duration>,
554554
) -> io::Result<impl Future<Output = io::Result<TcpStream>>> {
555-
let builder = match addr {
556-
&SocketAddr::V4(_) => TcpBuilder::new_v4()?,
557-
&SocketAddr::V6(_) => TcpBuilder::new_v6()?,
555+
let builder = match *addr {
556+
SocketAddr::V4(_) => TcpBuilder::new_v4()?,
557+
SocketAddr::V6(_) => TcpBuilder::new_v6()?,
558558
};
559559

560560
if reuse_address {
@@ -566,9 +566,9 @@ fn connect(
566566
builder.bind(SocketAddr::new(local_addr.clone(), 0))?;
567567
} else if cfg!(windows) {
568568
// Windows requires a socket be bound before calling connect
569-
let any: SocketAddr = match addr {
570-
&SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
571-
&SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
569+
let any: SocketAddr = match *addr {
570+
SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
571+
SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
572572
};
573573
builder.bind(any)?;
574574
}
@@ -619,7 +619,7 @@ impl ConnectingTcp {
619619
}
620620
};
621621

622-
if let Err(_) = result {
622+
if result.is_err() {
623623
// Fallback to the remaining future (could be preferred or fallback)
624624
// if we get an error
625625
future.await

src/client/dispatch.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
1212
let (giver, taker) = want::new();
1313
let tx = Sender {
1414
buffered_once: false,
15-
giver: giver,
15+
giver,
1616
inner: tx,
1717
};
18-
let rx = Receiver {
19-
inner: rx,
20-
taker: taker,
21-
};
18+
let rx = Receiver { inner: rx, taker };
2219
(tx, rx)
2320
}
2421

@@ -183,7 +180,7 @@ struct Envelope<T, U>(Option<(T, Callback<T, U>)>);
183180
impl<T, U> Drop for Envelope<T, U> {
184181
fn drop(&mut self) {
185182
if let Some((val, cb)) = self.0.take() {
186-
let _ = cb.send(Err((
183+
cb.send(Err((
187184
crate::Error::new_canceled().with("connection closed"),
188185
Some(val),
189186
)));

src/client/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ where
210210
/// # fn main() {}
211211
/// ```
212212
pub fn request(&self, mut req: Request<B>) -> ResponseFuture {
213-
let is_http_connect = req.method() == &Method::CONNECT;
213+
let is_http_connect = req.method() == Method::CONNECT;
214214
match req.version() {
215215
Version::HTTP_11 => (),
216216
Version::HTTP_10 => {
@@ -237,7 +237,7 @@ where
237237
}
238238
};
239239

240-
let pool_key = Arc::new(domain.to_string());
240+
let pool_key = Arc::new(domain);
241241
ResponseFuture::new(Box::new(self.retryably_send_request(req, pool_key)))
242242
}
243243

@@ -302,14 +302,14 @@ where
302302
}
303303

304304
// CONNECT always sends authority-form, so check it first...
305-
if req.method() == &Method::CONNECT {
305+
if req.method() == Method::CONNECT {
306306
authority_form(req.uri_mut());
307307
} else if pooled.conn_info.is_proxied {
308308
absolute_form(req.uri_mut());
309309
} else {
310310
origin_form(req.uri_mut());
311311
};
312-
} else if req.method() == &Method::CONNECT {
312+
} else if req.method() == Method::CONNECT {
313313
debug!("client does not support CONNECT requests over HTTP2");
314314
return Either::Left(future::err(ClientError::Normal(
315315
crate::Error::new_user_unsupported_request_method(),
@@ -422,7 +422,7 @@ where
422422
});
423423
// An execute error here isn't important, we're just trying
424424
// to prevent a waste of a socket...
425-
let _ = executor.execute(bg);
425+
executor.execute(bg);
426426
}
427427
Either::Left(future::ok(checked_out))
428428
}

src/client/pool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ impl<T: Poolable> PoolInner<T> {
352352
Some(value) => {
353353
// borrow-check scope...
354354
{
355-
let idle_list = self.idle.entry(key.clone()).or_insert(Vec::new());
355+
let idle_list = self.idle.entry(key.clone()).or_insert_with(Vec::new);
356356
if self.max_idle_per_host <= idle_list.len() {
357357
trace!("max idle per host for {:?}, dropping connection", key);
358358
return;
359359
}
360360

361361
debug!("pooling idle connection for {:?}", key);
362362
idle_list.push(Idle {
363-
value: value,
363+
value,
364364
idle_at: Instant::now(),
365365
});
366366
}
@@ -610,7 +610,7 @@ impl<T: Poolable> Checkout<T> {
610610
inner
611611
.waiters
612612
.entry(self.key.clone())
613-
.or_insert(VecDeque::new())
613+
.or_insert_with(VecDeque::new)
614614
.push_back(tx);
615615

616616
// register the waker with this oneshot

src/common/buf.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ impl<T: Buf> Buf for BufList<T> {
3434

3535
#[inline]
3636
fn bytes(&self) -> &[u8] {
37-
for buf in &self.bufs {
38-
return buf.bytes();
39-
}
40-
&[]
37+
self.bufs.front().map(Buf::bytes).unwrap_or_default()
4138
}
4239

4340
#[inline]

src/common/io/rewind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ where
5858
) -> Poll<io::Result<usize>> {
5959
if let Some(mut prefix) = self.pre.take() {
6060
// If there are no remaining bytes, let the bytes get dropped.
61-
if prefix.len() > 0 {
61+
if !prefix.is_empty() {
6262
let copy_len = cmp::min(prefix.len(), buf.len());
6363
prefix.copy_to_slice(&mut buf[..copy_len]);
6464
// Put back whats left
65-
if prefix.len() > 0 {
65+
if !prefix.is_empty() {
6666
self.pre = Some(prefix);
6767
}
6868

src/common/lazy.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ where
4949
type Output = R::Output;
5050

5151
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
52-
match self.inner {
53-
Inner::Fut(ref mut f) => return Pin::new(f).poll(cx),
54-
_ => (),
52+
if let Inner::Fut(ref mut f) = self.inner {
53+
return Pin::new(f).poll(cx);
5554
}
5655

5756
match mem::replace(&mut self.inner, Inner::Empty) {

src/headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool {
9696
}
9797

9898
pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) {
99-
const CHUNKED: &'static str = "chunked";
99+
const CHUNKED: &str = "chunked";
100100

101101
if let Some(line) = entry.iter_mut().next_back() {
102102
// + 2 for ", "

0 commit comments

Comments
 (0)