about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-28 10:40:04 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-28 10:40:04 +0000
commitc14ff2884dc46a8a0ef7f5916b4730a4e516d9ab (patch)
treedd2a303288164091abb7fb5441f22601f2d64f78 /src/libsyntax
parent6303640e856dc3cccea655df104203649b5efd76 (diff)
parent469753f0abc4b9eac811d8b2955d478825f9c3e1 (diff)
downloadrust-c14ff2884dc46a8a0ef7f5916b4730a4e516d9ab.tar.gz
rust-c14ff2884dc46a8a0ef7f5916b4730a4e516d9ab.zip
Rollup merge of #35917 - jseyfried:remove_attr_ext_traits, r=nrc
syntax: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr.rs175
-rw-r--r--src/libsyntax/config.rs2
-rw-r--r--src/libsyntax/ext/expand.rs1
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/libsyntax/parse/mod.rs2
-rw-r--r--src/libsyntax/print/pprust.rs1
-rw-r--r--src/libsyntax/test.rs2
7 files changed, 72 insertions, 113 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 4897425f2c0..6060ff529f2 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,93 +130,38 @@ 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 {
-    fn check_name(&self, name: &str) -> bool {
-        name == &self.name()[..]
-    }
-
-    /// Retrieve the name of the meta item, e.g. `foo` in `#[foo]`,
-    /// `#[foo="bar"]` and `#[foo(bar)]`
-    fn name(&self) -> InternedString;
-
-    /// Gets the string value if self is a MetaItemKind::NameValue variant
-    /// containing a string, otherwise None.
-    fn value_str(&self) -> Option<InternedString>;
-
-    /// Gets a list of inner meta items from a list MetaItem type.
-    fn meta_item_list(&self) -> Option<&[NestedMetaItem]>;
-
-    /// Indicates if the attribute is a Word.
-    fn is_word(&self) -> bool;
-
-    /// Indicates if the attribute is a Value String.
-    fn is_value_str(&self) -> bool {
-        self.value_str().is_some()
-    }
-
-    /// Indicates if the attribute is a Meta-Item List.
-    fn is_meta_item_list(&self) -> bool {
-        self.meta_item_list().is_some()
-    }
-
-    fn span(&self) -> Span;
-}
-
-impl AttrMetaMethods for Attribute {
-    fn check_name(&self, name: &str) -> bool {
+impl Attribute {
+    pub fn check_name(&self, name: &str) -> bool {
         let matches = name == &self.name()[..];
         if matches {
             mark_used(self);
@@ -209,23 +169,32 @@ impl AttrMetaMethods for Attribute {
         matches
     }
 
-    fn name(&self) -> InternedString { self.meta().name() }
+    pub fn name(&self) -> InternedString { self.meta().name() }
 
-    fn value_str(&self) -> Option<InternedString> {
+    pub fn value_str(&self) -> Option<InternedString> {
         self.meta().value_str()
     }
 
-    fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
+    pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
         self.meta().meta_item_list()
     }
 
-    fn is_word(&self) -> bool { self.meta().is_word() }
+    pub fn is_word(&self) -> bool { self.meta().is_word() }
 
-    fn span(&self) -> Span { self.meta().span }
+    pub fn span(&self) -> Span { self.meta().span }
+
+    pub fn is_meta_item_list(&self) -> bool {
+        self.meta_item_list().is_some()
+    }
+
+    /// Indicates if the attribute is a Value String.
+    pub fn is_value_str(&self) -> bool {
+        self.value_str().is_some()
+    }
 }
 
-impl AttrMetaMethods for MetaItem {
-    fn name(&self) -> InternedString {
+impl MetaItem {
+    pub fn name(&self) -> InternedString {
         match self.node {
             MetaItemKind::Word(ref n) => (*n).clone(),
             MetaItemKind::NameValue(ref n, _) => (*n).clone(),
@@ -233,7 +202,7 @@ impl AttrMetaMethods for MetaItem {
         }
     }
 
-    fn value_str(&self) -> Option<InternedString> {
+    pub fn value_str(&self) -> Option<InternedString> {
         match self.node {
             MetaItemKind::NameValue(_, ref v) => {
                 match v.node {
@@ -245,53 +214,45 @@ impl AttrMetaMethods for MetaItem {
         }
     }
 
-    fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
+    pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
         match self.node {
             MetaItemKind::List(_, ref l) => Some(&l[..]),
             _ => None
         }
     }
 
-    fn is_word(&self) -> bool {
+    pub fn is_word(&self) -> bool {
         match self.node {
             MetaItemKind::Word(_) => true,
             _ => false,
         }
     }
 
-    fn span(&self) -> Span { self.span }
-}
+    pub fn span(&self) -> Span { self.span }
 
-// Annoying, but required to get test_cfg to work
-impl AttrMetaMethods for P<MetaItem> {
-    fn name(&self) -> InternedString { (**self).name() }
-    fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
-    fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
-        (**self).meta_item_list()
+    pub fn check_name(&self, name: &str) -> bool {
+        name == &self.name()[..]
     }
-    fn is_word(&self) -> bool { (**self).is_word() }
-    fn is_value_str(&self) -> bool { (**self).is_value_str() }
-    fn is_meta_item_list(&self) -> bool { (**self).is_meta_item_list() }
-    fn span(&self) -> Span { (**self).span() }
-}
 
+    pub fn is_value_str(&self) -> bool {
+        self.value_str().is_some()
+    }
 
-pub trait AttributeMethods {
-    fn meta(&self) -> &MetaItem;
-    fn with_desugared_doc<T, F>(&self, f: F) -> T where
-        F: FnOnce(&Attribute) -> T;
+    pub fn is_meta_item_list(&self) -> bool {
+        self.meta_item_list().is_some()
+    }
 }
 
-impl AttributeMethods for Attribute {
+impl Attribute {
     /// Extract the MetaItem from inside this Attribute.
-    fn meta(&self) -> &MetaItem {
+    pub fn meta(&self) -> &MetaItem {
         &self.node.value
     }
 
     /// Convert self to a normal #[doc="foo"] comment, if it is a
     /// comment like `///` or `/** */`. (Returns self unchanged for
     /// non-sugared doc attributes.)
-    fn with_desugared_doc<T, F>(&self, f: F) -> T where
+    pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
         F: FnOnce(&Attribute) -> T,
     {
         if self.node.is_sugared_doc {
@@ -431,7 +392,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());
@@ -439,9 +400,9 @@ pub fn list_contains_name<AM: AttrNestedMetaItemMethods>(items: &[AM], name: &st
     })
 }
 
-pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool {
+pub fn contains_name(attrs: &[Attribute], name: &str) -> bool {
     debug!("attr::contains_name (name={})", name);
-    metas.iter().any(|item| {
+    attrs.iter().any(|item| {
         debug!("  testing: {}", item.name());
         item.check_name(name)
     })
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index 4663143f4b1..ff1ecd44371 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::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/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 26599208ec0..15ebf95d623 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -13,7 +13,6 @@ use ast::{MacStmtStyle, Stmt, StmtKind, ItemKind};
 use ast;
 use ext::hygiene::Mark;
 use attr::{self, HasAttrs};
-use attr::AttrMetaMethods;
 use codemap::{dummy_spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
 use syntax_pos::{self, Span, ExpnId};
 use config::StripUnconfigured;
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 1839f7b8a75..1e15c156356 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;
 use codemap::{CodeMap, Spanned};
 use syntax_pos::Span;
 use errors::Handler;
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 8272aa7b440..af95e44a567 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -678,7 +678,7 @@ mod tests {
     use codemap::Spanned;
     use ast::{self, PatKind};
     use abi::Abi;
-    use attr::{first_attr_value_str_by_name, AttrMetaMethods};
+    use attr::first_attr_value_str_by_name;
     use parse;
     use parse::parser::Parser;
     use parse::token::{str_to_ident};
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index a48cf6768e9..99c00789219 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -16,7 +16,6 @@ use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
 use ast::Attribute;
 use util::parser::AssocOp;
 use attr;
-use attr::{AttrMetaMethods, AttributeMethods};
 use codemap::{self, CodeMap};
 use syntax_pos::{self, BytePos};
 use errors;
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index 7d93f9dfc48..6155ad729a2 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;
 use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
 use std::rc::Rc;