Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable and fix warnings from clippy::uninlined_format_args #3063

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-mixed-uninlined-format-args = false
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 6 additions & 7 deletions axum-extra/src/response/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,10 +51,10 @@ impl IntoResponse for MultipartForm {
let mut serialized_form: Vec<u8> = 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()
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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\
Expand All @@ -273,7 +273,6 @@ mod tests {
\r\n\
rawpart\r\n\
--{boundary}--",
boundary = boundary
)
);

Expand All @@ -285,7 +284,7 @@ mod tests {
for _ in 0..256 {
let boundary = generate_boundary();
let mime_type: Result<Mime, _> =
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."
Expand Down
3 changes: 1 addition & 2 deletions axum-extra/src/routing/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>(),
err
)
});
f.write_str(&out)?;
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/typed_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion axum/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down
2 changes: 1 addition & 1 deletion axum/src/extract/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions axum/src/test_helpers/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down