about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-10-13 01:40:02 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2016-11-06 20:06:04 +0100
commitb1a3f88e5501521548ddea4e918d55cc1c777187 (patch)
treeace3c8df41df1e63dd622d388c3204b815444c25
parent5fe733a15945b7599fdf820ceec1597259dd8490 (diff)
downloadrust-b1a3f88e5501521548ddea4e918d55cc1c777187.tar.gz
rust-b1a3f88e5501521548ddea4e918d55cc1c777187.zip
Print more tags in rustdoc
-rw-r--r--src/librustdoc/html/render.rs48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index a848a011f88..e3efcc5c2f9 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2492,16 +2492,48 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
     Ok(())
 }
 
+fn attribute_without_value(s: &str) -> bool {
+    vec!("must_use", "no_mangle", "unsafe_destructor_blind_to_params").iter().any(|x| x == &s)
+}
+
+fn attribute_with_value(s: &str) -> bool {
+    vec!("export_name", "lang", "link_section", "must_use").iter().any(|x| x == &s)
+}
+
+fn attribute_with_values(s: &str) -> bool {
+    vec!("repr").iter().any(|x| x == &s)
+}
+
+fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String {
+    match *attr {
+        clean::Word(ref s) if attribute_without_value(&*s) || recurse => {
+            format!("{}", s)
+        }
+        clean::NameValue(ref k, ref v) if attribute_with_value(&*k) => {
+            format!("{} = \"{}\"", k, v)
+        }
+        clean::List(ref k, ref values) if attribute_with_values(&*k) => {
+            let mut display = Vec::new();
+
+            for value in values {
+                let s = render_attribute(value, true);
+                if s.len() > 0 {
+                    display.push(format!("{}", s));
+                }
+            }
+            format!("{}({})", k, display.join(", "))
+        }
+        _ => {
+            String::new()
+        }
+    }
+}
+
 fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
     for attr in &it.attrs {
-        match *attr {
-            clean::Word(ref s) if *s == "must_use" => {
-                write!(w, "#[{}]\n", s)?;
-            }
-            clean::NameValue(ref k, ref v) if *k == "must_use" => {
-                write!(w, "#[{} = \"{}\"]\n", k, v)?;
-            }
-            _ => ()
+        let s = render_attribute(attr, false);
+        if s.len() > 0 {
+            write!(w, "#[{}]\n", s)?;
         }
     }
     Ok(())