From 09fc36e3b5ca245d31f9dbddeb41006ac457273e Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 23 Jul 2017 15:02:06 -0700 Subject: [PATCH] rustdoc: make major section headers self-links The sidebar already has links to these h2's ids, but for convenience, the h2 itself should also be a link (retaining its present appearance). This should address most of #24484. --- src/librustdoc/html/render.rs | 49 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9b1d256304dd0..e89bd7aae9bf1 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2141,7 +2141,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, if !types.is_empty() { write!(w, " -

Associated Types

+

+ Associated Types +

")?; for t in &types { @@ -2152,7 +2154,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, if !consts.is_empty() { write!(w, " -

Associated Constants

+

+ Associated Constants +

")?; for t in &consts { @@ -2164,7 +2168,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, // Output the documentation for each function individually if !required.is_empty() { write!(w, " -

Required Methods

+

+ Required Methods +

")?; for m in &required { @@ -2174,7 +2180,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } if !provided.is_empty() { write!(w, " -

Provided Methods

+

+ Provided Methods +

")?; for m in &provided { @@ -2188,7 +2196,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, let cache = cache(); write!(w, " -

Implementors

+

+ Implementors +

    ")?; if let Some(implementors) = cache.implementors.get(&it.def_id) { @@ -2419,7 +2429,8 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, }).peekable(); if let doctree::Plain = s.struct_type { if fields.peek().is_some() { - write!(w, "

    Fields

    ")?; + write!(w, "

    + Fields

    ")?; for (field, ty) in fields { let id = derive_id(format!("{}.{}", ItemType::StructField, @@ -2467,7 +2478,8 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } }).peekable(); if fields.peek().is_some() { - write!(w, "

    Fields

    ")?; + write!(w, "

    + Fields

    ")?; for (field, ty) in fields { write!(w, "{name}: {ty} ", @@ -2539,7 +2551,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, document(w, cx, it)?; if !e.variants.is_empty() { - write!(w, "

    Variants

    \n")?; + write!(w, "

    + Variants

    \n")?; for variant in &e.variants { let id = derive_id(format!("{}.{}", ItemType::Variant, @@ -2810,12 +2823,19 @@ fn render_assoc_items(w: &mut fmt::Formatter, if !non_trait.is_empty() { let render_mode = match what { AssocItemRender::All => { - write!(w, "

    Methods

    ")?; + write!(w, " +

    + Methods +

    + ")?; RenderMode::Normal } AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => { - write!(w, "

    Methods from \ - {}<Target = {}>

    ", trait_, type_)?; + write!(w, " +

    + Methods from {}<Target = {}> +

    + ", trait_, type_)?; RenderMode::ForDeref { mut_: deref_mut_ } } }; @@ -2837,8 +2857,11 @@ fn render_assoc_items(w: &mut fmt::Formatter, }).is_some(); render_deref_methods(w, cx, impl_, containing_item, has_deref_mut)?; } - write!(w, "

    Trait \ - Implementations

    ")?; + write!(w, " +

    + Trait Implementations +

    + ")?; for i in &traits { let did = i.trait_did().unwrap(); let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);