提交 f177a00a 编写于 作者: J Jeffrey Seyfried

Refactor `P<ast::MetaItem>` -> `ast::MetaItem`.

上级 e97686d0
......@@ -93,7 +93,7 @@ pub enum NativeLibraryKind {
pub struct NativeLibrary {
pub kind: NativeLibraryKind,
pub name: String,
pub cfg: Option<P<ast::MetaItem>>,
pub cfg: Option<ast::MetaItem>,
}
/// The data we save and restore about an inlined item or method. This is not
......
......@@ -11,7 +11,6 @@
use borrowck::BorrowckCtxt;
use syntax::ast::{self, MetaItem};
use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP};
use rustc::hir;
......@@ -35,7 +34,7 @@
use self::dataflow::{DefinitelyInitializedLvals};
use self::gather_moves::{MoveData, MovePathIndex, LookupResult};
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<P<MetaItem>> {
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
for attr in attrs {
if attr.check_name("rustc_mir") {
let items = attr.meta_item_list();
......
......@@ -919,7 +919,7 @@ pub fn hash_attributes(&mut self, attributes: &[ast::Attribute]) {
if !attr.is_sugared_doc &&
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
SawAttribute(attr.style).hash(self.st);
self.hash_meta_item(&*attr.value);
self.hash_meta_item(&attr.value);
}
}
}
......
......@@ -505,7 +505,7 @@ pub struct Crate {
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialEq)]
pub enum NestedMetaItemKind {
/// A full MetaItem, for recursive meta items.
MetaItem(P<MetaItem>),
MetaItem(MetaItem),
/// A literal.
///
/// E.g. "foo", 64, true
......@@ -1758,7 +1758,7 @@ pub enum AttrStyle {
pub struct Attribute {
pub id: AttrId,
pub style: AttrStyle,
pub value: P<MetaItem>,
pub value: MetaItem,
pub is_sugared_doc: bool,
pub span: Span,
}
......
......@@ -107,7 +107,7 @@ pub fn is_known(attr: &Attribute) -> bool {
impl NestedMetaItem {
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
pub fn meta_item(&self) -> Option<&P<MetaItem>> {
pub fn meta_item(&self) -> Option<&MetaItem> {
match self.node {
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
_ => None
......@@ -145,7 +145,7 @@ pub fn value_str(&self) -> Option<InternedString> {
}
/// Returns a MetaItem if self is a MetaItem with Kind Word.
pub fn word(&self) -> Option<&P<MetaItem>> {
pub fn word(&self) -> Option<&MetaItem> {
self.meta_item().and_then(|meta_item| if meta_item.is_word() {
Some(meta_item)
} else {
......@@ -294,16 +294,16 @@ pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
/* Constructors */
pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P<MetaItem> {
pub fn mk_name_value_item_str(name: Name, value: InternedString) -> MetaItem {
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
}
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P<MetaItem> {
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> MetaItem {
mk_spanned_name_value_item(DUMMY_SP, name, value)
}
pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
mk_spanned_list_item(DUMMY_SP, name, items)
}
......@@ -311,20 +311,20 @@ pub fn mk_list_word_item(name: Name) -> ast::NestedMetaItem {
dummy_spanned(NestedMetaItemKind::MetaItem(mk_spanned_word_item(DUMMY_SP, name)))
}
pub fn mk_word_item(name: Name) -> P<MetaItem> {
pub fn mk_word_item(name: Name) -> MetaItem {
mk_spanned_word_item(DUMMY_SP, name)
}
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
P(MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) })
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> MetaItem {
MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) }
}
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
P(MetaItem { span: sp, name: name, node: MetaItemKind::List(items) })
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { span: sp, name: name, node: MetaItemKind::List(items) }
}
pub fn mk_spanned_word_item(sp: Span, name: Name) -> P<MetaItem> {
P(MetaItem { span: sp, name: name, node: MetaItemKind::Word })
pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem {
MetaItem { span: sp, name: name, node: MetaItemKind::Word }
}
......@@ -341,12 +341,12 @@ pub fn mk_attr_id() -> AttrId {
}
/// Returns an inner attribute with the given value.
pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
pub fn mk_attr_inner(id: AttrId, item: MetaItem) -> Attribute {
mk_spanned_attr_inner(DUMMY_SP, id, item)
}
/// Returns an innter attribute with the given value and span.
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
Attribute {
id: id,
style: ast::AttrStyle::Inner,
......@@ -358,12 +358,12 @@ pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribu
/// Returns an outer attribute with the given value.
pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
pub fn mk_attr_outer(id: AttrId, item: MetaItem) -> Attribute {
mk_spanned_attr_outer(DUMMY_SP, id, item)
}
/// Returns an outer attribute with the given value and span.
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
Attribute {
id: id,
style: ast::AttrStyle::Outer,
......@@ -373,7 +373,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribu
}
}
pub fn mk_doc_attr_outer(id: AttrId, item: P<MetaItem>, is_sugared_doc: bool) -> Attribute {
pub fn mk_doc_attr_outer(id: AttrId, item: MetaItem, is_sugared_doc: bool) -> Attribute {
Attribute {
id: id,
style: ast::AttrStyle::Outer,
......@@ -390,11 +390,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
Attribute {
id: id,
style: style,
value: P(MetaItem {
value: MetaItem {
span: mk_sp(lo, hi),
name: token::intern("doc"),
node: MetaItemKind::NameValue(lit),
}),
},
is_sugared_doc: true,
span: mk_sp(lo, hi),
}
......@@ -423,8 +423,7 @@ pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
.and_then(|at| at.value_str())
}
pub fn last_meta_item_value_str_by_name(items: &[P<MetaItem>], name: &str)
-> Option<InternedString> {
pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Option<InternedString> {
items.iter()
.rev()
.find(|mi| mi.check_name(name))
......@@ -859,7 +858,7 @@ pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute],
find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
}
pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
pub fn require_unique_names(diagnostic: &Handler, metas: &[MetaItem]) {
let mut set = HashSet::new();
for meta in metas {
let name = meta.name();
......
......@@ -275,9 +275,9 @@ fn item_ty_poly(&self,
generics: Generics) -> P<ast::Item>;
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item>;
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute;
fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem>;
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem;
fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem;
......@@ -285,12 +285,12 @@ fn meta_list(&self,
sp: Span,
name: ast::Name,
mis: Vec<ast::NestedMetaItem> )
-> P<ast::MetaItem>;
-> ast::MetaItem;
fn meta_name_value(&self,
sp: Span,
name: ast::Name,
value: ast::LitKind)
-> P<ast::MetaItem>;
-> ast::MetaItem;
fn item_use(&self, sp: Span,
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
......@@ -1146,11 +1146,11 @@ fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item> {
self.item_ty_poly(span, name, ty, Generics::default())
}
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute {
attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi)
}
fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem> {
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem {
attr::mk_spanned_word_item(sp, w)
}
......@@ -1159,12 +1159,12 @@ fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem {
}
fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
-> P<ast::MetaItem> {
-> ast::MetaItem {
attr::mk_spanned_list_item(sp, name, mis)
}
fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
-> P<ast::MetaItem> {
-> ast::MetaItem {
attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
}
......
......@@ -211,7 +211,7 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
impl_to_tokens_slice! { P<ast::Item>, [] }
impl_to_tokens_slice! { ast::Arg, [TokenTree::Token(DUMMY_SP, token::Comma)] }
impl ToTokens for P<ast::MetaItem> {
impl ToTokens for ast::MetaItem {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
let nt = token::NtMeta(self.clone());
vec![TokenTree::Token(DUMMY_SP, token::Interpolated(Rc::new(nt)))]
......@@ -405,7 +405,7 @@ pub fn parse_block_panic(parser: &mut Parser) -> P<Block> {
panictry!(parser.parse_block())
}
pub fn parse_meta_item_panic(parser: &mut Parser) -> P<ast::MetaItem> {
pub fn parse_meta_item_panic(parser: &mut Parser) -> ast::MetaItem {
panictry!(parser.parse_meta_item())
}
......
......@@ -995,7 +995,7 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
NameValue(ref lit) => !lit.node.is_str(),
List(ref list) => list.iter().any(|li| {
match li.node {
MetaItem(ref mi) => contains_novel_literal(&**mi),
MetaItem(ref mi) => contains_novel_literal(&mi),
Literal(_) => true,
}
}),
......@@ -1013,7 +1013,7 @@ fn visit_attribute(&mut self, attr: &ast::Attribute) {
self.context.check_attribute(attr, false);
}
if contains_novel_literal(&*(attr.value)) {
if contains_novel_literal(&attr.value) {
gate_feature_post!(&self, attr_literals, attr.span,
"non-string literals in attributes, or string \
literals in top-level positions, are experimental");
......
......@@ -43,7 +43,7 @@ fn fold_crate(&mut self, c: Crate) -> Crate {
noop_fold_crate(c, self)
}
fn fold_meta_items(&mut self, meta_items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> {
fn fold_meta_items(&mut self, meta_items: Vec<MetaItem>) -> Vec<MetaItem> {
noop_fold_meta_items(meta_items, self)
}
......@@ -51,7 +51,7 @@ fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem {
noop_fold_meta_list_item(list_item, self)
}
fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
fn fold_meta_item(&mut self, meta_item: MetaItem) -> MetaItem {
noop_fold_meta_item(meta_item, self)
}
......@@ -293,8 +293,7 @@ fn new_span(&mut self, sp: Span) -> Span {
}
}
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T)
-> Vec<P<MetaItem>> {
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<MetaItem>, fld: &mut T) -> Vec<MetaItem> {
meta_items.move_map(|x| fld.fold_meta_item(x))
}
......@@ -519,18 +518,18 @@ pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
}
}
pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
mi.map(|MetaItem { name, node, span }| MetaItem {
name: name,
node: match node {
pub fn noop_fold_meta_item<T: Folder>(mi: MetaItem, fld: &mut T) -> MetaItem {
MetaItem {
name: mi.name,
node: match mi.node {
MetaItemKind::Word => MetaItemKind::Word,
MetaItemKind::List(mis) => {
MetaItemKind::List(mis.move_map(|e| fld.fold_meta_list_item(e)))
},
MetaItemKind::NameValue(s) => MetaItemKind::NameValue(s),
},
span: fld.new_span(span)
})
span: fld.new_span(mi.span)
}
}
pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {
......
......@@ -16,7 +16,6 @@
use parse::PResult;
use parse::token;
use parse::parser::{Parser, TokenType};
use ptr::P;
#[derive(PartialEq, Eq, Debug)]
enum InnerAttributeParsePolicy<'a> {
......@@ -211,7 +210,7 @@ fn parse_unsuffixed_lit(&mut self) -> PResult<'a, ast::Lit> {
///
/// meta_item : IDENT ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
let nt_meta = match self.token {
token::Interpolated(ref nt) => match **nt {
token::NtMeta(ref e) => Some(e.clone()),
......@@ -235,7 +234,7 @@ pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
ast::MetaItemKind::Word
};
let hi = self.prev_span.hi;
Ok(P(ast::MetaItem { name: ident.name, node: node, span: mk_sp(lo, hi) }))
Ok(ast::MetaItem { name: ident.name, node: node, span: mk_sp(lo, hi) })
}
/// matches meta_item_inner : (meta_item | UNSUFFIXED_LIT) ;
......
......@@ -117,7 +117,7 @@ pub fn parse_item_from_source_str<'a>(name: String, source: String, sess: &'a Pa
}
pub fn parse_meta_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
-> PResult<'a, P<ast::MetaItem>> {
-> PResult<'a, ast::MetaItem> {
new_parser_from_source_str(sess, name, source).parse_meta_item()
}
......
......@@ -301,7 +301,7 @@ pub enum Nonterminal {
NtTy(P<ast::Ty>),
NtIdent(ast::SpannedIdent),
/// Stuff inside brackets for attributes
NtMeta(P<ast::MetaItem>),
NtMeta(ast::MetaItem),
NtPath(ast::Path),
NtTT(tokenstream::TokenTree),
// These are not exposed to macros, but are used by quasiquote.
......
......@@ -69,11 +69,11 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
krate.module.items.insert(0, P(ast::Item {
attrs: vec![ast::Attribute {
style: ast::AttrStyle::Outer,
value: P(ast::MetaItem {
value: ast::MetaItem {
name: token::intern("prelude_import"),
node: ast::MetaItemKind::Word,
span: span,
}),
},
id: attr::mk_attr_id(),
is_sugared_doc: false,
span: span,
......
......@@ -116,7 +116,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
// Expand `#[derive]`s after other attribute macro invocations.
if cx.resolver.find_attr_invoc(&mut item.attrs.clone()).is_some() {
return vec![Annotatable::Item(item.map_attrs(|mut attrs| {
attrs.push(cx.attribute(span, P(mitem.clone())));
attrs.push(cx.attribute(span, mitem.clone()));
attrs.extend(derive_attrs);
attrs
}))];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册