about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorcgswords <cameronswords@gmail.com>2016-07-15 13:13:17 -0700
committercgswords <cameronswords@gmail.com>2016-07-25 14:27:10 -0700
commita5e5ea1646367b82864af3a2a508993d76b792af (patch)
tree4d316bf57d10fba4b3ad3532b7ab32416749e59e /src/librustdoc
parent9316ae515e2f8f3f497fb4f1559910c1eef2433d (diff)
downloadrust-a5e5ea1646367b82864af3a2a508993d76b792af.tar.gz
rust-a5e5ea1646367b82864af3a2a508993d76b792af.zip
General MetaItem encapsulation rewrites.
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/clean/mod.rs79
1 files changed, 50 insertions, 29 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 0211b2c9bc7..8d69c55ecf1 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -498,21 +498,20 @@ pub enum Attribute {
 
 impl Clean<Attribute> for ast::MetaItem {
     fn clean(&self, cx: &DocContext) -> Attribute {
-        match self.node {
-            ast::MetaItemKind::Word(ref s) => Word(s.to_string()),
-            ast::MetaItemKind::List(ref s, ref l) => {
-                List(s.to_string(), l.clean(cx))
-            }
-            ast::MetaItemKind::NameValue(ref s, ref v) => {
-                NameValue(s.to_string(), lit_to_string(v))
-            }
-        }
+        if self.is_word() {
+            Word(self.name().to_string())
+        } else if let Some(v) = self.value_str() {
+            NameValue(self.name().to_string(), v.to_string())
+        } else { // must be a list
+            let l = self.meta_item_list().unwrap();
+              List(self.name().to_string(), l.clean(cx))
+       }
     }
 }
 
 impl Clean<Attribute> for ast::Attribute {
     fn clean(&self, cx: &DocContext) -> Attribute {
-        self.with_desugared_doc(|a| a.node.value.clean(cx))
+        self.with_desugared_doc(|a| a.meta().clean(cx))
     }
 }
 
@@ -535,6 +534,28 @@ impl attr::AttrMetaMethods for Attribute {
         }
     }
     fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
+
+    fn is_word(&self) -> bool {
+      match *self {
+        Word(_) => true,
+        _ => false,
+      }
+    }
+
+    fn is_value_str(&self) -> bool {
+      match *self {
+        NameValue(..) => true,
+        _ => false,
+      }
+    }
+
+    fn is_meta_item_list(&self) -> bool {
+      match *self {
+        List(..) => true,
+        _ => false,
+      }
+    }
+
     fn span(&self) -> syntax_pos::Span { unimplemented!() }
 }
 
@@ -2568,25 +2589,25 @@ impl ToSource for syntax_pos::Span {
     }
 }
 
-fn lit_to_string(lit: &ast::Lit) -> String {
-    match lit.node {
-        ast::LitKind::Str(ref st, _) => st.to_string(),
-        ast::LitKind::ByteStr(ref data) => format!("{:?}", data),
-        ast::LitKind::Byte(b) => {
-            let mut res = String::from("b'");
-            for c in (b as char).escape_default() {
-                res.push(c);
-            }
-            res.push('\'');
-            res
-        },
-        ast::LitKind::Char(c) => format!("'{}'", c),
-        ast::LitKind::Int(i, _t) => i.to_string(),
-        ast::LitKind::Float(ref f, _t) => f.to_string(),
-        ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(),
-        ast::LitKind::Bool(b) => b.to_string(),
-    }
-}
+// fn lit_to_string(lit: &ast::Lit) -> String {
+//     match lit.node {
+//         ast::LitKind::Str(ref st, _) => st.to_string(),
+//         ast::LitKind::ByteStr(ref data) => format!("{:?}", data),
+//         ast::LitKind::Byte(b) => {
+//             let mut res = String::from("b'");
+//             for c in (b as char).escape_default() {
+//                 res.push(c);
+//             }
+//             res.push('\'');
+//             res
+//         },
+//         ast::LitKind::Char(c) => format!("'{}'", c),
+//         ast::LitKind::Int(i, _t) => i.to_string(),
+//         ast::LitKind::Float(ref f, _t) => f.to_string(),
+//         ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(),
+//         ast::LitKind::Bool(b) => b.to_string(),
+//     }
+// }
 
 fn name_from_pat(p: &hir::Pat) -> String {
     use rustc::hir::*;