Skip to content

Commit 1a98305

Browse files
committedFeb 10, 2023
rustdoc: clean up write! calls with less stuttering
1 parent 8cca42a commit 1a98305

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed
 

‎src/librustdoc/html/render/print_item.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,10 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
10811081
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
10821082
wrap_item(w, |w| {
10831083
render_attributes_in_pre(w, it, "");
1084-
write!(w, "{}", visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx));
10851084
write!(
10861085
w,
1087-
"type {}{}{where_clause} = {type_};",
1086+
"{}type {}{}{where_clause} = {type_};",
1087+
visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx),
10881088
it.name.unwrap(),
10891089
t.generics.print(cx),
10901090
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
@@ -1138,13 +1138,11 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
11381138
<a href=\"#{id}\" class=\"anchor field\">§</a>\
11391139
<code>{name}: {ty}</code>\
11401140
</span>",
1141-
id = id,
1142-
name = name,
11431141
shortty = ItemType::StructField,
11441142
ty = ty.print(cx),
11451143
);
11461144
if let Some(stability_class) = field.stability_class(cx.tcx()) {
1147-
write!(w, "<span class=\"stab {stab}\"></span>", stab = stability_class);
1145+
write!(w, "<span class=\"stab {stability_class}\"></span>");
11481146
}
11491147
document(w, cx, field, Some(it), HeadingOffset::H3);
11501148
}
@@ -1242,7 +1240,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12421240
w,
12431241
"<section id=\"{id}\" class=\"variant\">\
12441242
<a href=\"#{id}\" class=\"anchor\">§</a>",
1245-
id = id,
12461243
);
12471244
render_stability_since_raw_with_extra(
12481245
w,
@@ -1280,8 +1277,11 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12801277
if let Some((heading, fields)) = heading_and_fields {
12811278
let variant_id =
12821279
cx.derive_id(format!("{}.{}.fields", ItemType::Variant, variant.name.unwrap()));
1283-
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
1284-
write!(w, "<h4>{heading}</h4>", heading = heading);
1280+
write!(
1281+
w,
1282+
"<div class=\"sub-variant\" id=\"{variant_id}\">\
1283+
<h4>{heading}</h4>",
1284+
);
12851285
document_non_exhaustive(w, variant);
12861286
for field in fields {
12871287
match *field.kind {
@@ -1299,7 +1299,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12991299
<a href=\"#{id}\" class=\"anchor field\">§</a>\
13001300
<code>{f}: {t}</code>\
13011301
</span>",
1302-
id = id,
13031302
f = field.name.unwrap(),
13041303
t = ty.print(cx)
13051304
);
@@ -1450,11 +1449,9 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
14501449
w,
14511450
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
14521451
<a href=\"#{id}\" class=\"anchor field\">§</a>\
1453-
<code>{name}: {ty}</code>\
1452+
<code>{field_name}: {ty}</code>\
14541453
</span>",
14551454
item_type = ItemType::StructField,
1456-
id = id,
1457-
name = field_name,
14581455
ty = ty.print(cx)
14591456
);
14601457
document(w, cx, field, Some(it), HeadingOffset::H3);
@@ -1842,8 +1839,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
18421839
if layout.abi.is_unsized() {
18431840
write!(w, "(unsized)");
18441841
} else {
1845-
let bytes = layout.size.bytes() - tag_size;
1846-
write!(w, "{size} byte{pl}", size = bytes, pl = if bytes == 1 { "" } else { "s" },);
1842+
let size = layout.size.bytes() - tag_size;
1843+
write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" },);
18471844
}
18481845
}
18491846

@@ -1898,7 +1895,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
18981895

18991896
for (index, layout) in variants.iter_enumerated() {
19001897
let name = adt.variant(index).name;
1901-
write!(w, "<li><code>{name}</code>: ", name = name);
1898+
write!(w, "<li><code>{name}</code>: ");
19021899
write_size_of_layout(w, layout, tag_size);
19031900
writeln!(w, "</li>");
19041901
}

0 commit comments

Comments
 (0)