Skip to content

Commit 4eb08bb

Browse files
committed
Refactor away AttrNestedMetaItemMethods.
1 parent 8250a26 commit 4eb08bb

File tree

18 files changed

+50
-59
lines changed

18 files changed

+50
-59
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use session::Session;
1212

1313
use syntax::ast;
14-
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
14+
use syntax::attr::AttrMetaMethods;
1515
use syntax::visit;
1616
use syntax::visit::Visitor;
1717

src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use util::nodemap::FnvHashMap;
3838
use std::cmp;
3939
use std::default::Default as StdDefault;
4040
use std::mem;
41-
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
41+
use syntax::attr::{self, AttrMetaMethods};
4242
use syntax::parse::token::InternedString;
4343
use syntax::ast;
4444
use syntax_pos::Span;

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use borrowck::BorrowckCtxt;
1212

1313
use syntax::ast::{self, MetaItem};
14-
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
14+
use syntax::attr::AttrMetaMethods;
1515
use syntax::ptr::P;
1616
use syntax_pos::{Span, DUMMY_SP};
1717

src/librustc_incremental/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::env;
5656
use std::fs::File;
5757
use std::io::Write;
5858
use syntax::ast;
59-
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
59+
use syntax::attr::AttrMetaMethods;
6060
use syntax::parse::token::InternedString;
6161
use syntax_pos::Span;
6262

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc::hir::def_id::DefId;
3232
use rustc::hir::intravisit::Visitor;
3333
use rustc_data_structures::fnv::FnvHashSet;
3434
use syntax::ast::{self, Attribute, NestedMetaItem};
35-
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
35+
use syntax::attr::AttrMetaMethods;
3636
use syntax::parse::token::InternedString;
3737
use rustc::ty::TyCtxt;
3838

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use lint::{LintPass, LateLintPass};
4444
use std::collections::HashSet;
4545

4646
use syntax::{ast};
47-
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods, AttributeMethods};
47+
use syntax::attr::{self, AttrMetaMethods, AttributeMethods};
4848
use syntax_pos::{Span};
4949

5050
use rustc::hir::{self, PatKind};

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use syntax::ast;
3535
use syntax::abi::Abi;
3636
use syntax::codemap;
3737
use syntax::parse;
38-
use syntax::attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
38+
use syntax::attr::{self, AttrMetaMethods};
3939
use syntax::parse::token::InternedString;
4040
use syntax::visit;
4141
use syntax_pos::{self, Span, mk_sp, Pos};

src/librustc_metadata/macro_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc::session::Session;
1818
use std::collections::{HashSet, HashMap};
1919
use syntax::parse::token;
2020
use syntax::ast;
21-
use syntax::attr::{self, AttrNestedMetaItemMethods, AttrMetaMethods};
21+
use syntax::attr::{self, AttrMetaMethods};
2222
use syntax::ext;
2323
use syntax_pos::Span;
2424

src/librustc_plugin/load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::env;
2020
use std::mem;
2121
use std::path::PathBuf;
2222
use syntax::ast;
23-
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
23+
use syntax::attr::{AttrMetaMethods};
2424
use syntax_pos::{Span, COMMAND_LINE_SP};
2525

2626
/// Pointer to a registrar function.

src/librustc_trans/assert_module_sources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
3030
use rustc::ty::TyCtxt;
3131
use syntax::ast;
32-
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
32+
use syntax::attr::AttrMetaMethods;
3333
use syntax::parse::token::InternedString;
3434

3535
use {ModuleSource, ModuleTranslation};

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use self::Visibility::*;
2626
use syntax::abi::Abi;
2727
use syntax::ast;
2828
use syntax::attr;
29-
use syntax::attr::{AttributeMethods, AttrMetaMethods, AttrNestedMetaItemMethods};
29+
use syntax::attr::{AttributeMethods, AttrMetaMethods};
3030
use syntax::codemap::Spanned;
3131
use syntax::parse::token::{self, InternedString, keywords};
3232
use syntax::ptr::P;
@@ -542,7 +542,7 @@ impl Clean<Attribute> for ast::Attribute {
542542
}
543543

