diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 9a26a925847..5a828e8376e 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1787,6 +1787,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
let types = t.items.iter().filter(|m| {
match m.inner { clean::AssociatedTypeItem(..) => true, _ => false }
}).collect::>();
+ let consts = t.items.iter().filter(|m| {
+ match m.inner { clean::AssociatedConstItem(..) => true, _ => false }
+ }).collect::>();
let required = t.items.iter().filter(|m| {
match m.inner { clean::TyMethodItem(_) => true, _ => false }
}).collect::>();
@@ -1803,7 +1806,15 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
try!(render_assoc_item(w, t, AssocItemLink::Anchor));
try!(write!(w, ";\n"));
}
- if !types.is_empty() && !required.is_empty() {
+ if !types.is_empty() && !consts.is_empty() {
+ try!(w.write_str("\n"));
+ }
+ for t in &consts {
+ try!(write!(w, " "));
+ try!(render_assoc_item(w, t, AssocItemLink::Anchor));
+ try!(write!(w, ";\n"));
+ }
+ if !consts.is_empty() && !required.is_empty() {
try!(w.write_str("\n"));
}
for m in &required {
@@ -1905,11 +1916,11 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
fn assoc_const(w: &mut fmt::Formatter, it: &clean::Item,
- ty: &clean::Type, default: &Option)
+ ty: &clean::Type, default: Option<&String>)
-> fmt::Result {
try!(write!(w, "const {}", it.name.as_ref().unwrap()));
try!(write!(w, ": {}", ty));
- if let Some(ref default) = *default {
+ if let Some(default) = default {
try!(write!(w, " = {}", default));
}
Ok(())
@@ -1971,7 +1982,7 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
link)
}
clean::AssociatedConstItem(ref ty, ref default) => {
- assoc_const(w, meth, ty, default)
+ assoc_const(w, meth, ty, default.as_ref())
}
clean::AssociatedTypeItem(ref bounds, ref default) => {
assoc_type(w, meth, bounds, default)
@@ -2335,9 +2346,15 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
clean::AssociatedConstItem(ref ty, ref default) => {
let name = item.name.as_ref().unwrap();
try!(write!(w, "",
- *name,
- shortty(item)));
- try!(assoc_const(w, item, ty, default));
+ *name, shortty(item)));
+ try!(assoc_const(w, item, ty, default.as_ref()));
+ try!(write!(w, "
\n"));
+ }
+ clean::ConstantItem(ref c) => {
+ let name = item.name.as_ref().unwrap();
+ try!(write!(w, "",
+ *name, shortty(item)));
+ try!(assoc_const(w, item, &c.type_, Some(&c.expr)));
try!(write!(w, "
\n"));
}
clean::AssociatedTypeItem(ref bounds, ref default) => {
diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs
new file mode 100644
index 00000000000..cd8d7ec16dc
--- /dev/null
+++ b/src/test/rustdoc/assoc-consts.rs
@@ -0,0 +1,25 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 or the MIT license
+// , at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(associated_consts)]
+
+pub trait Foo {
+ // @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \
+ // 'const FOO: usize;'
+ const FOO: usize;
+}
+
+pub struct Bar;
+
+impl Bar {
+ // @has assoc_consts/struct.Bar.html '//*[@id="assoc_const.BAR"]' \
+ // 'const BAR: usize = 3'
+ pub const BAR: usize = 3;
+}