Skip to content

Commit 16b34bf

Browse files
Use more named format args
1 parent a1a94b1 commit 16b34bf

16 files changed

+130
-85
lines changed

src/librustdoc/clean/auto_trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ where
163163
fn get_lifetime(region: Region<'_>, names_map: &FxHashMap<Symbol, Lifetime>) -> Lifetime {
164164
region_name(region)
165165
.map(|name| {
166-
names_map.get(&name).unwrap_or_else(|| {
167-
panic!("Missing lifetime with name {:?} for {region:?}", name.as_str())
168-
})
166+
names_map
167+
.get(&name)
168+
.unwrap_or_else(|| panic!("Missing lifetime with name {name:?} for {region:?}"))
169169
})
170170
.unwrap_or(&Lifetime::statik())
171171
.clone()

src/librustdoc/clean/utils.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,12 @@ pub(super) fn render_macro_arms<'a>(
601601
) -> String {
602602
let mut out = String::new();
603603
for matcher in matchers {
604-
writeln!(out, " {} => {{ ... }}{arm_delim}", render_macro_matcher(tcx, matcher))
605-
.unwrap();
604+
writeln!(
605+
out,
606+
" {matcher} => {{ ... }}{arm_delim}",
607+
matcher = render_macro_matcher(tcx, matcher),
608+
)
609+
.unwrap();
606610
}
607611
out
608612
}
@@ -618,19 +622,21 @@ pub(super) fn display_macro_source(
618622
let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]);
619623

620624
if def.macro_rules {
621-
format!("macro_rules! {name} {{\n{}}}", render_macro_arms(cx.tcx, matchers, ";"))
625+
format!("macro_rules! {name} {{\n{arms}}}", arms = render_macro_arms(cx.tcx, matchers, ";"))
622626
} else {
623627
if matchers.len() <= 1 {
624628
format!(
625-
"{}macro {name}{} {{\n ...\n}}",
626-
visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
627-
matchers.map(|matcher| render_macro_matcher(cx.tcx, matcher)).collect::<String>(),
629+
"{vis}macro {name}{matchers} {{\n ...\n}}",
630+
vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
631+
matchers = matchers
632+
.map(|matcher| render_macro_matcher(cx.tcx, matcher))
633+
.collect::<String>(),
628634
)
629635
} else {
630636
format!(
631-
"{}macro {name} {{\n{}}}",
632-
visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
633-
render_macro_arms(cx.tcx, matchers, ","),
637+
"{vis}macro {name} {{\n{arms}}}",
638+
vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
639+
arms = render_macro_arms(cx.tcx, matchers, ","),
634640
)
635641
}
636642
}

