From ff4e06104903c8cb03600739fa51afb905188b18 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sat, 9 May 2015 00:03:42 +0200 Subject: [PATCH 1/2] rustdoc: Link associated items in search index to trait This is related to isssue #22442 and solves it partly. This solves the links of associated types and constants, so that they link to the trait page. --- src/librustdoc/html/render.rs | 2 ++ src/librustdoc/html/static/main.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 5a828e8376e52..4074a6594427d 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -905,6 +905,8 @@ impl DocFolder for Cache { // Index this method for searching later on if let Some(ref s) = item.name { let (parent, is_method) = match item.inner { + clean::AssociatedTypeItem(..) | + clean::AssociatedConstItem(..) | clean::TyMethodItem(..) | clean::StructFieldItem(..) | clean::VariantItem(..) => { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c2a59278a86dc..02c6c8dca9d84 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -34,7 +34,8 @@ "macro", "primitive", "associatedtype", - "constant"]; + "constant", + "associatedconstant"]; $('.js-only').removeClass('js-only'); From c46f3ff12b0a0b9c55df89eeb92603e9e488b2a7 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sat, 9 May 2015 00:16:20 +0200 Subject: [PATCH 2/2] rustdoc: Add Associated Constants section Section only visible if there are assoc. consts. present. --- src/librustdoc/html/render.rs | 11 +++++++++++ src/test/rustdoc/assoc-consts.rs | 1 + 2 files changed, 12 insertions(+) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 4074a6594427d..55e16db596a39 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1862,6 +1862,17 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, try!(write!(w, "")); } + if !consts.is_empty() { + try!(write!(w, " +

Associated Constants

+
+ ")); + for t in &consts { + try!(trait_item(w, *t)); + } + try!(write!(w, "
")); + } + // Output the documentation for each function individually if !required.is_empty() { try!(write!(w, " diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index cd8d7ec16dce4..20d4c744414c6 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -13,6 +13,7 @@ pub trait Foo { // @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \ // 'const FOO: usize;' + // @has - '//*[@id="associatedconstant.FOO"]' 'const FOO' const FOO: usize; }