Skip to content

Commit f84eda9

Browse files
committed
Use format arguments capture feature
see rust-lang/rust#90473
1 parent 7ea5429 commit f84eda9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+130
-165
lines changed

cargo-registry-markdown/lib.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -390,62 +390,55 @@ mod tests {
390390
assert_eq!(
391391
result,
392392
format!(
393-
"<p><a href=\"https://{}/rust-lang/test/blob/HEAD/hi\" rel=\"nofollow noopener noreferrer\">hi</a></p>\n",
394-
host
393+
"<p><a href=\"https://{host}/rust-lang/test/blob/HEAD/hi\" rel=\"nofollow noopener noreferrer\">hi</a></p>\n"
395394
)
396395
);
397396

398397
let result = markdown_to_html(relative, Some(&url), "");
399398
assert_eq!(
400399
result,
401400
format!(
402-
"<p><a href=\"https://{}/rust-lang/test/blob/HEAD/there\" rel=\"nofollow noopener noreferrer\">there</a></p>\n",
403-
host
401+
"<p><a href=\"https://{host}/rust-lang/test/blob/HEAD/there\" rel=\"nofollow noopener noreferrer\">there</a></p>\n"
404402
)
405403
);
406404

407405
let result = markdown_to_html(image, Some(&url), "");
408406
assert_eq!(
409407
result,
410408
format!(
411-
"<p><img src=\"https://{}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\"></p>\n",
412-
host
409+
"<p><img src=\"https://{host}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\"></p>\n",
413410
)
414411
);
415412

416413
let result = markdown_to_html(html_image, Some(&url), "");
417414
assert_eq!(
418415
result,
419416
format!(
420-
"<img src=\"https://{}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\">\n",
421-
host
417+
"<img src=\"https://{host}/rust-lang/test/raw/HEAD/img.png\" alt=\"alt\">\n",
422418
)
423419
);
424420

425421
let result = markdown_to_html(svg, Some(&url), "");
426422
assert_eq!(
427423
result,
428424
format!(
429-
"<p><img src=\"https://{}/rust-lang/test/raw/HEAD/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
430-
host
425+
"<p><img src=\"https://{host}/rust-lang/test/raw/HEAD/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
431426
)
432427
);
433428

434429
let result = markdown_to_html(svg, Some(&url), "subdir");
435430
assert_eq!(
436431
result,
437432
format!(
438-
"<p><img src=\"https://{}/rust-lang/test/raw/HEAD/subdir/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
439-
host
433+
"<p><img src=\"https://{host}/rust-lang/test/raw/HEAD/subdir/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
440434
)
441435
);
442436

443437
let result = markdown_to_html(svg, Some(&url), "subdir1/subdir2");
444438
assert_eq!(
445439
result,
446440
format!(
447-
"<p><img src=\"https://{}/rust-lang/test/raw/HEAD/subdir1/subdir2/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
448-
host
441+
"<p><img src=\"https://{host}/rust-lang/test/raw/HEAD/subdir1/subdir2/sanitize.svg?sanitize=true\" alt=\"alt\"></p>\n",
449442
)
450443
);
451444
}

