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

chore: fix new clippy lints #272

Merged
merged 1 commit into from
Jan 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion worker-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn remove_unused_js() -> Result<()> {
}

for to_remove in [
format!("{}_bg.js", OUT_NAME),
format!("{OUT_NAME}_bg.js"),
"shim.js".into(),
"glue.js".into(),
] {
Expand Down
8 changes: 4 additions & 4 deletions worker-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
})
.get("/user/:id/test", |_req, ctx| {
if let Some(id) = ctx.param("id") {
return Response::ok(format!("TEST user id: {}", id));
return Response::ok(format!("TEST user id: {id}"));
}

Response::error("Error", 500)
Expand Down Expand Up @@ -594,7 +594,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
.get_async("/cache-api/get/:key", |_req, ctx| async move {
if let Some(key) = ctx.param("key") {
let cache = Cache::default();
if let Some(resp) = cache.get(format!("https://{}", key), true).await? {
if let Some(resp) = cache.get(format!("https://{key}"), true).await? {
return Ok(resp);
} else {
return Response::ok("cache miss");
Expand All @@ -611,7 +611,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
// Cache API respects Cache-Control headers. Setting s-max-age to 10
// will limit the response to be in cache for 10 seconds max
resp.headers_mut().set("cache-control", "s-maxage=10")?;
cache.put(format!("https://{}", key), resp.cloned()?).await?;
cache.put(format!("https://{key}"), resp.cloned()?).await?;
return Ok(resp);
}
Response::error("key missing", 400)
Expand All @@ -620,7 +620,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
if let Some(key) = ctx.param("key") {
let cache = Cache::default();

let res = cache.delete(format!("https://{}", key), true).await?;
let res = cache.delete(format!("https://{key}"), true).await?;
return Response::ok(serde_json::to_string(&res)?);
}
Response::error("key missing", 400)
Expand Down
2 changes: 1 addition & 1 deletion worker-sandbox/src/test/export_durable_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl DurableObject for MyClass {

ensure!(
keys == vec!["anything", "array", "map"],
format!("Didn't list all of the keys: {:?}", keys)
format!("Didn't list all of the keys: {keys:?}")
);
let vals = storage
.get_multiple(keys)
Expand Down
6 changes: 3 additions & 3 deletions worker-sandbox/tests/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ fn cache_stream() {
#[test]
fn cache_api() {
let key = "example.org";
let get_endpoint = format!("cache-api/get/{}", key);
let put_endpoint = format!("cache-api/put/{}", key);
let delete_endpoint = format!("cache-api/delete/{}", key);
let get_endpoint = format!("cache-api/get/{key}");
let put_endpoint = format!("cache-api/put/{key}");
let delete_endpoint = format!("cache-api/delete/{key}");

// First time should result in cache miss
let body = get(get_endpoint.as_str(), |r| r).text().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion worker/src/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Cors {
headers.set("Access-Control-Allow-Credentials", "true")?;
}
if let Some(ref max_age) = self.max_age {
headers.set("Access-Control-Max-Age", format!("{}", max_age).as_str())?;
headers.set("Access-Control-Max-Age", format!("{max_age}").as_str())?;
}
if !self.origins.is_empty() {
headers.set(
Expand Down
4 changes: 2 additions & 2 deletions worker/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ extern "C" {
impl Env {
fn get_binding<T: EnvBinding>(&self, name: &str) -> Result<T> {
let binding = js_sys::Reflect::get(self, &JsValue::from(name))
.map_err(|_| Error::JsError(format!("Env does not contain binding `{}`", name)))?;
.map_err(|_| Error::JsError(format!("Env does not contain binding `{name}`")))?;
if binding.is_undefined() {
Err(format!("Binding `{}` is undefined.", name).into())
Err(format!("Binding `{name}` is undefined.").into())
} else {
// Can't just use JsCast::dyn_into here because the type name might not be in scope
// resulting in a terribly annoying javascript error which can't be caught
Expand Down
12 changes: 6 additions & 6 deletions worker/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ impl std::fmt::Display for Error {
match self {
Error::BadEncoding => write!(f, "content-type mismatch"),
Error::BodyUsed => write!(f, "body has already been read"),
Error::Json((msg, status)) => write!(f, "{} (status: {})", msg, status),
Error::Json((msg, status)) => write!(f, "{msg} (status: {status})"),
Error::JsError(s) | Error::RustError(s) => {
write!(f, "{}", s)
write!(f, "{s}")
}
Error::Internal(_) => write!(f, "unrecognized JavaScript object"),
Error::BindingError(name) => write!(f, "no binding found for `{}`", name),
Error::RouteInsertError(e) => write!(f, "failed to insert route: {}", e),
Error::BindingError(name) => write!(f, "no binding found for `{name}`"),
Error::RouteInsertError(e) => write!(f, "failed to insert route: {e}"),
Error::RouteNoDataError => write!(f, "route has no corresponding shared data"),
Error::SerdeJsonError(e) => write!(f, "Serde Error: {}", e),
Error::SerdeJsonError(e) => write!(f, "Serde Error: {e}"),
#[cfg(feature = "queue")]
Error::SerdeWasmBindgenError(e) => write!(f, "Serde Error: {}", e),
Error::SerdeWasmBindgenError(e) => write!(f, "Serde Error: {e}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion worker/src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl std::fmt::Debug for Headers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Headers {\n")?;
for (k, v) in self.entries() {
f.write_str(&format!("{} = {}\n", k, v))?;
f.write_str(&format!("{k} = {v}\n"))?;
}
f.write_str("}\n")
}
Expand Down
2 changes: 1 addition & 1 deletion worker/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Request {
pub fn url(&self) -> Result<Url> {
let url = self.edge_request.url();
url.parse()
.map_err(|e| Error::RustError(format!("failed to parse Url from {}: {}", e, url)))
.map_err(|e| Error::RustError(format!("failed to parse Url from {e}: {url}")))
}

#[allow(clippy::should_implement_trait)]
Expand Down