Skip to content

Commit

Permalink
Apply clippy fixes, except in #[test] code
Browse files Browse the repository at this point in the history
  • Loading branch information
bossmc committed Oct 25, 2022
1 parent 0888623 commit 5907545
Show file tree
Hide file tree
Showing 32 changed files with 107 additions and 102 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
components: clippy
toolchain: ${{ matrix.rust }}
override: true

Expand All @@ -91,6 +92,12 @@ jobs:
command: test
args: ${{ matrix.features }}

- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: ${{ matrix.features }} --lib --examples --benches

- name: Test all benches
if: matrix.benches
uses: actions-rs/cargo@v1
Expand Down
1 change: 1 addition & 0 deletions benches/body.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "nightly")]
#![feature(test)]
#![deny(warnings)]

Expand Down
3 changes: 1 addition & 2 deletions benches/connect.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg(feature = "nightly")]
#![feature(test)]
#![deny(warnings)]

extern crate test;

// TODO: Reimplement http_connector bench using hyper::client::conn
// (instead of removed HttpConnector).

Expand Down
3 changes: 1 addition & 2 deletions benches/end_to_end.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg(feature = "nightly")]
#![feature(test)]
#![deny(warnings)]

extern crate test;

// TODO: Reimplement Opts::bench using hyper::server::conn and hyper::client::conn
// (instead of Server and HttpClient).

Expand Down
1 change: 1 addition & 0 deletions benches/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "nightly")]
#![feature(test)]
#![deny(warnings)]

Expand Down
5 changes: 3 additions & 2 deletions benches/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "nightly")]
#![feature(test)]
#![deny(warnings)]

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

