From e7b7f8855f97cb66b2b4008888c7ba0e8f2c2db6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 25 Aug 2022 17:41:25 -0700 Subject: [PATCH] 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. --- src/librustdoc/html/render/print_item.rs | 18 ++++++++++++++---- src/test/rustdoc-gui/item-summary-table.goml | 2 +- src/test/rustdoc/short-docblock-codeblock.rs | 4 +--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 6d0a825fec866..07a8e8f48dc31 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -371,16 +371,21 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: } clean::ImportKind::Glob => String::new(), }; + let stab_tags = stab_tags.unwrap_or_default(); + let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() { + ("", "") + } else { + ("
", "
") + }; write!( w, "
\ {vis}{imp}\
\ -
{stab_tags}
", + {stab_tags_before}{stab_tags}{stab_tags_after}", stab = stab.unwrap_or_default(), vis = myitem.visibility.print_with_space(myitem.item_id, cx), imp = import.print(cx), - stab_tags = stab_tags.unwrap_or_default(), ); w.write_str(ITEM_TABLE_ROW_CLOSE); } @@ -412,6 +417,12 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: let doc_value = myitem.doc_value().unwrap_or_default(); w.write_str(ITEM_TABLE_ROW_OPEN); + let docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(); + let (docs_before, docs_after) = if docs.is_empty() { + ("", "") + } else { + ("
", "
") + }; write!( w, "
\ @@ -420,11 +431,10 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: {unsafety_flag}\ {stab_tags}\
\ -
{docs}
", + {docs_before}{docs}{docs_after}", name = myitem.name.unwrap(), visibility_emoji = visibility_emoji, stab_tags = extra_info_tags(myitem, item, cx.tcx()), - docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(), class = myitem.type_(), add = add, stab = stab.unwrap_or_default(), diff --git a/src/test/rustdoc-gui/item-summary-table.goml b/src/test/rustdoc-gui/item-summary-table.goml index 6bf4e288c4377..4bff32b3d5db1 100644 --- a/src/test/rustdoc-gui/item-summary-table.goml +++ b/src/test/rustdoc-gui/item-summary-table.goml @@ -3,4 +3,4 @@ goto: file://|DOC_PATH|/lib2/summary_table/index.html // We check that we picked the right item first. assert-text: (".item-table .item-left", "Foo") // Then we check that its summary is empty. -assert-text: (".item-table .item-right", "") +assert-false: ".item-table .item-right" diff --git a/src/test/rustdoc/short-docblock-codeblock.rs b/src/test/rustdoc/short-docblock-codeblock.rs index c6b318b0677ce..3c5fa7b36adbf 100644 --- a/src/test/rustdoc/short-docblock-codeblock.rs +++ b/src/test/rustdoc/short-docblock-codeblock.rs @@ -1,8 +1,6 @@ #![crate_name = "foo"] -// @has foo/index.html '//*[@class="item-right docblock-short"]' "" -// @!has foo/index.html '//*[@class="item-right docblock-short"]' "Some text." -// @!has foo/index.html '//*[@class="item-right docblock-short"]' "let x = 12;" +// @count foo/index.html '//*[@class="item-right docblock-short"]' 0 /// ``` /// let x = 12;