Refactor away AttrNestedMetaItemMethods
.
This commit is contained in:
parent
8250a26b5b
commit
4eb08bb2ab
18 changed files with 50 additions and 59 deletions
|
@ -11,7 +11,7 @@
|
|||
use session::Session;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ use util::nodemap::FnvHashMap;
|
|||
use std::cmp;
|
||||
use std::default::Default as StdDefault;
|
||||
use std::mem;
|
||||
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use borrowck::BorrowckCtxt;
|
||||
|
||||
use syntax::ast::{self, MetaItem};
|
||||
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::ptr::P;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ use std::env;
|
|||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use syntax::ast;
|
||||
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax_pos::Span;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ use rustc::hir::def_id::DefId;
|
|||
use rustc::hir::intravisit::Visitor;
|
||||
use rustc_data_structures::fnv::FnvHashSet;
|
||||
use syntax::ast::{self, Attribute, NestedMetaItem};
|
||||
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::parse::token::InternedString;
|
||||
use rustc::ty::TyCtxt;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ use lint::{LintPass, LateLintPass};
|
|||
use std::collections::HashSet;
|
||||
|
||||
use syntax::{ast};
|
||||
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods, AttributeMethods};
|
||||
use syntax::attr::{self, AttrMetaMethods, AttributeMethods};
|
||||
use syntax_pos::{Span};
|
||||
|
||||
use rustc::hir::{self, PatKind};
|
||||
|
|
|
@ -35,7 +35,7 @@ use syntax::ast;
|
|||
use syntax::abi::Abi;
|
||||
use syntax::codemap;
|
||||
use syntax::parse;
|
||||
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::visit;
|
||||
use syntax_pos::{self, Span, mk_sp, Pos};
|
||||
|
|
|
@ -18,7 +18,7 @@ use rustc::session::Session;
|
|||
use std::collections::{HashSet, HashMap};
|
||||
use syntax::parse::token;
|
||||
use syntax::ast;
|
||||
use syntax::attr::{self, AttrNestedMetaItemMethods, AttrMetaMethods};
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::ext;
|
||||
use syntax_pos::Span;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::env;
|
|||
use std::mem;
|
||||
use std::path::PathBuf;
|
||||
use syntax::ast;
|
||||
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::{AttrMetaMethods};
|
||||
use syntax_pos::{Span, COMMAND_LINE_SP};
|
||||
|
||||
/// Pointer to a registrar function.
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
use rustc::ty::TyCtxt;
|
||||
use syntax::ast;
|
||||
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::parse::token::InternedString;
|
||||
|
||||
use {ModuleSource, ModuleTranslation};
|
||||
|
|
|
@ -26,7 +26,7 @@ pub use self::Visibility::*;
|
|||
use syntax::abi::Abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::{AttributeMethods, AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::parse::token::{self, InternedString, keywords};
|
||||
use syntax::ptr::P;
|
||||
|
@ -542,7 +542,7 @@ impl Clean<Attribute> for ast::Attribute {
|
|||
}
|
||||
|
||||
// This is a rough approximation that gets us what we want.
|
||||
impl attr::AttrNestedMetaItemMethods for Attribute {
|
||||
impl Attribute {
|
||||
fn check_name(&self, name: &str) -> bool {
|
||||
self.name().map_or(false, |mi_name| &*mi_name == name)
|
||||
}
|
||||
|
|
|
@ -141,7 +141,6 @@ pub fn run(input: &str,
|
|||
// Look for #![doc(test(no_crate_inject))], used by crates in the std facade
|
||||
fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::attr::AttrNestedMetaItemMethods;
|
||||
use syntax::print::pprust;
|
||||
|
||||
let mut opts = TestOptions {
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::mem;
|
|||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use rustc::hir::map as hir_map;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
//! The compiler code necessary to implement the `#[derive]` extensions.
|
||||
|
||||
use syntax::ast::{self, MetaItem};
|
||||
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxEnv};
|
||||
use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier};
|
||||
use syntax::ext::build::AstBuilder;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue