From c2540cc59b8967291cf8166bcfb256a5091420a0 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 29 Oct 2018 16:39:46 -0700 Subject: [PATCH] clippy warnings --- src/client/request.rs | 3 ++- src/config.rs | 4 +++- src/h1/client.rs | 8 ++++++-- src/h1/codec.rs | 8 ++++++-- src/h1/decoder.rs | 16 ++++++++++++---- src/h1/dispatcher.rs | 34 +++++++++++++++++----------------- src/h1/encoder.rs | 4 +++- src/h1/service.rs | 2 +- src/response.rs | 12 ++++++++---- src/service.rs | 6 ++---- src/ws/client/service.rs | 4 ++-- src/ws/frame.rs | 14 +++++++++++--- src/ws/mask.rs | 9 +++------ 13 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/client/request.rs b/src/client/request.rs index bf82927e..8c794933 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -536,7 +536,8 @@ impl ClientRequestBuilder { #[inline] fn parts<'a>( - parts: &'a mut Option, err: &Option, + parts: &'a mut Option, + err: &Option, ) -> Option<&'a mut ClientRequest> { if err.is_some() { return None; diff --git a/src/config.rs b/src/config.rs index ff22ea48..833bca7f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,7 +66,9 @@ impl Default for ServiceConfig { impl ServiceConfig { /// Create instance of `ServiceConfig` pub(crate) fn new( - keep_alive: KeepAlive, client_timeout: u64, client_disconnect: u64, + keep_alive: KeepAlive, + client_timeout: u64, + client_disconnect: u64, ) -> ServiceConfig { let (keep_alive, ka_enabled) = match keep_alive { KeepAlive::Timeout(val) => (val as u64, true), diff --git a/src/h1/client.rs b/src/h1/client.rs index 8ec1f0ae..b55af185 100644 --- a/src/h1/client.rs +++ b/src/h1/client.rs @@ -102,7 +102,9 @@ impl ClientCodec { } fn encode_response( - &mut self, msg: ClientRequest, buffer: &mut BytesMut, + &mut self, + msg: ClientRequest, + buffer: &mut BytesMut, ) -> io::Result<()> { // Connection upgrade if msg.upgrade() { @@ -187,7 +189,9 @@ impl Encoder for ClientCodec { type Error = io::Error; fn encode( - &mut self, item: Self::Item, dst: &mut BytesMut, + &mut self, + item: Self::Item, + dst: &mut BytesMut, ) -> Result<(), Self::Error> { match item { Message::Item(res) => { diff --git a/src/h1/codec.rs b/src/h1/codec.rs index 1484d56b..7cc516d6 100644 --- a/src/h1/codec.rs +++ b/src/h1/codec.rs @@ -103,7 +103,9 @@ impl Codec { } fn encode_response( - &mut self, mut msg: Response, buffer: &mut BytesMut, + &mut self, + mut msg: Response, + buffer: &mut BytesMut, ) -> io::Result<()> { let ka = self.flags.contains(Flags::KEEPALIVE_ENABLED) && msg .keep_alive() @@ -277,7 +279,9 @@ impl Encoder for Codec { type Error = io::Error; fn encode( - &mut self, item: Self::Item, dst: &mut BytesMut, + &mut self, + item: Self::Item, + dst: &mut BytesMut, ) -> Result<(), Self::Error> { match item { Message::Item(res) => { diff --git a/src/h1/decoder.rs b/src/h1/decoder.rs index 2c1e6c1f..e8d07af1 100644 --- a/src/h1/decoder.rs +++ b/src/h1/decoder.rs @@ -334,7 +334,9 @@ pub(crate) struct HeaderIndex { impl HeaderIndex { pub(crate) fn record( - bytes: &[u8], headers: &[httparse::Header], indices: &mut [HeaderIndex], + bytes: &[u8], + headers: &[httparse::Header], + indices: &mut [HeaderIndex], ) { let bytes_ptr = bytes.as_ptr() as usize; for (header, indices) in headers.iter().zip(indices.iter_mut()) { @@ -491,7 +493,10 @@ macro_rules! byte ( impl ChunkedState { fn step( - &self, body: &mut BytesMut, size: &mut u64, buf: &mut Option, + &self, + body: &mut BytesMut, + size: &mut u64, + buf: &mut Option, ) -> Poll { use self::ChunkedState::*; match *self { @@ -554,7 +559,8 @@ impl ChunkedState { } } fn read_size_lf( - rdr: &mut BytesMut, size: &mut u64, + rdr: &mut BytesMut, + size: &mut u64, ) -> Poll { match byte!(rdr) { b'\n' if *size > 0 => Ok(Async::Ready(ChunkedState::Body)), @@ -567,7 +573,9 @@ impl ChunkedState { } fn read_body( - rdr: &mut BytesMut, rem: &mut u64, buf: &mut Option, + rdr: &mut BytesMut, + rem: &mut u64, + buf: &mut Option, ) -> Poll { trace!("Chunked read, remaining={:?}", rem); diff --git a/src/h1/dispatcher.rs b/src/h1/dispatcher.rs index a7f97e8c..513c1961 100644 --- a/src/h1/dispatcher.rs +++ b/src/h1/dispatcher.rs @@ -90,7 +90,10 @@ where /// Create http/1 dispatcher with slow request timeout. pub fn with_timeout( - stream: T, config: ServiceConfig, timeout: Option, service: S, + stream: T, + config: ServiceConfig, + timeout: Option, + service: S, ) -> Self { let keepalive = config.keep_alive_enabled(); let flags = if keepalive { @@ -173,19 +176,15 @@ where // process loop { let state = match self.state { - State::None => loop { - break if let Some(msg) = self.messages.pop_front() { - match msg { - DispatcherMessage::Item(req) => { - Some(self.handle_request(req)?) - } - DispatcherMessage::Error(res) => Some(State::SendResponse( - Some((Message::Item(res), Body::Empty)), - )), - } - } else { - None - }; + State::None => if let Some(msg) = self.messages.pop_front() { + match msg { + DispatcherMessage::Item(req) => Some(self.handle_request(req)?), + DispatcherMessage::Error(res) => Some(State::SendResponse( + Some((Message::Item(res), Body::Empty)), + )), + } + } else { + None }, // call inner service State::ServiceCall(ref mut fut) => { @@ -255,7 +254,7 @@ where .framed .as_mut() .unwrap() - .start_send(Message::Chunk(Some(item.into()))) + .start_send(Message::Chunk(Some(item))) { Ok(AsyncSink::Ready) => { self.flags.remove(Flags::FLUSHED); @@ -299,7 +298,8 @@ where } fn handle_request( - &mut self, req: Request, + &mut self, + req: Request, ) -> Result, DispatchError> { let mut task = self.service.call(req); match task.poll().map_err(DispatchError::Service)? { @@ -324,7 +324,7 @@ where } let mut updated = false; - 'outer: loop { + loop { match self.framed.as_mut().unwrap().poll() { Ok(Async::Ready(Some(msg))) => { updated = true; diff --git a/src/h1/encoder.rs b/src/h1/encoder.rs index 63ba05d0..fc0a3a1b 100644 --- a/src/h1/encoder.rs +++ b/src/h1/encoder.rs @@ -107,7 +107,9 @@ impl ResponseEncoder { } fn streaming_encoding( - &mut self, version: Version, resp: &mut Response, + &mut self, + version: Version, + resp: &mut Response, ) -> TransferEncoding { match resp.chunked() { Some(true) => { diff --git a/src/h1/service.rs b/src/h1/service.rs index d691ae75..7e5e8c5f 100644 --- a/src/h1/service.rs +++ b/src/h1/service.rs @@ -253,7 +253,7 @@ where type Future = Dispatcher; fn poll_ready(&mut self) -> Poll<(), Self::Error> { - self.srv.poll_ready().map_err(|e| DispatchError::Service(e)) + self.srv.poll_ready().map_err(DispatchError::Service) } fn call(&mut self, req: Self::Request) -> Self::Future { diff --git a/src/response.rs b/src/response.rs index e834748e..1901443f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -690,9 +690,10 @@ impl ResponseBuilder { } #[inline] -#[cfg_attr(feature = "cargo-clippy", allow(clippy::borrowed_box))] +#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))] fn parts<'a>( - parts: &'a mut Option>, err: &Option, + parts: &'a mut Option>, + err: &Option, ) -> Option<&'a mut Box> { if err.is_some() { return None; @@ -871,7 +872,8 @@ impl ResponsePool { #[inline] pub fn get_builder( - pool: &'static ResponsePool, status: StatusCode, + pool: &'static ResponsePool, + status: StatusCode, ) -> ResponseBuilder { if let Some(mut msg) = pool.0.borrow_mut().pop_front() { msg.status = status; @@ -894,7 +896,9 @@ impl ResponsePool { #[inline] pub fn get_response( - pool: &'static ResponsePool, status: StatusCode, body: Body, + pool: &'static ResponsePool, + status: StatusCode, + body: Body, ) -> Response { if let Some(mut msg) = pool.0.borrow_mut().pop_front() { msg.status = status; diff --git a/src/service.rs b/src/service.rs index a2852914..16dcf8c6 100644 --- a/src/service.rs +++ b/src/service.rs @@ -97,12 +97,10 @@ where } match self.framed.as_mut().unwrap().poll_complete() { Ok(Async::Ready(_)) => { - return Err((self.err.take().unwrap(), self.framed.take().unwrap())) + Err((self.err.take().unwrap(), self.framed.take().unwrap())) } Ok(Async::NotReady) => Ok(Async::NotReady), - Err(_) => { - return Err((self.err.take().unwrap(), self.framed.take().unwrap())) - } + Err(_) => Err((self.err.take().unwrap(), self.framed.take().unwrap())), } } } diff --git a/src/ws/client/service.rs b/src/ws/client/service.rs index b494564b..485ce562 100644 --- a/src/ws/client/service.rs +++ b/src/ws/client/service.rs @@ -137,13 +137,13 @@ where let fut = Box::new( self.connector .call(connect) - .map_err(|e| ClientError::from(e)) + .map_err(ClientError::from) .and_then(move |io| { // h1 protocol let framed = Framed::new(io, h1::ClientCodec::default()); framed .send(request.into()) - .map_err(|e| ClientError::from(e)) + .map_err(ClientError::from) .and_then(|framed| { framed .into_future() diff --git a/src/ws/frame.rs b/src/ws/frame.rs index de1b9239..ca5f0e89 100644 --- a/src/ws/frame.rs +++ b/src/ws/frame.rs @@ -13,7 +13,9 @@ pub struct Parser; impl Parser { fn parse_metadata( - src: &[u8], server: bool, max_size: usize, + src: &[u8], + server: bool, + max_size: usize, ) -> Result)>, ProtocolError> { let chunk_len = src.len(); @@ -86,7 +88,9 @@ impl Parser { /// Parse the input stream into a frame. pub fn parse( - src: &mut BytesMut, server: bool, max_size: usize, + src: &mut BytesMut, + server: bool, + max_size: usize, ) -> Result)>, ProtocolError> { // try to parse ws frame metadata let (idx, finished, opcode, length, mask) = @@ -148,7 +152,11 @@ impl Parser { /// Generate binary representation pub fn write_message>( - dst: &mut BytesMut, pl: B, op: OpCode, fin: bool, mask: bool, + dst: &mut BytesMut, + pl: B, + op: OpCode, + fin: bool, + mask: bool, ) { let payload = pl.into(); let one: u8 = if fin { diff --git a/src/ws/mask.rs b/src/ws/mask.rs index a88c21af..e9bfb3d5 100644 --- a/src/ws/mask.rs +++ b/src/ws/mask.rs @@ -1,5 +1,5 @@ //! This is code from [Tungstenite project](https://github.com/snapview/tungstenite-rs) -#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] +#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] use std::ptr::copy_nonoverlapping; use std::slice; @@ -19,7 +19,7 @@ impl<'a> ShortSlice<'a> { /// Faster version of `apply_mask()` which operates on 8-byte blocks. #[inline] -#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))] +#[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))] pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) { // Extend the mask to 64 bits let mut mask_u64 = ((mask_u32 as u64) << 32) | (mask_u32 as u64); @@ -50,10 +50,7 @@ pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) { // TODO: copy_nonoverlapping here compiles to call memcpy. While it is not so // inefficient, it could be done better. The compiler does not understand that // a `ShortSlice` must be smaller than a u64. -#[cfg_attr( - feature = "cargo-clippy", - allow(clippy::needless_pass_by_value) -)] +#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] fn xor_short(buf: ShortSlice, mask: u64) { // Unsafe: we know that a `ShortSlice` fits in a u64 unsafe {