about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-23 03:21:17 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-25 20:41:32 +0000
commit4eb08bb2ab43f0ad80071469771381a4dd03603d (patch)
tree8669ce3afa99114fbbdd7fa391d20b9da1521460 /src/libsyntax
parent8250a26b5bcea9190ac63e756c35d8a54bf9da0c (diff)
downloadrust-4eb08bb2ab43f0ad80071469771381a4dd03603d.tar.gz
rust-4eb08bb2ab43f0ad80071469771381a4dd03603d.zip
Refactor away `AttrNestedMetaItemMethods`.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr.rs74
-rw-r--r--src/libsyntax/config.rs2
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/libsyntax/test.rs2
4 files changed, 36 insertions, 44 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 4897425f2c0..f1a820ce1d4 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -81,32 +81,47 @@ pub fn is_used(attr: &Attribute) -> bool {
     })
 }
 
-pub trait AttrNestedMetaItemMethods {
+impl NestedMetaItem {
+    /// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
+    pub fn meta_item(&self) -> Option<&P<MetaItem>> {
+        match self.node {
+            NestedMetaItemKind::MetaItem(ref item) => Some(&item),
+            _ => None
+        }
+    }
+
+    /// Returns the Lit if self is a NestedMetaItemKind::Literal.
+    pub fn literal(&self) -> Option<&Lit> {
+        match self.node {
+            NestedMetaItemKind::Literal(ref lit) => Some(&lit),
+            _ => None
+        }
+    }
+
+    /// Returns the Span for `self`.
+    pub fn span(&self) -> Span {
+        self.span
+    }
+
     /// Returns true if this list item is a MetaItem with a name of `name`.
-    fn check_name(&self, name: &str) -> bool {
+    pub fn check_name(&self, name: &str) -> bool {
         self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
     }
 
     /// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
     /// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem
-    fn name(&self) -> Option<InternedString> {
+    pub fn name(&self) -> Option<InternedString> {
         self.meta_item().and_then(|meta_item| Some(meta_item.name()))
     }
 
-    /// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
-    fn meta_item(&self) -> Option<&P<MetaItem>>;
-
-    /// Returns the Lit if self is a NestedMetaItemKind::Literal.
-    fn literal(&self) -> Option<&Lit>;
-
     /// Gets the string value if self is a MetaItem and the MetaItem is a
     /// MetaItemKind::NameValue variant containing a string, otherwise None.
-    fn value_str(&self) -> Option<InternedString> {
+    pub fn value_str(&self) -> Option<InternedString> {
         self.meta_item().and_then(|meta_item| meta_item.value_str())
     }
 
     /// Returns a MetaItem if self is a MetaItem with Kind Word.
-    fn word(&self) -> Option<&P<MetaItem>> {
+    pub fn word(&self) -> Option<&P<MetaItem>> {
         self.meta_item().and_then(|meta_item| if meta_item.is_word() {
             Some(meta_item)
         } else {
@@ -115,57 +130,34 @@ pub trait AttrNestedMetaItemMethods {
     }
 
     /// Gets a list of inner meta items from a list MetaItem type.
-    fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
+    pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
         self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
     }
 
     /// Returns `true` if the variant is MetaItem.
-    fn is_meta_item(&self) -> bool {
+    pub fn is_meta_item(&self) -> bool {
         self.meta_item().is_some()
     }
 
     /// Returns `true` if the variant is Literal.
-    fn is_literal(&self) -> bool {
+    pub fn is_literal(&self) -> bool {
         self.literal().is_some()
     }
 
     /// Returns `true` if self is a MetaItem and the meta item is a word.
-    fn is_word(&self) -> bool {
+    pub fn is_word(&self) -> bool {
         self.word().is_some()
     }
 
     /// Returns `true` if self is a MetaItem and the meta item is a ValueString.
-    fn is_value_str(&self) -> bool {
+    pub fn is_value_str(&self) -> bool {
         self.value_str().is_some()
     }
 
     /// Returns `true` if self is a MetaItem and the meta item is a list.
-    fn is_meta_item_list(&self) -> bool {
+    pub fn is_meta_item_list(&self) -> bool {
         self.meta_item_list().is_some()
     }
-
-    /// Returns the Span for `self`.
-    fn span(&self) -> Span;
-}
-
-impl AttrNestedMetaItemMethods for NestedMetaItem {
-    fn meta_item(&self) -> Option<&P<MetaItem>> {
-        match self.node {
-            NestedMetaItemKind::MetaItem(ref item) => Some(&item),
-            _ => None
-        }
-    }
-
-    fn literal(&self) -> Option<&Lit> {
-        match self.node {
-            NestedMetaItemKind::Literal(ref lit) => Some(&lit),
-            _ => None
-        }
-    }
-
-    fn span(&self) -> Span {
-        self.span
-    }
 }
 
 pub trait AttrMetaMethods {
@@ -431,7 +423,7 @@ pub fn contains(haystack: &[P<MetaItem>], needle: &MetaItem) -> bool {
     })
 }
 
-pub fn list_contains_name<AM: AttrNestedMetaItemMethods>(items: &[AM], name: &str) -> bool {
+pub fn list_contains_name(items: &[NestedMetaItem], name: &str) -> bool {
     debug!("attr::list_contains_name (name={})", name);
     items.iter().any(|item| {
         debug!("  testing: {:?}", item.name());
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index 4663143f4b1..ed05dc243b3 100644
--- a/src/libsyntax/config.rs
+++ b/src/libsyntax/config.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use attr::{AttrMetaMethods, AttrNestedMetaItemMethods, HasAttrs};
+use attr::{AttrMetaMethods, HasAttrs};
 use feature_gate::{emit_feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
 use fold::Folder;
 use {fold, attr};
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index df1d5c4d9ca..d2aa9a4cb6b 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -27,7 +27,7 @@ use self::AttributeGate::*;
 
 use abi::Abi;
 use ast::{self, NodeId, PatKind};
-use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
+use attr::{self, AttrMetaMethods};
 use codemap::CodeMap;
 use syntax_pos::Span;
 use errors::Handler;
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index ce917f248e1..0a14eae7d35 100644
--- a/src/libsyntax/test.rs
+++ b/src/libsyntax/test.rs
@@ -19,7 +19,7 @@ use std::iter;
 use std::slice;
 use std::mem;
 use std::vec;
-use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
+use attr::{self, AttrMetaMethods};
 use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
 use std::rc::Rc;