style(lib): address clippy code style warnings
* Remove unnecessary return statements. * Combine identical `match` arms. * Collapse nested conditional. * Use `assert_ne` where applicable. * Lifetime elision.
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							5d19ef88b4
						
					
				
				
					commit
					1059eb349a
				
			| @@ -103,7 +103,6 @@ impl Service for HttpConnector { | |||||||
|         let port = match uri.port() { |         let port = match uri.port() { | ||||||
|             Some(port) => port, |             Some(port) => port, | ||||||
|             None => match uri.scheme() { |             None => match uri.scheme() { | ||||||
|                 Some("http") => 80, |  | ||||||
|                 Some("https") => 443, |                 Some("https") => 443, | ||||||
|                 _ => 80, |                 _ => 80, | ||||||
|             }, |             }, | ||||||
|   | |||||||
| @@ -76,7 +76,7 @@ impl Client<HttpConnector, http::Body> { | |||||||
| impl<C, B> Client<C, B> { | impl<C, B> Client<C, B> { | ||||||
|     /// Return a reference to a handle to the event loop this Client is associated with. |     /// Return a reference to a handle to the event loop this Client is associated with. | ||||||
|     #[inline] |     #[inline] | ||||||
|     pub fn handle<'a>(&'a self) -> &'a Handle { |     pub fn handle(&self) -> &Handle { | ||||||
|         &self.handle |         &self.handle | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -128,11 +128,11 @@ impl From<FromUtf8Error> for Error { | |||||||
| impl From<httparse::Error> for Error { | impl From<httparse::Error> for Error { | ||||||
|     fn from(err: httparse::Error) -> Error { |     fn from(err: httparse::Error) -> Error { | ||||||
|         match err { |         match err { | ||||||
|             httparse::Error::HeaderName => Header, |             httparse::Error::HeaderName | | ||||||
|             httparse::Error::HeaderValue => Header, |             httparse::Error::HeaderValue | | ||||||
|             httparse::Error::NewLine => Header, |             httparse::Error::NewLine | | ||||||
|             httparse::Error::Status => Status, |  | ||||||
|             httparse::Error::Token => Header, |             httparse::Error::Token => Header, | ||||||
|  |             httparse::Error::Status => Status, | ||||||
|             httparse::Error::TooManyHeaders => TooLarge, |             httparse::Error::TooManyHeaders => TooLarge, | ||||||
|             httparse::Error::Version => Version, |             httparse::Error::Version => Version, | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -222,16 +222,16 @@ mod tests { | |||||||
|  |  | ||||||
|         // left has more params |         // left has more params | ||||||
|         cookie.append("foo", "bar"); |         cookie.append("foo", "bar"); | ||||||
|         assert!(cookie != cookie2); |         assert_ne!(cookie, cookie2); | ||||||
|  |  | ||||||
|         // same len, different params |         // same len, different params | ||||||
|         cookie2.append("bar", "foo"); |         cookie2.append("bar", "foo"); | ||||||
|         assert!(cookie != cookie2); |         assert_ne!(cookie, cookie2); | ||||||
|  |  | ||||||
|  |  | ||||||
|         // right has more params, and matching KV |         // right has more params, and matching KV | ||||||
|         cookie2.append("foo", "bar"); |         cookie2.append("foo", "bar"); | ||||||
|         assert!(cookie != cookie2); |         assert_ne!(cookie, cookie2); | ||||||
|  |  | ||||||
|         // same params, different order |         // same params, different order | ||||||
|         cookie.append("bar", "foo"); |         cookie.append("bar", "foo"); | ||||||
|   | |||||||
| @@ -505,14 +505,13 @@ impl FromStr for Link { | |||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.3 |                     // https://tools.ietf.org/html/rfc5988#section-5.3 | ||||||
|                     if link_header.rel.is_none() { |                     if link_header.rel.is_none() { | ||||||
|                         link_header.rel = match link_param_split.next() { |                         link_header.rel = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => { |                             Some(s) => { | ||||||
|                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) |                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) | ||||||
|                                     .split(' ') |                                     .split(' ') | ||||||
|                                     .map(|t| t.trim().parse()) |                                     .map(|t| t.trim().parse()) | ||||||
|                                     .collect::<Result<Vec<RelationType>, _>>() |                                     .collect::<Result<Vec<RelationType>, _>>() | ||||||
|                                     .or_else(|_| return Err(::Error::Header)) |                                     .or_else(|_| Err(::Error::Header)) | ||||||
|                                     .ok() |                                     .ok() | ||||||
|                             }, |                             }, | ||||||
|                         }; |                         }; | ||||||
| @@ -521,8 +520,7 @@ impl FromStr for Link { | |||||||
|                     // Parse the `Context IRI`. |                     // Parse the `Context IRI`. | ||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.2 |                     // https://tools.ietf.org/html/rfc5988#section-5.2 | ||||||
|                     link_header.anchor = match link_param_split.next() { |                     link_header.anchor = match link_param_split.next() { | ||||||
|                         None => return Err(::Error::Header), |                         None | Some("") => return Err(::Error::Header), | ||||||
|                         Some("") =>  return Err(::Error::Header), |  | ||||||
|                         Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { |                         Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { | ||||||
|                             Err(_) => return Err(::Error::Header), |                             Err(_) => return Err(::Error::Header), | ||||||
|                             Ok(a) => Some(String::from(a)), |                             Ok(a) => Some(String::from(a)), | ||||||
| @@ -533,14 +531,13 @@ impl FromStr for Link { | |||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.3 |                     // https://tools.ietf.org/html/rfc5988#section-5.3 | ||||||
|                     if link_header.rev.is_none() { |                     if link_header.rev.is_none() { | ||||||
|                         link_header.rev = match link_param_split.next() { |                         link_header.rev = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => { |                             Some(s) => { | ||||||
|                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) |                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) | ||||||
|                                     .split(' ') |                                     .split(' ') | ||||||
|                                     .map(|t| t.trim().parse()) |                                     .map(|t| t.trim().parse()) | ||||||
|                                     .collect::<Result<Vec<RelationType>, _>>() |                                     .collect::<Result<Vec<RelationType>, _>>() | ||||||
|                                     .or_else(|_| return Err(::Error::Header)) |                                     .or_else(|_| Err(::Error::Header)) | ||||||
|                                     .ok() |                                     .ok() | ||||||
|                             }, |                             }, | ||||||
|                         } |                         } | ||||||
| @@ -552,8 +549,7 @@ impl FromStr for Link { | |||||||
|  |  | ||||||
|                     v.push( |                     v.push( | ||||||
|                         match link_param_split.next() { |                         match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => match s.trim().parse() { |                             Some(s) => match s.trim().parse() { | ||||||
|                                 Err(_) => return Err(::Error::Header), |                                 Err(_) => return Err(::Error::Header), | ||||||
|                                 Ok(t) => t, |                                 Ok(t) => t, | ||||||
| @@ -567,14 +563,13 @@ impl FromStr for Link { | |||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.4 |                     // https://tools.ietf.org/html/rfc5988#section-5.4 | ||||||
|                     if link_header.media_desc.is_none() { |                     if link_header.media_desc.is_none() { | ||||||
|                         link_header.media_desc = match link_param_split.next() { |                         link_header.media_desc = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => { |                             Some(s) => { | ||||||
|                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) |                                 s.trim_matches(|c: char| c == '"' || c.is_whitespace()) | ||||||
|                                     .split(',') |                                     .split(',') | ||||||
|                                     .map(|t| t.trim().parse()) |                                     .map(|t| t.trim().parse()) | ||||||
|                                     .collect::<Result<Vec<MediaDesc>, _>>() |                                     .collect::<Result<Vec<MediaDesc>, _>>() | ||||||
|                                     .or_else(|_| return Err(::Error::Header)) |                                     .or_else(|_| Err(::Error::Header)) | ||||||
|                                     .ok() |                                     .ok() | ||||||
|                             }, |                             }, | ||||||
|                         }; |                         }; | ||||||
| @@ -584,8 +579,7 @@ impl FromStr for Link { | |||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.4 |                     // https://tools.ietf.org/html/rfc5988#section-5.4 | ||||||
|                     if link_header.title.is_none() { |                     if link_header.title.is_none() { | ||||||
|                         link_header.title = match link_param_split.next() { |                         link_header.title = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { |                             Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { | ||||||
|                                 Err(_) => return Err(::Error::Header), |                                 Err(_) => return Err(::Error::Header), | ||||||
|                                 Ok(t) => Some(String::from(t)), |                                 Ok(t) => Some(String::from(t)), | ||||||
| @@ -600,8 +594,7 @@ impl FromStr for Link { | |||||||
|                     //       https://tools.ietf.org/html/rfc5987#section-3.2.1 |                     //       https://tools.ietf.org/html/rfc5987#section-3.2.1 | ||||||
|                     if link_header.title_star.is_none() { |                     if link_header.title_star.is_none() { | ||||||
|                         link_header.title_star = match link_param_split.next() { |                         link_header.title_star = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => Some(String::from(s.trim())), |                             Some(s) => Some(String::from(s.trim())), | ||||||
|                         }; |                         }; | ||||||
|                     } |                     } | ||||||
| @@ -610,8 +603,7 @@ impl FromStr for Link { | |||||||
|                     // https://tools.ietf.org/html/rfc5988#section-5.4 |                     // https://tools.ietf.org/html/rfc5988#section-5.4 | ||||||
|                     if link_header.media_type.is_none() { |                     if link_header.media_type.is_none() { | ||||||
|                         link_header.media_type = match link_param_split.next() { |                         link_header.media_type = match link_param_split.next() { | ||||||
|                             None => return Err(::Error::Header), |                             None | Some("") => return Err(::Error::Header), | ||||||
|                             Some("") =>  return Err(::Error::Header), |  | ||||||
|                             Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { |                             Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) { | ||||||
|                                 Err(_) => return Err(::Error::Header), |                                 Err(_) => return Err(::Error::Header), | ||||||
|                                 Ok(t) => match t.parse() { |                                 Ok(t) => match t.parse() { | ||||||
|   | |||||||
| @@ -104,8 +104,8 @@ impl FromStr for StrictTransportSecurity { | |||||||
|             .fold(Ok((None, None)), |res, dir| match (res, dir) { |             .fold(Ok((None, None)), |res, dir| match (res, dir) { | ||||||
|                 (Ok((None, sub)), Ok(Directive::MaxAge(age))) => Ok((Some(age), sub)), |                 (Ok((None, sub)), Ok(Directive::MaxAge(age))) => Ok((Some(age), sub)), | ||||||
|                 (Ok((age, None)), Ok(Directive::IncludeSubdomains)) => Ok((age, Some(()))), |                 (Ok((age, None)), Ok(Directive::IncludeSubdomains)) => Ok((age, Some(()))), | ||||||
|                 (Ok((Some(_), _)), Ok(Directive::MaxAge(_))) => Err(::Error::Header), |                 (Ok((Some(_), _)), Ok(Directive::MaxAge(_))) | | ||||||
|                 (Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) => Err(::Error::Header), |                 (Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) | | ||||||
|                 (_, Err(_)) => Err(::Error::Header), |                 (_, Err(_)) => Err(::Error::Header), | ||||||
|                 (res, _) => res |                 (res, _) => res | ||||||
|             }) |             }) | ||||||
|   | |||||||
| @@ -109,7 +109,7 @@ impl<V: ?Sized + Any + 'static> PtrMapCell<V> { | |||||||
|                 let one = mem::replace(map, PtrMap::Empty); |                 let one = mem::replace(map, PtrMap::Empty); | ||||||
|                 match one { |                 match one { | ||||||
|                     PtrMap::One(id, one) => { |                     PtrMap::One(id, one) => { | ||||||
|                         debug_assert!(id != key); |                         debug_assert_ne!(id, key); | ||||||
|                         let mut hm = HashMap::with_capacity(2); |                         let mut hm = HashMap::with_capacity(2); | ||||||
|                         hm.insert(id, one); |                         hm.insert(id, one); | ||||||
|                         hm.insert(key, val); |                         hm.insert(key, val); | ||||||
|   | |||||||
| @@ -918,7 +918,7 @@ mod tests { | |||||||
|  |  | ||||||
|         headers1.set(ContentLength(11)); |         headers1.set(ContentLength(11)); | ||||||
|         headers2.set(Host::new("foo.bar", None)); |         headers2.set(Host::new("foo.bar", None)); | ||||||
|         assert!(headers1 != headers2); |         assert_ne!(headers1, headers2); | ||||||
|  |  | ||||||
|         headers1 = Headers::new(); |         headers1 = Headers::new(); | ||||||
|         headers2 = Headers::new(); |         headers2 = Headers::new(); | ||||||
| @@ -928,7 +928,7 @@ mod tests { | |||||||
|         assert_eq!(headers1, headers2); |         assert_eq!(headers1, headers2); | ||||||
|  |  | ||||||
|         headers1.set(ContentLength(10)); |         headers1.set(ContentLength(10)); | ||||||
|         assert!(headers1 != headers2); |         assert_ne!(headers1, headers2); | ||||||
|  |  | ||||||
|         headers1 = Headers::new(); |         headers1 = Headers::new(); | ||||||
|         headers2 = Headers::new(); |         headers2 = Headers::new(); | ||||||
| @@ -936,7 +936,7 @@ mod tests { | |||||||
|         headers1.set(Host::new("foo.bar", None)); |         headers1.set(Host::new("foo.bar", None)); | ||||||
|         headers1.set(ContentLength(11)); |         headers1.set(ContentLength(11)); | ||||||
|         headers2.set(ContentLength(11)); |         headers2.set(ContentLength(11)); | ||||||
|         assert!(headers1 != headers2); |         assert_ne!(headers1, headers2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     #[cfg(feature = "nightly")] |     #[cfg(feature = "nightly")] | ||||||
|   | |||||||
| @@ -231,7 +231,7 @@ impl ::std::ops::Index<usize> for Raw { | |||||||
|  |  | ||||||
| macro_rules! literals { | macro_rules! literals { | ||||||
|     ($($len:expr => $($value:expr),+;)+) => ( |     ($($len:expr => $($value:expr),+;)+) => ( | ||||||
|         fn maybe_literal<'a>(s: Cow<'a, [u8]>) -> Bytes { |         fn maybe_literal(s: Cow<[u8]>) -> Bytes { | ||||||
|             match s.len() { |             match s.len() { | ||||||
|                 $($len => { |                 $($len => { | ||||||
|                     $( |                     $( | ||||||
|   | |||||||
| @@ -119,12 +119,12 @@ where I: AsyncRead + AsyncWrite, | |||||||
|                     (true, Reading::Body(decoder)) |                     (true, Reading::Body(decoder)) | ||||||
|                 }; |                 }; | ||||||
|                 self.state.reading = reading; |                 self.state.reading = reading; | ||||||
|                 return Ok(Async::Ready(Some(Frame::Message { message: head, body: body }))); |                 Ok(Async::Ready(Some(Frame::Message { message: head, body: body }))) | ||||||
|             }, |             }, | ||||||
|             _ => { |             _ => { | ||||||
|                 error!("unimplemented HTTP Version = {:?}", version); |                 error!("unimplemented HTTP Version = {:?}", version); | ||||||
|                 self.state.close_read(); |                 self.state.close_read(); | ||||||
|                 return Ok(Async::Ready(Some(Frame::Error { error: ::Error::Version }))); |                 Ok(Async::Ready(Some(Frame::Error { error: ::Error::Version }))) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -139,13 +139,11 @@ where I: AsyncRead + AsyncWrite, | |||||||
|                 let slice = try_nb!(decoder.decode(&mut self.io)); |                 let slice = try_nb!(decoder.decode(&mut self.io)); | ||||||
|                 if !slice.is_empty() { |                 if !slice.is_empty() { | ||||||
|                     return Ok(Async::Ready(Some(http::Chunk::from(slice)))); |                     return Ok(Async::Ready(Some(http::Chunk::from(slice)))); | ||||||
|                 } else { |                 } else if decoder.is_eof() { | ||||||
|                     if decoder.is_eof() { |  | ||||||
|                     (Reading::KeepAlive, Ok(Async::Ready(None))) |                     (Reading::KeepAlive, Ok(Async::Ready(None))) | ||||||
|                 } else { |                 } else { | ||||||
|                     (Reading::Closed, Ok(Async::Ready(None))) |                     (Reading::Closed, Ok(Async::Ready(None))) | ||||||
|                 } |                 } | ||||||
|                 } |  | ||||||
|  |  | ||||||
|             }, |             }, | ||||||
|             Reading::Init | Reading::KeepAlive | Reading::Closed => unreachable!() |             Reading::Init | Reading::KeepAlive | Reading::Closed => unreachable!() | ||||||
|   | |||||||
| @@ -198,7 +198,7 @@ impl ChunkedState { | |||||||
|             // LWS can follow the chunk size, but no more digits can come |             // LWS can follow the chunk size, but no more digits can come | ||||||
|             b'\t' | b' ' => Ok(ChunkedState::SizeLws), |             b'\t' | b' ' => Ok(ChunkedState::SizeLws), | ||||||
|             b';' => Ok(ChunkedState::Extension), |             b';' => Ok(ChunkedState::Extension), | ||||||
|             b'\r' => return Ok(ChunkedState::SizeLf), |             b'\r' => Ok(ChunkedState::SizeLf), | ||||||
|             _ => { |             _ => { | ||||||
|                 Err(io::Error::new(io::ErrorKind::InvalidInput, |                 Err(io::Error::new(io::ErrorKind::InvalidInput, | ||||||
|                                    "Invalid chunk size linear white space")) |                                    "Invalid chunk size linear white space")) | ||||||
| @@ -208,8 +208,8 @@ impl ChunkedState { | |||||||
|     fn read_extension<R: MemRead>(rdr: &mut R) -> io::Result<ChunkedState> { |     fn read_extension<R: MemRead>(rdr: &mut R) -> io::Result<ChunkedState> { | ||||||
|         trace!("read_extension"); |         trace!("read_extension"); | ||||||
|         match byte!(rdr) { |         match byte!(rdr) { | ||||||
|             b'\r' => return Ok(ChunkedState::SizeLf), |             b'\r' => Ok(ChunkedState::SizeLf), | ||||||
|             _ => return Ok(ChunkedState::Extension), // no supported extensions |             _ => Ok(ChunkedState::Extension), // no supported extensions | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     fn read_size_lf<R: MemRead>(rdr: &mut R, size: &mut u64) -> io::Result<ChunkedState> { |     fn read_size_lf<R: MemRead>(rdr: &mut R, size: &mut u64) -> io::Result<ChunkedState> { | ||||||
|   | |||||||
| @@ -426,7 +426,7 @@ impl<S, B> Server<S, B> | |||||||
|         let wait = WaitUntilZero { info: info.clone() }; |         let wait = WaitUntilZero { info: info.clone() }; | ||||||
|         match core.run(wait.select(timeout)) { |         match core.run(wait.select(timeout)) { | ||||||
|             Ok(_) => Ok(()), |             Ok(_) => Ok(()), | ||||||
|             Err((e, _)) => return Err(e.into()) |             Err((e, _)) => Err(e.into()) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -648,11 +648,11 @@ impl StatusClass { | |||||||
|     pub fn default_code(&self) -> StatusCode { |     pub fn default_code(&self) -> StatusCode { | ||||||
|         match *self { |         match *self { | ||||||
|             StatusClass::Informational => StatusCode::Continue, |             StatusClass::Informational => StatusCode::Continue, | ||||||
|             StatusClass::Success => StatusCode::Ok, |             StatusClass::Success | | ||||||
|  |             StatusClass::NoClass => StatusCode::Ok, | ||||||
|             StatusClass::Redirection => StatusCode::MultipleChoices, |             StatusClass::Redirection => StatusCode::MultipleChoices, | ||||||
|             StatusClass::ClientError => StatusCode::BadRequest, |             StatusClass::ClientError => StatusCode::BadRequest, | ||||||
|             StatusClass::ServerError => StatusCode::InternalServerError, |             StatusClass::ServerError => StatusCode::InternalServerError, | ||||||
|             StatusClass::NoClass => StatusCode::Ok, |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ impl Uri { | |||||||
|             }) |             }) | ||||||
|         } else if (s.contains("/") || s.contains("?")) && !s.contains("://") { |         } else if (s.contains("/") || s.contains("?")) && !s.contains("://") { | ||||||
|             // last possibility is authority-form, above are illegal characters |             // last possibility is authority-form, above are illegal characters | ||||||
|             return Err(UriError(ErrorKind::Malformed)) |             Err(UriError(ErrorKind::Malformed)) | ||||||
|         } else { |         } else { | ||||||
|             // authority-form |             // authority-form | ||||||
|             let len = s.len(); |             let len = s.len(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user