about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-30 23:40:27 +0000
committerbors <bors@rust-lang.org>2015-04-30 23:40:27 +0000
commitc634ec2e88a85d7f553ec0d6746e24a886bc6fd4 (patch)
treec62f07daef30abdb90a890ec550df97e171b1828
parent8a60e5667fa77c4a7a4e13bf7ab4ad6f1d033ca9 (diff)
parent543b910f9be6b4d8d757f0471f00ba0a691bc5f6 (diff)
downloadrust-c634ec2e88a85d7f553ec0d6746e24a886bc6fd4.tar.gz
rust-c634ec2e88a85d7f553ec0d6746e24a886bc6fd4.zip
Auto merge of #24989 - alexcrichton:rustdoc-associated-constant, r=brson
Associated constants were now showing up for traits and would panic if they were
found on an inherent impl. This commit unblocks the nighly builders.
-rw-r--r--src/librustdoc/html/render.rs31
-rw-r--r--src/test/rustdoc/assoc-consts.rs25
2 files changed, 49 insertions, 7 deletions
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::<Vec<_>>();
+    let consts = t.items.iter().filter(|m| {
+        match m.inner { clean::AssociatedConstItem(..) => true, _ => false }
+    }).collect::<Vec<_>>();
     let required = t.items.iter().filter(|m| {
         match m.inner { clean::TyMethodItem(_) => true, _ => false }
     }).collect::<Vec<_>>();
@@ -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<String>)
+               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, "<h4 id='assoc_const.{}' class='{}'><code>",
-                            *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, "</code></h4>\n"));
+            }
+            clean::ConstantItem(ref c) => {
+                let name = item.name.as_ref().unwrap();
+                try!(write!(w, "<h4 id='assoc_const.{}' class='{}'><code>",
+                            *name, shortty(item)));
+                try!(assoc_const(w, item, &c.type_, Some(&c.expr)));
                 try!(write!(w, "</code></h4>\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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
+}