From d5a6c83207e674bc5eef76a3de69adebdc8665fa Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 28 Jan 2020 20:27:33 +0900 Subject: [PATCH] Suppress/fix clippy warnings --- actix-connect/src/ssl/rustls.rs | 2 +- actix-ioframe/src/dispatcher.rs | 2 +- actix-macros/src/lib.rs | 1 + actix-rt/src/runtime.rs | 3 +-- actix-server/src/builder.rs | 2 +- actix-server/src/config.rs | 2 +- actix-server/src/worker.rs | 9 ++++----- actix-server/tests/test_server.rs | 8 ++++---- actix-service/src/and_then.rs | 2 +- actix-service/src/and_then_apply_fn.rs | 5 +++-- actix-service/src/apply.rs | 12 ++++++------ actix-service/src/then.rs | 8 ++++---- actix-testing/src/lib.rs | 2 +- actix-utils/src/condition.rs | 6 +++--- actix-utils/src/order.rs | 4 ++-- router/src/lib.rs | 4 ++-- router/src/resource.rs | 23 ++++++++++++----------- router/src/router.rs | 1 + string/src/lib.rs | 2 +- 19 files changed, 50 insertions(+), 48 deletions(-) diff --git a/actix-connect/src/ssl/rustls.rs b/actix-connect/src/ssl/rustls.rs index 01cb2fab..1964b3aa 100644 --- a/actix-connect/src/ssl/rustls.rs +++ b/actix-connect/src/ssl/rustls.rs @@ -38,7 +38,7 @@ where { pub fn service(connector: Arc) -> RustlsConnectorService { RustlsConnectorService { - connector: connector, + connector, _t: PhantomData, } } diff --git a/actix-ioframe/src/dispatcher.rs b/actix-ioframe/src/dispatcher.rs index 1565f797..3e000da6 100644 --- a/actix-ioframe/src/dispatcher.rs +++ b/actix-ioframe/src/dispatcher.rs @@ -213,7 +213,7 @@ where // drain service responses match Pin::new(&mut self.rx).poll_next(cx) { Poll::Ready(Some(Ok(msg))) => { - if let Err(_) = self.framed.write(msg) { + if self.framed.write(msg).is_err() { return Poll::Ready(Ok(())); } } diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index ec270f28..b6a57b9d 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -14,6 +14,7 @@ use quote::quote; /// println!("Hello world"); /// } /// ``` +#[allow(clippy::needless_doctest_main)] #[proc_macro_attribute] #[cfg(not(test))] // Work around for rust-lang/rust#62127 pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index a03361d6..bbafb6f0 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -86,7 +86,6 @@ impl Runtime { where F: Future + 'static, { - let res = self.local.block_on(&mut self.rt, f); - res + self.local.block_on(&mut self.rt, f) } } diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 0f3722c9..ee1c3e2f 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -220,7 +220,7 @@ impl ServerBuilder { self.services.push(StreamNewService::create( name.as_ref().to_string(), token, - factory.clone(), + factory, addr, )); self.sockets diff --git a/actix-server/src/config.rs b/actix-server/src/config.rs index d1060ec5..464635b1 100644 --- a/actix-server/src/config.rs +++ b/actix-server/src/config.rs @@ -91,7 +91,7 @@ impl ConfiguredService { pub(super) fn stream(&mut self, token: Token, name: String, addr: net::SocketAddr) { self.names.insert(token, (name.clone(), addr)); - self.topics.insert(name.clone(), token); + self.topics.insert(name, token); self.services.push(token); } } diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 4dbe3493..f51fd310 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -315,6 +315,8 @@ enum WorkerState { impl Future for Worker { type Output = (); + // FIXME: remove this attribute + #[allow(clippy::never_loop)] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { // `StopWorker` message handler if let Poll::Ready(Some(StopCommand { graceful, result })) = @@ -368,11 +370,8 @@ impl Future for Worker { Ok(false) => { // push connection back to queue if let Some(conn) = conn { - match self.state { - WorkerState::Unavailable(ref mut conns) => { - conns.push(conn); - } - _ => (), + if let WorkerState::Unavailable(ref mut conns) = self.state { + conns.push(conn); } } Poll::Pending diff --git a/actix-server/tests/test_server.rs b/actix-server/tests/test_server.rs index a1cf1928..46587a80 100644 --- a/actix-server/tests/test_server.rs +++ b/actix-server/tests/test_server.rs @@ -41,7 +41,7 @@ fn test_bind() { thread::sleep(time::Duration::from_millis(500)); assert!(net::TcpStream::connect(addr).is_ok()); - let _ = sys.stop(); + sys.stop(); let _ = h.join(); } @@ -66,7 +66,7 @@ fn test_listen() { thread::sleep(time::Duration::from_millis(500)); assert!(net::TcpStream::connect(addr).is_ok()); - let _ = sys.stop(); + sys.stop(); let _ = h.join(); } @@ -130,7 +130,7 @@ fn test_start() { assert!(net::TcpStream::connect(addr).is_err()); thread::sleep(time::Duration::from_millis(100)); - let _ = sys.stop(); + sys.stop(); let _ = h.join(); } @@ -178,6 +178,6 @@ fn test_configure() { assert!(net::TcpStream::connect(addr2).is_ok()); assert!(net::TcpStream::connect(addr3).is_ok()); assert_eq!(num.load(Relaxed), 1); - let _ = sys.stop(); + sys.stop(); let _ = h.join(); } diff --git a/actix-service/src/and_then.rs b/actix-service/src/and_then.rs index b67de0a0..76ed35e9 100644 --- a/actix-service/src/and_then.rs +++ b/actix-service/src/and_then.rs @@ -313,7 +313,7 @@ mod tests { let mut srv = pipeline(Srv1(cnt.clone())).and_then(Srv2(cnt)); let res = srv.call("srv1").await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv1", "srv2"))); + assert_eq!(res.unwrap(), ("srv1", "srv2")); } #[actix_rt::test] diff --git a/actix-service/src/and_then_apply_fn.rs b/actix-service/src/and_then_apply_fn.rs index 4ff3b4d0..07f3b50d 100644 --- a/actix-service/src/and_then_apply_fn.rs +++ b/actix-service/src/and_then_apply_fn.rs @@ -290,6 +290,7 @@ mod tests { Poll::Ready(Ok(())) } + #[allow(clippy::unit_arg)] fn call(&mut self, req: Self::Request) -> Self::Future { ok(req) } @@ -297,7 +298,7 @@ mod tests { #[actix_rt::test] async fn test_service() { - let mut srv = pipeline(|r: &'static str| ok(r)) + let mut srv = pipeline(ok) .and_then_apply_fn(Srv, |req: &'static str, s| { s.call(()).map_ok(move |res| (req, res)) }); @@ -311,7 +312,7 @@ mod tests { #[actix_rt::test] async fn test_service_factory() { - let new_srv = pipeline_factory(|| ok::<_, ()>(fn_service(|r: &'static str| ok(r)))) + let new_srv = pipeline_factory(|| ok::<_, ()>(fn_service(ok))) .and_then_apply_fn( || ok(Srv), |req: &'static str, s| s.call(()).map_ok(move |res| (req, res)), diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index b8cc7426..df5df317 100644 --- a/actix-service/src/apply.rs +++ b/actix-service/src/apply.rs @@ -233,8 +233,8 @@ mod tests { let mut srv = pipeline(apply_fn(Srv, |req: &'static str, srv| { let fut = srv.call(()); async move { - let res = fut.await.unwrap(); - Ok((req, res)) + fut.await.unwrap(); + Ok((req, ())) } })); @@ -242,7 +242,7 @@ mod tests { let res = srv.call("srv").await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv", ()))); + assert_eq!(res.unwrap(), ("srv", ())); } #[actix_rt::test] @@ -252,8 +252,8 @@ mod tests { |req: &'static str, srv| { let fut = srv.call(()); async move { - let res = fut.await.unwrap(); - Ok((req, res)) + fut.await.unwrap(); + Ok((req, ())) } }, )); @@ -264,6 +264,6 @@ mod tests { let res = srv.call("srv").await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv", ()))); + assert_eq!(res.unwrap(), ("srv", ())); } } diff --git a/actix-service/src/then.rs b/actix-service/src/then.rs index b3a624ab..53ff1753 100644 --- a/actix-service/src/then.rs +++ b/actix-service/src/then.rs @@ -305,11 +305,11 @@ mod tests { let res = srv.call(Ok("srv1")).await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv1", "ok"))); + assert_eq!(res.unwrap(), ("srv1", "ok")); let res = srv.call(Err("srv")).await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv2", "err"))); + assert_eq!(res.unwrap(), ("srv2", "err")); } #[actix_rt::test] @@ -321,10 +321,10 @@ mod tests { let mut srv = factory.new_service(&()).await.unwrap(); let res = srv.call(Ok("srv1")).await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv1", "ok"))); + assert_eq!(res.unwrap(), ("srv1", "ok")); let res = srv.call(Err("srv")).await; assert!(res.is_ok()); - assert_eq!(res.unwrap(), (("srv2", "err"))); + assert_eq!(res.unwrap(), ("srv2", "err")); } } diff --git a/actix-testing/src/lib.rs b/actix-testing/src/lib.rs index 4fd68f9a..c1e192e1 100644 --- a/actix-testing/src/lib.rs +++ b/actix-testing/src/lib.rs @@ -1,6 +1,6 @@ //! Various helpers for Actix applications to use during testing. #![deny(rust_2018_idioms, warnings)] -#![allow(clippy::type_complexity)] +#![allow(clippy::type_complexity, clippy::needless_doctest_main)] use std::sync::mpsc; use std::{net, thread}; diff --git a/actix-utils/src/condition.rs b/actix-utils/src/condition.rs index 8830453d..097034da 100644 --- a/actix-utils/src/condition.rs +++ b/actix-utils/src/condition.rs @@ -107,7 +107,7 @@ mod tests { Poll::Pending ); cond.notify(); - assert_eq!(waiter.await, ()); + waiter.await; let mut waiter = cond.wait(); assert_eq!( @@ -121,7 +121,7 @@ mod tests { ); drop(cond); - assert_eq!(waiter.await, ()); - assert_eq!(waiter2.await, ()); + waiter.await; + waiter2.await; } } diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index fc099b6e..7dd4e2fc 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -242,7 +242,7 @@ mod tests { let rx2 = rx2; let rx3 = rx3; let tx_stop = tx_stop; - let _ = actix_rt::System::new("test").block_on(async { + actix_rt::System::new("test").block_on(async { let mut srv = InOrderService::new(Srv); let _ = lazy(|cx| srv.poll_ready(cx)).await; @@ -251,7 +251,7 @@ mod tests { let res3 = srv.call(rx3); actix_rt::spawn(async move { - let _ = poll_fn(|cx| { + poll_fn(|cx| { let _ = srv.poll_ready(cx); Poll::<()>::Pending }) diff --git a/router/src/lib.rs b/router/src/lib.rs index 7e41c4c3..75485b5a 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -69,7 +69,7 @@ impl<'a> IntoPattern for &'a str { } fn patterns(&self) -> Vec { - vec![self.to_string()] + vec![(*self).to_string()] } } @@ -79,7 +79,7 @@ impl> IntoPattern for Vec { } fn patterns(&self) -> Vec { - self.into_iter().map(|v| v.as_ref().to_string()).collect() + self.iter().map(|v| v.as_ref().to_string()).collect() } } diff --git a/router/src/resource.rs b/router/src/resource.rs index 00157775..b8a8c4d4 100644 --- a/router/src/resource.rs +++ b/router/src/resource.rs @@ -294,7 +294,7 @@ impl ResourceDef { return false; } for idx in 0..idx { - path.add(names[idx].clone(), segments[idx]); + path.add(names[idx], segments[idx]); } path.skip((pos + len) as u16); true @@ -326,7 +326,7 @@ impl ResourceDef { return false; } for idx in 0..idx { - path.add(names[idx].clone(), segments[idx]); + path.add(names[idx], segments[idx]); } path.skip((pos + len) as u16); true @@ -413,7 +413,7 @@ impl ResourceDef { let path = res.resource_path(); for idx in 0..idx { - path.add(names[idx].clone(), segments[idx]); + path.add(names[idx], segments[idx]); } path.skip((pos + len) as u16); true @@ -452,7 +452,7 @@ impl ResourceDef { let path = res.resource_path(); for idx in 0..idx { - path.add(names[idx].clone(), segments[idx]); + path.add(names[idx], segments[idx]); } path.skip((pos + len) as u16); true @@ -734,6 +734,7 @@ mod tests { assert_eq!(path.get("id").unwrap(), "012345"); } + #[allow(clippy::cognitive_complexity)] #[test] fn test_dynamic_set() { let re = ResourceDef::new(vec![ @@ -899,31 +900,31 @@ mod tests { fn test_resource_path() { let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/test"); - assert!(resource.resource_path(&mut s, &mut (&["user1"]).into_iter())); + assert!(resource.resource_path(&mut s, &mut (&["user1"]).iter())); assert_eq!(s, "/user/user1/test"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}/test"); - assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).into_iter())); + assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter())); assert_eq!(s, "/user/item/item2/test"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}"); - assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).into_iter())); + assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter())); assert_eq!(s, "/user/item/item2"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}/"); - assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).into_iter())); + assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter())); assert_eq!(s, "/user/item/item2/"); let mut s = String::new(); - assert!(!resource.resource_path(&mut s, &mut (&["item"]).into_iter())); + assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter())); let mut s = String::new(); - assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).into_iter())); + assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter())); assert_eq!(s, "/user/item/item2/"); - assert!(!resource.resource_path(&mut s, &mut (&["item"]).into_iter())); + assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter())); let mut s = String::new(); assert!(resource.resource_path(&mut s, &mut vec!["item", "item2"].into_iter())); diff --git a/router/src/router.rs b/router/src/router.rs index c65ac2db..bcbe61f9 100644 --- a/router/src/router.rs +++ b/router/src/router.rs @@ -104,6 +104,7 @@ mod tests { use crate::path::Path; use crate::router::{ResourceId, Router}; + #[allow(clippy::cognitive_complexity)] #[test] fn test_recognizer_1() { let mut router = Router::::build(); diff --git a/string/src/lib.rs b/string/src/lib.rs index 6e5d422f..2b600bde 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -204,7 +204,7 @@ mod test { #[test] fn test_from_static_str() { - const _S: ByteString = ByteString::from_static("hello"); + static _S: ByteString = ByteString::from_static("hello"); let _ = ByteString::from_static("str"); }