Skip to content

Commit df644c3

Browse files
authored
Rollup merge of #104556 - notriddle:notriddle/variant, r=GuillaumeGomez
rustdoc: use `code-header` class to format enum variants The font size and weights should be exactly the same after this PR, but the spacing is changed to be the same as methods. Preview: http://notriddle.com/notriddle-rustdoc-demos/variant/test_dingus_enum/enum.TestEnum.html
2 parents 9e27e4e + 616f34e commit df644c3

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
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
@@ -706,16 +706,14 @@ a {
706706
}
707707

708708
.small-section-header {
709-
display: flex;
710-
justify-content: space-between;
711709
position: relative;
712710
}
713711

714712
.small-section-header:hover > .anchor {
715713
display: initial;
716714
}
717715

718-
.impl:hover > .anchor, .trait-impl:hover > .anchor {
716+
.impl:hover > .anchor, .trait-impl:hover > .anchor, .variant:hover > .anchor {
719717
display: inline-block;
720718
position: absolute;
721719
}
@@ -1234,12 +1232,6 @@ a.test-arrow:hover {
12341232
font-size: 1.25rem;
12351233
}
12361234

1237-
h3.variant {
1238-
font-weight: 600;
1239-
font-size: 1.125rem;
1240-
margin-bottom: 10px;
1241-
}
1242-
12431235
.sub-variant h4 {
12441236
font-size: 1rem;
12451237
font-weight: 400;
@@ -1908,6 +1900,7 @@ in storage.js
19081900
}
19091901
}
19101902

1903+
.variant,
19111904
.implementors-toggle > summary,
19121905
.impl,
19131906
#implementors-list > .docblock,
@@ -1919,6 +1912,7 @@ in storage.js
19191912
margin-bottom: 0.75em;
19201913
}
19211914

1915+
.variants > .docblock,
19221916
.impl-items > .rustdoc-toggle[open]:not(:last-child),
19231917
.methods > .rustdoc-toggle[open]:not(:last-child),
19241918
.implementors-toggle[open]:not(:last-child) {
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Verifies that there is non-zero margin on variants and their docblocks.
2+
goto: "file://" + |DOC_PATH| + "/test_docs/enum.WhoLetTheDogOut.html"
3+
4+
assert-css: (".variants > .variant", {"margin": "0px 0px 12px"})
5+
assert-css: (".variants > .docblock", {"margin": "0px 0px 32px 24px"})

src/test/rustdoc/issue-88600.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ pub struct S;
88

99
// @has issue_88600/enum.FooEnum.html
1010
pub enum FooEnum {
11-
// @has - '//*[@id="variant.HiddenTupleItem"]//code' 'HiddenTupleItem(_)'
11+
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)'
1212
// @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0
1313
HiddenTupleItem(#[doc(hidden)] H),
14-
// @has - '//*[@id="variant.MultipleHidden"]//code' 'MultipleHidden(_, _)'
14+
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)'
1515
// @count - '//*[@id="variant.MultipleHidden.field.0"]' 0
1616
// @count - '//*[@id="variant.MultipleHidden.field.1"]' 0
1717
MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H),
18-
// @has - '//*[@id="variant.MixedHiddenFirst"]//code' 'MixedHiddenFirst(_, S)'
18+
// @has - '//*[@id="variant.MixedHiddenFirst"]//h3' 'MixedHiddenFirst(_, S)'
1919
// @count - '//*[@id="variant.MixedHiddenFirst.field.0"]' 0
2020
// @has - '//*[@id="variant.MixedHiddenFirst.field.1"]' '1: S'
2121
MixedHiddenFirst(#[doc(hidden)] H, /** dox */ S),
22-
// @has - '//*[@id="variant.MixedHiddenLast"]//code' 'MixedHiddenLast(S, _)'
22+
// @has - '//*[@id="variant.MixedHiddenLast"]//h3' 'MixedHiddenLast(S, _)'
2323
// @has - '//*[@id="variant.MixedHiddenLast.field.0"]' '0: S'
2424
// @count - '//*[@id="variant.MixedHiddenLast.field.1"]' 0
2525
MixedHiddenLast(/** dox */ S, #[doc(hidden)] H),
26-
// @has - '//*[@id="variant.HiddenStruct"]//code' 'HiddenStruct'
26+
// @has - '//*[@id="variant.HiddenStruct"]//h3' 'HiddenStruct'
2727
// @count - '//*[@id="variant.HiddenStruct.field.h"]' 0
2828
// @has - '//*[@id="variant.HiddenStruct.field.s"]' 's: S'
2929
HiddenStruct {

0 commit comments

Comments
 (0)