544544
// This is a rough approximation that gets us what we want.
545-
impl attr::AttrNestedMetaItemMethods for Attribute {
545+
impl Attribute {
546546
fn check_name(&self, name: &str) -> bool {
547547
self.name().map_or(false, |mi_name| &*mi_name == name)
548548
}

src/librustdoc/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ pub fn run(input: &str,
141141
// Look for #![doc(test(no_crate_inject))], used by crates in the std facade
142142
fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
143143
use syntax::attr::AttrMetaMethods;
144-
use syntax::attr::AttrNestedMetaItemMethods;
145144
use syntax::print::pprust;
146145

147146
let mut opts = TestOptions {

src/librustdoc/visit_ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::mem;
1717
use syntax::abi;
1818
use syntax::ast;
1919
use syntax::attr;
20-
use syntax::attr::{AttrMetaMethods, AttrNestedMetaItemMethods};
20+
use syntax::attr::AttrMetaMethods;
2121
use syntax_pos::Span;
2222

2323
use rustc::hir::map as hir_map;

src/libsyntax/attr.rs

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,47 @@ pub fn is_used(attr: &Attribute) -> bool {
8181
})
8282
}
8383

84-
pub trait AttrNestedMetaItemMethods {
84+
impl NestedMetaItem {
85+
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
86+
pub fn meta_item(&self) -> Option<&P<MetaItem>> {
87+
match self.node {
88+
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
89+
_ => None
90+
}
91+
}
92+
93+
/// Returns the Lit if self is a NestedMetaItemKind::Literal.
94+
pub fn literal(&self) -> Option<&Lit> {
95+
match self.node {
96+
NestedMetaItemKind::Literal(ref lit) => Some(&lit),
97+
_ => None
98+
}
99+
}
100+
101+
/// Returns the Span for `self`.
102+
pub fn span(&self) -> Span {
103+
self.span
104+
}
105+
85106
/// Returns true if this list item is a MetaItem with a name of `name`.
86-
fn check_name(&self, name: &str) -> bool {
107+
pub fn check_name(&self, name: &str) -> bool {
87108
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
88109
}
89110

90111
/// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
91112
/// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem
92-
fn name(&self) -> Option<InternedString> {
113+
pub fn name(&self) -> Option<InternedString> {
93114
self.meta_item().and_then(|meta_item| Some(meta_item.name()))
94115
}
95116

96-
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
97-
fn meta_item(&self) -> Option<&P<MetaItem>>;
98-
99-
/// Returns the Lit if self is a NestedMetaItemKind::Literal.
100-
fn literal(&self) -> Option<&Lit>;
101-
102117
/// Gets the string value if self is a MetaItem and the MetaItem is a
103118
/// MetaItemKind::NameValue variant containing a string, otherwise None.
104-
fn value_str(&self) -> Option<InternedString> {
119+
pub fn value_str(&self) -> Option<InternedString> {
105120
self.meta_item().and_then(|meta_item| meta_item.value_str())
106121
}
107122

108123
/// Returns a MetaItem if self is a MetaItem with Kind Word.
109-
fn word(&self) -> Option<&P<MetaItem>> {
124+
pub fn word(&self) -> Option<&P<MetaItem>> {
110125
self.meta_item().and_then(|meta_item| if meta_item.is_word() {
111126
Some(meta_item)
112127
} else {
@@ -115,57 +130,34 @@ pub trait AttrNestedMetaItemMethods {
115130
}
116131

117132
/// Gets a list of inner meta items from a list MetaItem type.
118-
fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
133+
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
119134
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
120135
}
121136

122137
/// Returns `true` if the variant is MetaItem.
123-
fn is_meta_item(&self) -> bool {
138+
pub fn is_meta_item(&self) -> bool {
124139
self.meta_item().is_some()
125140
}
126141

127142
/// Returns `true` if the variant is Literal.
128-
fn is_literal(&self) -> bool {
143+
pub fn is_literal(&self) -> bool {
129144
self.literal().is_some()
130145
}
131146

132147
/// Returns `true` if self is a MetaItem and the meta item is a word.
133-
fn is_word(&self) -> bool {
148+
pub fn is_word(&self) -> bool {
134149
self.word().is_some()
135150
}
136151

137152
/// Returns `true` if self is a MetaItem and the meta item is a ValueString.
138-
fn is_value_str(&self) -> bool {
153+
pub fn is_value_str(&self) -> bool {
139154
self.value_str().is_some()
140155
}
141156

142157
/// Returns `true` if self is a MetaItem and the meta item is a list.
143-
fn is_meta_item_list(&self) -> bool {
158+
pub fn is_meta_item_list(&self) -> bool {
144159
self.meta_item_list().is_some()
145160
}
146-
147-
/// Returns the Span for `self`.
148-
fn span(&self) -> Span;
149-
}
150-
151-
impl AttrNestedMetaItemMethods for NestedMetaItem {
152-
fn meta_item(&self) -> Option<&P<MetaItem>> {
153-
match self.node {
154-
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
155-
_ => None
156-
}
157-
}
158-
159-
fn literal(&self) -> Option<&Lit> {
160-
match self.node {
161-
NestedMetaItemKind::Literal(ref lit) => Some(&lit),
162-
_ => None
163-
}
164-
}
165-
166-
fn span(&self) -> Span {
167-
self.span
168-
}
169161
}
170162

171163
pub trait AttrMetaMethods {
@@ -431,7 +423,7 @@ pub fn contains(haystack: &[P<MetaItem>], needle: &MetaItem) -> bool {
431423
})
432424
}
433425

434-
pub fn list_contains_name<AM: AttrNestedMetaItemMethods>(items: &[AM], name: &str) -> bool {
426+
pub fn list_contains_name(items: &[NestedMetaItem], name: &str) -> bool {
435427
debug!("attr::list_contains_name (name={})", name);
436428
items.iter().any(|item| {
437429
debug!(" testing: {:?}", item.name());

src/libsyntax/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use attr::{AttrMetaMethods, AttrNestedMetaItemMethods, HasAttrs};
11+
use attr::{AttrMetaMethods, HasAttrs};
1212
use feature_gate::{emit_feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
1313
use fold::Folder;
1414
use {fold, attr};

src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use self::AttributeGate::*;
2727

2828
use abi::Abi;
2929
use ast::{self, NodeId, PatKind};
30-
use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
30+
use attr::{self, AttrMetaMethods};
3131
use codemap::CodeMap;
3232
use syntax_pos::Span;
3333
use errors::Handler;

src/libsyntax/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::iter;
1919
use std::slice;
2020
use std::mem;
2121
use std::vec;
22-
use attr::{self, AttrMetaMethods, AttrNestedMetaItemMethods};
22+
use attr::{self, AttrMetaMethods};
2323
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
2424
use std::rc::Rc;
2525

src/libsyntax_ext/deriving/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! The compiler code necessary to implement the `#[derive]` extensions.
1212
1313
use syntax::ast::{self, MetaItem};
14-
use syntax::attr::{AttrNestedMetaItemMethods, AttrMetaMethods};
14+
use syntax::attr::AttrMetaMethods;
1515
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxEnv};
1616
use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier};
1717
use syntax::ext::build::AstBuilder;

0 commit comments

Comments
 (0)