Skip to content

Commit

Permalink
style(lib): address most clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored and seanmonstar committed Jan 3, 2020
1 parent 0f13719 commit 0eaf304
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 200 deletions.
4 changes: 2 additions & 2 deletions benches/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Opts {
} else {
self.request_body
.map(Body::from)
.unwrap_or_else(|| Body::empty())
.unwrap_or_else(Body::empty)
};
let mut req = Request::new(body);
*req.method_mut() = self.request_method.clone();
Expand Down Expand Up @@ -355,5 +355,5 @@ fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
panic!("server error: {}", err);
}
});
return addr;
addr
}
4 changes: 2 additions & 2 deletions benches/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn throughput_fixedsize_large_payload(b: &mut test::Bencher) {
#[bench]
fn throughput_fixedsize_many_chunks(b: &mut test::Bencher) {
bench_server!(b, ("content-length", "1000000"), || {
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
})
}
Expand All @@ -127,7 +127,7 @@ fn throughput_chunked_large_payload(b: &mut test::Bencher) {
#[bench]
fn throughput_chunked_many_chunks(b: &mut test::Bencher) {
bench_server!(b, ("transfer-encoding", "chunked"), || {
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures_util::future::join;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};

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

async fn index1(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
Ok(Response::new(Body::from(INDEX1)))
Expand Down
2 changes: 1 addition & 1 deletion examples/send_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ async fn simple_file_send(filename: &str) -> Result<Response<Body>> {
return Ok(internal_server_error());
}

return Ok(not_found());
Ok(not_found())
}
2 changes: 1 addition & 1 deletion examples/tower_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_util::future;
use hyper::service::Service;
use hyper::{Body, Request, Response, Server};

const ROOT: &'static str = "/";
const ROOT: &str = "/";

#[derive(Debug)]
pub struct Svc;
Expand Down
14 changes: 3 additions & 11 deletions src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ impl Body {
let (tx, rx) = mpsc::channel(0);
let (abort_tx, abort_rx) = oneshot::channel();

let tx = Sender {
abort_tx: abort_tx,
tx: tx,
};
let tx = Sender { abort_tx, tx };
let rx = Body::new(Kind::Chan {
content_length,
abort_rx,
Expand All @@ -131,7 +128,6 @@ impl Body {
///
/// ```
/// # use hyper::Body;
/// # fn main() {
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec![
/// Ok("hello"),
/// Ok(" "),
Expand All @@ -141,7 +137,6 @@ impl Body {
/// let stream = futures_util::stream::iter(chunks);
///
/// let body = Body::wrap_stream(stream);
/// # }
/// ```
///
/// # Optional
Expand Down Expand Up @@ -169,10 +164,7 @@ impl Body {
}

fn new(kind: Kind) -> Body {
Body {
kind: kind,
extra: None,
}
Body { kind, extra: None }
}

pub(crate) fn h2(recv: h2::RecvStream, content_length: Option<u64>) -> Self {
Expand Down Expand Up @@ -253,7 +245,7 @@ impl Body {
Some(chunk) => {
if let Some(ref mut len) = *len {
debug_assert!(*len >= chunk.len() as u64);
*len = *len - chunk.len() as u64;
*len -= chunk.len() as u64;
}
Poll::Ready(Some(Ok(chunk)))
}
Expand Down
3 changes: 1 addition & 2 deletions src/body/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ pub trait Payload: sealed::Sealed + Send + 'static {
/// Note: Trailers aren't currently used for HTTP/1, only for HTTP/2.
fn poll_trailers(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
_cx: &mut task::Context<'_>,
) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
drop(cx);
Poll::Ready(Ok(None))
}

Expand Down
10 changes: 5 additions & 5 deletions src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ where
};

Parts {
io: io,
read_buf: read_buf,
io,
read_buf,
_inner: (),
}
}
Expand All @@ -363,9 +363,9 @@ 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<crate::Result<()>> {
match self.inner.as_mut().expect("already upgraded") {
&mut ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
&mut ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
match *self.inner.as_mut().expect("already upgraded") {
ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/client/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl ConnectingTcpRemote {
}
}

return Err(err.take().expect("missing connect error"));
Err(err.take().expect("missing connect error"))
}
}

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

if reuse_address {
Expand All @@ -566,9 +566,9 @@ fn connect(
builder.bind(SocketAddr::new(local_addr.clone(), 0))?;
} else if cfg!(windows) {
// Windows requires a socket be bound before calling connect
let any: SocketAddr = match addr {
&SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
&SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
let any: SocketAddr = match *addr {
SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
};
builder.bind(any)?;
}
Expand Down Expand Up @@ -619,7 +619,7 @@ impl ConnectingTcp {
}
};

if let Err(_) = result {
if result.is_err() {
// Fallback to the remaining future (could be preferred or fallback)
// if we get an error
future.await
Expand Down
9 changes: 3 additions & 6 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
let (giver, taker) = want::new();
let tx = Sender {
buffered_once: false,
giver: giver,
giver,
inner: tx,
};
let rx = Receiver {
inner: rx,
taker: taker,
};
let rx = Receiver { inner: rx, taker };
(tx, rx)
}

Expand Down Expand Up @@ -183,7 +180,7 @@ struct Envelope<T, U>(Option<(T, Callback<T, U>)>);
impl<T, U> Drop for Envelope<T, U> {
fn drop(&mut self) {
if let Some((val, cb)) = self.0.take() {
let _ = cb.send(Err((
cb.send(Err((
crate::Error::new_canceled().with("connection closed"),
Some(val),
)));
Expand Down
10 changes: 5 additions & 5 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ where
/// # fn main() {}
/// ```
pub fn request(&self, mut req: Request<B>) -> ResponseFuture {
let is_http_connect = req.method() == &Method::CONNECT;
let is_http_connect = req.method() == Method::CONNECT;
match req.version() {
Version::HTTP_11 => (),
Version::HTTP_10 => {
Expand All @@ -237,7 +237,7 @@ where
}
};

let pool_key = Arc::new(domain.to_string());
let pool_key = Arc::new(domain);
ResponseFuture::new(Box::new(self.retryably_send_request(req, pool_key)))
}

Expand Down Expand Up @@ -302,14 +302,14 @@ where
}

// CONNECT always sends authority-form, so check it first...
if req.method() == &Method::CONNECT {
if req.method() == Method::CONNECT {
authority_form(req.uri_mut());
} else if pooled.conn_info.is_proxied {
absolute_form(req.uri_mut());
} else {
origin_form(req.uri_mut());
};
} else if req.method() == &Method::CONNECT {
} else if req.method() == Method::CONNECT {
debug!("client does not support CONNECT requests over HTTP2");
return Either::Left(future::err(ClientError::Normal(
crate::Error::new_user_unsupported_request_method(),
Expand Down Expand Up @@ -422,7 +422,7 @@ where
});
// An execute error here isn't important, we're just trying
// to prevent a waste of a socket...
let _ = executor.execute(bg);
executor.execute(bg);
}
Either::Left(future::ok(checked_out))
}
Expand Down
6 changes: 3 additions & 3 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ impl<T: Poolable> PoolInner<T> {
Some(value) => {
// borrow-check scope...
{
let idle_list = self.idle.entry(key.clone()).or_insert(Vec::new());
let idle_list = self.idle.entry(key.clone()).or_insert_with(Vec::new);
if self.max_idle_per_host <= idle_list.len() {
trace!("max idle per host for {:?}, dropping connection", key);
return;
}

debug!("pooling idle connection for {:?}", key);
idle_list.push(Idle {
value: value,
value,
idle_at: Instant::now(),
});
}
Expand Down Expand Up @@ -610,7 +610,7 @@ impl<T: Poolable> Checkout<T> {
inner
.waiters
.entry(self.key.clone())
.or_insert(VecDeque::new())
.or_insert_with(VecDeque::new)
.push_back(tx);

// register the waker with this oneshot
Expand Down
5 changes: 1 addition & 4 deletions src/common/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl<T: Buf> Buf for BufList<T> {

#[inline]
fn bytes(&self) -> &[u8] {
for buf in &self.bufs {
return buf.bytes();
}
&[]
self.bufs.front().map(Buf::bytes).unwrap_or_default()
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/common/io/rewind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ where
) -> Poll<io::Result<usize>> {
if let Some(mut prefix) = self.pre.take() {
// If there are no remaining bytes, let the bytes get dropped.
if prefix.len() > 0 {
if !prefix.is_empty() {
let copy_len = cmp::min(prefix.len(), buf.len());
prefix.copy_to_slice(&mut buf[..copy_len]);
// Put back whats left
if prefix.len() > 0 {
if !prefix.is_empty() {
self.pre = Some(prefix);
}

Expand Down
5 changes: 2 additions & 3 deletions src/common/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ where
type Output = R::Output;

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

match mem::replace(&mut self.inner, Inner::Empty) {
Expand Down
2 changes: 1 addition & 1 deletion src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool {
}

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

if let Some(line) = entry.iter_mut().next_back() {
// + 2 for ", "
Expand Down
Loading

0 comments on commit 0eaf304

Please sign in to comment.