From 4525eb112b0d154204268b8c5a88263700191d02 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 17 Nov 2022 15:24:39 -0700 Subject: [PATCH] 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. --- src/librustdoc/html/render/print_item.rs | 31 +++++++++++----------- src/librustdoc/html/static/css/rustdoc.css | 12 +++------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index ac11a860a4f..c95f117a205 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -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, "
"); for variant in e.variants() { let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap())); write!( w, - "

\ - \ - {name}", + "
\ + ", 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(""); - 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("

"); + write!(w, "

{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("

"); use crate::clean::Variant; @@ -1324,7 +1324,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: write!( w, "
\ - \ + \ \ {f}: {t}\ ", @@ -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, "
"); } let def_id = it.item_id.expect_def_id(); render_assoc_items(w, cx, it, def_id, AssocItemRender::All); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 9b1cac85cfd..27ffd7682e9 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -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) {