Skip to content

Commit 4525eb1

Browse files
committed
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.
1 parent 83356b7 commit 4525eb1

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/librustdoc/html/render/print_item.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use super::{
1919
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
2020
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
2121
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
22-
render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context,
23-
ImplRenderingParameters,
22+
render_impl, render_rightside, render_stability_since_raw,
23+
render_stability_since_raw_with_extra, AssocItemLink, Context, ImplRenderingParameters,
2424
};
2525
use crate::clean;
2626
use crate::config::ModuleSorting;
@@ -1267,30 +1267,30 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12671267
document_non_exhaustive_header(it)
12681268
);
12691269
document_non_exhaustive(w, it);
1270+
write!(w, "<div class=\"variants\">");
12701271
for variant in e.variants() {
12711272
let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap()));
12721273
write!(
12731274
w,
1274-
"<h3 id=\"{id}\" class=\"variant small-section-header\">\
1275-
<a href=\"#{id}\" class=\"anchor field\"></a>\
1276-
<code>{name}",
1275+
"<section id=\"{id}\" class=\"variant\">\
1276+
<a href=\"#{id}\" class=\"anchor\"></a>",
12771277
id = id,
1278-
name = variant.name.unwrap()
12791278
);
1280-
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
1281-
w.write_str("(");
1282-
print_tuple_struct_fields(w, cx, s);
1283-
w.write_str(")");
1284-
}
1285-
w.write_str("</code>");
1286-
render_stability_since_raw(
1279+
render_stability_since_raw_with_extra(
12871280
w,
12881281
variant.stable_since(tcx),
12891282
variant.const_stability(tcx),
12901283
it.stable_since(tcx),
12911284
it.const_stable_since(tcx),
1285+
" rightside",
12921286
);
1293-
w.write_str("</h3>");
1287+
write!(w, "<h3 class=\"code-header\">{name}", name = variant.name.unwrap());
1288+
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
1289+
w.write_str("(");
1290+
print_tuple_struct_fields(w, cx, s);
1291+
w.write_str(")");
1292+
}
1293+
w.write_str("</h3></section>");
12941294

12951295
use crate::clean::Variant;
12961296

@@ -1324,7 +1324,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
13241324
write!(
13251325
w,
13261326
"<div class=\"sub-variant-field\">\
1327-
<span id=\"{id}\" class=\"variant small-section-header\">\
1327+
<span id=\"{id}\" class=\"small-section-header\">\
13281328
<a href=\"#{id}\" class=\"anchor field\"></a>\
13291329
<code>{f}:&nbsp;{t}</code>\
13301330
</span>",
@@ -1343,6 +1343,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
13431343

13441344
document(w, cx, variant, Some(it), HeadingOffset::H4);
13451345
}
1346+
write!(w, "</div>");
13461347
}
13471348
let def_id = it.item_id.expect_def_id();
13481349
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);

src/librustdoc/html/static/css/rustdoc.css

+3-9
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,14 @@ a {
709709
}
710710

711711
.small-section-header {
712-
display: flex;
713-
justify-content: space-between;
714712
position: relative;
715713
}
716714

717715
.small-section-header:hover > .anchor {
718716
display: initial;
719717
}
720718

721-
.impl:hover > .anchor, .trait-impl:hover > .anchor {
719+
.impl:hover > .anchor, .trait-impl:hover > .anchor, .variant:hover > .anchor {
722720
display: inline-block;
723721
position: absolute;
724722
}
@@ -1235,12 +1233,6 @@ a.test-arrow:hover {
12351233
font-size: 1.25rem;
12361234
}
12371235

1238-
h3.variant {
1239-
font-weight: 600;
1240-
font-size: 1.125rem;
1241-
margin-bottom: 10px;
1242-
}
1243-
12441236
.sub-variant h4 {
12451237
font-size: 1rem;
12461238
font-weight: 400;
@@ -1909,6 +1901,7 @@ in storage.js
19091901
}
19101902
}
19111903

1904+
.variant,
19121905
.implementors-toggle > summary,
19131906
.impl,
19141907
#implementors-list > .docblock,
@@ -1920,6 +1913,7 @@ in storage.js
19201913
margin-bottom: 0.75em;
19211914
}
19221915

1916+
.variants > .docblock,
19231917
.impl-items > .rustdoc-toggle[open]:not(:last-child),
19241918
.methods > .rustdoc-toggle[open]:not(:last-child),
19251919
.implementors-toggle[open]:not(:last-child) {

0 commit comments

Comments
 (0)