cargo-registry-s3/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Bucket {
8585
"{}.s3{}.amazonaws.com",
8686
self.name,
8787
match self.region {
88-
Some(ref r) if !r.is_empty() => format!("-{}", r),
88+
Some(ref r) if !r.is_empty() => format!("-{r}"),
8989
Some(_) => String::new(),
9090
None => String::new(),
9191
}
@@ -95,13 +95,9 @@ impl Bucket {
9595
fn auth(&self, verb: &str, date: &str, path: &str, md5: &str, content_type: &str) -> String {
9696
let string = format!(
9797
"{verb}\n{md5}\n{ty}\n{date}\n{headers}/{name}/{path}",
98-
verb = verb,
99-
md5 = md5,
10098
ty = content_type,
101-
date = date,
10299
headers = "",
103100
name = self.name,
104-
path = path
105101
);
106102
let signature = {
107103
let key = self.secret_key.as_bytes();

src/admin/delete_crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn delete(opts: Opts, conn: &PgConnection) {
3737
let n = diesel::delete(crates::table.find(krate.id))
3838
.execute(conn)
3939
.unwrap();
40-
println!(" {} deleted", n);
40+
println!(" {n} deleted");
4141

4242
if !dialoguer::confirm("commit?") {
4343
panic!("aborting transaction");

src/admin/on_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Event {
3131
let response = Client::new()
3232
.post("https://events.pagerduty.com/generic/2010-04-15/create_event.json")
3333
.header(header::ACCEPT, "application/vnd.pagerduty+json;version=2")
34-
.header(header::AUTHORIZATION, format!("Token token={}", api_token))
34+
.header(header::AUTHORIZATION, format!("Token token={api_token}"))
3535
.json(&FullEvent {
3636
service_key,
3737
event: self,

src/admin/render_readmes.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
5252
};
5353
let older_than = older_than.naive_utc();
5454

55-
println!("Start time: {}", start_time);
56-
println!("Rendering readmes older than: {}", older_than);
55+
println!("Start time: {start_time}");
56+
println!("Rendering readmes older than: {older_than}");
5757

5858
let mut query = versions::table
5959
.inner_join(crates::table)
@@ -67,14 +67,14 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
6767
.into_boxed();
6868

6969
if let Some(crate_name) = opts.crate_name {
70-
println!("Rendering readmes for {}", crate_name);
70+
println!("Rendering readmes for {crate_name}");
7171
query = query.filter(crates::name.eq(crate_name));
7272
}
7373

7474
let version_ids: Vec<i32> = query.load(&conn).expect("error loading version ids");
7575

7676
let total_versions = version_ids.len();
77-
println!("Rendering {} versions", total_versions);
77+
println!("Rendering {total_versions} versions");
7878

7979
let page_size = opts.page_size;
8080

@@ -138,8 +138,8 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
138138
}
139139
for handle in tasks {
140140
match handle.join() {
141-
Err(err) => println!("Thread panicked: {:?}", err),
142-
Ok(Err(err)) => println!("Thread failed: {:?}", err),
141+
Err(err) => println!("Thread panicked: {err:?}"),
142+
Ok(Err(err)) => println!("Thread failed: {err:?}"),
143143
_ => {}
144144
}
145145
}
@@ -161,7 +161,7 @@ fn get_readme(
161161

162162
let location = match uploader {
163163
Uploader::S3 { .. } => location,
164-
Uploader::Local => format!("http://localhost:8888/{}", location),
164+
Uploader::Local => format!("http://localhost:8888/{location}"),
165165
};
166166

167167
let mut extra_headers = header::HeaderMap::new();
@@ -188,7 +188,7 @@ fn render_pkg_readme<R: Read>(mut archive: Archive<R>, pkg_name: &str) -> anyhow
188188
let mut entries = archive.entries().context("Invalid tar archive entries")?;
189189

190190
let manifest: Manifest = {
191-
let path = format!("{}/Cargo.toml", pkg_name);
191+
let path = format!("{pkg_name}/Cargo.toml");
192192
let contents = find_file_by_path(&mut entries, Path::new(&path))
193193
.context("Failed to read Cargo.toml file")?;
194194

@@ -201,9 +201,9 @@ fn render_pkg_readme<R: Read>(mut archive: Archive<R>, pkg_name: &str) -> anyhow
201201
.readme
202202
.clone()
203203
.unwrap_or_else(|| "README.md".into());
204-
let path = format!("{}/{}", pkg_name, readme_path);
204+
let path = format!("{pkg_name}/{readme_path}");
205205
let contents = find_file_by_path(&mut entries, Path::new(&path))
206-
.with_context(|| format!("Failed to read {} file", readme_path))?;
206+
.with_context(|| format!("Failed to read {readme_path} file"))?;
207207

208208
// pkg_path_in_vcs Unsupported from admin::render_readmes. See #4095
209209
// Would need access to cargo_vcs_info

src/bin/enqueue-job.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() -> Result<()> {
1111
let mut args = std::env::args().skip(1);
1212

1313
let job = args.next().unwrap_or_default();
14-
println!("Enqueueing background job: {}", job);
14+
println!("Enqueueing background job: {job}");
1515

1616
match &*job {
1717
"update_downloads" => {

src/bin/monitor.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ fn check_failing_background_jobs(conn: &PgConnection) -> Result<()> {
5454
on_call::Event::Trigger {
5555
incident_key: Some(EVENT_KEY.into()),
5656
description: format!(
57-
"{} jobs have been in the queue for more than {} minutes",
58-
stalled_job_count, max_job_time
57+
"{stalled_job_count} jobs have been in the queue for more than {max_job_time} minutes"
5958
),
6059
}
6160
} else {
@@ -95,7 +94,7 @@ fn check_stalled_update_downloads(conn: &PgConnection) -> Result<()> {
9594
if minutes > max_job_time {
9695
return log_and_trigger_event(on_call::Event::Trigger {
9796
incident_key: Some(EVENT_KEY.into()),
98-
description: format!("update_downloads job running for {} minutes", minutes),
97+
description: format!("update_downloads job running for {minutes} minutes"),
9998
});
10099
}
101100
};
@@ -130,13 +129,13 @@ fn check_spam_attack(conn: &PgConnection) -> Result<()> {
130129
.optional()?;
131130

132131
if let Some(bad_crate) = bad_crate {
133-
event_description = Some(format!("Crate named {} published", bad_crate));
132+
event_description = Some(format!("Crate named {bad_crate} published"));
134133
}
135134

136135
let event = if let Some(event_description) = event_description {
137136
on_call::Event::Trigger {
138137
incident_key: Some(EVENT_KEY.into()),
139-
description: format!("{}, possible spam attack underway", event_description,),
138+
description: format!("{event_description}, possible spam attack underway"),
140139
}
141140
} else {
142141
on_call::Event::Resolve {
@@ -153,11 +152,11 @@ fn log_and_trigger_event(event: on_call::Event) -> Result<()> {
153152
match event {
154153
on_call::Event::Trigger {
155154
ref description, ..
156-
} => println!("Paging on-call: {}", description),
155+
} => println!("Paging on-call: {description}"),
157156
on_call::Event::Resolve {
158157
description: Some(ref description),
159158
..
160-
} => println!("{}", description),
159+
} => println!("{description}"),
161160
_ => {} // noop
162161
}
163162
event.send()

src/bin/server.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
110110

111111
// Do not change this line! Removing the line or changing its contents in any way will break
112112
// the test suite :)
113-
println!("Listening at http://{}", addr);
113+
println!("Listening at http://{addr}");
114114

115115
// Creating this file tells heroku to tell nginx that the application is ready
116116
// to receive traffic.
@@ -120,7 +120,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
120120
} else {
121121
"/tmp/app-initialized"
122122
};
123-
println!("Writing to {}", path);
123+
println!("Writing to {path}");
124124
File::create(path).unwrap();
125125

126126
// Launch nginx via the Heroku nginx buildpack
@@ -137,7 +137,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
137137
println!("Persisting remaining downloads counters");
138138
match app.downloads_counter.persist_all_shards(&app) {
139139
Ok(stats) => stats.log(),
140-
Err(err) => println!("downloads_counter error: {}", err),
140+
Err(err) => println!("downloads_counter error: {err}"),
141141
}
142142

143143
println!("Server has gracefully shutdown!");
@@ -154,7 +154,7 @@ fn downloads_counter_thread(app: Arc<App>) {
154154

155155
match app.downloads_counter.persist_next_shard(&app) {
156156
Ok(stats) => stats.log(),
157-
Err(err) => println!("downloads_counter error: {}", err),
157+
Err(err) => println!("downloads_counter error: {err}"),
158158
}
159159
});
160160
}
@@ -169,7 +169,7 @@ fn log_instance_metrics_thread(app: Arc<App>) {
169169

170170
std::thread::spawn(move || loop {
171171
if let Err(err) = log_instance_metrics_inner(&app) {
172-
eprintln!("log_instance_metrics error: {}", err);
172+
eprintln!("log_instance_metrics error: {err}");
173173
}
174174
std::thread::sleep(interval);
175175
});

src/boot/categories.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Category {
3838
fn required_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> Result<&'a str> {
3939
toml.get(key)
4040
.and_then(toml::Value::as_str)
41-
.with_context(|| format!("Expected category TOML attribute '{}' to be a String", key))
41+
.with_context(|| format!("Expected category TOML attribute '{key}' to be a String"))
4242
}
4343

4444
fn optional_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> &'a str {
@@ -54,7 +54,7 @@ fn categories_from_toml(
5454
for (slug, details) in categories {
5555
let details = details
5656
.as_table()
57-
.with_context(|| format!("category {} was not a TOML table", slug))?;
57+
.with_context(|| format!("category {slug} was not a TOML table"))?;
5858

5959
let category = Category::from_parent(
6060
slug,
@@ -66,7 +66,7 @@ fn categories_from_toml(
6666
if let Some(categories) = details.get("categories") {
6767
let categories = categories
6868
.as_table()
69-
.with_context(|| format!("child categories of {} were not a table", slug))?;
69+
.with_context(|| format!("child categories of {slug} were not a table"))?;
7070

7171
result.extend(categories_from_toml(categories, Some(&category))?);
7272
}

src/controllers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod prelude {
7272
let query_string = url::form_urlencoded::Serializer::new(String::new())
7373
.extend_pairs(params)
7474
.finish();
75-
format!("?{}", query_string)
75+
format!("?{query_string}")
7676
}
7777

7878
fn log_metadata<V: std::fmt::Display>(&mut self, key: &'static str, value: V) {

src/controllers/krate/search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn search(req: &mut dyn RequestExt) -> EndpointResult {
104104
.filter(
105105
categories::slug
106106
.eq(cat)
107-
.or(categories::slug.like(format!("{}::%", cat))),
107+
.or(categories::slug.like(format!("{cat}::%"))),
108108
),
109109
),
110110
);

src/controllers/token.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn new(req: &mut dyn RequestExt) -> EndpointResult {
4242
.ok_or_else(|| bad_request("missing header: Content-Length"))?;
4343

4444
if length > max_size {
45-
return Err(bad_request(&format!("max content length is: {}", max_size)));
45+
return Err(bad_request(&format!("max content length is: {max_size}")));
4646
}
4747

4848
let mut json = vec![0; length as usize];
@@ -52,7 +52,7 @@ pub fn new(req: &mut dyn RequestExt) -> EndpointResult {
5252
String::from_utf8(json).map_err(|_| bad_request(&"json body was not valid utf-8"))?;
5353

5454
let new: NewApiTokenRequest = json::from_str(&json)
55-
.map_err(|e| bad_request(&format!("invalid new token request: {:?}", e)))?;
55+
.map_err(|e| bad_request(&format!("invalid new token request: {e:?}")))?;
5656

5757
let name = &new.api_token.name;
5858
if name.is_empty() {
@@ -88,7 +88,7 @@ pub fn new(req: &mut dyn RequestExt) -> EndpointResult {
8888
pub fn revoke(req: &mut dyn RequestExt) -> EndpointResult {
8989
let id = req.params()["id"]
9090
.parse::<i32>()
91-
.map_err(|e| bad_request(&format!("invalid token id: {:?}", e)))?;
91+
.map_err(|e| bad_request(&format!("invalid token id: {e:?}")))?;
9292

9393
let authenticated_user = req.authenticate()?;
9494
let conn = req.db_conn()?;

src/controllers/util.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ fn verify_origin(req: &dyn RequestExt) -> AppResult<()> {
5757
.find(|value| !allowed_origins.iter().any(|it| it == value));
5858

5959
if let Some(bad_origin) = bad_origin {
60-
let error_message = format!(
61-
"only same-origin requests can be authenticated. got {:?}",
62-
bad_origin
63-
);
60+
let error_message =
61+
format!("only same-origin requests can be authenticated. got {bad_origin:?}");
6462
return Err(internal(&error_message).chain(forbidden()));
6563
}
6664
Ok(())

src/email.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ https://{}/confirm/{}",
7474
) -> AppResult<()> {
7575
let subject = "Crate ownership invitation";
7676
let body = format!(
77-
"{} has invited you to become an owner of the crate {}!\n
78-
Visit https://{domain}/accept-invite/{} to accept this invitation,
77+
"{user_name} has invited you to become an owner of the crate {crate_name}!\n
78+
Visit https://{domain}/accept-invite/{token} to accept this invitation,
7979
or go to https://{domain}/me/pending-invites to manage all of your crate ownership invitations.",
80-
user_name,
81-
crate_name,
82-
token,
8380
domain = crate::config::domain_name()
8481
);
8582

0 commit comments

Comments
 (0)