Rollup merge of #35917 - jseyfried:remove_attr_ext_traits, r=nrc

syntax: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`
This commit is contained in:
Jeffrey Seyfried 2016-08-28 10:40:04 +00:00
commit c14ff2884d
44 changed files with 92 additions and 216 deletions

View File

@ -11,7 +11,6 @@
use session::Session; use session::Session;
use syntax::ast; use syntax::ast;
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
use syntax::visit; use syntax::visit;
use syntax::visit::Visitor; use syntax::visit::Visitor;

View File

@ -38,7 +38,7 @@ use util::nodemap::FnvHashMap;
use std::cmp; use std::cmp;
use std::default::Default as StdDefault; use std::default::Default as StdDefault;
use std::mem; use std::mem;
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods}; use syntax::attr;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax::ast; use syntax::ast;
use syntax_pos::Span; use syntax_pos::Span;

View File

@ -30,7 +30,6 @@ use middle::weak_lang_items;
use util::nodemap::FnvHashMap; use util::nodemap::FnvHashMap;
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use hir::intravisit::Visitor; use hir::intravisit::Visitor;
use hir; use hir;

View File

@ -17,7 +17,6 @@
use session::Session; use session::Session;
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) { pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
for attr in &krate.attrs { for attr in &krate.attrs {

View File

@ -27,7 +27,7 @@ use syntax_pos::{Span, DUMMY_SP};
use syntax::ast; use syntax::ast;
use syntax::ast::{NodeId, Attribute}; use syntax::ast::{NodeId, Attribute};
use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version}; use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version};
use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods}; use syntax::attr::{self, Stability, Deprecation};
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap}; use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
use hir; use hir;

View File

@ -25,7 +25,6 @@ use middle::cstore;
use syntax::ast::{self, IntTy, UintTy}; use syntax::ast::{self, IntTy, UintTy};
use syntax::attr; use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::parse; use syntax::parse;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
@ -1773,8 +1772,9 @@ mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use super::{OutputType, OutputTypes, Externs, PanicStrategy}; use super::{OutputType, OutputTypes, Externs, PanicStrategy};
use syntax::attr; use syntax::{ast, attr};
use syntax::attr::AttrMetaMethods; use syntax::parse::token::InternedString;
use syntax::codemap::dummy_spanned;
fn optgroups() -> Vec<OptGroup> { fn optgroups() -> Vec<OptGroup> {
super::rustc_optgroups().into_iter() super::rustc_optgroups().into_iter()
@ -1803,7 +1803,9 @@ mod tests {
let (sessopts, cfg) = build_session_options_and_crate_config(matches); let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
let cfg = build_configuration(&sess, cfg); let cfg = build_configuration(&sess, cfg);
assert!((attr::contains_name(&cfg[..], "test"))); assert!(attr::contains(&cfg, &dummy_spanned(ast::MetaItemKind::Word({
InternedString::new("test")
}))));
} }
// When the user supplies --test and --cfg test, don't implicitly add // When the user supplies --test and --cfg test, don't implicitly add

View File

@ -37,7 +37,6 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
use std::cmp; use std::cmp;
use std::fmt; use std::fmt;
use syntax::ast; use syntax::ast;
use syntax::attr::{AttributeMethods, AttrMetaMethods};
use syntax_pos::Span; use syntax_pos::Span;
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;

View File

@ -43,7 +43,7 @@ use std::rc::Rc;
use std::slice; use std::slice;
use std::vec::IntoIter; use std::vec::IntoIter;
use syntax::ast::{self, CrateNum, Name, NodeId}; use syntax::ast::{self, CrateNum, Name, NodeId};
use syntax::attr::{self, AttrMetaMethods}; use syntax::attr;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};

View File

@ -27,7 +27,6 @@ use rustc::middle::mem_categorization as mc;
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]

View File

@ -11,7 +11,6 @@
use borrowck::BorrowckCtxt; use borrowck::BorrowckCtxt;
use syntax::ast::{self, MetaItem}; use syntax::ast::{self, MetaItem};
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
@ -127,8 +126,6 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
bd: BD) -> DataflowResults<BD> bd: BD) -> DataflowResults<BD>
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveDataParamEnv<'tcx>> + DataflowOperator where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveDataParamEnv<'tcx>> + DataflowOperator
{ {
use syntax::attr::AttrMetaMethods;
let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> { let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
if let Some(item) = has_rustc_mir_with(attrs, name) { if let Some(item) = has_rustc_mir_with(attrs, name) {
if let Some(s) = item.value_str() { if let Some(s) = item.value_str() {

View File

@ -43,7 +43,6 @@ use std::mem;
use std::rc::Rc; use std::rc::Rc;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax_pos::{MultiSpan, Span}; use syntax_pos::{MultiSpan, Span};
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;

View File

@ -49,7 +49,7 @@ use std::fs;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use syntax::{ast, diagnostics, visit}; use syntax::{ast, diagnostics, visit};
use syntax::attr::{self, AttrMetaMethods}; use syntax::attr;
use syntax::parse::{self, PResult, token}; use syntax::parse::{self, PResult, token};
use syntax::util::node_count::NodeCounter; use syntax::util::node_count::NodeCounter;
use syntax; use syntax;

View File

@ -95,7 +95,6 @@ use std::thread;
use rustc::session::early_error; use rustc::session::early_error;
use syntax::{ast, json}; use syntax::{ast, json};
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader}; use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
use syntax::feature_gate::{GatedCfg, UnstableFeatures}; use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult}; use syntax::parse::{self, PResult};

View File

@ -56,7 +56,6 @@ use std::env;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use syntax::ast; use syntax::ast;
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax_pos::Span; use syntax_pos::Span;

View File

@ -28,7 +28,6 @@
//! at the beginning. //! at the beginning.
use syntax::ast; use syntax::ast;
use syntax::attr::AttributeMethods;
use std::hash::{Hash, SipHasher, Hasher}; use std::hash::{Hash, SipHasher, Hasher};
use rustc::dep_graph::DepNode; use rustc::dep_graph::DepNode;
use rustc::hir; use rustc::hir;

View File

@ -32,7 +32,6 @@ use rustc::hir::def_id::DefId;
use rustc::hir::intravisit::Visitor; use rustc::hir::intravisit::Visitor;
use rustc_data_structures::fnv::FnvHashSet; use rustc_data_structures::fnv::FnvHashSet;
use syntax::ast::{self, Attribute, NestedMetaItem}; use syntax::ast::{self, Attribute, NestedMetaItem};
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;

View File

@ -14,7 +14,7 @@ use lint::{LateContext, LintContext, LintArray};
use lint::{LintPass, LateLintPass}; use lint::{LintPass, LateLintPass};
use syntax::ast; use syntax::ast;
use syntax::attr::{self, AttrMetaMethods}; use syntax::attr;
use syntax_pos::Span; use syntax_pos::Span;
use rustc::hir::{self, PatKind}; use rustc::hir::{self, PatKind};

View File

@ -44,7 +44,7 @@ use lint::{LintPass, LateLintPass};
use std::collections::HashSet; use std::collections::HashSet;
use syntax::{ast}; use syntax::{ast};
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods, AttributeMethods}; use syntax::attr;
use syntax_pos::{Span}; use syntax_pos::{Span};
use rustc::hir::{self, PatKind}; use rustc::hir::{self, PatKind};
@ -1145,7 +1145,7 @@ impl LintPass for UnstableFeatures {
impl LateLintPass for UnstableFeatures { impl LateLintPass for UnstableFeatures {
fn check_attribute(&mut self, ctx: &LateContext, attr: &ast::Attribute) { fn check_attribute(&mut self, ctx: &LateContext, attr: &ast::Attribute) {
if attr::contains_name(&[attr.meta().clone()], "feature") { if attr.meta().check_name("feature") {
if let Some(items) = attr.meta().meta_item_list() { if let Some(items) = attr.meta().meta_item_list() {
for item in items { for item in items {
ctx.span_lint(UNSTABLE_FEATURES, item.span(), "unstable feature"); ctx.span_lint(UNSTABLE_FEATURES, item.span(), "unstable feature");

View File

@ -18,7 +18,7 @@ use lint::{LintPass, EarlyLintPass, LateLintPass};
use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::Entry::{Occupied, Vacant};
use syntax::ast; use syntax::ast;
use syntax::attr::{self, AttrMetaMethods}; use syntax::attr;
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType}; use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
use syntax::parse::token::keywords; use syntax::parse::token::keywords;
use syntax::ptr::P; use syntax::ptr::P;

View File

@ -35,7 +35,7 @@ use syntax::ast;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::codemap; use syntax::codemap;
use syntax::parse; use syntax::parse;
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods}; use syntax::attr;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax::visit; use syntax::visit;
use syntax_pos::{self, Span, mk_sp, Pos}; use syntax_pos::{self, Span, mk_sp, Pos};

View File

@ -18,7 +18,7 @@ use rustc::session::Session;
use std::collections::{HashSet, HashMap}; use std::collections::{HashSet, HashMap};
use syntax::parse::token; use syntax::parse::token;
use syntax::ast; use syntax::ast;
use syntax::attr::{self, AttrNestedMetaItemMethods, AttrMetaMethods}; use syntax::attr;
use syntax::ext; use syntax::ext;
use syntax_pos::Span; use syntax_pos::Span;

View File

@ -32,7 +32,6 @@ use rustc::ty::{self, Ty, TyCtxt};
use syntax::parse::token; use syntax::parse::token;
use rustc::hir; use rustc::hir;
use rustc_const_math::{ConstInt, ConstUsize}; use rustc_const_math::{ConstInt, ConstUsize};
use syntax::attr::AttrMetaMethods;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Cx<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { pub struct Cx<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {

View File

@ -20,7 +20,6 @@ use std::env;
use std::mem; use std::mem;
use std::path::PathBuf; use std::path::PathBuf;
use syntax::ast; use syntax::ast;
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax_pos::{Span, COMMAND_LINE_SP}; use syntax_pos::{Span, COMMAND_LINE_SP};
/// Pointer to a registrar function. /// Pointer to a registrar function.

View File

@ -29,7 +29,6 @@
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use syntax::ast; use syntax::ast;
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use {ModuleSource, ModuleTranslation}; use {ModuleSource, ModuleTranslation};

View File

@ -42,7 +42,6 @@ use std::process::Command;
use std::str; use std::str;
use flate; use flate;
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax_pos::Span; use syntax_pos::Span;
// RLIB LLVM-BYTECODE OBJECT LAYOUT // RLIB LLVM-BYTECODE OBJECT LAYOUT

View File

@ -93,7 +93,6 @@ use std::rc::Rc;
use std::str; use std::str;
use std::i32; use std::i32;
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
use syntax::attr::AttrMetaMethods;
use syntax::attr; use syntax::attr;
use rustc::hir; use rustc::hir;
use syntax::ast; use syntax::ast;

View File

@ -29,7 +29,7 @@ use rustc::hir;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use syntax::ast; use syntax::ast;
use syntax::attr::{self, AttrMetaMethods}; use syntax::attr;
use syntax::parse::token; use syntax::parse::token;
pub fn ptrcast(val: ValueRef, ty: Type) -> ValueRef { pub fn ptrcast(val: ValueRef, ty: Type) -> ValueRef {

View File

@ -17,7 +17,6 @@
use rustc::hir; use rustc::hir;
use rustc::hir::intravisit::{self, Visitor}; use rustc::hir::intravisit::{self, Visitor};
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use common::SharedCrateContext; use common::SharedCrateContext;
use monomorphize::Instance; use monomorphize::Instance;

View File

@ -113,7 +113,6 @@ use std::ops::Deref;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{self, Spanned}; use syntax::codemap::{self, Spanned};
use syntax::feature_gate::{GateIssue, emit_feature_err}; use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::parse::token::{self, InternedString, keywords}; use syntax::parse::token::{self, InternedString, keywords};

View File

@ -26,9 +26,8 @@ pub use self::Visibility::*;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::attr::{AttributeMethods, AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax::codemap::Spanned; use syntax::codemap::Spanned;
use syntax::parse::token::{self, InternedString, keywords}; use syntax::parse::token::keywords;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::print::pprust as syntax_pprust; use syntax::print::pprust as syntax_pprust;
use syntax_pos::{self, DUMMY_SP, Pos}; use syntax_pos::{self, DUMMY_SP, Pos};
@ -541,62 +540,6 @@ impl Clean<Attribute> for ast::Attribute {
} }
} }
// This is a rough approximation that gets us what we want.
impl attr::AttrNestedMetaItemMethods for Attribute {
fn check_name(&self, name: &str) -> bool {
self.name().map_or(false, |mi_name| &*mi_name == name)
}
fn literal(&self) -> Option<&ast::Lit> { None }
fn is_literal(&self) -> bool {
match *self {
Literal(..) => true,
_ => false,
}
}
fn meta_item(&self) -> Option<&P<ast::MetaItem>> { None }
fn name(&self) -> Option<InternedString> {
match *self {
Word(ref n) | List(ref n, _) | NameValue(ref n, _) => {
Some(token::intern_and_get_ident(n))
},
_ => None
}
}
fn value_str(&self) -> Option<InternedString> {
match *self {
NameValue(_, ref v) => {
Some(token::intern_and_get_ident(v))
}
_ => None,
}
}
fn word(&self) -> Option<&P<ast::MetaItem>> { None }
fn is_word(&self) -> bool {
match *self {
Word(_) => true,
_ => false,
}
}
fn meta_item_list<'a>(&'a self) -> Option<&'a [ast::NestedMetaItem]> { None }
fn is_meta_item_list(&self) -> bool {
match *self {
List(..) => true,
_ => false,
}
}
fn span(&self) -> syntax_pos::Span { unimplemented!() }
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
pub struct TyParam { pub struct TyParam {
pub name: String, pub name: String,

View File

@ -140,8 +140,6 @@ pub fn run(input: &str,
// Look for #![doc(test(no_crate_inject))], used by crates in the std facade // Look for #![doc(test(no_crate_inject))], used by crates in the std facade
fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions { fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
use syntax::attr::AttrMetaMethods;
use syntax::attr::AttrNestedMetaItemMethods;
use syntax::print::pprust; use syntax::print::pprust;
let mut opts = TestOptions { let mut opts = TestOptions {

View File

@ -17,7 +17,6 @@ use std::mem;
use syntax::abi; use syntax::abi;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax_pos::Span; use syntax_pos::Span;
use rustc::hir::map as hir_map; use rustc::hir::map as hir_map;

View File

@ -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`. /// 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)) 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]`, /// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
/// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem /// `#[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())) 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 /// Gets the string value if self is a MetaItem and the MetaItem is a
/// MetaItemKind::NameValue variant containing a string, otherwise None. /// 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()) self.meta_item().and_then(|meta_item| meta_item.value_str())
} }
/// Returns a MetaItem if self is a MetaItem with Kind Word. /// 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() { self.meta_item().and_then(|meta_item| if meta_item.is_word() {
Some(meta_item) Some(meta_item)
} else { } else {
@ -115,93 +130,38 @@ pub trait AttrNestedMetaItemMethods {
} }
/// Gets a list of inner meta items from a list MetaItem type. /// 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()) self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
} }
/// Returns `true` if the variant is MetaItem. /// 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() self.meta_item().is_some()
} }
/// Returns `true` if the variant is Literal. /// Returns `true` if the variant is Literal.
fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
self.literal().is_some() self.literal().is_some()
} }
/// Returns `true` if self is a MetaItem and the meta item is a word. /// 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() self.word().is_some()
} }
/// Returns `true` if self is a MetaItem and the meta item is a ValueString. /// 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() self.value_str().is_some()
} }
/// Returns `true` if self is a MetaItem and the meta item is a list. /// 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() self.meta_item_list().is_some()
} }
/// Returns the Span for `self`.
fn span(&self) -> Span;
} }
impl AttrNestedMetaItemMethods for NestedMetaItem { impl Attribute {
fn meta_item(&self) -> Option<&P<MetaItem>> { pub fn check_name(&self, name: &str) -> bool {
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 {
let matches = name == &self.name()[..]; let matches = name == &self.name()[..];
if matches { if matches {
mark_used(self); mark_used(self);
@ -209,23 +169,32 @@ impl AttrMetaMethods for Attribute {
matches 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() self.meta().value_str()
} }
fn meta_item_list(&self) -> Option<&[NestedMetaItem]> { pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
self.meta().meta_item_list() 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 { impl MetaItem {
fn name(&self) -> InternedString { pub fn name(&self) -> InternedString {
match self.node { match self.node {
MetaItemKind::Word(ref n) => (*n).clone(), MetaItemKind::Word(ref n) => (*n).clone(),
MetaItemKind::NameValue(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 { match self.node {
MetaItemKind::NameValue(_, ref v) => { MetaItemKind::NameValue(_, ref v) => {
match v.node { 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 { match self.node {
MetaItemKind::List(_, ref l) => Some(&l[..]), MetaItemKind::List(_, ref l) => Some(&l[..]),
_ => None _ => None
} }
} }
fn is_word(&self) -> bool { pub fn is_word(&self) -> bool {
match self.node { match self.node {
MetaItemKind::Word(_) => true, MetaItemKind::Word(_) => true,
_ => false, _ => false,
} }
} }
fn span(&self) -> Span { self.span } pub fn span(&self) -> Span { self.span }
}
// Annoying, but required to get test_cfg to work pub fn check_name(&self, name: &str) -> bool {
impl AttrMetaMethods for P<MetaItem> { name == &self.name()[..]
fn name(&self) -> InternedString { (**self).name() } }
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
fn meta_item_list(&self) -> Option<&[NestedMetaItem]> { pub fn is_value_str(&self) -> bool {
(**self).meta_item_list() 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 {
pub trait AttributeMethods {
fn meta(&self) -> &MetaItem;
fn with_desugared_doc<T, F>(&self, f: F) -> T where
F: FnOnce(&Attribute) -> T;
}
impl AttributeMethods for Attribute {
/// Extract the MetaItem from inside this Attribute. /// Extract the MetaItem from inside this Attribute.
fn meta(&self) -> &MetaItem { pub fn meta(&self) -> &MetaItem {
&self.node.value &self.node.value
} }
/// Convert self to a normal #[doc="foo"] comment, if it is a /// Convert self to a normal #[doc="foo"] comment, if it is a
/// comment like `///` or `/** */`. (Returns self unchanged for /// comment like `///` or `/** */`. (Returns self unchanged for
/// non-sugared doc attributes.) /// 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, F: FnOnce(&Attribute) -> T,
{ {
if self.node.is_sugared_doc { 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); debug!("attr::list_contains_name (name={})", name);
items.iter().any(|item| { items.iter().any(|item| {
debug!(" testing: {:?}", item.name()); 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); debug!("attr::contains_name (name={})", name);
metas.iter().any(|item| { attrs.iter().any(|item| {
debug!(" testing: {}", item.name()); debug!(" testing: {}", item.name());
item.check_name(name) item.check_name(name)
}) })

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 feature_gate::{emit_feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
use fold::Folder; use fold::Folder;
use {fold, attr}; use {fold, attr};

View File

@ -13,7 +13,6 @@ use ast::{MacStmtStyle, Stmt, StmtKind, ItemKind};
use ast; use ast;
use ext::hygiene::Mark; use ext::hygiene::Mark;
use attr::{self, HasAttrs}; use attr::{self, HasAttrs};
use attr::AttrMetaMethods;
use codemap::{dummy_spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use codemap::{dummy_spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
use syntax_pos::{self, Span, ExpnId}; use syntax_pos::{self, Span, ExpnId};
use config::StripUnconfigured; use config::StripUnconfigured;

View File

@ -27,7 +27,7 @@ use self::AttributeGate::*;
use abi::Abi; use abi::Abi;
use ast::{self, NodeId, PatKind}; use ast::{self, NodeId, PatKind};
use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods}; use attr;
use codemap::{CodeMap, Spanned}; use codemap::{CodeMap, Spanned};
use syntax_pos::Span; use syntax_pos::Span;
use errors::Handler; use errors::Handler;

View File

@ -678,7 +678,7 @@ mod tests {
use codemap::Spanned; use codemap::Spanned;
use ast::{self, PatKind}; use ast::{self, PatKind};
use abi::Abi; use abi::Abi;
use attr::{first_attr_value_str_by_name, AttrMetaMethods}; use attr::first_attr_value_str_by_name;
use parse; use parse;
use parse::parser::Parser; use parse::parser::Parser;
use parse::token::{str_to_ident}; use parse::token::{str_to_ident};

View File

@ -16,7 +16,6 @@ use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::Attribute; use ast::Attribute;
use util::parser::AssocOp; use util::parser::AssocOp;
use attr; use attr;
use attr::{AttrMetaMethods, AttributeMethods};
use codemap::{self, CodeMap}; use codemap::{self, CodeMap};
use syntax_pos::{self, BytePos}; use syntax_pos::{self, BytePos};
use errors; use errors;

View File

@ -19,7 +19,7 @@ use std::iter;
use std::slice; use std::slice;
use std::mem; use std::mem;
use std::vec; use std::vec;
use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods}; use attr;
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos}; use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
use std::rc::Rc; use std::rc::Rc;

View File

@ -194,7 +194,6 @@ use std::vec;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind, VariantData}; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind, VariantData};
use syntax::attr; use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::codemap::{self, dummy_spanned, respan}; use syntax::codemap::{self, dummy_spanned, respan};

View File

@ -11,7 +11,6 @@
//! The compiler code necessary to implement the `#[derive]` extensions. //! The compiler code necessary to implement the `#[derive]` extensions.
use syntax::ast::{self, MetaItem}; use syntax::ast::{self, MetaItem};
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxEnv}; use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxEnv};
use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier}; use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;

View File

@ -18,7 +18,6 @@ extern crate rustc;
extern crate rustc_plugin; extern crate rustc_plugin;
use syntax::ast::{self, Item, MetaItem, ItemKind}; use syntax::ast::{self, Item, MetaItem, ItemKind};
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::parse::{self, token}; use syntax::parse::{self, token};
use syntax::ptr::P; use syntax::ptr::P;

View File

@ -21,7 +21,6 @@ extern crate rustc;
extern crate rustc_plugin; extern crate rustc_plugin;
use syntax::ast; use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token; use syntax::parse::token;

View File

@ -19,7 +19,6 @@ extern crate syntax_pos;
use syntax::ast::{self, Item, MetaItem, ItemKind}; use syntax::ast::{self, Item, MetaItem, ItemKind};
use syntax::codemap::DUMMY_SP; use syntax::codemap::DUMMY_SP;
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::ext::quote::rt::ToTokens; use syntax::ext::quote::rt::ToTokens;
use syntax::parse::{self, token}; use syntax::parse::{self, token};