rustdoc: use code-header class to format enum variants

The font size and weights should be exactly the same after this commit,
but the spacing is changed to be exactly the same as methods.
This commit is contained in:
Michael Howell 2022-11-17 15:24:39 -07:00
parent 83356b78c4
commit 4525eb112b
2 changed files with 19 additions and 24 deletions

View File

@ -19,8 +19,8 @@ use super::{
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context,
ImplRenderingParameters,
render_impl, render_rightside, render_stability_since_raw,
render_stability_since_raw_with_extra, AssocItemLink, Context, ImplRenderingParameters,
};
use crate::clean;
use crate::config::ModuleSorting;
@ -1267,30 +1267,30 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
document_non_exhaustive_header(it)
);
document_non_exhaustive(w, it);
write!(w, "<div class=\"variants\">");
for variant in e.variants() {
let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap()));
write!(
w,
"<h3 id=\"{id}\" class=\"variant small-section-header\">\
<a href=\"#{id}\" class=\"anchor field\"></a>\
<code>{name}",
"<section id=\"{id}\" class=\"variant\">\
<a href=\"#{id}\" class=\"anchor\"></a>",
id = id,
name = variant.name.unwrap()
);
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
w.write_str("(");
print_tuple_struct_fields(w, cx, s);
w.write_str(")");
}
w.write_str("</code>");
render_stability_since_raw(
render_stability_since_raw_with_extra(
w,
variant.stable_since(tcx),
variant.const_stability(tcx),
it.stable_since(tcx),
it.const_stable_since(tcx),
" rightside",
);
w.write_str("</h3>");
write!(w, "<h3 class=\"code-header\">{name}", name = variant.name.unwrap());
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
w.write_str("(");
print_tuple_struct_fields(w, cx, s);
w.write_str(")");
}
w.write_str("</h3></section>");
use crate::clean::Variant;
@ -1324,7 +1324,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
write!(
w,
"<div class=\"sub-variant-field\">\
<span id=\"{id}\" class=\"variant small-section-header\">\
<span id=\"{id}\" class=\"small-section-header\">\
<a href=\"#{id}\" class=\"anchor field\"></a>\
<code>{f}:&nbsp;{t}</code>\
</span>",
@ -1343,6 +1343,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
document(w, cx, variant, Some(it), HeadingOffset::H4);
}
write!(w, "</div>");
}
let def_id = it.item_id.expect_def_id();
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);

View File

@ -709,8 +709,6 @@ a {
}
.small-section-header {
display: flex;
justify-content: space-between;
position: relative;
}
@ -718,7 +716,7 @@ a {
display: initial;
}
.impl:hover > .anchor, .trait-impl:hover > .anchor {
.impl:hover > .anchor, .trait-impl:hover > .anchor, .variant:hover > .anchor {
display: inline-block;
position: absolute;
}
@ -1235,12 +1233,6 @@ a.test-arrow:hover {
font-size: 1.25rem;
}
h3.variant {
font-weight: 600;
font-size: 1.125rem;
margin-bottom: 10px;
}
.sub-variant h4 {
font-size: 1rem;
font-weight: 400;
@ -1909,6 +1901,7 @@ in storage.js
}
}
.variant,
.implementors-toggle > summary,
.impl,
#implementors-list > .docblock,
@ -1920,6 +1913,7 @@ in storage.js
margin-bottom: 0.75em;
}
.variants > .docblock,
.impl-items > .rustdoc-toggle[open]:not(:last-child),
.methods > .rustdoc-toggle[open]:not(:last-child),
.implementors-toggle[open]:not(:last-child) {