From 99c07e4d86aca7720d6acd3bdb06978fc6ff0541 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 3 Dec 2024 21:27:14 +0000 Subject: [PATCH] Enable and fix warnings from clippy::uninlined_format_args (#3063) --- .clippy.toml | 1 + Cargo.toml | 1 + axum-extra/src/response/multiple.rs | 13 ++++++------- axum-extra/src/routing/typed.rs | 3 +-- axum-extra/src/typed_header.rs | 2 +- axum/benches/benches.rs | 2 +- axum/src/extract/ws.rs | 2 +- axum/src/test_helpers/test_client.rs | 10 +++++----- 8 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000000..b95e806aae --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +allow-mixed-uninlined-format-args = false diff --git a/Cargo.toml b/Cargo.toml index 298b9b3b3f..3027edbfd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ rest_pat_in_fully_bound_structs = "warn" str_to_string = "warn" suboptimal_flops = "warn" todo = "warn" +uninlined_format_args = "warn" unnested_or_patterns = "warn" unused_self = "warn" verbose_file_reads = "warn" diff --git a/axum-extra/src/response/multiple.rs b/axum-extra/src/response/multiple.rs index 250dc02457..390ef3e726 100644 --- a/axum-extra/src/response/multiple.rs +++ b/axum-extra/src/response/multiple.rs @@ -34,7 +34,7 @@ impl IntoResponse for MultipartForm { // see RFC5758 for details let boundary = generate_boundary(); let mut headers = HeaderMap::new(); - let mime_type: Mime = match format!("multipart/form-data; boundary={}", boundary).parse() { + let mime_type: Mime = match format!("multipart/form-data; boundary={boundary}").parse() { Ok(m) => m, // Realistically this should never happen unless the boundary generation code // is modified, and that will be caught by unit tests @@ -51,10 +51,10 @@ impl IntoResponse for MultipartForm { let mut serialized_form: Vec = Vec::new(); for part in self.parts { // for each part, the boundary is preceded by two dashes - serialized_form.extend_from_slice(format!("--{}\r\n", boundary).as_bytes()); + serialized_form.extend_from_slice(format!("--{boundary}\r\n").as_bytes()); serialized_form.extend_from_slice(&part.serialize()); } - serialized_form.extend_from_slice(format!("--{}--", boundary).as_bytes()); + serialized_form.extend_from_slice(format!("--{boundary}--").as_bytes()); (headers, serialized_form).into_response() } } @@ -184,7 +184,7 @@ impl Part { let mut serialized_part = format!("Content-Disposition: form-data; name=\"{}\"", self.name); // specify a filename if one was set if let Some(filename) = &self.filename { - serialized_part += &format!("; filename=\"{}\"", filename); + serialized_part += &format!("; filename=\"{filename}\""); } serialized_part += "\r\n"; // specify the MIME type @@ -256,7 +256,7 @@ mod tests { let body: &[u8] = &response.into_body().collect().await?.to_bytes(); assert_eq!( std::str::from_utf8(body)?, - &format!( + format!( "--{boundary}\r\n\ Content-Disposition: form-data; name=\"part1\"\r\n\ Content-Type: text/plain; charset=utf-8\r\n\ @@ -273,7 +273,6 @@ mod tests { \r\n\ rawpart\r\n\ --{boundary}--", - boundary = boundary ) ); @@ -285,7 +284,7 @@ mod tests { for _ in 0..256 { let boundary = generate_boundary(); let mime_type: Result = - format!("multipart/form-data; boundary={}", boundary).parse(); + format!("multipart/form-data; boundary={boundary}").parse(); assert!( mime_type.is_ok(), "The generated boundary was unable to be parsed into a valid mime type." diff --git a/axum-extra/src/routing/typed.rs b/axum-extra/src/routing/typed.rs index 02c5be672c..eccdfb19de 100644 --- a/axum-extra/src/routing/typed.rs +++ b/axum-extra/src/routing/typed.rs @@ -299,9 +299,8 @@ where .serialize(serde_html_form::ser::Serializer::new(&mut urlencoder)) .unwrap_or_else(|err| { panic!( - "failed to URL encode value of type `{}`: {}", + "failed to URL encode value of type `{}`: {err}", type_name::(), - err ) }); f.write_str(&out)?; diff --git a/axum-extra/src/typed_header.rs b/axum-extra/src/typed_header.rs index ef94c3779c..7ffd598047 100644 --- a/axum-extra/src/typed_header.rs +++ b/axum-extra/src/typed_header.rs @@ -168,7 +168,7 @@ impl std::fmt::Display for TypedHeaderRejection { write!(f, "Header of type `{}` was missing", self.name) } TypedHeaderRejectionReason::Error(err) => { - write!(f, "{} ({})", err, self.name) + write!(f, "{err} ({})", self.name) } } } diff --git a/axum/benches/benches.rs b/axum/benches/benches.rs index 445f5de03e..c38ef91830 100644 --- a/axum/benches/benches.rs +++ b/axum/benches/benches.rs @@ -172,7 +172,7 @@ impl BenchmarkBuilder { cmd.stdout(Stdio::piped()); cmd.arg("--host"); - cmd.arg(format!("http://{}{}", addr, self.path.unwrap_or(""))); + cmd.arg(format!("http://{addr}{}", self.path.unwrap_or(""))); cmd.args(["--connections", "10"]); cmd.args(["--threads", "10"]); diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 6bf3b44628..fa06d249ad 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -995,7 +995,7 @@ mod tests { if status != 200 { let body = response.into_body().collect().await.unwrap().to_bytes(); let body = std::str::from_utf8(&body).unwrap(); - panic!("response status was {}: {body}", status); + panic!("response status was {status}: {body}"); } let upgraded = hyper::upgrade::on(response).await.unwrap(); let upgraded = TokioIo::new(upgraded); diff --git a/axum/src/test_helpers/test_client.rs b/axum/src/test_helpers/test_client.rs index 2dfa95a01f..adab69445e 100644 --- a/axum/src/test_helpers/test_client.rs +++ b/axum/src/test_helpers/test_client.rs @@ -54,33 +54,33 @@ impl TestClient { pub(crate) fn get(&self, url: &str) -> RequestBuilder { RequestBuilder { - builder: self.client.get(format!("http://{}{}", self.addr, url)), + builder: self.client.get(format!("http://{}{url}", self.addr)), } } pub(crate) fn head(&self, url: &str) -> RequestBuilder { RequestBuilder { - builder: self.client.head(format!("http://{}{}", self.addr, url)), + builder: self.client.head(format!("http://{}{url}", self.addr)), } } pub(crate) fn post(&self, url: &str) -> RequestBuilder { RequestBuilder { - builder: self.client.post(format!("http://{}{}", self.addr, url)), + builder: self.client.post(format!("http://{}{url}", self.addr)), } } #[allow(dead_code)] pub(crate) fn put(&self, url: &str) -> RequestBuilder { RequestBuilder { - builder: self.client.put(format!("http://{}{}", self.addr, url)), + builder: self.client.put(format!("http://{}{url}", self.addr)), } } #[allow(dead_code)] pub(crate) fn patch(&self, url: &str) -> RequestBuilder { RequestBuilder { - builder: self.client.patch(format!("http://{}{}", self.addr, url)), + builder: self.client.patch(format!("http://{}{url}", self.addr)), } }