Refactor P<ast::MetaItem>
-> ast::MetaItem
.
This commit is contained in:
parent
e97686d048
commit
f177a00ac9
14 changed files with 54 additions and 58 deletions
|
@ -93,7 +93,7 @@ pub enum NativeLibraryKind {
|
||||||
pub struct NativeLibrary {
|
pub struct NativeLibrary {
|
||||||
pub kind: NativeLibraryKind,
|
pub kind: NativeLibraryKind,
|
||||||
pub name: String,
|
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
|
/// The data we save and restore about an inlined item or method. This is not
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
use borrowck::BorrowckCtxt;
|
use borrowck::BorrowckCtxt;
|
||||||
|
|
||||||
use syntax::ast::{self, MetaItem};
|
use syntax::ast::{self, MetaItem};
|
||||||
use syntax::ptr::P;
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
|
@ -35,7 +34,7 @@ use self::dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
|
||||||
use self::dataflow::{DefinitelyInitializedLvals};
|
use self::dataflow::{DefinitelyInitializedLvals};
|
||||||
use self::gather_moves::{MoveData, MovePathIndex, LookupResult};
|
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 {
|
for attr in attrs {
|
||||||
if attr.check_name("rustc_mir") {
|
if attr.check_name("rustc_mir") {
|
||||||
let items = attr.meta_item_list();
|
let items = attr.meta_item_list();
|
||||||
|
|
|
@ -919,7 +919,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
|
||||||
if !attr.is_sugared_doc &&
|
if !attr.is_sugared_doc &&
|
||||||
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
|
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
|
||||||
SawAttribute(attr.style).hash(self.st);
|
SawAttribute(attr.style).hash(self.st);
|
||||||
self.hash_meta_item(&*attr.value);
|
self.hash_meta_item(&attr.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,7 +505,7 @@ pub type NestedMetaItem = Spanned<NestedMetaItemKind>;
|
||||||
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialEq)]
|
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialEq)]
|
||||||
pub enum NestedMetaItemKind {
|
pub enum NestedMetaItemKind {
|
||||||
/// A full MetaItem, for recursive meta items.
|
/// A full MetaItem, for recursive meta items.
|
||||||
MetaItem(P<MetaItem>),
|
MetaItem(MetaItem),
|
||||||
/// A literal.
|
/// A literal.
|
||||||
///
|
///
|
||||||
/// E.g. "foo", 64, true
|
/// E.g. "foo", 64, true
|
||||||
|
@ -1758,7 +1758,7 @@ pub struct AttrId(pub usize);
|
||||||
pub struct Attribute {
|
pub struct Attribute {
|
||||||
pub id: AttrId,
|
pub id: AttrId,
|
||||||
pub style: AttrStyle,
|
pub style: AttrStyle,
|
||||||
pub value: P<MetaItem>,
|
pub value: MetaItem,
|
||||||
pub is_sugared_doc: bool,
|
pub is_sugared_doc: bool,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub fn is_known(attr: &Attribute) -> bool {
|
||||||
|
|
||||||
impl NestedMetaItem {
|
impl NestedMetaItem {
|
||||||
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
|
/// 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 {
|
match self.node {
|
||||||
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
|
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
|
||||||
_ => None
|
_ => None
|
||||||
|
@ -145,7 +145,7 @@ impl NestedMetaItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a MetaItem if self is a MetaItem with Kind Word.
|
/// 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() {
|
self.meta_item().and_then(|meta_item| if meta_item.is_word() {
|
||||||
Some(meta_item)
|
Some(meta_item)
|
||||||
} else {
|
} else {
|
||||||
|
@ -294,16 +294,16 @@ impl Attribute {
|
||||||
|
|
||||||
/* Constructors */
|
/* 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));
|
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
|
||||||
mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
|
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)
|
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)
|
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)))
|
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)
|
mk_spanned_word_item(DUMMY_SP, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
|
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> MetaItem {
|
||||||
P(MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) })
|
MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
|
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
|
||||||
P(MetaItem { span: sp, name: name, node: MetaItemKind::List(items) })
|
MetaItem { span: sp, name: name, node: MetaItemKind::List(items) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_spanned_word_item(sp: Span, name: Name) -> P<MetaItem> {
|
pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem {
|
||||||
P(MetaItem { span: sp, name: name, node: MetaItemKind::Word })
|
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.
|
/// 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)
|
mk_spanned_attr_inner(DUMMY_SP, id, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an innter attribute with the given value and span.
|
/// 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 {
|
Attribute {
|
||||||
id: id,
|
id: id,
|
||||||
style: ast::AttrStyle::Inner,
|
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.
|
/// 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)
|
mk_spanned_attr_outer(DUMMY_SP, id, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an outer attribute with the given value and span.
|
/// 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 {
|
Attribute {
|
||||||
id: id,
|
id: id,
|
||||||
style: ast::AttrStyle::Outer,
|
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 {
|
Attribute {
|
||||||
id: id,
|
id: id,
|
||||||
style: ast::AttrStyle::Outer,
|
style: ast::AttrStyle::Outer,
|
||||||
|
@ -390,11 +390,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
|
||||||
Attribute {
|
Attribute {
|
||||||
id: id,
|
id: id,
|
||||||
style: style,
|
style: style,
|
||||||
value: P(MetaItem {
|
value: MetaItem {
|
||||||
span: mk_sp(lo, hi),
|
span: mk_sp(lo, hi),
|
||||||
name: token::intern("doc"),
|
name: token::intern("doc"),
|
||||||
node: MetaItemKind::NameValue(lit),
|
node: MetaItemKind::NameValue(lit),
|
||||||
}),
|
},
|
||||||
is_sugared_doc: true,
|
is_sugared_doc: true,
|
||||||
span: mk_sp(lo, hi),
|
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())
|
.and_then(|at| at.value_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_meta_item_value_str_by_name(items: &[P<MetaItem>], name: &str)
|
pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Option<InternedString> {
|
||||||
-> Option<InternedString> {
|
|
||||||
items.iter()
|
items.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.find(|mi| mi.check_name(name))
|
.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)
|
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();
|
let mut set = HashSet::new();
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
let name = meta.name();
|
let name = meta.name();
|
||||||
|
|
|
@ -275,9 +275,9 @@ pub trait AstBuilder {
|
||||||
generics: Generics) -> P<ast::Item>;
|
generics: Generics) -> P<ast::Item>;
|
||||||
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> 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;
|
fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem;
|
||||||
|
|
||||||
|
@ -285,12 +285,12 @@ pub trait AstBuilder {
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: ast::Name,
|
name: ast::Name,
|
||||||
mis: Vec<ast::NestedMetaItem> )
|
mis: Vec<ast::NestedMetaItem> )
|
||||||
-> P<ast::MetaItem>;
|
-> ast::MetaItem;
|
||||||
fn meta_name_value(&self,
|
fn meta_name_value(&self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: ast::Name,
|
name: ast::Name,
|
||||||
value: ast::LitKind)
|
value: ast::LitKind)
|
||||||
-> P<ast::MetaItem>;
|
-> ast::MetaItem;
|
||||||
|
|
||||||
fn item_use(&self, sp: Span,
|
fn item_use(&self, sp: Span,
|
||||||
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
|
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
|
||||||
|
@ -1146,11 +1146,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.item_ty_poly(span, name, ty, Generics::default())
|
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)
|
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)
|
attr::mk_spanned_word_item(sp, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1159,12 +1159,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<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)
|
attr::mk_spanned_list_item(sp, name, mis)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
|
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))
|
attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ pub mod rt {
|
||||||
impl_to_tokens_slice! { P<ast::Item>, [] }
|
impl_to_tokens_slice! { P<ast::Item>, [] }
|
||||||
impl_to_tokens_slice! { ast::Arg, [TokenTree::Token(DUMMY_SP, token::Comma)] }
|
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> {
|
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||||
let nt = token::NtMeta(self.clone());
|
let nt = token::NtMeta(self.clone());
|
||||||
vec![TokenTree::Token(DUMMY_SP, token::Interpolated(Rc::new(nt)))]
|
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())
|
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())
|
panictry!(parser.parse_meta_item())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -995,7 +995,7 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
|
||||||
NameValue(ref lit) => !lit.node.is_str(),
|
NameValue(ref lit) => !lit.node.is_str(),
|
||||||
List(ref list) => list.iter().any(|li| {
|
List(ref list) => list.iter().any(|li| {
|
||||||
match li.node {
|
match li.node {
|
||||||
MetaItem(ref mi) => contains_novel_literal(&**mi),
|
MetaItem(ref mi) => contains_novel_literal(&mi),
|
||||||
Literal(_) => true,
|
Literal(_) => true,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -1013,7 +1013,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
self.context.check_attribute(attr, false);
|
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,
|
gate_feature_post!(&self, attr_literals, attr.span,
|
||||||
"non-string literals in attributes, or string \
|
"non-string literals in attributes, or string \
|
||||||
literals in top-level positions, are experimental");
|
literals in top-level positions, are experimental");
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub trait Folder : Sized {
|
||||||
noop_fold_crate(c, self)
|
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)
|
noop_fold_meta_items(meta_items, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ pub trait Folder : Sized {
|
||||||
noop_fold_meta_list_item(list_item, self)
|
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)
|
noop_fold_meta_item(meta_item, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,8 +293,7 @@ pub trait Folder : Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T)
|
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<MetaItem>, fld: &mut T) -> Vec<MetaItem> {
|
||||||
-> Vec<P<MetaItem>> {
|
|
||||||
meta_items.move_map(|x| fld.fold_meta_item(x))
|
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> {
|
pub fn noop_fold_meta_item<T: Folder>(mi: MetaItem, fld: &mut T) -> MetaItem {
|
||||||
mi.map(|MetaItem { name, node, span }| MetaItem {
|
MetaItem {
|
||||||
name: name,
|
name: mi.name,
|
||||||
node: match node {
|
node: match mi.node {
|
||||||
MetaItemKind::Word => MetaItemKind::Word,
|
MetaItemKind::Word => MetaItemKind::Word,
|
||||||
MetaItemKind::List(mis) => {
|
MetaItemKind::List(mis) => {
|
||||||
MetaItemKind::List(mis.move_map(|e| fld.fold_meta_list_item(e)))
|
MetaItemKind::List(mis.move_map(|e| fld.fold_meta_list_item(e)))
|
||||||
},
|
},
|
||||||
MetaItemKind::NameValue(s) => MetaItemKind::NameValue(s),
|
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 {
|
pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {
|
||||||
|
|
|
@ -16,7 +16,6 @@ use parse::common::SeqSep;
|
||||||
use parse::PResult;
|
use parse::PResult;
|
||||||
use parse::token;
|
use parse::token;
|
||||||
use parse::parser::{Parser, TokenType};
|
use parse::parser::{Parser, TokenType};
|
||||||
use ptr::P;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
enum InnerAttributeParsePolicy<'a> {
|
enum InnerAttributeParsePolicy<'a> {
|
||||||
|
@ -211,7 +210,7 @@ impl<'a> Parser<'a> {
|
||||||
///
|
///
|
||||||
/// meta_item : IDENT ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
|
/// meta_item : IDENT ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
|
||||||
/// meta_item_inner : (meta_item | 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 {
|
let nt_meta = match self.token {
|
||||||
token::Interpolated(ref nt) => match **nt {
|
token::Interpolated(ref nt) => match **nt {
|
||||||
token::NtMeta(ref e) => Some(e.clone()),
|
token::NtMeta(ref e) => Some(e.clone()),
|
||||||
|
@ -235,7 +234,7 @@ impl<'a> Parser<'a> {
|
||||||
ast::MetaItemKind::Word
|
ast::MetaItemKind::Word
|
||||||
};
|
};
|
||||||
let hi = self.prev_span.hi;
|
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) ;
|
/// 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)
|
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()
|
new_parser_from_source_str(sess, name, source).parse_meta_item()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ pub enum Nonterminal {
|
||||||
NtTy(P<ast::Ty>),
|
NtTy(P<ast::Ty>),
|
||||||
NtIdent(ast::SpannedIdent),
|
NtIdent(ast::SpannedIdent),
|
||||||
/// Stuff inside brackets for attributes
|
/// Stuff inside brackets for attributes
|
||||||
NtMeta(P<ast::MetaItem>),
|
NtMeta(ast::MetaItem),
|
||||||
NtPath(ast::Path),
|
NtPath(ast::Path),
|
||||||
NtTT(tokenstream::TokenTree),
|
NtTT(tokenstream::TokenTree),
|
||||||
// These are not exposed to macros, but are used by quasiquote.
|
// 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 {
|
krate.module.items.insert(0, P(ast::Item {
|
||||||
attrs: vec![ast::Attribute {
|
attrs: vec![ast::Attribute {
|
||||||
style: ast::AttrStyle::Outer,
|
style: ast::AttrStyle::Outer,
|
||||||
value: P(ast::MetaItem {
|
value: ast::MetaItem {
|
||||||
name: token::intern("prelude_import"),
|
name: token::intern("prelude_import"),
|
||||||
node: ast::MetaItemKind::Word,
|
node: ast::MetaItemKind::Word,
|
||||||
span: span,
|
span: span,
|
||||||
}),
|
},
|
||||||
id: attr::mk_attr_id(),
|
id: attr::mk_attr_id(),
|
||||||
is_sugared_doc: false,
|
is_sugared_doc: false,
|
||||||
span: span,
|
span: span,
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
|
||||||
// Expand `#[derive]`s after other attribute macro invocations.
|
// Expand `#[derive]`s after other attribute macro invocations.
|
||||||
if cx.resolver.find_attr_invoc(&mut item.attrs.clone()).is_some() {
|
if cx.resolver.find_attr_invoc(&mut item.attrs.clone()).is_some() {
|
||||||
return vec![Annotatable::Item(item.map_attrs(|mut attrs| {
|
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.extend(derive_attrs);
|
||||||
attrs
|
attrs
|
||||||
}))];
|
}))];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue