diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-12-19 15:04:42 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-01-02 16:55:12 +0100 |
| commit | 122b141f58fd12deea53fb73efcaaaa56fb87bd1 (patch) | |
| tree | fd19c293a0c7c313ddeb385b9316567e633d7747 /src/librustdoc/html | |
| parent | c4739bc920a192b852ceb48fb500831594d5ff96 (diff) | |
| download | rust-122b141f58fd12deea53fb73efcaaaa56fb87bd1.tar.gz rust-122b141f58fd12deea53fb73efcaaaa56fb87bd1.zip | |
End of rework of Attributes struct
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render/cache.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 15 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index c408e576639..497cbbb4250 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -78,7 +78,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { ty: item.type_(), name: item.name.unwrap().to_string(), path: fqp[..fqp.len() - 1].join("::"), - desc: item.doc_value().map_or_else(|| String::new(), short_markdown_summary), + desc: item.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)), parent: Some(did), parent_idx: None, search_type: get_index_search_type(&item), @@ -127,7 +127,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { let crate_doc = krate .module .as_ref() - .map(|module| module.doc_value().map_or_else(|| String::new(), short_markdown_summary)) + .map(|module| module.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s))) .unwrap_or_default(); #[derive(Serialize)] diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 2f5ee4f238d..4339fa077e5 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -30,7 +30,6 @@ crate mod cache; #[cfg(test)] mod tests; -use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::cmp::Ordering; use std::collections::{BTreeMap, VecDeque}; @@ -198,11 +197,11 @@ impl SharedContext<'_> { /// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the /// `collapsed_doc_value` of the given item. - crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<Cow<'a, str>> { + crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<String> { if self.collapsed { - item.collapsed_doc_value().map(|s| s.into()) + item.collapsed_doc_value().map(|s| s.to_string()) } else { - item.doc_value().map(|s| s.into()) + item.doc_value().map(|s| s.to_string()) } } } @@ -1622,7 +1621,7 @@ impl Context<'_> { let short = short.to_string(); map.entry(short).or_default().push(( myname, - Some(item.doc_value().map_or_else(|| String::new(), plain_text_summary)), + Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))), )); } @@ -1880,7 +1879,7 @@ fn document_short( return; } if let Some(s) = item.doc_value() { - let mut summary_html = MarkdownSummaryLine(s, &item.links()).into_string(); + let mut summary_html = MarkdownSummaryLine(&s, &item.links()).into_string(); if s.contains('\n') { let link = format!(r#" <a href="{}">Read more</a>"#, naive_assoc_href(item, link)); @@ -2197,7 +2196,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl let stab = myitem.stability_class(cx.tcx()); let add = if stab.is_some() { " " } else { "" }; - let doc_value = myitem.doc_value().unwrap_or(""); + let doc_value = myitem.doc_value().unwrap_or_else(String::new); write!( w, "<tr class=\"{stab}{add}module-item\">\ @@ -2207,7 +2206,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl </tr>", name = *myitem.name.as_ref().unwrap(), stab_tags = extra_info_tags(myitem, item, cx.tcx()), - docs = MarkdownSummaryLine(doc_value, &myitem.links()).into_string(), + docs = MarkdownSummaryLine(&doc_value, &myitem.links()).into_string(), class = myitem.type_(), add = add, stab = stab.unwrap_or_else(String::new), |
