1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 00:01:11 +01:00

Suppress/fix clippy warnings

This commit is contained in:
Yuki Okushi 2020-01-28 20:27:33 +09:00
parent ee0db9a617
commit d5a6c83207
19 changed files with 50 additions and 48 deletions

View File

@ -38,7 +38,7 @@ where
{
pub fn service(connector: Arc<ClientConfig>) -> RustlsConnectorService<T, U> {
RustlsConnectorService {
connector: connector,
connector,
_t: PhantomData,
}
}

View File

@ -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(()));
}
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -220,7 +220,7 @@ impl ServerBuilder {
self.services.push(StreamNewService::create(
name.as_ref().to_string(),
token,
factory.clone(),
factory,
addr,
));
self.sockets

View File

@ -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);
}
}

View File

@ -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<Self::Output> {
// `StopWorker` message handler
if let Poll::Ready(Some(StopCommand { graceful, result })) =
@ -368,12 +370,9 @@ impl Future for Worker {
Ok(false) => {
// push connection back to queue
if let Some(conn) = conn {
match self.state {
WorkerState::Unavailable(ref mut conns) => {
if let WorkerState::Unavailable(ref mut conns) = self.state {
conns.push(conn);
}
_ => (),
}
}
Poll::Pending
}

View File

@ -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();
}

View File

@ -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]

View File

@ -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)),

View File

@ -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", ()));
}
}

View File

@ -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"));
}
}

View File

@ -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};

View File

@ -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;
}
}

View File

@ -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
})

View File

@ -69,7 +69,7 @@ impl<'a> IntoPattern for &'a str {
}
fn patterns(&self) -> Vec<String> {
vec![self.to_string()]
vec![(*self).to_string()]
}
}
@ -79,7 +79,7 @@ impl<T: AsRef<str>> IntoPattern for Vec<T> {
}
fn patterns(&self) -> Vec<String> {
self.into_iter().map(|v| v.as_ref().to_string()).collect()
self.iter().map(|v| v.as_ref().to_string()).collect()
}
}

View File

@ -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()));

View File

@ -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::<usize>::build();

View File

@ -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");
}