diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-23 03:54:53 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-25 20:41:40 +0000 |
| commit | bfb01bbb263923106b33fdaa140a5fa464426162 (patch) | |
| tree | 8eb2504236468bde9b6c4c4d8ee75765b05bb246 /src/libsyntax | |
| parent | e264828b27b30980f6a9c316e17dc44e6b9be09f (diff) | |
| download | rust-bfb01bbb263923106b33fdaa140a5fa464426162.tar.gz rust-bfb01bbb263923106b33fdaa140a5fa464426162.zip | |
Refactor away `AttrMetaMethods`.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr.rs | 92 | ||||
| -rw-r--r-- | src/libsyntax/config.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 2 |
7 files changed, 38 insertions, 64 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index f8fecd5fda0..6060ff529f2 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -160,40 +160,8 @@ impl NestedMetaItem { } } -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); @@ -201,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() } + + pub fn span(&self) -> Span { self.meta().span } - 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(), @@ -225,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 { @@ -237,34 +214,33 @@ 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 } + + pub fn check_name(&self, name: &str) -> bool { + name == &self.name()[..] + } -// 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 is_value_str(&self) -> bool { + self.value_str().is_some() + } + + pub fn is_meta_item_list(&self) -> bool { + self.meta_item_list().is_some() } - 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() } } impl Attribute { @@ -424,9 +400,9 @@ pub fn list_contains_name(items: &[NestedMetaItem], name: &str) -> bool { }) } -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 ed05dc243b3..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, 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 031d9a2d3f4..bc0f4de4471 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 d2aa9a4cb6b..cd2705fb7d8 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}; +use attr; use codemap::CodeMap; use syntax_pos::Span; use errors::Handler; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index cd1fdcfe9d1..6f06dd14d8f 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 0caf9ae0d78..28f1016c51f 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; use codemap::{self, CodeMap}; use syntax_pos::{self, BytePos}; use errors; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 0a14eae7d35..e3e2457c471 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}; +use attr; use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos}; use std::rc::Rc; |
