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