From 5cc64e8da8db1baba601fff5ae90cf8cef2ba183 Mon Sep 17 00:00:00 2001
From: Yotam Ofek
Date: Mon, 10 Feb 2025 17:46:32 +0000
Subject: librustdoc: lazily format "read more" link in `document_short`
---
src/librustdoc/html/render/mod.rs | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
(limited to 'src')
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 6896925753a..204631063a2 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -569,18 +569,27 @@ fn document_short<'a, 'cx: 'a>(
let (mut summary_html, has_more_content) =
MarkdownSummaryLine(&s, &item.links(cx)).into_string_with_has_more_content();
- if has_more_content {
- let link =
- format!(" Read more", assoc_href_attr(item, link, cx).maybe_display());
+ let link = if has_more_content {
+ let link = fmt::from_fn(|f| {
+ write!(
+ f,
+ " Read more",
+ assoc_href_attr(item, link, cx).maybe_display()
+ )
+ });
if let Some(idx) = summary_html.rfind("
") {
- summary_html.insert_str(idx, &link);
+ summary_html.insert_str(idx, &link.to_string());
+ None
} else {
- summary_html.push_str(&link);
+ Some(link)
}
+ } else {
+ None
}
+ .maybe_display();
- write!(f, "{summary_html}
")?;
+ write!(f, "{summary_html}{link}
")?;
}
Ok(())
})
--
cgit 1.4.1-3-g733a5