From 5de1c9de7507f25ac73dd3c4ad148bca38e36918 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Aug 2023 23:06:34 +0100 Subject: [PATCH] chore: address clippy lints --- actix-files/src/lib.rs | 7 +++++-- actix-http/src/h1/payload.rs | 7 ++++--- actix-multipart/src/server.rs | 4 ++-- actix-router/benches/quoter.rs | 9 +++++---- actix-router/src/url.rs | 8 +++++++- actix-web/src/app_service.rs | 6 +----- actix-web/src/handler.rs | 2 +- actix-web/src/route.rs | 2 +- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 1d8609889..7871905f6 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -66,6 +66,7 @@ type PathFilter = dyn Fn(&Path, &RequestHead) -> bool; #[cfg(test)] mod tests { use std::{ + fmt::Write as _, fs::{self}, ops::Add, time::{Duration, SystemTime}, @@ -848,8 +849,10 @@ mod tests { let filename_encoded = filename .as_bytes() .iter() - .map(|c| format!("%{:02X}", c)) - .collect::(); + .fold(String::new(), |mut buf, c| { + write!(&mut buf, "%{:02X}", c).unwrap(); + buf + }); std::fs::File::create(tmpdir.path().join(filename)).unwrap(); let srv = test::init_service(App::new().service(Files::new("", tmpdir.path()))).await; diff --git a/actix-http/src/h1/payload.rs b/actix-http/src/h1/payload.rs index 1ed785a1b..2ad3a14a3 100644 --- a/actix-http/src/h1/payload.rs +++ b/actix-http/src/h1/payload.rs @@ -117,6 +117,7 @@ impl PayloadSender { } } + #[allow(clippy::needless_pass_by_ref_mut)] #[inline] pub fn need_read(&self, cx: &mut Context<'_>) -> PayloadStatus { // we check need_read only if Payload (other side) is alive, @@ -174,7 +175,7 @@ impl Inner { /// Register future waiting data from payload. /// Waker would be used in `Inner::wake` - fn register(&mut self, cx: &mut Context<'_>) { + fn register(&mut self, cx: &Context<'_>) { if self .task .as_ref() @@ -186,7 +187,7 @@ impl Inner { // Register future feeding data to payload. /// Waker would be used in `Inner::wake_io` - fn register_io(&mut self, cx: &mut Context<'_>) { + fn register_io(&mut self, cx: &Context<'_>) { if self .io_task .as_ref() @@ -221,7 +222,7 @@ impl Inner { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut Context<'_>, + cx: &Context<'_>, ) -> Poll>> { if let Some(data) = self.items.pop_front() { self.len -= data.len(); diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index b20429040..c08031eba 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -252,7 +252,7 @@ impl InnerMultipart { fn poll( &mut self, safety: &Safety, - cx: &mut Context<'_>, + cx: &Context<'_>, ) -> Poll>> { if self.state == InnerState::Eof { Poll::Ready(None) @@ -740,7 +740,7 @@ impl Safety { self.clean.get() } - fn clone(&self, cx: &mut Context<'_>) -> Safety { + fn clone(&self, cx: &Context<'_>) -> Safety { let payload = Rc::clone(&self.payload); let s = Safety { task: LocalWaker::new(), diff --git a/actix-router/benches/quoter.rs b/actix-router/benches/quoter.rs index 2065fd563..c78240809 100644 --- a/actix-router/benches/quoter.rs +++ b/actix-router/benches/quoter.rs @@ -1,6 +1,6 @@ #![allow(clippy::uninlined_format_args)] -use std::borrow::Cow; +use std::{borrow::Cow, fmt::Write as _}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; @@ -8,9 +8,10 @@ fn compare_quoters(c: &mut Criterion) { let mut group = c.benchmark_group("Compare Quoters"); let quoter = actix_router::Quoter::new(b"", b""); - let path_quoted = (0..=0x7f) - .map(|c| format!("%{:02X}", c)) - .collect::(); + let path_quoted = (0..=0x7f).fold(String::new(), |mut buf, c| { + write!(&mut buf, "%{:02X}", c).unwrap(); + buf + }); let path_unquoted = ('\u{00}'..='\u{7f}').collect::(); group.bench_function("quoter_unquoted", |b| { diff --git a/actix-router/src/url.rs b/actix-router/src/url.rs index 2920e271d..b3d9e1121 100644 --- a/actix-router/src/url.rs +++ b/actix-router/src/url.rs @@ -62,6 +62,8 @@ impl ResourcePath for Url { #[cfg(test)] mod tests { + use std::fmt::Write as _; + use http::Uri; use super::*; @@ -78,7 +80,11 @@ mod tests { } fn percent_encode(data: &[u8]) -> String { - data.iter().map(|c| format!("%{:02X}", c)).collect() + data.iter() + .fold(String::with_capacity(data.len() * 3), |mut buf, c| { + write!(&mut buf, "%{:02X}", c).unwrap(); + buf + }) } #[test] diff --git a/actix-web/src/app_service.rs b/actix-web/src/app_service.rs index 513e7a8a1..f2dca954c 100644 --- a/actix-web/src/app_service.rs +++ b/actix-web/src/app_service.rs @@ -112,11 +112,7 @@ where let endpoint_fut = self.endpoint.new_service(()); // take extensions or create new one as app data container. - let mut app_data = self - .extensions - .borrow_mut() - .take() - .unwrap_or_else(Extensions::new); + let mut app_data = self.extensions.borrow_mut().take().unwrap_or_default(); Box::pin(async move { // async data factories diff --git a/actix-web/src/handler.rs b/actix-web/src/handler.rs index 0c5e58e28..3d6b7f039 100644 --- a/actix-web/src/handler.rs +++ b/actix-web/src/handler.rs @@ -167,7 +167,7 @@ mod tests { async fn handler_min() {} #[rustfmt::skip] - #[allow(clippy::too_many_arguments, clippy::just_underscores_and_digits)] + #[allow(clippy::too_many_arguments, clippy::just_underscores_and_digits, clippy::let_unit_value)] async fn handler_max( _01: (), _02: (), _03: (), _04: (), _05: (), _06: (), _07: (), _08: (), _09: (), _10: (), _11: (), _12: (), diff --git a/actix-web/src/route.rs b/actix-web/src/route.rs index 674d0082a..a46c1fdd4 100644 --- a/actix-web/src/route.rs +++ b/actix-web/src/route.rs @@ -92,7 +92,7 @@ pub struct RouteService { } impl RouteService { - // TODO: does this need to take &mut ? + #[allow(clippy::needless_pass_by_ref_mut)] pub fn check(&self, req: &mut ServiceRequest) -> bool { let guard_ctx = req.guard_ctx();