Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 2, 2021
1 parent 29777fc commit 0d52eb9
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -1457,8 +1457,8 @@ fn render_impl(
}

fn render_default_items(
w: &mut Buffer,
tmp_w: &mut Buffer,
boring: &mut Buffer,
interesting: &mut Buffer,
cx: &Context<'_>,
t: &clean::Trait,
i: &clean::Impl,
Expand All @@ -1477,8 +1477,8 @@ fn render_impl(
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);

doc_impl_item(
w,
tmp_w,
boring,
interesting,
cx,
trait_item,
parent,
Expand Down Expand Up @@ -1513,10 +1513,14 @@ fn render_impl(
);
}
}
let details_str = if impl_items.is_empty() && default_impl_items.is_empty() {
""
} else {
"<details class=\"rustdoc-toggle implementors-toggle\" open><summary>"
let toggled = !impl_items.is_empty() || !default_impl_items.is_empty();
let open_details = |close_tags: &mut String| {
if toggled {
close_tags.insert_str(0, "</details>");
"<details class=\"rustdoc-toggle implementors-toggle\" open><summary>"
} else {
""
}
};
if render_mode == RenderMode::Normal {
let id = cx.derive_id(match i.inner_impl().trait_ {
Expand All @@ -1538,11 +1542,10 @@ fn render_impl(
write!(
w,
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">",
details_str, id, aliases
open_details(&mut close_tags),
id,
aliases
);
if !impl_items.is_empty() || !default_impl_items.is_empty() {
close_tags.insert_str(0, "</details>");
}
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
if show_def_docs {
for it in &i.inner_impl().items {
Expand All @@ -1566,14 +1569,11 @@ fn render_impl(
write!(
w,
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
details_str,
open_details(&mut close_tags),
id,
aliases,
i.inner_impl().print(false, cx)
);
if !impl_items.is_empty() || !default_impl_items.is_empty() {
close_tags.insert_str(0, "</details>");
}
}
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
render_stability_since_raw(
Expand All @@ -1584,7 +1584,7 @@ fn render_impl(
outer_const_version,
);
write_srclink(cx, &i.impl_item, w);
if impl_items.is_empty() && default_impl_items.is_empty() {
if !toggled {
w.write_str("</h3>");
} else {
w.write_str("</h3></summary>");
Expand Down Expand Up @@ -1613,7 +1613,7 @@ fn render_impl(
);
}
}
if !impl_items.is_empty() || !default_impl_items.is_empty() {
if toggled {
w.write_str("<div class=\"impl-items\">");
w.push_buffer(default_impl_items);
if trait_.is_some() && !impl_items.is_empty() {
Expand Down

0 comments on commit 0d52eb9

Please sign in to comment.