style(lib): address most clippy lints
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							0f13719873
						
					
				
				
					commit
					0eaf304644
				
			| @@ -13,7 +13,7 @@ use crate::common::{task, Pin, Poll, Unpin}; | ||||
| use crate::headers::connection_keep_alive; | ||||
| use crate::proto::{BodyLength, DecodedLength, MessageHead}; | ||||
|  | ||||
| const H2_PREFACE: &'static [u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"; | ||||
| const H2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"; | ||||
|  | ||||
| /// This handles a connection, which will have been established over an | ||||
| /// `AsyncRead + AsyncWrite` (like a socket), and will likely include multiple | ||||
| @@ -391,9 +391,8 @@ where | ||||
|  | ||||
|     pub fn can_write_head(&self) -> bool { | ||||
|         if !T::should_read_first() { | ||||
|             match self.state.reading { | ||||
|                 Reading::Closed => return false, | ||||
|                 _ => {} | ||||
|             if let Reading::Closed = self.state.reading { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         match self.state.writing { | ||||
| @@ -486,7 +485,7 @@ where | ||||
|         let outgoing_is_keep_alive = head | ||||
|             .headers | ||||
|             .get(CONNECTION) | ||||
|             .and_then(|value| Some(connection_keep_alive(value))) | ||||
|             .map(connection_keep_alive) | ||||
|             .unwrap_or(false); | ||||
|  | ||||
|         if !outgoing_is_keep_alive { | ||||
| @@ -510,20 +509,16 @@ where | ||||
|     // If we know the remote speaks an older version, we try to fix up any messages | ||||
|     // to work with our older peer. | ||||
|     fn enforce_version(&mut self, head: &mut MessageHead<T::Outgoing>) { | ||||
|         match self.state.version { | ||||
|             Version::HTTP_10 => { | ||||
|                 // Fixes response or connection when keep-alive header is not present | ||||
|                 self.fix_keep_alive(head); | ||||
|                 // If the remote only knows HTTP/1.0, we should force ourselves | ||||
|                 // to do only speak HTTP/1.0 as well. | ||||
|                 head.version = Version::HTTP_10; | ||||
|             } | ||||
|             _ => { | ||||
|                 // If the remote speaks HTTP/1.1, then it *should* be fine with | ||||
|                 // both HTTP/1.0 and HTTP/1.1 from us. So again, we just let | ||||
|                 // the user's headers be. | ||||
|             } | ||||
|         if let Version::HTTP_10 = self.state.version { | ||||
|             // Fixes response or connection when keep-alive header is not present | ||||
|             self.fix_keep_alive(head); | ||||
|             // If the remote only knows HTTP/1.0, we should force ourselves | ||||
|             // to do only speak HTTP/1.0 as well. | ||||
|             head.version = Version::HTTP_10; | ||||
|         } | ||||
|         // If the remote speaks HTTP/1.1, then it *should* be fine with | ||||
|         // both HTTP/1.0 and HTTP/1.1 from us. So again, we just let | ||||
|         // the user's headers be. | ||||
|     } | ||||
|  | ||||
|     pub fn write_body(&mut self, chunk: B) { | ||||
| @@ -603,21 +598,18 @@ where | ||||
|     // - Client: there is nothing we can do | ||||
|     // - Server: if Response hasn't been written yet, we can send a 4xx response | ||||
|     fn on_parse_error(&mut self, err: crate::Error) -> crate::Result<()> { | ||||
|         match self.state.writing { | ||||
|             Writing::Init => { | ||||
|                 if self.has_h2_prefix() { | ||||
|                     return Err(crate::Error::new_version_h2()); | ||||
|                 } | ||||
|                 if let Some(msg) = T::on_error(&err) { | ||||
|                     // Drop the cached headers so as to not trigger a debug | ||||
|                     // assert in `write_head`... | ||||
|                     self.state.cached_headers.take(); | ||||
|                     self.write_head(msg, None); | ||||
|                     self.state.error = Some(err); | ||||
|                     return Ok(()); | ||||
|                 } | ||||
|         if let Writing::Init = self.state.writing { | ||||
|             if self.has_h2_prefix() { | ||||
|                 return Err(crate::Error::new_version_h2()); | ||||
|             } | ||||
|             if let Some(msg) = T::on_error(&err) { | ||||
|                 // Drop the cached headers so as to not trigger a debug | ||||
|                 // assert in `write_head`... | ||||
|                 self.state.cached_headers.take(); | ||||
|                 self.write_head(msg, None); | ||||
|                 self.state.error = Some(err); | ||||
|                 return Ok(()); | ||||
|             } | ||||
|             _ => (), | ||||
|         } | ||||
|  | ||||
|         // fallback is pass the error back up | ||||
|   | ||||
| @@ -62,8 +62,8 @@ where | ||||
| { | ||||
|     pub fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self { | ||||
|         Dispatcher { | ||||
|             conn: conn, | ||||
|             dispatch: dispatch, | ||||
|             conn, | ||||
|             dispatch, | ||||
|             body_tx: None, | ||||
|             body_rx: Box::pin(None), | ||||
|             is_closing: false, | ||||
| @@ -443,7 +443,7 @@ where | ||||
|     pub fn new(service: S) -> Server<S, B> { | ||||
|         Server { | ||||
|             in_flight: Box::pin(None), | ||||
|             service: service, | ||||
|             service, | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -580,7 +580,7 @@ where | ||||
|                     *res.status_mut() = msg.subject; | ||||
|                     *res.headers_mut() = msg.headers; | ||||
|                     *res.version_mut() = msg.version; | ||||
|                     let _ = cb.send(Ok(res)); | ||||
|                     cb.send(Ok(res)); | ||||
|                     Ok(()) | ||||
|                 } else { | ||||
|                     // Getting here is likely a bug! An error should have happened | ||||
| @@ -591,7 +591,7 @@ where | ||||
|             } | ||||
|             Err(err) => { | ||||
|                 if let Some(cb) = self.callback.take() { | ||||
|                     let _ = cb.send(Err((err, None))); | ||||
|                     cb.send(Err((err, None))); | ||||
|                     Ok(()) | ||||
|                 } else if !self.rx_closed { | ||||
|                     self.rx.close(); | ||||
| @@ -599,7 +599,7 @@ where | ||||
|                         trace!("canceling queued request with connection error: {}", err); | ||||
|                         // in this case, the message was never even started, so it's safe to tell | ||||
|                         // the user that the request was completely canceled | ||||
|                         let _ = cb.send(Err((crate::Error::new_canceled().with(err), Some(req)))); | ||||
|                         cb.send(Err((crate::Error::new_canceled().with(err), Some(req)))); | ||||
|                         Ok(()) | ||||
|                     } else { | ||||
|                         Err(err) | ||||
|   | ||||
| @@ -49,7 +49,7 @@ enum BufKind<B> { | ||||
| impl Encoder { | ||||
|     fn new(kind: Kind) -> Encoder { | ||||
|         Encoder { | ||||
|             kind: kind, | ||||
|             kind, | ||||
|             is_last: false, | ||||
|         } | ||||
|     } | ||||
| @@ -307,7 +307,7 @@ impl fmt::Write for ChunkSize { | ||||
|     fn write_str(&mut self, num: &str) -> fmt::Result { | ||||
|         use std::io::Write; | ||||
|         (&mut self.bytes[self.len.into()..]) | ||||
|             .write(num.as_bytes()) | ||||
|             .write_all(num.as_bytes()) | ||||
|             .expect("&mut [u8].write() cannot error"); | ||||
|         self.len += num.len() as u8; // safe because bytes is never bigger than 256 | ||||
|         Ok(()) | ||||
|   | ||||
| @@ -57,7 +57,7 @@ where | ||||
|     pub fn new(io: T) -> Buffered<T, B> { | ||||
|         Buffered { | ||||
|             flush_pipeline: false, | ||||
|             io: io, | ||||
|             io, | ||||
|             read_blocked: false, | ||||
|             read_buf: BytesMut::with_capacity(0), | ||||
|             read_buf_strategy: ReadStrategy::default(), | ||||
| @@ -168,12 +168,9 @@ where | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             match ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? { | ||||
|                 0 => { | ||||
|                     trace!("parse eof"); | ||||
|                     return Poll::Ready(Err(crate::Error::new_incomplete())); | ||||
|                 } | ||||
|                 _ => {} | ||||
|             if ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? == 0 { | ||||
|                 trace!("parse eof"); | ||||
|                 return Poll::Ready(Err(crate::Error::new_incomplete())); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -216,9 +213,8 @@ where | ||||
|         } else if self.write_buf.remaining() == 0 { | ||||
|             Pin::new(&mut self.io).poll_flush(cx) | ||||
|         } else { | ||||
|             match self.write_buf.strategy { | ||||
|                 WriteStrategy::Flatten => return self.poll_flush_flattened(cx), | ||||
|                 _ => (), | ||||
|             if let WriteStrategy::Flatten = self.write_buf.strategy { | ||||
|                 return self.poll_flush_flattened(cx); | ||||
|             } | ||||
|             loop { | ||||
|                 let n = | ||||
| @@ -325,35 +321,33 @@ impl ReadStrategy { | ||||
|     } | ||||
|  | ||||
|     fn record(&mut self, bytes_read: usize) { | ||||
|         match *self { | ||||
|             ReadStrategy::Adaptive { | ||||
|                 ref mut decrease_now, | ||||
|                 ref mut next, | ||||
|                 max, | ||||
|                 .. | ||||
|             } => { | ||||
|                 if bytes_read >= *next { | ||||
|                     *next = cmp::min(incr_power_of_two(*next), max); | ||||
|                     *decrease_now = false; | ||||
|                 } else { | ||||
|                     let decr_to = prev_power_of_two(*next); | ||||
|                     if bytes_read < decr_to { | ||||
|                         if *decrease_now { | ||||
|                             *next = cmp::max(decr_to, INIT_BUFFER_SIZE); | ||||
|                             *decrease_now = false; | ||||
|                         } else { | ||||
|                             // Decreasing is a two "record" process. | ||||
|                             *decrease_now = true; | ||||
|                         } | ||||
|                     } else { | ||||
|                         // A read within the current range should cancel | ||||
|                         // a potential decrease, since we just saw proof | ||||
|                         // that we still need this size. | ||||
|         if let ReadStrategy::Adaptive { | ||||
|             ref mut decrease_now, | ||||
|             ref mut next, | ||||
|             max, | ||||
|             .. | ||||
|         } = *self | ||||
|         { | ||||
|             if bytes_read >= *next { | ||||
|                 *next = cmp::min(incr_power_of_two(*next), max); | ||||
|                 *decrease_now = false; | ||||
|             } else { | ||||
|                 let decr_to = prev_power_of_two(*next); | ||||
|                 if bytes_read < decr_to { | ||||
|                     if *decrease_now { | ||||
|                         *next = cmp::max(decr_to, INIT_BUFFER_SIZE); | ||||
|                         *decrease_now = false; | ||||
|                     } else { | ||||
|                         // Decreasing is a two "record" process. | ||||
|                         *decrease_now = true; | ||||
|                     } | ||||
|                 } else { | ||||
|                     // A read within the current range should cancel | ||||
|                     // a potential decrease, since we just saw proof | ||||
|                     // that we still need this size. | ||||
|                     *decrease_now = false; | ||||
|                 } | ||||
|             } | ||||
|             _ => (), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -384,10 +378,7 @@ pub struct Cursor<T> { | ||||
| impl<T: AsRef<[u8]>> Cursor<T> { | ||||
|     #[inline] | ||||
|     pub(crate) fn new(bytes: T) -> Cursor<T> { | ||||
|         Cursor { | ||||
|             bytes: bytes, | ||||
|             pos: 0, | ||||
|         } | ||||
|         Cursor { bytes, pos: 0 } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -527,14 +518,15 @@ impl<B: Buf> Buf for WriteBuf<B> { | ||||
|     #[inline] | ||||
|     fn advance(&mut self, cnt: usize) { | ||||
|         let hrem = self.headers.remaining(); | ||||
|         if hrem == cnt { | ||||
|             self.headers.reset(); | ||||
|         } else if hrem > cnt { | ||||
|             self.headers.advance(cnt); | ||||
|         } else { | ||||
|             let qcnt = cnt - hrem; | ||||
|             self.headers.reset(); | ||||
|             self.queue.advance(qcnt); | ||||
|  | ||||
|         match hrem.cmp(&cnt) { | ||||
|             cmp::Ordering::Equal => self.headers.reset(), | ||||
|             cmp::Ordering::Greater => self.headers.advance(cnt), | ||||
|             cmp::Ordering::Less => { | ||||
|                 let qcnt = cnt - hrem; | ||||
|                 self.headers.reset(); | ||||
|                 self.queue.advance(qcnt); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -558,7 +550,7 @@ impl<'a, B: Buf> WriteBufAuto<'a, B> { | ||||
|         WriteBufAuto { | ||||
|             bytes_called: Cell::new(false), | ||||
|             bytes_vec_called: Cell::new(false), | ||||
|             inner: inner, | ||||
|             inner, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -472,10 +472,8 @@ impl Http1Transaction for Server { | ||||
|                     continue 'headers; | ||||
|                 } | ||||
|                 header::CONNECTION => { | ||||
|                     if !is_last { | ||||
|                         if headers::connection_close(&value) { | ||||
|                             is_last = true; | ||||
|                         } | ||||
|                     if !is_last && headers::connection_close(&value) { | ||||
|                         is_last = true; | ||||
|                     } | ||||
|                     if !is_name_written { | ||||
|                         is_name_written = true; | ||||
| @@ -594,9 +592,8 @@ impl Server { | ||||
|     } | ||||
|  | ||||
|     fn can_chunked(method: &Option<Method>, status: StatusCode) -> bool { | ||||
|         if method == &Some(Method::HEAD) { | ||||
|             false | ||||
|         } else if method == &Some(Method::CONNECT) && status.is_success() { | ||||
|         if method == &Some(Method::HEAD) || method == &Some(Method::CONNECT) && status.is_success() | ||||
|         { | ||||
|             false | ||||
|         } else { | ||||
|             match status { | ||||
| @@ -766,7 +763,7 @@ impl Client { | ||||
|             101 => { | ||||
|                 return Ok(Some((DecodedLength::ZERO, true))); | ||||
|             } | ||||
|             100..=199 => { | ||||
|             100 | 102..=199 => { | ||||
|                 trace!("ignoring informational response: {}", inc.subject.as_u16()); | ||||
|                 return Ok(None); | ||||
|             } | ||||
|   | ||||
| @@ -44,9 +44,10 @@ where | ||||
|     let (conn_drop_ref, rx) = mpsc::channel(1); | ||||
|     let (cancel_tx, conn_eof) = oneshot::channel(); | ||||
|  | ||||
|     let conn_drop_rx = rx.into_future().map(|(item, _rx)| match item { | ||||
|         Some(never) => match never {}, | ||||
|         None => (), | ||||
|     let conn_drop_rx = rx.into_future().map(|(item, _rx)| { | ||||
|         if let Some(never) = item { | ||||
|             match never {} | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     let conn = conn.map_err(|e| debug!("connection error: {}", e)); | ||||
|   | ||||
| @@ -47,10 +47,8 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) { | ||||
|             warn!("TE headers not set to \"trailers\" are illegal in HTTP/2 requests"); | ||||
|             headers.remove(TE); | ||||
|         } | ||||
|     } else { | ||||
|         if headers.remove(TE).is_some() { | ||||
|             warn!("TE headers illegal in HTTP/2 responses"); | ||||
|         } | ||||
|     } else if headers.remove(TE).is_some() { | ||||
|         warn!("TE headers illegal in HTTP/2 responses"); | ||||
|     } | ||||
|  | ||||
|     if let Some(header) = headers.remove(CONNECTION) { | ||||
| @@ -94,7 +92,7 @@ where | ||||
|         PipeToSendStream { | ||||
|             body_tx: tx, | ||||
|             data_done: false, | ||||
|             stream: stream, | ||||
|             stream, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -125,17 +123,15 @@ where | ||||
|                             None => return Poll::Ready(Err(crate::Error::new_canceled())), | ||||
|                         } | ||||
|                     } | ||||
|                 } else { | ||||
|                     if let Poll::Ready(reason) = me | ||||
|                         .body_tx | ||||
|                         .poll_reset(cx) | ||||
|                         .map_err(crate::Error::new_body_write)? | ||||
|                     { | ||||
|                         debug!("stream received RST_STREAM: {:?}", reason); | ||||
|                         return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from( | ||||
|                             reason, | ||||
|                         )))); | ||||
|                     } | ||||
|                 } else if let Poll::Ready(reason) = me | ||||
|                     .body_tx | ||||
|                     .poll_reset(cx) | ||||
|                     .map_err(crate::Error::new_body_write)? | ||||
|                 { | ||||
|                     debug!("stream received RST_STREAM: {:?}", reason); | ||||
|                     return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from( | ||||
|                         reason, | ||||
|                     )))); | ||||
|                 } | ||||
|  | ||||
|                 match ready!(me.stream.as_mut().poll_data(cx)) { | ||||
| @@ -172,7 +168,7 @@ where | ||||
|                 if let Poll::Ready(reason) = me | ||||
|                     .body_tx | ||||
|                     .poll_reset(cx) | ||||
|                     .map_err(|e| crate::Error::new_body_write(e))? | ||||
|                     .map_err(crate::Error::new_body_write)? | ||||
|                 { | ||||
|                     debug!("stream received RST_STREAM: {:?}", reason); | ||||
|                     return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from( | ||||
| @@ -238,6 +234,8 @@ impl<B: Buf> Buf for SendBuf<B> { | ||||
|  | ||||
|     #[inline] | ||||
|     fn advance(&mut self, cnt: usize) { | ||||
|         self.0.as_mut().map(|b| b.advance(cnt)); | ||||
|         if let Some(b) = self.0.as_mut() { | ||||
|             b.advance(cnt) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -259,10 +259,8 @@ where | ||||
|                         Poll::Pending => { | ||||
|                             // Response is not yet ready, so we want to check if the client has sent a | ||||
|                             // RST_STREAM frame which would cancel the current request. | ||||
|                             if let Poll::Ready(reason) = me | ||||
|                                 .reply | ||||
|                                 .poll_reset(cx) | ||||
|                                 .map_err(|e| crate::Error::new_h2(e))? | ||||
|                             if let Poll::Ready(reason) = | ||||
|                                 me.reply.poll_reset(cx).map_err(crate::Error::new_h2)? | ||||
|                             { | ||||
|                                 debug!("stream received RST_STREAM: {:?}", reason); | ||||
|                                 return Poll::Ready(Err(crate::Error::new_h2(reason.into()))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user