src/librustdoc/docfs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl DocFS {
7272
let sender = self.errors.clone().expect("can't write after closing");
7373
self.pool.execute(move || {
7474
fs::write(&path, contents).unwrap_or_else(|e| {
75-
sender.send(format!("\"{}\": {e}", path.display())).unwrap_or_else(|_| {
76-
panic!("failed to send error on \"{}\"", path.display())
77-
})
75+
sender.send(format!("\"{path}\": {e}", path = path.display())).unwrap_or_else(
76+
|_| panic!("failed to send error on \"{}\"", path.display()),
77+
)
7878
});
7979
});
8080
} else {

src/librustdoc/externalfiles.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ pub(crate) fn load_string<P: AsRef<Path>>(
8181
let contents = match fs::read(file_path) {
8282
Ok(bytes) => bytes,
8383
Err(e) => {
84-
diag.struct_err(format!("error reading `{}`: {e}", file_path.display())).emit();
84+
diag.struct_err(format!(
85+
"error reading `{file_path}`: {e}",
86+
file_path = file_path.display()
87+
))
88+
.emit();
8589
return Err(LoadStringError::ReadFail);
8690
}
8791
};

src/librustdoc/html/format.rs

+32-19
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ impl Buffer {
109109
self.buffer
110110
}
111111

112+
pub(crate) fn push(&mut self, c: char) {
113+
self.buffer.push(c);
114+
}
115+
112116
pub(crate) fn push_str(&mut self, s: &str) {
113117
self.buffer.push_str(s);
114118
}
@@ -451,9 +455,9 @@ impl clean::GenericBound {
451455
hir::TraitBoundModifier::MaybeConst => "",
452456
};
453457
if f.alternate() {
454-
write!(f, "{modifier_str}{:#}", ty.print(cx))
458+
write!(f, "{modifier_str}{ty:#}", ty = ty.print(cx))
455459
} else {
456-
write!(f, "{modifier_str}{}", ty.print(cx))
460+
write!(f, "{modifier_str}{ty}", ty = ty.print(cx))
457461
}
458462
}
459463
})
@@ -631,14 +635,14 @@ fn generate_macro_def_id_path(
631635
let url = match cache.extern_locations[&def_id.krate] {
632636
ExternalLocation::Remote(ref s) => {
633637
// `ExternalLocation::Remote` always end with a `/`.
634-
format!("{s}{}", path.iter().map(|p| p.as_str()).join("/"))
638+
format!("{s}{path}", path = path.iter().map(|p| p.as_str()).join("/"))
635639
}
636640
ExternalLocation::Local => {
637641
// `root_path` always end with a `/`.
638642
format!(
639-
"{}{crate_name}/{}",
640-
root_path.unwrap_or(""),
641-
path.iter().map(|p| p.as_str()).join("/")
643+
"{root_path}{crate_name}/{path}",
644+
root_path = root_path.unwrap_or(""),
645+
path = path.iter().map(|p| p.as_str()).join("/")
642646
)
643647
}
644648
ExternalLocation::Unknown => {
@@ -827,17 +831,17 @@ fn resolved_path<'cx>(
827831
let path = if use_absolute {
828832
if let Ok((_, _, fqp)) = href(did, cx) {
829833
format!(
830-
"{}::{}",
831-
join_with_double_colon(&fqp[..fqp.len() - 1]),
832-
anchor(did, *fqp.last().unwrap(), cx)
834+
"{path}::{anchor}",
835+
path = join_with_double_colon(&fqp[..fqp.len() - 1]),
836+
anchor = anchor(did, *fqp.last().unwrap(), cx)
833837
)
834838
} else {
835839
last.name.to_string()
836840
}
837841
} else {
838842
anchor(did, last.name, cx).to_string()
839843
};
840-
write!(w, "{path}{}", last.args.print(cx))?;
844+
write!(w, "{path}{args}", args = last.args.print(cx))?;
841845
}
842846
Ok(())
843847
}
@@ -945,8 +949,8 @@ pub(crate) fn anchor<'a, 'cx: 'a>(
945949
if let Ok((url, short_ty, fqp)) = parts {
946950
write!(
947951
f,
948-
r#"<a class="{short_ty}" href="{url}" title="{short_ty} {}">{text}</a>"#,
949-
join_with_double_colon(&fqp),
952+
r#"<a class="{short_ty}" href="{url}" title="{short_ty} {path}">{text}</a>"#,
953+
path = join_with_double_colon(&fqp),
950954
)
951955
} else {
952956
f.write_str(text.as_str())
@@ -1080,9 +1084,9 @@ fn fmt_type<'cx>(
10801084

10811085
if matches!(**t, clean::Generic(_)) || t.is_assoc_ty() {
10821086
let text = if f.alternate() {
1083-
format!("*{m} {:#}", t.print(cx))
1087+
format!("*{m} {ty:#}", ty = t.print(cx))
10841088
} else {
1085-
format!("*{m} {}", t.print(cx))
1089+
format!("*{m} {ty}", ty = t.print(cx))
10861090
};
10871091
primitive_link(f, clean::PrimitiveType::RawPointer, &text, cx)
10881092
} else {
@@ -1440,11 +1444,20 @@ impl clean::FnDecl {
14401444
clean::SelfValue => {
14411445
write!(f, "self")?;
14421446
}
1443-
clean::SelfBorrowed(Some(ref lt), mtbl) => {
1444-
write!(f, "{amp}{} {}self", lt.print(), mtbl.print_with_space())?;
1447+
clean::SelfBorrowed(Some(ref lt), mutability) => {
1448+
write!(
1449+
f,
1450+
"{amp}{lifetime} {mutability}self",
1451+
lifetime = lt.print(),
1452+
mutability = mutability.print_with_space(),
1453+
)?;
14451454
}
1446-
clean::SelfBorrowed(None, mtbl) => {
1447-
write!(f, "{amp}{}self", mtbl.print_with_space())?;
1455+
clean::SelfBorrowed(None, mutability) => {
1456+
write!(
1457+
f,
1458+
"{amp}{mutability}self",
1459+
mutability = mutability.print_with_space(),
1460+
)?;
14481461
}
14491462
clean::SelfExplicit(ref typ) => {
14501463
write!(f, "self: ")?;
@@ -1627,7 +1640,7 @@ impl clean::Import {
16271640
if name == self.source.path.last() {
16281641
write!(f, "use {};", self.source.print(cx))
16291642
} else {
1630-
write!(f, "use {} as {name};", self.source.print(cx))
1643+
write!(f, "use {source} as {name};", source = self.source.print(cx))
16311644
}
16321645
}
16331646
clean::ImportKind::Glob => {

src/librustdoc/html/highlight.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn string_without_closing_tag<T: Display>(
937937
write!(out, "{text}").unwrap();
938938
return None;
939939
}
940-
write!(out, "<span class=\"{}\">{text}", klass.as_html()).unwrap();
940+
write!(out, "<span class=\"{klass}\">{text}", klass = klass.as_html()).unwrap();
941941
return Some("</span>");
942942
};
943943

@@ -947,11 +947,15 @@ fn string_without_closing_tag<T: Display>(
947947
match t {
948948
"self" | "Self" => write!(
949949
&mut path,
950-
"<span class=\"{}\">{t}</span>",
951-
Class::Self_(DUMMY_SP).as_html(),
950+
"<span class=\"{klass}\">{t}</span>",
951+
klass = Class::Self_(DUMMY_SP).as_html(),
952952
),
953953
"crate" | "super" => {
954-
write!(&mut path, "<span class=\"{}\">{t}</span>", Class::KeyWord.as_html())
954+
write!(
955+
&mut path,
956+
"<span class=\"{klass}\">{t}</span>",
957+
klass = Class::KeyWord.as_html(),
958+
)
955959
}
956960
t => write!(&mut path, "{t}"),
957961
}

src/librustdoc/html/markdown.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
246246
return Some(Event::Html(
247247
format!(
248248
"<div class=\"example-wrap\">\
249-
<pre class=\"language-{lang}\"><code>{}</code></pre>\
249+
<pre class=\"language-{lang}\"><code>{text}</code></pre>\
250250
</div>",
251-
Escape(&original_text),
251+
text = Escape(&original_text),
252252
)
253253
.into(),
254254
));
@@ -308,7 +308,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
308308
// insert newline to clearly separate it from the
309309
// previous block so we can shorten the html output
310310
let mut s = Buffer::new();
311-
s.push_str("\n");
311+
s.push('\n');
312312

313313
highlight::render_example_with_highlighting(
314314
&text,
@@ -394,7 +394,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
394394
l.href == link.href
395395
&& Some(&**text) == l.original_text.get(1..l.original_text.len() - 1)
396396
}) {
397-
debug!("replacing {text} with {}", link.new_text);
397+
debug!("replacing {text} with {new_text}", new_text = link.new_text);
398398
*text = CowStr::Borrowed(&link.new_text);
399399
}
400400
}
@@ -410,7 +410,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
410410
.iter()
411411
.find(|l| l.href == link.href && **text == *l.original_text)
412412
{
413-
debug!("replacing {text} with {}", link.new_text);
413+
debug!("replacing {text} with {new_text}", new_text = link.new_text);
414414
*text = CowStr::Borrowed(&link.new_text);
415415
}
416416
}
@@ -1038,7 +1038,7 @@ impl MarkdownWithToc<'_> {
10381038
html::push_html(&mut s, p);
10391039
}
10401040

1041-
format!("<nav id=\"TOC\">{}</nav>{s}", toc.into_toc().print())
1041+
format!("<nav id=\"TOC\">{toc}</nav>{s}", toc = toc.into_toc().print())
10421042
}
10431043
}
10441044

src/librustdoc/html/render/context.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ impl<'tcx> Context<'tcx> {
206206
format!("API documentation for the Rust `{}` crate.", self.shared.layout.krate)
207207
} else {
208208
format!(
209-
"API documentation for the Rust `{}` {tyname} in crate `{}`.",
210-
it.name.as_ref().unwrap(),
211-
self.shared.layout.krate
209+
"API documentation for the Rust `{name}` {tyname} in crate `{krate}`.",
210+
name = it.name.as_ref().unwrap(),
211+
krate = self.shared.layout.krate,
212212
)
213213
};
214214
let name;
@@ -263,7 +263,12 @@ impl<'tcx> Context<'tcx> {
263263
current_path.push_str(&item_path(ty, names.last().unwrap().as_str()));
264264
redirections.borrow_mut().insert(current_path, path);
265265
}
266-
None => return layout::redirect(&format!("{}{path}", self.root_path())),
266+
None => {
267+
return layout::redirect(&format!(
268+
"{root}{path}",
269+
root = self.root_path()
270+
));
271+
}
267272
}
268273
}
269274
}

src/librustdoc/html/render/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,10 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option<Strin
565565
};
566566

567567
debug!(
568-
"Portability {:?} {:?} (parent: {parent:?}) - {:?} = {cfg:?}",
569-
item.name,
570-
item.cfg,
571-
parent.and_then(|p| p.cfg.as_ref()),
568+
"Portability {name:?} {item_cfg:?} (parent: {parent:?}) - {parent_cfg:?} = {cfg:?}",
569+
name = item.name,
570+
item_cfg = item.cfg,
571+
parent_cfg = parent.and_then(|p| p.cfg.as_ref()),
572572
);
573573

574574
Some(cfg?.render_long_html())
@@ -1243,7 +1243,10 @@ fn render_deref_methods(
12431243
_ => None,
12441244
})
12451245
.expect("Expected associated type binding");
1246-
debug!("Render deref methods for {:#?}, target {target:#?}", impl_.inner_impl().for_);
1246+
debug!(
1247+
"Render deref methods for {for_:#?}, target {target:#?}",
1248+
for_ = impl_.inner_impl().for_
1249+
);
12471250
let what =
12481251
AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut };
12491252
if let Some(did) = target.def_id(cache) {

0 commit comments

Comments
 (0)