let mut buf = [0u8; 8192];
while rx.try_recv().is_err() {
sock.read(&mut buf).unwrap();
let _ = sock.read(&mut buf).unwrap();
sock.write_all(
b"\
HTTP/1.1 200 OK\r\n\
Expand Down Expand Up @@ -196,7 +197,7 @@ fn raw_tcp_throughput_large_payload(b: &mut test::Bencher) {
let mut buf = [0u8; 8192];
while rx.try_recv().is_err() {
let r = sock.read(&mut buf).unwrap();
extern crate test;

if r == 0 {
break;
}
Expand Down
6 changes: 3 additions & 3 deletions benches/support/tokiort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ impl Timer for TokioTimer {
fn sleep(&self, duration: Duration) -> Box<dyn Sleep + Unpin> {
let s = tokio::time::sleep(duration);
let hs = TokioSleep { inner: Box::pin(s) };
return Box::new(hs);
Box::new(hs)
}

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

Expand Down
4 changes: 1 addition & 3 deletions examples/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let in_addr: SocketAddr = ([127, 0, 0, 1], 3001).into();
let out_addr: SocketAddr = ([127, 0, 0, 1], 3000).into();

let out_addr_clone = out_addr.clone();

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

println!("Listening on http://{}", in_addr);
Expand All @@ -27,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = service_fn(move |mut req| {
let uri_string = format!(
"http://{}{}",
out_addr_clone,
out_addr,
req.uri()
.path_and_query()
.map(|x| x.as_str())
Expand Down
2 changes: 1 addition & 1 deletion examples/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn proxy(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Erro
}

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

fn empty() -> BoxBody<Bytes, hyper::Error> {
Expand Down
3 changes: 1 addition & 2 deletions examples/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ async fn main() {
res = &mut conn => {
if let Err(err) = res {
println!("Error serving connection: {:?}", err);
return;
}
}
// Continue polling the connection after enabling graceful shutdown.
Expand All @@ -178,7 +177,7 @@ async fn main() {
});

// Client requests a HTTP connection upgrade.
let request = client_upgrade_request(addr.clone());
let request = client_upgrade_request(addr);
if let Err(e) = request.await {
eprintln!("client error: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn main() -> Result<()> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
let service = service_fn(move |req| response_examples(req));
let service = service_fn(response_examples);

if let Err(err) = http1::Builder::new()
.serve_connection(stream, service)
Expand Down
17 changes: 6 additions & 11 deletions src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,12 @@ impl Recv {
if !content_length.is_exact() && recv.is_end_stream() {
content_length = DecodedLength::ZERO;
}
let body = Recv::new(Kind::H2 {
Recv::new(Kind::H2 {
data_done: false,
ping,
content_length,
recv,
});

body
})
}

#[cfg(feature = "ffi")]
Expand Down Expand Up @@ -170,13 +168,9 @@ impl Body for Recv {
want_tx.send(WANT_READY);

if !data_rx.is_terminated() {
match ready!(Pin::new(data_rx).poll_next(cx)?) {
Some(chunk) => {
len.sub_if(chunk.len() as u64);
return Poll::Ready(Some(Ok(Frame::data(chunk))));
}
// fall through to trailers
None => (),
if let Some(chunk) = ready!(Pin::new(data_rx).poll_next(cx)?) {
len.sub_if(chunk.len() as u64);
return Poll::Ready(Some(Ok(Frame::data(chunk))));
}
}

Expand Down Expand Up @@ -339,6 +333,7 @@ impl Sender {

/// Aborts the body in an abnormal fashion.
#[allow(unused)]
#[allow(clippy::redundant_clone)]
pub(crate) fn abort(self) {
let _ = self
.data_tx
Expand Down
9 changes: 7 additions & 2 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct SendRequest<B> {
/// This allows taking apart a `Connection` at a later time, in order to
/// reclaim the IO object, and additional related pieces.
#[derive(Debug)]
#[non_exhaustive]
pub struct Parts<T> {
/// The original IO object used in the handshake.
pub io: T,
Expand All @@ -45,7 +46,6 @@ pub struct Parts<T> {
/// You will want to check for any existing bytes if you plan to continue
/// communicating on the IO object.
pub read_buf: Bytes,
_inner: (),
}


Expand Down Expand Up @@ -76,7 +76,6 @@ where
Parts {
io,
read_buf,
_inner: (),
}
}

Expand Down Expand Up @@ -546,3 +545,9 @@ impl Builder {
}
}
}

impl std::default::Default for Builder {
fn default() -> Self {
Self::new()
}
}
6 changes: 6 additions & 0 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,9 @@ impl Builder {
}
}
}

impl std::default::Default for Builder {
fn default() -> Self {
Self::new()
}
}
2 changes: 2 additions & 0 deletions src/common/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ pub(crate) struct BufList<T> {
}

impl<T: Buf> BufList<T> {
#[cfg(feature = "http1")]
pub(crate) fn new() -> BufList<T> {
BufList {
bufs: VecDeque::new(),
}
}

#[cfg(feature = "http1")]
#[inline]
pub(crate) fn push(&mut self, buf: T) {
debug_assert!(buf.has_remaining());
Expand Down
4 changes: 3 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(super) enum Parse {
Header(Header),
TooLarge,
Status,
#[cfg(feature = "http1")]
#[cfg_attr(debug_assertions, allow(unused))]
Internal,
}
Expand Down Expand Up @@ -193,7 +194,7 @@ impl Error {
pub(crate) fn find_source<E: StdError + 'static>(&self) -> Option<&E> {
let mut cause = self.source();
while let Some(err) = cause {
if let Some(ref typed) = err.downcast_ref() {
if let Some(typed) = err.downcast_ref() {
return Some(typed);
}
cause = err.source();
Expand Down Expand Up @@ -351,6 +352,7 @@ impl Error {
}
Kind::Parse(Parse::TooLarge) => "message head is too large",
Kind::Parse(Parse::Status) => "invalid HTTP status-code parsed",
#[cfg(feature = "http1")]
Kind::Parse(Parse::Internal) => {
"internal error inside Hyper and/or its dependencies, please report"
}
Expand Down
2 changes: 1 addition & 1 deletion src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl HeaderCaseMap {
&'a self,
name: &HeaderName,
) -> impl Iterator<Item = impl AsRef<[u8]> + 'a> + 'a {
self.get_all_internal(name).into_iter()
self.get_all_internal(name)
}

/// Returns a view of all spellings associated with that header name,
Expand Down
23 changes: 11 additions & 12 deletions src/ext/h1_reason_phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ impl ReasonPhrase {

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

impl Into<Bytes> for ReasonPhrase {
fn into(self) -> Bytes {
self.0
impl From<ReasonPhrase> for Bytes {
fn from(rp: ReasonPhrase) -> Self {
rp.0
}
}

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

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

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

#[test]
fn basic_valid() {
const PHRASE: &'static [u8] = b"OK";
const PHRASE: &[u8] = b"OK";
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
}

#[test]
fn empty_valid() {
const PHRASE: &'static [u8] = b"";
const PHRASE: &[u8] = b"";
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
}

#[test]
fn obs_text_valid() {
const PHRASE: &'static [u8] = b"hyp\xe9r";
const PHRASE: &[u8] = b"hyp\xe9r";
assert_eq!(ReasonPhrase::from_static(PHRASE).as_bytes(), PHRASE);
assert_eq!(ReasonPhrase::try_from(PHRASE).unwrap().as_bytes(), PHRASE);
}

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

#[test]
#[should_panic]
Expand All @@ -206,7 +205,7 @@ mod tests {
assert!(ReasonPhrase::try_from(NEWLINE_PHRASE).is_err());
}

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

#[test]
#[should_panic]
Expand Down
7 changes: 2 additions & 5 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
}
}

return content_length
content_length
}

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

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

#[cfg(feature = "http2")]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![allow(clippy::module_inception)]
#![cfg_attr(test, deny(rust_2018_idioms))]
#![cfg_attr(all(test, feature = "full"), deny(unreachable_pub))]
#![cfg_attr(all(test, feature = "full"), deny(warnings))]
Expand Down
Loading

0 comments on commit 5907545

Please sign in to comment.