From 4092c7f326fa18c65b40ae703c68dfa4128be92d Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 17 Jul 2019 15:08:30 +0600 Subject: [PATCH] clippy warnings --- actix-cors/src/lib.rs | 2 + actix-files/src/lib.rs | 4 +- actix-files/src/named.rs | 8 ++-- actix-framed/src/lib.rs | 6 +++ actix-identity/src/lib.rs | 12 +++--- actix-multipart/src/lib.rs | 2 + actix-multipart/src/server.rs | 12 +++--- actix-session/src/cookie.rs | 2 +- actix-web-actors/src/lib.rs | 1 + actix-web-actors/src/ws.rs | 2 +- actix-web-codegen/src/route.rs | 65 ++++++++++++++------------------ awc/src/builder.rs | 6 +++ awc/src/lib.rs | 1 + awc/src/request.rs | 20 +++------- awc/src/test.rs | 2 +- awc/src/ws.rs | 2 +- src/info.rs | 6 +-- src/lib.rs | 1 + src/middleware/compress.rs | 1 - src/middleware/defaultheaders.rs | 1 - src/server.rs | 8 ++-- src/test.rs | 2 +- src/types/form.rs | 1 - src/types/json.rs | 1 - src/types/payload.rs | 1 - test-server/src/lib.rs | 5 ++- 26 files changed, 84 insertions(+), 90 deletions(-) diff --git a/actix-cors/src/lib.rs b/actix-cors/src/lib.rs index ea1eb383b..d9a44d0b8 100644 --- a/actix-cors/src/lib.rs +++ b/actix-cors/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)] //! Cross-origin resource sharing (CORS) for Actix applications //! //! CORS middleware could be used with application and with resource. @@ -162,6 +163,7 @@ impl AllOrSome { /// .max_age(3600); /// # } /// ``` +#[derive(Default)] pub struct Cors { cors: Option, methods: bool, diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 82abb9990..c870c9dd0 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)] + //! Static files support use std::cell::RefCell; use std::fmt::Write; @@ -57,7 +59,7 @@ pub struct ChunkedReadFile { fn handle_error(err: BlockingError) -> Error { match err { BlockingError::Error(err) => err.into(), - BlockingError::Canceled => ErrorInternalServerError("Unexpected error").into(), + BlockingError::Canceled => ErrorInternalServerError("Unexpected error"), } } diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 6b948da8e..3273a4d67 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -24,8 +24,8 @@ use crate::ChunkedReadFile; bitflags! { pub(crate) struct Flags: u32 { - const ETAG = 0b00000001; - const LAST_MD = 0b00000010; + const ETAG = 0b0000_0001; + const LAST_MD = 0b0000_0010; } } @@ -311,8 +311,8 @@ impl Responder for NamedFile { return Ok(resp.streaming(reader)); } - match req.method() { - &Method::HEAD | &Method::GET => (), + match *req.method() { + Method::HEAD | Method::GET => (), _ => { return Ok(HttpResponse::MethodNotAllowed() .header(header::CONTENT_TYPE, "text/plain") diff --git a/actix-framed/src/lib.rs b/actix-framed/src/lib.rs index c6405e20b..5e72ba5ba 100644 --- a/actix-framed/src/lib.rs +++ b/actix-framed/src/lib.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::type_complexity, + clippy::new_without_default, + dead_code, + deprecated +)] mod app; mod helpers; mod request; diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index fe7216a01..0ae58fe89 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -333,8 +333,7 @@ struct CookieIdentityExtention { impl CookieIdentityInner { fn new(key: &[u8]) -> CookieIdentityInner { - let key_v2: Vec = - key.iter().chain([1, 0, 0, 0].iter()).map(|e| *e).collect(); + let key_v2: Vec = key.iter().chain([1, 0, 0, 0].iter()).cloned().collect(); CookieIdentityInner { key: Key::from_master(key), key_v2: Key::from_master(&key_v2), @@ -585,13 +584,14 @@ impl IdentityPolicy for CookieIdentityPolicy { ) } else if self.0.always_update_cookie() && id.is_some() { let visit_timestamp = SystemTime::now(); - let mut login_timestamp = None; - if self.0.requires_oob_data() { + let login_timestamp = if self.0.requires_oob_data() { let CookieIdentityExtention { login_timestamp: lt, } = res.request().extensions_mut().remove().unwrap(); - login_timestamp = lt; - } + lt + } else { + None + }; self.0.set_cookie( res, Some(CookieValue { diff --git a/actix-multipart/src/lib.rs b/actix-multipart/src/lib.rs index d8f365b2c..43eb048ca 100644 --- a/actix-multipart/src/lib.rs +++ b/actix-multipart/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::borrow_interior_mutable_const)] + mod error; mod extractor; mod server; diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index e1a5543d4..c28a8d6af 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -418,7 +418,7 @@ impl Stream for Field { inner.poll(&self.safety) } else if !self.safety.is_clean() { - return Err(MultipartError::NotConsumed); + Err(MultipartError::NotConsumed) } else { Ok(Async::NotReady) } @@ -533,11 +533,9 @@ impl InnerField { let b_size = boundary.len() + b_len; if len < b_size { return Ok(Async::NotReady); - } else { - if &payload.buf[b_len..b_size] == boundary.as_bytes() { - // found boundary - return Ok(Async::Ready(None)); - } + } else if &payload.buf[b_len..b_size] == boundary.as_bytes() { + // found boundary + return Ok(Async::Ready(None)); } } } @@ -557,7 +555,7 @@ impl InnerField { // check boundary if (&payload.buf[cur..cur + 2] == b"\r\n" && &payload.buf[cur + 2..cur + 4] == b"--") - || (&payload.buf[cur..cur + 1] == b"\r" + || (&payload.buf[cur..=cur] == b"\r" && &payload.buf[cur + 1..cur + 3] == b"--") { if cur != 0 { diff --git a/actix-session/src/cookie.rs b/actix-session/src/cookie.rs index 87fc0b164..192737780 100644 --- a/actix-session/src/cookie.rs +++ b/actix-session/src/cookie.rs @@ -342,7 +342,7 @@ where } } (SessionStatus::Purged, _) => { - inner.remove_cookie(&mut res); + let _ = inner.remove_cookie(&mut res); res } _ => res, diff --git a/actix-web-actors/src/lib.rs b/actix-web-actors/src/lib.rs index 5b64d7e0a..6360917cd 100644 --- a/actix-web-actors/src/lib.rs +++ b/actix-web-actors/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::borrow_interior_mutable_const)] //! Actix actors integration for Actix web framework mod context; pub mod ws; diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index fece826dd..08d8b1089 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -435,7 +435,7 @@ where } } Frame::Binary(data) => Message::Binary( - data.map(|b| b.freeze()).unwrap_or_else(|| Bytes::new()), + data.map(|b| b.freeze()).unwrap_or_else(Bytes::new), ), Frame::Ping(s) => Message::Ping(s), Frame::Pong(s) => Message::Pong(s), diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 268adecb0..5215f60c8 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -12,9 +12,9 @@ enum ResourceType { impl fmt::Display for ResourceType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &ResourceType::Async => write!(f, "to_async"), - &ResourceType::Sync => write!(f, "to"), + match *self { + ResourceType::Async => write!(f, "to_async"), + ResourceType::Sync => write!(f, "to"), } } } @@ -34,16 +34,16 @@ pub enum GuardType { impl fmt::Display for GuardType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &GuardType::Get => write!(f, "Get"), - &GuardType::Post => write!(f, "Post"), - &GuardType::Put => write!(f, "Put"), - &GuardType::Delete => write!(f, "Delete"), - &GuardType::Head => write!(f, "Head"), - &GuardType::Connect => write!(f, "Connect"), - &GuardType::Options => write!(f, "Options"), - &GuardType::Trace => write!(f, "Trace"), - &GuardType::Patch => write!(f, "Patch"), + match *self { + GuardType::Get => write!(f, "Get"), + GuardType::Post => write!(f, "Post"), + GuardType::Put => write!(f, "Put"), + GuardType::Delete => write!(f, "Delete"), + GuardType::Head => write!(f, "Head"), + GuardType::Connect => write!(f, "Connect"), + GuardType::Options => write!(f, "Options"), + GuardType::Trace => write!(f, "Trace"), + GuardType::Patch => write!(f, "Patch"), } } } @@ -92,37 +92,27 @@ impl actix_web::dev::HttpServiceFactory for {name} {{ fn guess_resource_type(typ: &syn::Type) -> ResourceType { let mut guess = ResourceType::Sync; - match typ { - syn::Type::ImplTrait(typ) => { - for bound in typ.bounds.iter() { - match bound { - syn::TypeParamBound::Trait(bound) => { - for bound in bound.path.segments.iter() { - if bound.ident == "Future" { - guess = ResourceType::Async; - break; - } else if bound.ident == "Responder" { - guess = ResourceType::Sync; - break; - } - } + if let syn::Type::ImplTrait(typ) = typ { + for bound in typ.bounds.iter() { + if let syn::TypeParamBound::Trait(bound) = bound { + for bound in bound.path.segments.iter() { + if bound.ident == "Future" { + guess = ResourceType::Async; + break; + } else if bound.ident == "Responder" { + guess = ResourceType::Sync; + break; } - _ => (), } } } - _ => (), } guess } impl Args { - pub fn new( - args: &Vec, - input: TokenStream, - guard: GuardType, - ) -> Self { + pub fn new(args: &[syn::NestedMeta], input: TokenStream, guard: GuardType) -> Self { if args.is_empty() { panic!( "invalid server definition, expected: #[{}(\"some path\")]", @@ -164,9 +154,10 @@ impl Args { ResourceType::Async } else { match ast.decl.output { - syn::ReturnType::Default => { - panic!("Function {} has no return type. Cannot be used as handler") - } + syn::ReturnType::Default => panic!( + "Function {} has no return type. Cannot be used as handler", + name + ), syn::ReturnType::Type(_, ref typ) => guess_resource_type(typ.as_ref()), } }; diff --git a/awc/src/builder.rs b/awc/src/builder.rs index a58265c5f..463f40303 100644 --- a/awc/src/builder.rs +++ b/awc/src/builder.rs @@ -21,6 +21,12 @@ pub struct ClientBuilder { max_redirects: usize, } +impl Default for ClientBuilder { + fn default() -> Self { + Self::new() + } +} + impl ClientBuilder { pub fn new() -> Self { ClientBuilder { diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 45231326d..da63bbd93 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::borrow_interior_mutable_const)] //! An HTTP Client //! //! ```rust diff --git a/awc/src/request.rs b/awc/src/request.rs index 36cd6fcf3..0e5445897 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -185,9 +185,7 @@ impl ClientRequest { { match HeaderName::try_from(key) { Ok(key) => match value.try_into() { - Ok(value) => { - let _ = self.head.headers.append(key, value); - } + Ok(value) => self.head.headers.append(key, value), Err(e) => self.err = Some(e.into()), }, Err(e) => self.err = Some(e.into()), @@ -203,9 +201,7 @@ impl ClientRequest { { match HeaderName::try_from(key) { Ok(key) => match value.try_into() { - Ok(value) => { - let _ = self.head.headers.insert(key, value); - } + Ok(value) => self.head.headers.insert(key, value), Err(e) => self.err = Some(e.into()), }, Err(e) => self.err = Some(e.into()), @@ -223,9 +219,7 @@ impl ClientRequest { Ok(key) => { if !self.head.headers.contains_key(&key) { match value.try_into() { - Ok(value) => { - let _ = self.head.headers.insert(key, value); - } + Ok(value) => self.head.headers.insert(key, value), Err(e) => self.err = Some(e.into()), } } @@ -257,9 +251,7 @@ impl ClientRequest { HeaderValue: HttpTryFrom, { match HeaderValue::try_from(value) { - Ok(value) => { - let _ = self.head.headers.insert(header::CONTENT_TYPE, value); - } + Ok(value) => self.head.headers.insert(header::CONTENT_TYPE, value), Err(e) => self.err = Some(e.into()), } self @@ -321,7 +313,7 @@ impl ClientRequest { /// })); /// } /// ``` - pub fn cookie<'c>(mut self, cookie: Cookie<'c>) -> Self { + pub fn cookie(mut self, cookie: Cookie<'_>) -> Self { if self.cookies.is_none() { let mut jar = CookieJar::new(); jar.add(cookie.into_owned()); @@ -465,7 +457,7 @@ impl ClientRequest { }); // set request timeout - if let Some(timeout) = slf.timeout.or_else(|| config.timeout.clone()) { + if let Some(timeout) = slf.timeout.or_else(|| config.timeout) { Either::B(Either::A(Timeout::new(fut, timeout).map_err(|e| { if let Some(e) = e.into_inner() { e diff --git a/awc/src/test.rs b/awc/src/test.rs index f2c513bab..b852adb2d 100644 --- a/awc/src/test.rs +++ b/awc/src/test.rs @@ -68,7 +68,7 @@ impl TestResponse { } /// Set cookie for this response - pub fn cookie<'a>(mut self, cookie: Cookie<'a>) -> Self { + pub fn cookie(mut self, cookie: Cookie<'_>) -> Self { self.cookies.add(cookie.into_owned()); self } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 95bf6ef70..27f454ed3 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -90,7 +90,7 @@ impl WebsocketsRequest { } /// Set a cookie - pub fn cookie<'c>(mut self, cookie: Cookie<'c>) -> Self { + pub fn cookie(mut self, cookie: Cookie<'_>) -> Self { if self.cookies.is_none() { let mut jar = CookieJar::new(); jar.add(cookie.into_owned()); diff --git a/src/info.rs b/src/info.rs index 0caa96832..ba59605de 100644 --- a/src/info.rs +++ b/src/info.rs @@ -25,11 +25,7 @@ impl ConnectionInfo { Ref::map(req.extensions(), |e| e.get().unwrap()) } - #[allow( - clippy::cyclomatic_complexity, - clippy::cognitive_complexity, - clippy::borrow_interior_mutable_const - )] + #[allow(clippy::cognitive_complexity)] fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo { let mut host = None; let mut scheme = None; diff --git a/src/lib.rs b/src/lib.rs index 345987ffa..857bc294e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::borrow_interior_mutable_const)] //! Actix web is a small, pragmatic, and extremely fast web framework //! for Rust. //! diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs index c9d2107f4..86665d824 100644 --- a/src/middleware/compress.rs +++ b/src/middleware/compress.rs @@ -107,7 +107,6 @@ where self.service.poll_ready() } - #[allow(clippy::borrow_interior_mutable_const)] fn call(&mut self, req: ServiceRequest) -> Self::Future { // negotiate content-encoding let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) { diff --git a/src/middleware/defaultheaders.rs b/src/middleware/defaultheaders.rs index a353f5fc5..ab2d36c2c 100644 --- a/src/middleware/defaultheaders.rs +++ b/src/middleware/defaultheaders.rs @@ -125,7 +125,6 @@ where self.service.poll_ready() } - #[allow(clippy::borrow_interior_mutable_const)] fn call(&mut self, req: ServiceRequest) -> Self::Future { let inner = self.inner.clone(); diff --git a/src/server.rs b/src/server.rs index 353f29ba9..43236fa34 100644 --- a/src/server.rs +++ b/src/server.rs @@ -288,13 +288,13 @@ where lst, move || { let c = cfg.lock(); - acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then( + acceptor.clone().map_err(SslError::Ssl).and_then( HttpService::build() .keep_alive(c.keep_alive) .client_timeout(c.client_timeout) .client_disconnect(c.client_shutdown) .finish(factory()) - .map_err(|e| SslError::Service(e)) + .map_err(SslError::Service) .map_init_err(|_| ()), ) }, @@ -339,13 +339,13 @@ where lst, move || { let c = cfg.lock(); - acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then( + acceptor.clone().map_err(SslError::Ssl).and_then( HttpService::build() .keep_alive(c.keep_alive) .client_timeout(c.client_timeout) .client_disconnect(c.client_shutdown) .finish(factory()) - .map_err(|e| SslError::Service(e)) + .map_err(SslError::Service) .map_init_err(|_| ()), ) }, diff --git a/src/test.rs b/src/test.rs index 208360a29..562fdf436 100644 --- a/src/test.rs +++ b/src/test.rs @@ -79,7 +79,7 @@ where F: FnOnce() -> R, R: IntoFuture, { - RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(|| f()))) + RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f))) } #[doc(hidden)] diff --git a/src/types/form.rs b/src/types/form.rs index ac202b17d..e61145b0d 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -192,7 +192,6 @@ pub struct UrlEncoded { impl UrlEncoded { /// Create a new future to URL encode a request - #[allow(clippy::borrow_interior_mutable_const)] pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded { // check content type if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" { diff --git a/src/types/json.rs b/src/types/json.rs index 70feef8d3..f309a3c5a 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -298,7 +298,6 @@ where U: DeserializeOwned + 'static, { /// Create `JsonBody` for request. - #[allow(clippy::borrow_interior_mutable_const)] pub fn new( req: &HttpRequest, payload: &mut Payload, diff --git a/src/types/payload.rs b/src/types/payload.rs index 34c3e2984..8a634b4c9 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -298,7 +298,6 @@ pub struct HttpMessageBody { impl HttpMessageBody { /// Create `MessageBody` for request. - #[allow(clippy::borrow_interior_mutable_const)] pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody { let mut len = None; if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) { diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs index c49026faa..38405cd55 100644 --- a/test-server/src/lib.rs +++ b/test-server/src/lib.rs @@ -65,7 +65,7 @@ where F: FnOnce() -> R, R: IntoFuture, { - RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(|| f()))) + RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f))) } /// The `TestServer` type. @@ -107,6 +107,7 @@ pub struct TestServerRuntime { } impl TestServer { + #[allow(clippy::new_ret_no_self)] /// Start new test server with application factory pub fn new(factory: F) -> TestServerRuntime { let (tx, rx) = mpsc::channel(); @@ -191,7 +192,7 @@ impl TestServerRuntime { F: FnOnce() -> R, R: Future, { - self.rt.block_on(lazy(|| f())) + self.rt.block_on(lazy(f)) } /// Execute function on current core