From ec8eb23707c2baec53f3ca019aff674c7ca61e0e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 8 Apr 2024 11:55:49 +0500 Subject: [PATCH] Glommio clippy (#341) --- .github/workflows/cov.yml | 1 + .github/workflows/linux.yml | 4 ++-- .github/workflows/osx.yml | 7 ++++++- .github/workflows/windows.yml | 19 +------------------ ntex-bytes/Cargo.toml | 2 +- ntex-bytes/src/buf/buf_mut.rs | 2 +- ntex-bytes/src/bytes.rs | 2 +- ntex-bytes/tests/test_buf_mut.rs | 1 - ntex-glommio/src/io.rs | 2 ++ ntex-glommio/src/signals.rs | 2 +- ntex-http/src/value.rs | 2 +- ntex-router/src/path.rs | 6 +----- ntex-tokio/src/lib.rs | 6 +++--- ntex/Cargo.toml | 2 +- ntex/src/web/app.rs | 8 ++++---- ntex/src/web/httprequest.rs | 6 +----- ntex/src/web/request.rs | 6 +----- 17 files changed, 28 insertions(+), 50 deletions(-) diff --git a/.github/workflows/cov.yml b/.github/workflows/cov.yml index 6be5c2797..9853ebde0 100644 --- a/.github/workflows/cov.yml +++ b/.github/workflows/cov.yml @@ -38,5 +38,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: + token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info fail_ci_if_error: true diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a54d0398d..dad535ead 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -53,12 +53,12 @@ jobs: continue-on-error: true run: | cd ntex - cargo test --no-default-features --no-fail-fast --features="async-std,cookie,url,compress,openssl,rustls,ws" + cargo test --no-default-features --no-fail-fast --features="async-std,cookie,url,compress,openssl,rustls,ws,brotli" - name: Install cargo-cache continue-on-error: true run: | - cargo install cargo-cache --version 0.6.2 --no-default-features --features ci-autoclean + cargo install cargo-cache --no-default-features --features ci-autoclean - name: Clear the cargo caches continue-on-error: true diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index c7307552b..40d90c898 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -40,7 +40,12 @@ jobs: - name: Run tests run: cargo test --all --all-features --no-fail-fast -- --nocapture - - name: Clear the cargo caches + - name: Install cargo-cache + continue-on-error: true run: | cargo install cargo-cache --no-default-features --features ci-autoclean + + - name: Clear the cargo caches + continue-on-error: true + run: | cargo-cache diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f5ba5b4c5..a12ab6410 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -63,21 +63,4 @@ jobs: - name: Run tests run: | - cargo test --lib --all-features --no-fail-fast -- --nocapture \ - --skip test_panic_in_worker \ - --skip test_connection_force_close \ - --skip test_connection_server_close \ - --skip test_freeze \ - --skip test_simple \ - --skip test_test_methods \ - --skip test_connection_wait_queue_force_close \ - --skip test_params \ - --skip test_body \ - --skip test_form \ - --skip test_json \ - --skip test_connection_reuse \ - --skip test_connection_wait_queue \ - --skip test_no_decompress \ - --skip test_connection_reuse_h2 \ - --skip test_h2_tcp \ - --skip test_timer + cargo test --lib --all-features --no-fail-fast -- --nocapture --skip test_panic_in_worker --skip test_connection_force_close --skip test_connection_server_close --skip test_freeze --skip test_simple --skip test_test_methods --skip test_connection_wait_queue_force_close --skip test_params --skip test_body --skip test_form --skip test_json --skip test_connection_reuse --skip test_connection_wait_queue --skip test_no_decompress --skip test_connection_reuse_h2 --skip test_h2_tcp --skip test_timer diff --git a/ntex-bytes/Cargo.toml b/ntex-bytes/Cargo.toml index fc11acbf2..9d88d9ff4 100644 --- a/ntex-bytes/Cargo.toml +++ b/ntex-bytes/Cargo.toml @@ -30,4 +30,4 @@ simdutf8 = { version = "0.1.4", optional = true } serde_test = "1" serde_json = "1" ntex = { version = "1", features = ["tokio"] } -ntex-bytes = { version = "*", features = ["mpool"] } +ntex-bytes = { path = ".", features = ["mpool"] } diff --git a/ntex-bytes/src/buf/buf_mut.rs b/ntex-bytes/src/buf/buf_mut.rs index 7bbb50762..9c3ec2d19 100644 --- a/ntex-bytes/src/buf/buf_mut.rs +++ b/ntex-bytes/src/buf/buf_mut.rs @@ -1,4 +1,4 @@ -use std::{cmp, mem, ptr, usize}; +use std::{cmp, mem, ptr}; use super::{UninitSlice, Writer}; diff --git a/ntex-bytes/src/bytes.rs b/ntex-bytes/src/bytes.rs index 753cdf5e9..d62e6e4c8 100644 --- a/ntex-bytes/src/bytes.rs +++ b/ntex-bytes/src/bytes.rs @@ -2,7 +2,7 @@ use std::borrow::{Borrow, BorrowMut}; use std::ops::{Deref, DerefMut, RangeBounds}; use std::sync::atomic::Ordering::{Acquire, Relaxed, Release}; use std::sync::atomic::{self, AtomicUsize}; -use std::{cmp, fmt, hash, mem, ptr, ptr::NonNull, slice, usize}; +use std::{cmp, fmt, hash, mem, ptr, ptr::NonNull, slice}; use crate::pool::{PoolId, PoolRef}; use crate::{buf::IntoIter, buf::UninitSlice, debug, Buf, BufMut}; diff --git a/ntex-bytes/tests/test_buf_mut.rs b/ntex-bytes/tests/test_buf_mut.rs index 37d80f984..0209cb3ab 100644 --- a/ntex-bytes/tests/test_buf_mut.rs +++ b/ntex-bytes/tests/test_buf_mut.rs @@ -2,7 +2,6 @@ use ntex_bytes::{BufMut, BytesMut}; use std::fmt::Write; -use std::usize; #[test] fn test_vec_as_mut_buf() { diff --git a/ntex-glommio/src/io.rs b/ntex-glommio/src/io.rs index d2d3456c0..7d60c0de3 100644 --- a/ntex-glommio/src/io.rs +++ b/ntex-glommio/src/io.rs @@ -202,6 +202,7 @@ impl Future for WriteTask { match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) { Poll::Ready(Ok(())) => { let io = this.io.clone(); + #[allow(clippy::await_holding_refcell_ref)] let fut = Box::pin(async move { io.0.borrow() .shutdown(std::net::Shutdown::Write) @@ -510,6 +511,7 @@ impl Future for UnixWriteTask { match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) { Poll::Ready(Ok(())) => { let io = this.io.clone(); + #[allow(clippy::await_holding_refcell_ref)] let fut = Box::pin(async move { io.0.borrow() .shutdown(std::net::Shutdown::Write) diff --git a/ntex-glommio/src/signals.rs b/ntex-glommio/src/signals.rs index d06077ee2..366ace9c9 100644 --- a/ntex-glommio/src/signals.rs +++ b/ntex-glommio/src/signals.rs @@ -1,7 +1,7 @@ use std::{cell::RefCell, future::Future, pin::Pin, rc::Rc, task::Context, task::Poll}; thread_local! { - static SRUN: RefCell = RefCell::new(false); + static SRUN: RefCell = const { RefCell::new(false) }; static SHANDLERS: Rc>>> = Default::default(); } diff --git a/ntex-http/src/value.rs b/ntex-http/src/value.rs index 0c6cceeaa..27b197c66 100644 --- a/ntex-http/src/value.rs +++ b/ntex-http/src/value.rs @@ -708,7 +708,7 @@ macro_rules! from_integers { let val = HeaderValue::from(n); assert_eq!(val, &n.to_string()); - let n = ::std::$t::MAX; + let n = $t::MAX; let val = HeaderValue::from(n); assert_eq!(val, &n.to_string()); } diff --git a/ntex-router/src/path.rs b/ntex-router/src/path.rs index aa8b5b017..1a6b62df0 100644 --- a/ntex-router/src/path.rs +++ b/ntex-router/src/path.rs @@ -147,11 +147,7 @@ impl Path { /// If keyed parameter is not available empty string is used as default /// value. pub fn query(&self, key: &str) -> &str { - if let Some(s) = self.get(key) { - s - } else { - "" - } + self.get(key).unwrap_or_default() } /// Return iterator to items in parameter container diff --git a/ntex-tokio/src/lib.rs b/ntex-tokio/src/lib.rs index b157829df..79d538e2b 100644 --- a/ntex-tokio/src/lib.rs +++ b/ntex-tokio/src/lib.rs @@ -1,4 +1,4 @@ -use std::{io::Result, net, net::SocketAddr, path::Path}; +use std::{io::Result, net, net::SocketAddr}; use ntex_bytes::PoolRef; use ntex_io::Io; @@ -32,7 +32,7 @@ pub async fn tcp_connect_in(addr: SocketAddr, pool: PoolRef) -> Result { /// Opens a unix stream connection. pub async fn unix_connect<'a, P>(addr: P) -> Result where - P: AsRef + 'a, + P: AsRef + 'a, { let sock = tokio::net::UnixStream::connect(addr).await?; Ok(Io::new(UnixStream(sock))) @@ -42,7 +42,7 @@ where /// Opens a unix stream connection and specified memory pool. pub async fn unix_connect_in<'a, P>(addr: P, pool: PoolRef) -> Result where - P: AsRef + 'a, + P: AsRef + 'a, { let sock = tokio::net::UnixStream::connect(addr).await?; Ok(Io::with_memory_pool(UnixStream(sock), pool)) diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 1b31d63af..0da426c6f 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -17,7 +17,7 @@ license = "MIT OR Apache-2.0" edition = "2021" [package.metadata.docs.rs] -features = ["tokio", "openssl", "rustls", "compress", "cookie", "ws"] +features = ["tokio", "openssl", "rustls", "compress", "cookie", "ws", "brotli"] [lib] name = "ntex" diff --git a/ntex/src/web/app.rs b/ntex/src/web/app.rs index f939220ff..d99852d31 100644 --- a/ntex/src/web/app.rs +++ b/ntex/src/web/app.rs @@ -592,12 +592,10 @@ impl Service> for Filter { #[cfg(test)] mod tests { use super::*; - use crate::http::header::{self, HeaderValue}; - use crate::http::{Method, StatusCode}; - use crate::service::fn_service; - use crate::util::{Bytes, Ready}; + use crate::http::{header, header::HeaderValue, Method, StatusCode}; use crate::web::test::{call_service, init_service, read_body, TestRequest}; use crate::web::{self, middleware::DefaultHeaders, HttpRequest, HttpResponse}; + use crate::{service::fn_service, util::Ready}; #[crate::rt_test] async fn test_default_resource() { @@ -775,6 +773,8 @@ mod tests { #[cfg(feature = "url")] #[crate::rt_test] async fn test_external_resource() { + use crate::util::Bytes; + let srv = init_service( App::new() .external_resource("youtube", "https://youtube.com/watch/{video_id}") diff --git a/ntex/src/web/httprequest.rs b/ntex/src/web/httprequest.rs index eec94d4c3..468af1efa 100644 --- a/ntex/src/web/httprequest.rs +++ b/ntex/src/web/httprequest.rs @@ -97,11 +97,7 @@ impl HttpRequest { /// E.g., id=10 #[inline] pub fn query_string(&self) -> &str { - if let Some(query) = self.uri().query().as_ref() { - query - } else { - "" - } + self.uri().query().unwrap_or_default() } /// Io reference for current connection diff --git a/ntex/src/web/request.rs b/ntex/src/web/request.rs index cd1bafc8c..04d84ee9a 100644 --- a/ntex/src/web/request.rs +++ b/ntex/src/web/request.rs @@ -145,11 +145,7 @@ impl WebRequest { /// E.g., id=10 #[inline] pub fn query_string(&self) -> &str { - if let Some(query) = self.uri().query().as_ref() { - query - } else { - "" - } + self.uri().query().unwrap_or_default() } /// Peer socket address