From d39611d246c577d0541126b0c0f414e2e24a62d2 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 16 Jul 2024 22:13:33 +0200 Subject: [PATCH] Clippy warnings (#382) --- ntex-io/src/io.rs | 2 +- ntex-io/src/ioref.rs | 2 +- ntex-net/src/connect/service.rs | 5 +---- ntex-service/src/apply.rs | 6 +++--- ntex-service/src/ctx.rs | 2 +- ntex-service/src/fn_service.rs | 6 +++--- ntex-service/src/fn_shutdown.rs | 2 +- ntex-service/src/map.rs | 6 +++--- ntex-service/src/map_config.rs | 2 +- ntex-service/src/map_err.rs | 8 ++++---- ntex-service/src/map_init_err.rs | 4 ++-- ntex-service/src/middleware.rs | 4 ++-- ntex-util/src/services/inflight.rs | 2 +- ntex-util/src/services/onerequest.rs | 2 +- ntex-util/src/services/timeout.rs | 2 +- ntex-util/src/services/variant.rs | 2 +- ntex/Cargo.toml | 1 + ntex/src/web/info.rs | 6 +++--- ntex/src/web/middleware/logger.rs | 12 ++---------- 19 files changed, 33 insertions(+), 43 deletions(-) diff --git a/ntex-io/src/io.rs b/ntex-io/src/io.rs index 9db8ae6d..05e84158 100644 --- a/ntex-io/src/io.rs +++ b/ntex-io/src/io.rs @@ -1015,7 +1015,7 @@ mod tests { let (client, server) = IoTest::create(); let f = DropFilter { p: p.clone() }; - format!("{:?}", f); + let _ = format!("{:?}", f); let mut io = Io::new(server).add_filter(f); client.remote_buffer_cap(1024); diff --git a/ntex-io/src/ioref.rs b/ntex-io/src/ioref.rs index 9a25fb54..56750212 100644 --- a/ntex-io/src/ioref.rs +++ b/ntex-io/src/ioref.rs @@ -496,7 +496,7 @@ mod tests { read_order: read_order.clone(), write_order: write_order.clone(), }; - format!("{:?}", counter); + let _ = format!("{:?}", counter); let io = Io::new(server).add_filter(counter); client.remote_buffer_cap(1024); diff --git a/ntex-net/src/connect/service.rs b/ntex-net/src/connect/service.rs index 05e71ad3..4969b9fd 100644 --- a/ntex-net/src/connect/service.rs +++ b/ntex-net/src/connect/service.rs @@ -231,10 +231,7 @@ mod tests { ntex_service::fn_service(|_| async { Ok::<_, ()>(()) }) }); - let srv = Connector::default() - .tag("T") - .memory_pool(PoolId::P5) - .clone(); + let srv = Connector::default().tag("T").memory_pool(PoolId::P5); let result = srv.connect("").await; assert!(result.is_err()); let result = srv.connect("localhost:99999").await; diff --git a/ntex-service/src/apply.rs b/ntex-service/src/apply.rs index 56fb335f..5425d7d2 100644 --- a/ntex-service/src/apply.rs +++ b/ntex-service/src/apply.rs @@ -278,7 +278,7 @@ mod tests { let res = srv.call("srv").await; assert!(res.is_ok()); assert_eq!(res.unwrap(), ("srv", ())); - format!("{:?}", srv); + let _ = format!("{:?}", srv); } #[ntex::test] @@ -301,7 +301,7 @@ mod tests { let res = srv.call("srv").await; assert!(res.is_ok()); assert_eq!(res.unwrap(), ("srv", ())); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); assert!(Err == Err::from(())); } @@ -322,6 +322,6 @@ mod tests { let res = srv.call("srv").await; assert!(res.is_ok()); assert_eq!(res.unwrap(), ("srv", ())); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); } } diff --git a/ntex-service/src/ctx.rs b/ntex-service/src/ctx.rs index 827eba2f..049efad8 100644 --- a/ntex-service/src/ctx.rs +++ b/ntex-service/src/ctx.rs @@ -256,7 +256,7 @@ mod tests { req: &'static str, ctx: ServiceCtx<'_, Self>, ) -> Result { - format!("{:?}", ctx); + let _ = format!("{:?}", ctx); #[allow(clippy::clone_on_copy)] let _ = ctx.clone(); Ok(req) diff --git a/ntex-service/src/fn_service.rs b/ntex-service/src/fn_service.rs index 332e77ff..52e129a6 100644 --- a/ntex-service/src/fn_service.rs +++ b/ntex-service/src/fn_service.rs @@ -380,20 +380,20 @@ mod tests { #[ntex::test] async fn test_fn_service() { let new_srv = fn_service(|()| async { Ok::<_, ()>("srv") }).clone(); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); let srv = Pipeline::new(new_srv.create(()).await.unwrap()).bind(); let res = srv.call(()).await; assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(()))); assert!(res.is_ok()); assert_eq!(res.unwrap(), "srv"); - format!("{:?}", srv); + let _ = format!("{:?}", srv); let srv2 = Pipeline::new(new_srv.clone()).bind(); let res = srv2.call(()).await; assert!(res.is_ok()); assert_eq!(res.unwrap(), "srv"); - format!("{:?}", srv2); + let _ = format!("{:?}", srv2); assert_eq!(lazy(|cx| srv2.poll_shutdown(cx)).await, Poll::Ready(())); } diff --git a/ntex-service/src/fn_shutdown.rs b/ntex-service/src/fn_shutdown.rs index 456b5d4e..5e3c8134 100644 --- a/ntex-service/src/fn_shutdown.rs +++ b/ntex-service/src/fn_shutdown.rs @@ -94,6 +94,6 @@ mod tests { pipe.shutdown().await; assert!(is_called.get()); - format!("{:?}", pipe); + let _ = format!("{:?}", pipe); } } diff --git a/ntex-service/src/map.rs b/ntex-service/src/map.rs index 4669d742..7d4cb094 100644 --- a/ntex-service/src/map.rs +++ b/ntex-service/src/map.rs @@ -184,7 +184,7 @@ mod tests { srv.shutdown().await; assert_eq!(cnt_sht.get(), 1); - format!("{:?}", srv); + let _ = format!("{:?}", srv); } #[ntex::test] @@ -208,7 +208,7 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), ("ok")); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); } #[ntex::test] @@ -222,6 +222,6 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), ("ok")); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); } } diff --git a/ntex-service/src/map_config.rs b/ntex-service/src/map_config.rs index 6256bcaa..a8f334a1 100644 --- a/ntex-service/src/map_config.rs +++ b/ntex-service/src/map_config.rs @@ -134,7 +134,7 @@ mod tests { let _ = factory.create(&10).await; assert_eq!(item.get(), 11); - format!("{:?}", factory); + let _ = format!("{:?}", factory); } #[ntex::test] diff --git a/ntex-service/src/map_err.rs b/ntex-service/src/map_err.rs index b8d1eecb..fcb24263 100644 --- a/ntex-service/src/map_err.rs +++ b/ntex-service/src/map_err.rs @@ -209,7 +209,7 @@ mod tests { assert!(res.is_err()); assert_eq!(res.err().unwrap(), "error"); - format!("{:?}", srv); + let _ = format!("{:?}", srv); } #[ntex::test] @@ -223,7 +223,7 @@ mod tests { assert!(res.is_err()); assert_eq!(res.err().unwrap(), "error"); - format!("{:?}", srv); + let _ = format!("{:?}", srv); } #[ntex::test] @@ -236,7 +236,7 @@ mod tests { let res = srv.call(()).await; assert!(res.is_err()); assert_eq!(res.err().unwrap(), "error"); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); } #[ntex::test] @@ -250,6 +250,6 @@ mod tests { let res = srv.call(()).await; assert!(res.is_err()); assert_eq!(res.err().unwrap(), "error"); - format!("{:?}", new_srv); + let _ = format!("{:?}", new_srv); } } diff --git a/ntex-service/src/map_init_err.rs b/ntex-service/src/map_init_err.rs index d4730362..3973e0cf 100644 --- a/ntex-service/src/map_init_err.rs +++ b/ntex-service/src/map_init_err.rs @@ -88,7 +88,7 @@ mod tests { assert!(factory.create(&true).await.is_err()); assert!(factory.create(&false).await.is_ok()); - format!("{:?}", factory); + let _ = format!("{:?}", factory); } #[ntex::test] @@ -108,6 +108,6 @@ mod tests { assert!(factory.create(&true).await.is_err()); assert!(factory.create(&false).await.is_ok()); - format!("{:?}", factory); + let _ = format!("{:?}", factory); } } diff --git a/ntex-service/src/middleware.rs b/ntex-service/src/middleware.rs index c9f9fa20..825ab139 100644 --- a/ntex-service/src/middleware.rs +++ b/ntex-service/src/middleware.rs @@ -244,7 +244,7 @@ mod tests { let res = srv.call(10).await; assert!(res.is_ok()); assert_eq!(res.unwrap(), 20); - format!("{:?} {:?}", factory, srv); + let _ = format!("{:?} {:?}", factory, srv); assert_eq!(srv.ready().await, Ok(())); srv.shutdown().await; @@ -259,7 +259,7 @@ mod tests { let res = srv.call(10).await; assert!(res.is_ok()); assert_eq!(res.unwrap(), 20); - format!("{:?} {:?}", factory, srv); + let _ = format!("{:?} {:?}", factory, srv); assert_eq!(srv.ready().await, Ok(())); } diff --git a/ntex-util/src/services/inflight.rs b/ntex-util/src/services/inflight.rs index 5bdfec23..bf48df00 100644 --- a/ntex-util/src/services/inflight.rs +++ b/ntex-util/src/services/inflight.rs @@ -117,7 +117,7 @@ mod tests { let _ = tx.send(()); crate::time::sleep(Duration::from_millis(25)).await; assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(()))); - assert_eq!(srv.shutdown().await, ()); + srv.shutdown().await; } #[ntex_macros::rt_test2] diff --git a/ntex-util/src/services/onerequest.rs b/ntex-util/src/services/onerequest.rs index 33c26fba..7c7b5185 100644 --- a/ntex-util/src/services/onerequest.rs +++ b/ntex-util/src/services/onerequest.rs @@ -118,7 +118,7 @@ mod tests { let _ = tx.send(()); crate::time::sleep(Duration::from_millis(25)).await; assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(()))); - assert_eq!(srv.shutdown().await, ()); + srv.shutdown().await; } #[ntex_macros::rt_test2] diff --git a/ntex-util/src/services/timeout.rs b/ntex-util/src/services/timeout.rs index 04ddf31c..5c6aac4f 100644 --- a/ntex-util/src/services/timeout.rs +++ b/ntex-util/src/services/timeout.rs @@ -183,7 +183,7 @@ mod tests { Pipeline::new(TimeoutService::new(resolution, SleepService(wait_time)).clone()); assert_eq!(timeout.call(()).await, Ok(())); assert_eq!(timeout.ready().await, Ok(())); - assert_eq!(timeout.shutdown().await, ()); + timeout.shutdown().await; } #[ntex_macros::rt_test2] diff --git a/ntex-util/src/services/variant.rs b/ntex-util/src/services/variant.rs index 0e4757a8..bc8c26a5 100644 --- a/ntex-util/src/services/variant.rs +++ b/ntex-util/src/services/variant.rs @@ -283,7 +283,7 @@ mod tests { let service = factory.pipeline(&()).await.unwrap().clone(); assert!(service.ready().await.is_ok()); - assert_eq!(service.shutdown().await, ()); + service.shutdown().await; assert_eq!(service.call(Variant3::V1(())).await, Ok(1)); assert_eq!(service.call(Variant3::V2(())).await, Ok(2)); diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 30950409..a02d8a62 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -15,6 +15,7 @@ categories = [ ] license = "MIT OR Apache-2.0" edition = "2021" +rust-version = "1.75" [package.metadata.docs.rs] features = ["tokio", "openssl", "rustls", "compress", "cookie", "ws", "brotli"] diff --git a/ntex/src/web/info.rs b/ntex/src/web/info.rs index 51d336b8..2065121f 100644 --- a/ntex/src/web/info.rs +++ b/ntex/src/web/info.rs @@ -70,7 +70,7 @@ impl ConnectionInfo { if scheme.is_none() { if let Some(h) = req .headers - .get(&HeaderName::from_lowercase(X_FORWARDED_PROTO).unwrap()) + .get(HeaderName::from_lowercase(X_FORWARDED_PROTO).unwrap()) { if let Ok(h) = h.to_str() { scheme = h.split(',').next().map(|v| v.trim()); @@ -88,7 +88,7 @@ impl ConnectionInfo { if host.is_none() { if let Some(h) = req .headers - .get(&HeaderName::from_lowercase(X_FORWARDED_HOST).unwrap()) + .get(HeaderName::from_lowercase(X_FORWARDED_HOST).unwrap()) { if let Ok(h) = h.to_str() { host = h.split(',').next().map(|v| v.trim()); @@ -111,7 +111,7 @@ impl ConnectionInfo { if remote.is_none() { if let Some(h) = req .headers - .get(&HeaderName::from_lowercase(X_FORWARDED_FOR).unwrap()) + .get(HeaderName::from_lowercase(X_FORWARDED_FOR).unwrap()) { if let Ok(h) = h.to_str() { remote = h.split(',').next().map(|v| v.trim()); diff --git a/ntex/src/web/middleware/logger.rs b/ntex/src/web/middleware/logger.rs index 7ea0340d..cc5bbfeb 100644 --- a/ntex/src/web/middleware/logger.rs +++ b/ntex/src/web/middleware/logger.rs @@ -339,11 +339,7 @@ impl FormatText { } FormatText::ResponseHeader(ref name) => { let s = if let Some(val) = res.headers().get(name) { - if let Ok(s) = val.to_str() { - s - } else { - "-" - } + val.to_str().unwrap_or("-") } else { "-" }; @@ -380,11 +376,7 @@ impl FormatText { } FormatText::RequestHeader(ref name) => { let s = if let Some(val) = req.headers().get(name) { - if let Ok(s) = val.to_str() { - s - } else { - "-" - } + val.to_str().unwrap_or("-") } else { "-" };