Skip to content

Commit 4b88e8f

Browse files
committed
Auto merge of #25225 - bluss:doc-search-assoc-items, r=alexcrichton
Rustdoc fixes for associated items This is related to isssue #22442 and solves it partly. This solves the search index links of associated types and constants, so that they link to the trait page. Also add an Associated Constants section if constants are present.
2 parents a90dd32 + c46f3ff commit 4b88e8f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/librustdoc/html/render.rs

+13
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ impl DocFolder for Cache {
905905
// Index this method for searching later on
906906
if let Some(ref s) = item.name {
907907
let (parent, is_method) = match item.inner {
908+
clean::AssociatedTypeItem(..) |
909+
clean::AssociatedConstItem(..) |
908910
clean::TyMethodItem(..) |
909911
clean::StructFieldItem(..) |
910912
clean::VariantItem(..) => {
@@ -1862,6 +1864,17 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18621864
try!(write!(w, "</div>"));
18631865
}
18641866

1867+
if !consts.is_empty() {
1868+
try!(write!(w, "
1869+
<h2 id='associated-const'>Associated Constants</h2>
1870+
<div class='methods'>
1871+
"));
1872+
for t in &consts {
1873+
try!(trait_item(w, *t));
1874+
}
1875+
try!(write!(w, "</div>"));
1876+
}
1877+
18651878
// Output the documentation for each function individually
18661879
if !required.is_empty() {
18671880
try!(write!(w, "

src/librustdoc/html/static/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"macro",
3535
"primitive",
3636
"associatedtype",
37-
"constant"];
37+
"constant",
38+
"associatedconstant"];
3839

3940
$('.js-only').removeClass('js-only');
4041

src/test/rustdoc/assoc-consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pub trait Foo {
1414
// @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \
1515
// 'const FOO: usize;'
16+
// @has - '//*[@id="associatedconstant.FOO"]' 'const FOO'
1617
const FOO: usize;
1718
}
1819

0 commit comments

Comments
 (0)