Skip to content

Commit 5cc64e8

Browse files
committed
librustdoc: lazily format "read more" link in document_short
1 parent ea15f6d commit 5cc64e8

File tree

1 file changed

+15
-6
lines changed
  • src/librustdoc/html/render

1 file changed

+15
-6
lines changed

src/librustdoc/html/render/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,27 @@ fn document_short<'a, 'cx: 'a>(
569569
let (mut summary_html, has_more_content) =
570570
MarkdownSummaryLine(&s, &item.links(cx)).into_string_with_has_more_content();
571571

572-
if has_more_content {
573-
let link =
574-
format!(" <a{}>Read more</a>", assoc_href_attr(item, link, cx).maybe_display());
572+
let link = if has_more_content {
573+
let link = fmt::from_fn(|f| {
574+
write!(
575+
f,
576+
" <a{}>Read more</a>",
577+
assoc_href_attr(item, link, cx).maybe_display()
578+
)
579+
});
575580

576581
if let Some(idx) = summary_html.rfind("</p>") {
577-
summary_html.insert_str(idx, &link);
582+
summary_html.insert_str(idx, &link.to_string());
583+
None
578584
} else {
579-
summary_html.push_str(&link);
585+
Some(link)
580586
}
587+
} else {
588+
None
581589
}
590+
.maybe_display();
582591

583-
write!(f, "<div class='docblock'>{summary_html}</div>")?;
592+
write!(f, "<div class='docblock'>{summary_html}{link}</div>")?;
584593
}
585594
Ok(())
586595
})

0 commit comments

Comments
 (0)