Use the first paragraph, instead of cookie-cutter text, for rustdoc descriptions

Fixes #82283
This commit is contained in:
Michael Howell
2021-02-20 14:43:25 -07:00
parent e7c23ab933
commit 553852806d

View File

@@ -534,12 +534,17 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
if !root_path.ends_with('/') { if !root_path.ends_with('/') {
root_path.push('/'); root_path.push('/');
} }
let description = krate
.module
.as_ref()
.and_then(|item| Some(plain_text_summary(item.doc_value()?.as_str())))
.unwrap_or_else(|| String::from("List of all items in this crate"));
let mut page = layout::Page { let mut page = layout::Page {
title: "List of all items in this crate", title: "List of all items in this crate",
css_class: "mod", css_class: "mod",
root_path: "../", root_path: "../",
static_root_path: self.shared.static_root_path.as_deref(), static_root_path: self.shared.static_root_path.as_deref(),
description: "List of all items in this crate", description: description.as_str(),
keywords: BASIC_KEYWORDS, keywords: BASIC_KEYWORDS,
resource_suffix: &self.shared.resource_suffix, resource_suffix: &self.shared.resource_suffix,
extra_scripts: &[], extra_scripts: &[],
@@ -1548,7 +1553,10 @@ impl Context<'_> {
} }
title.push_str(" - Rust"); title.push_str(" - Rust");
let tyname = it.type_(); let tyname = it.type_();
let desc = if it.is_crate() { let desc = it.doc_value().as_ref().map(|doc| plain_text_summary(&doc));
let desc = if let Some(desc) = desc {
desc
} else if it.is_crate() {
format!("API documentation for the Rust `{}` crate.", self.shared.layout.krate) format!("API documentation for the Rust `{}` crate.", self.shared.layout.krate)
} else { } else {
format!( format!(