From f19548b76f3bafa9eb60f5a3deb2b74153ee5ffc Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 31 Oct 2021 10:23:35 -0700 Subject: [PATCH] Make h2 headings hyperlinks --- src/librustdoc/html/render/mod.rs | 14 +++++++------- src/librustdoc/html/render/print_item.rs | 11 ++++++----- src/librustdoc/html/static/css/rustdoc.css | 6 ++++++ src/test/rustdoc-gui/anchors.goml | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 16334890da674..377818b34d79f 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1054,7 +1054,7 @@ fn render_assoc_items_inner( AssocItemRender::All => { tmp_buf.write_str( "

\ - Implementations\ + Implementations\

", ); RenderMode::Normal @@ -1068,8 +1068,8 @@ fn render_assoc_items_inner( write!( tmp_buf, "

\ - Methods from {trait_}<Target = {type_}>\ \ + Methods from {trait_}<Target = {type_}>\

", id = id, trait_ = trait_.print(cx), @@ -1131,7 +1131,7 @@ fn render_assoc_items_inner( write!( w, "

\ - Trait Implementations\ + Trait Implementations\

\
{}
", impls @@ -1141,8 +1141,7 @@ fn render_assoc_items_inner( if !synthetic.is_empty() { w.write_str( "

\ - Auto Trait Implementations\ - \ + Auto Trait Implementations\

\
", ); @@ -1153,8 +1152,9 @@ fn render_assoc_items_inner( if !blanket_impl.is_empty() { w.write_str( "

\ - Blanket Implementations\ - \ + \ + Blanket Implementations\ + \

\
", ); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 44a9ec5ea4210..1fd3bfe92038f 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -660,7 +660,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra write!( w, "

\ - {1}\ + {1}\

{2}", id, title, extra_content ) @@ -1001,7 +1001,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni write!( w, "

\ - Fields

" + Fields" ); for (field, ty) in fields { let name = field.name.as_ref().expect("union field name"); @@ -1108,7 +1108,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum write!( w, "

\ - Variants{}

", + Variants{}", document_non_exhaustive_header(it) ); document_non_exhaustive(w, it); @@ -1300,7 +1300,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St write!( w, "

\ - {}{}\ + {}{}\

", if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" }, document_non_exhaustive_header(it) @@ -1732,7 +1732,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) { return; } - writeln!(w, "

Layout

"); + writeln!(w, "

"); + writeln!(w, "Layout

"); writeln!(w, "
"); let tcx = cx.tcx(); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e5c667a37c669..650d649dede70 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1129,6 +1129,7 @@ a.test-arrow:hover{ text-decoration: none; } +.small-section-header:hover > a:before, .section-header:hover a:before { position: absolute; left: -25px; @@ -1136,6 +1137,11 @@ a.test-arrow:hover{ content: '\2002\00a7\2002'; } +#deref-methods-str > a.anchor:before { + position: relative; + left: -0.5em; +} + .section-header:hover a { text-decoration: none; } diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index ca60be72cea46..05bf689f8c38a 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -23,7 +23,7 @@ assert-css: (".in-band a", {"color": "rgb(0, 0, 0)"}) // We move the cursor over the "Implementations" title so the anchor is displayed. move-cursor-to: "h2#implementations" -assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"}) +assert-css: ("h2#implementations", {"color": "rgb(0, 0, 0)"}) // Same thing with the impl block title. move-cursor-to: "#impl"