Skip to content

Commit 8468c71

Browse files
Rollup merge of #101018 - notriddle:notriddle/item-right-docblock-short, r=GuillaumeGomez
rustdoc: omit start/end tags for empty item description blocks Related to #100952 This is definitely not a complete solution, but it does shrink keysyms/index.html on smithay from 620K to 516K.
2 parents 5cc0d3a + e7b7f88 commit 8468c71

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/librustdoc/html/render/print_item.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,21 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
371371
}
372372
clean::ImportKind::Glob => String::new(),
373373
};
374+
let stab_tags = stab_tags.unwrap_or_default();
375+
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
376+
("", "")
377+
} else {
378+
("<div class=\"item-right docblock-short\">", "</div>")
379+
};
374380
write!(
375381
w,
376382
"<div class=\"item-left {stab}{add}import-item\"{id}>\
377383
<code>{vis}{imp}</code>\
378384
</div>\
379-
<div class=\"item-right docblock-short\">{stab_tags}</div>",
385+
{stab_tags_before}{stab_tags}{stab_tags_after}",
380386
stab = stab.unwrap_or_default(),
381387
vis = myitem.visibility.print_with_space(myitem.item_id, cx),
382388
imp = import.print(cx),
383-
stab_tags = stab_tags.unwrap_or_default(),
384389
);
385390
w.write_str(ITEM_TABLE_ROW_CLOSE);
386391
}
@@ -412,6 +417,12 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
412417

413418
let doc_value = myitem.doc_value().unwrap_or_default();
414419
w.write_str(ITEM_TABLE_ROW_OPEN);
420+
let docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string();
421+
let (docs_before, docs_after) = if docs.is_empty() {
422+
("", "")
423+
} else {
424+
("<div class=\"item-right docblock-short\">", "</div>")
425+
};
415426
write!(
416427
w,
417428
"<div class=\"item-left {stab}{add}module-item\">\
@@ -420,11 +431,10 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
420431
{unsafety_flag}\
421432
{stab_tags}\
422433
</div>\
423-
<div class=\"item-right docblock-short\">{docs}</div>",
434+
{docs_before}{docs}{docs_after}",
424435
name = myitem.name.unwrap(),
425436
visibility_emoji = visibility_emoji,
426437
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
427-
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
428438
class = myitem.type_(),
429439
add = add,
430440
stab = stab.unwrap_or_default(),

src/test/rustdoc-gui/item-summary-table.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ goto: file://|DOC_PATH|/lib2/summary_table/index.html
33
// We check that we picked the right item first.
44
assert-text: (".item-table .item-left", "Foo")
55
// Then we check that its summary is empty.
6-
assert-text: (".item-table .item-right", "")
6+
assert-false: ".item-table .item-right"

src/test/rustdoc/short-docblock-codeblock.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![crate_name = "foo"]
22

3-
// @has foo/index.html '//*[@class="item-right docblock-short"]' ""
4-
// @!has foo/index.html '//*[@class="item-right docblock-short"]' "Some text."
5-
// @!has foo/index.html '//*[@class="item-right docblock-short"]' "let x = 12;"
3+
// @count foo/index.html '//*[@class="item-right docblock-short"]' 0
64

75
/// ```
86
/// let x = 12;

0 commit comments

Comments
 (0)