Skip to content

Commit d93d77b

Browse files
committed
rustdoc: Simplify some document functions
* Remove `prefix` param of `document_short/full`, `render_markdown`, as its always an empty string. * Remove `Option` wrapping of `document_short` `parent`, as its always `Some`.
1 parent 1a6c98e commit d93d77b

File tree

1 file changed

+11
-45
lines changed
  • src/librustdoc/html/render

1 file changed

+11
-45
lines changed

src/librustdoc/html/render/mod.rs

+11-45
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
509509
info!("Documenting {}", name);
510510
}
511511
document_item_info(w, cx, item, false, parent);
512-
document_full(w, item, cx, "", false);
512+
document_full(w, item, cx, false);
513513
}
514514

515515
/// Render md_text as markdown.
@@ -518,15 +518,13 @@ fn render_markdown(
518518
cx: &Context<'_>,
519519
md_text: &str,
520520
links: Vec<RenderedLink>,
521-
prefix: &str,
522521
is_hidden: bool,
523522
) {
524523
let mut ids = cx.id_map.borrow_mut();
525524
write!(
526525
w,
527-
"<div class=\"docblock{}\">{}{}</div>",
526+
"<div class=\"docblock{}\">{}</div>",
528527
if is_hidden { " hidden" } else { "" },
529-
prefix,
530528
Markdown(
531529
md_text,
532530
&links,
@@ -546,12 +544,11 @@ fn document_short(
546544
item: &clean::Item,
547545
cx: &Context<'_>,
548546
link: AssocItemLink<'_>,
549-
prefix: &str,
550547
is_hidden: bool,
551-
parent: Option<&clean::Item>,
548+
parent: &clean::Item,
552549
show_def_docs: bool,
553550
) {
554-
document_item_info(w, cx, item, is_hidden, parent);
551+
document_item_info(w, cx, item, is_hidden, Some(parent));
555552
if !show_def_docs {
556553
return;
557554
}
@@ -570,39 +567,17 @@ fn document_short(
570567

571568
write!(
572569
w,
573-
"<div class='docblock{}'>{}{}</div>",
570+
"<div class='docblock{}'>{}</div>",
574571
if is_hidden { " hidden" } else { "" },
575-
prefix,
576572
summary_html,
577573
);
578-
} else if !prefix.is_empty() {
579-
write!(
580-
w,
581-
"<div class=\"docblock{}\">{}</div>",
582-
if is_hidden { " hidden" } else { "" },
583-
prefix
584-
);
585574
}
586575
}
587576

588-
fn document_full(
589-
w: &mut Buffer,
590-
item: &clean::Item,
591-
cx: &Context<'_>,
592-
prefix: &str,
593-
is_hidden: bool,
594-
) {
577+
fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_hidden: bool) {
595578
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
596579
debug!("Doc block: =====\n{}\n=====", s);
597-
render_markdown(w, cx, &*s, item.links(cx), prefix, is_hidden);
598-
} else if !prefix.is_empty() {
599-
if is_hidden {
600-
w.write_str("<div class=\"docblock hidden\">");
601-
} else {
602-
w.write_str("<div class=\"docblock\">");
603-
}
604-
w.write_str(prefix);
605-
w.write_str("</div>");
580+
render_markdown(w, cx, &s, item.links(cx), is_hidden);
606581
}
607582
}
608583

@@ -1547,30 +1522,21 @@ fn render_impl(
15471522
// because impls can't have a stability.
15481523
if item.doc_value().is_some() {
15491524
document_item_info(w, cx, it, is_hidden, Some(parent));
1550-
document_full(w, item, cx, "", is_hidden);
1525+
document_full(w, item, cx, is_hidden);
15511526
} else {
15521527
// In case the item isn't documented,
15531528
// provide short documentation from the trait.
1554-
document_short(
1555-
w,
1556-
it,
1557-
cx,
1558-
link,
1559-
"",
1560-
is_hidden,
1561-
Some(parent),
1562-
show_def_docs,
1563-
);
1529+
document_short(w, it, cx, link, is_hidden, parent, show_def_docs);
15641530
}
15651531
}
15661532
} else {
15671533
document_item_info(w, cx, item, is_hidden, Some(parent));
15681534
if show_def_docs {
1569-
document_full(w, item, cx, "", is_hidden);
1535+
document_full(w, item, cx, is_hidden);
15701536
}
15711537
}
15721538
} else {
1573-
document_short(w, item, cx, link, "", is_hidden, Some(parent), show_def_docs);
1539+
document_short(w, item, cx, link, is_hidden, parent, show_def_docs);
15741540
}
15751541
}
15761542
}

0 commit comments

Comments
 (0)