From aad013f5594178abe5e53b66a245138e74402e89 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 17 Aug 2019 05:15:51 +0900 Subject: [PATCH] Fix clippy warnings (#40) Add explicit `dyn`s Remove let binding Use += Return false Derive Default for TcpConnector Squash if/else Remove unnecessary return keywords Use is_empty() Fix clippy attribute Allow mut_from_ref --- actix-connect/src/connector.rs | 2 +- actix-connect/src/resolver.rs | 16 +++++++--------- actix-ioframe/src/dispatcher.rs | 4 ++-- actix-ioframe/src/service.rs | 12 ++++++------ actix-rt/src/arbiter.rs | 10 +++++----- actix-rt/src/runtime.rs | 2 +- actix-service/src/boxed.rs | 14 +++++++------- actix-service/src/cell.rs | 1 + actix-utils/src/inflight.rs | 2 +- actix-utils/src/order.rs | 2 +- actix-utils/src/stream.rs | 2 +- actix-utils/src/timeout.rs | 2 +- router/src/de.rs | 2 +- router/src/path.rs | 2 +- router/src/resource.rs | 4 ++-- 15 files changed, 38 insertions(+), 39 deletions(-) diff --git a/actix-connect/src/connector.rs b/actix-connect/src/connector.rs index ba9bf50c..ecb61996 100644 --- a/actix-connect/src/connector.rs +++ b/actix-connect/src/connector.rs @@ -52,7 +52,7 @@ impl NewService for TcpConnectorFactory { } /// Tcp connector service -#[derive(Debug)] +#[derive(Default, Debug)] pub struct TcpConnector(PhantomData); impl TcpConnector { diff --git a/actix-connect/src/resolver.rs b/actix-connect/src/resolver.rs index 1a76a618..0d0234a2 100644 --- a/actix-connect/src/resolver.rs +++ b/actix-connect/src/resolver.rs @@ -113,17 +113,15 @@ impl Service for Resolver { fn call(&mut self, mut req: Connect) -> Self::Future { if req.addr.is_some() { Either::B(ok(req)) + } else if let Ok(ip) = req.host().parse() { + req.addr = Some(either::Either::Left(SocketAddr::new(ip, req.port()))); + Either::B(ok(req)) } else { - if let Ok(ip) = req.host().parse() { - req.addr = Some(either::Either::Left(SocketAddr::new(ip, req.port()))); - Either::B(ok(req)) - } else { - trace!("DNS resolver: resolving host {:?}", req.host()); - if self.resolver.is_none() { - self.resolver = Some(get_default_resolver()); - } - Either::A(ResolverFuture::new(req, self.resolver.as_ref().unwrap())) + trace!("DNS resolver: resolving host {:?}", req.host()); + if self.resolver.is_none() { + self.resolver = Some(get_default_resolver()); } + Either::A(ResolverFuture::new(req, self.resolver.as_ref().unwrap())) } } } diff --git a/actix-ioframe/src/dispatcher.rs b/actix-ioframe/src/dispatcher.rs index 54e5deb5..422a10d4 100644 --- a/actix-ioframe/src/dispatcher.rs +++ b/actix-ioframe/src/dispatcher.rs @@ -44,7 +44,7 @@ where framed: Framed, rx: Option::Item>>>, inner: Cell::Item, S::Error>>, - disconnect: Option>, + disconnect: Option>, } impl FramedDispatcher @@ -63,7 +63,7 @@ where service: F, rx: mpsc::UnboundedReceiver::Item>>, sink: Sink<::Item>, - disconnect: Option>, + disconnect: Option>, ) -> Self { FramedDispatcher { framed, diff --git a/actix-ioframe/src/service.rs b/actix-ioframe/src/service.rs index c853372a..98dbd366 100644 --- a/actix-ioframe/src/service.rs +++ b/actix-ioframe/src/service.rs @@ -62,7 +62,7 @@ impl Builder { pub struct ServiceBuilder { connect: C, - disconnect: Option>, + disconnect: Option>, _t: PhantomData<(St, Io, Codec)>, } @@ -113,7 +113,7 @@ where pub struct NewServiceBuilder { connect: C, - disconnect: Option>, + disconnect: Option>, _t: PhantomData<(St, Io, Codec)>, } @@ -170,7 +170,7 @@ where pub(crate) struct FramedService { connect: C, handler: Rc, - disconnect: Option>, + disconnect: Option>, _t: PhantomData<(St, Io, Codec, Cfg)>, } @@ -198,7 +198,7 @@ where type Error = ServiceError; type InitError = C::InitError; type Service = FramedServiceImpl; - type Future = Box>; + type Future = Box>; fn new_service(&self, _: &Cfg) -> Self::Future { let handler = self.handler.clone(); @@ -221,7 +221,7 @@ where pub struct FramedServiceImpl { connect: C, handler: Rc, - disconnect: Option>, + disconnect: Option>, _t: PhantomData<(St, Io, Codec)>, } @@ -280,7 +280,7 @@ where ::Error: std::fmt::Debug, { inner: FramedServiceImplResponseInner, - disconnect: Option>, + disconnect: Option>, } enum FramedServiceImplResponseInner diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index b7cdca0a..88bcdbfb 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -16,15 +16,15 @@ use copyless::BoxHelper; thread_local!( static ADDR: RefCell> = RefCell::new(None); static RUNNING: Cell = Cell::new(false); - static Q: RefCell>>> = RefCell::new(Vec::new()); + static Q: RefCell>>> = RefCell::new(Vec::new()); ); pub(crate) static COUNT: AtomicUsize = AtomicUsize::new(0); pub(crate) enum ArbiterCommand { Stop, - Execute(Box + Send>), - ExecuteFn(Box), + Execute(Box + Send>), + ExecuteFn(Box), } impl fmt::Debug for ArbiterCommand { @@ -180,7 +180,7 @@ impl Arbiter { let _ = self .0 .unbounded_send(ArbiterCommand::ExecuteFn(Box::new(move || { - let _ = f(); + f(); }))); } @@ -312,7 +312,7 @@ impl FnExec for F where F: FnOnce() + Send + 'static, { - #[cfg_attr(feature = "cargo-clippy", allow(boxed_local))] + #[allow(clippy::boxed_local)] fn call_box(self: Box) { (*self)() } diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index d98f85da..c6b2a9fc 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -40,7 +40,7 @@ impl Error for RunError { fn description(&self) -> &str { self.inner.description() } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { self.inner.source() } } diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index b9e14897..16e37fa2 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -4,7 +4,7 @@ use futures::{Async, Future, IntoFuture, Poll}; use crate::{NewService, Service}; pub type BoxedService = Box< - Service< + dyn Service< Request = Req, Response = Res, Error = Err, @@ -13,7 +13,7 @@ pub type BoxedService = Box< >; pub type BoxedServiceResponse = - Either, Box>>; + Either, Box>>; pub struct BoxedNewService(Inner); @@ -46,14 +46,14 @@ where } type Inner = Box< - NewService< + dyn NewService< Config = C, Request = Req, Response = Res, Error = Err, InitError = InitErr, Service = BoxedService, - Future = Box, Error = InitErr>>, + Future = Box, Error = InitErr>>, >, >; @@ -70,7 +70,7 @@ where type InitError = InitErr; type Config = C; type Service = BoxedService; - type Future = Box>; + type Future = Box>; fn new_service(&self, cfg: &C) -> Self::Future { self.0.new_service(cfg) @@ -99,7 +99,7 @@ where type InitError = InitErr; type Config = C; type Service = BoxedService; - type Future = Box>; + type Future = Box>; fn new_service(&self, cfg: &C) -> Self::Future { Box::new( @@ -133,7 +133,7 @@ where type Error = Err; type Future = Either< FutureResult, - Box>, + Box>, >; fn poll_ready(&mut self) -> Poll<(), Self::Error> { diff --git a/actix-service/src/cell.rs b/actix-service/src/cell.rs index 0dddefcc..2dc6d6a6 100644 --- a/actix-service/src/cell.rs +++ b/actix-service/src/cell.rs @@ -34,6 +34,7 @@ impl Cell { unsafe { &mut *self.inner.as_ref().get() } } + #[allow(clippy::mut_from_ref)] pub(crate) unsafe fn get_mut_unsafe(&self) -> &mut T { &mut *self.inner.as_ref().get() } diff --git a/actix-utils/src/inflight.rs b/actix-utils/src/inflight.rs index d1c3b093..03d90873 100644 --- a/actix-utils/src/inflight.rs +++ b/actix-utils/src/inflight.rs @@ -119,7 +119,7 @@ mod tests { type Request = (); type Response = (); type Error = (); - type Future = Box>; + type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index cffb123f..fa7bb750 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -214,7 +214,7 @@ mod tests { type Request = oneshot::Receiver; type Response = usize; type Error = (); - type Future = Box>; + type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) diff --git a/actix-utils/src/stream.rs b/actix-utils/src/stream.rs index 68377355..e8ac8783 100644 --- a/actix-utils/src/stream.rs +++ b/actix-utils/src/stream.rs @@ -45,7 +45,7 @@ where type Request = S; type Response = (); type Error = E; - type Future = Box>; + type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index 37fd5df1..e05788f7 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -190,7 +190,7 @@ mod tests { type Request = (); type Response = (); type Error = (); - type Future = Box>; + type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) diff --git a/router/src/de.rs b/router/src/de.rs index 1ce797bd..56dac4e7 100644 --- a/router/src/de.rs +++ b/router/src/de.rs @@ -151,7 +151,7 @@ impl<'de, T: ResourcePath + 'de> Deserializer<'de> for PathDeserializer<'de, T> where V: Visitor<'de>, { - if self.path.len() < 1 { + if self.path.is_empty() { Err(de::value::Error::custom( "expeceted at least one parameters", )) diff --git a/router/src/path.rs b/router/src/path.rs index 25060729..19432c17 100644 --- a/router/src/path.rs +++ b/router/src/path.rs @@ -93,7 +93,7 @@ impl Path { #[inline] /// Skip first `n` chars in path pub fn skip(&mut self, n: u16) { - self.skip = self.skip + n; + self.skip += n; } pub(crate) fn add(&mut self, name: Rc, value: PathItem) { diff --git a/router/src/resource.rs b/router/src/resource.rs index 10a96209..ec96554f 100644 --- a/router/src/resource.rs +++ b/router/src/resource.rs @@ -207,7 +207,7 @@ impl ResourceDef { "Dynamic path match but not all segments found: {}", name ); - false; + return false; } } } else { @@ -279,7 +279,7 @@ impl ResourceDef { "Dynamic path match but not all segments found: {}", name ); - false; + return false; } } } else {