Skip to content
Permalink
Browse files

Rename `MetaItem.node` to `MetaItem.kind`

  • Loading branch information...
varkor committed Sep 26, 2019
1 parent b474867 commit 38121173e27d304366c6fd422318e1e424941b7c
@@ -361,7 +361,7 @@ impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItem {

impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
path,
node,
kind,
span
});

@@ -218,7 +218,7 @@ impl<'a> LintLevelsBuilder<'a> {
let mut reason = None;
let tail_li = &metas[metas.len()-1];
if let Some(item) = tail_li.meta_item() {
match item.node {
match item.kind {
ast::MetaItemKind::Word => {} // actual lint names handled later
ast::MetaItemKind::NameValue(ref name_value) => {
if item.path == sym::reason {
@@ -264,7 +264,7 @@ impl<'a> LintLevelsBuilder<'a> {
let mut err = bad_attr(sp);
let mut add_label = true;
if let Some(item) = li.meta_item() {
if let ast::MetaItemKind::NameValue(_) = item.node {
if let ast::MetaItemKind::NameValue(_) = item.kind {
if item.path == sym::reason {
err.span_label(sp, "reason in lint attribute must come last");
add_label = false;
@@ -59,7 +59,7 @@ impl LibFeatureCollector<'tcx> {
attr.check_name(**stab_attr)
}) {
let meta_item = attr.meta();
if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta_item {
if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta_item {
let mut feature = None;
let mut since = None;
for meta in metas {
@@ -1879,7 +1879,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
if meta_item.path.segments.len() != 1 {
error!("argument key must be an identifier");
}
match &meta_item.node {
match &meta_item.kind {
MetaItemKind::List(..) => {
error!(r#"expected `key` or `key="value"`"#);
}
@@ -700,7 +700,7 @@ impl RustcDefaultCalls {
let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| {
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
path: ast::Path::from_ident(ast::Ident::with_dummy_span(name)),
node: ast::MetaItemKind::Word,
kind: ast::MetaItemKind::Word,
span: DUMMY_SP,
});

@@ -556,7 +556,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
sym::bin
];

if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().node {
if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().kind {
let span = spanned.span;
let lev_candidate = find_best_match_for_name(
crate_types.iter(),
@@ -944,7 +944,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
let ill_formed = |span| span_err!(self.r.session, span, E0466, "bad macro import");
match attr.meta() {
Some(meta) => match meta.node {
Some(meta) => match meta.kind {
MetaItemKind::Word => {
import_all = Some(meta.span);
break;
@@ -2653,7 +2653,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if attr.path != sym::inline {
return ia;
}
match attr.meta().map(|i| i.node) {
match attr.meta().map(|i| i.kind) {
Some(MetaItemKind::Word) => {
mark_used(attr);
InlineAttr::Hint
@@ -2694,7 +2694,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
return ia;
}
let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s);
match attr.meta().map(|i| i.node) {
match attr.meta().map(|i| i.kind) {
Some(MetaItemKind::Word) => {
err(attr.span, "expected one argument");
ia
@@ -68,7 +68,7 @@ impl Cfg {
span: cfg.span
}),
};
match cfg.node {
match cfg.kind {
MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
MetaItemKind::NameValue(ref lit) => match lit.kind {
LitKind::Str(value, _) => Ok(Cfg::Cfg(name, Some(value))),
@@ -17,7 +17,7 @@ fn name_value_cfg(name: &str, value: &str) -> Cfg {
fn dummy_meta_item_word(name: &str) -> MetaItem {
MetaItem {
path: Path::from_ident(Ident::from_str(name)),
node: MetaItemKind::Word,
kind: MetaItemKind::Word,
span: DUMMY_SP,
}
}
@@ -26,7 +26,7 @@ macro_rules! dummy_meta_item_list {
($name:ident, [$($list:ident),* $(,)?]) => {
MetaItem {
path: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
kind: MetaItemKind::List(vec![
$(
NestedMetaItem::MetaItem(
dummy_meta_item_word(stringify!($list)),
@@ -778,11 +778,11 @@ impl Attributes {
fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
use syntax::ast::NestedMetaItem::MetaItem;

if let ast::MetaItemKind::List(ref nmis) = mi.node {
if let ast::MetaItemKind::List(ref nmis) = mi.kind {
if nmis.len() == 1 {
if let MetaItem(ref cfg_mi) = nmis[0] {
if cfg_mi.check_name(sym::cfg) {
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.node {
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.kind {
if cfg_nmis.len() == 1 {
if let MetaItem(ref content_mi) = cfg_nmis[0] {
return Some(content_mi);
@@ -472,7 +472,7 @@ pub enum NestedMetaItem {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct MetaItem {
pub path: Path,
pub node: MetaItemKind,
pub kind: MetaItemKind,
pub span: Span,
}

@@ -106,7 +106,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
attrs.iter().fold(None, |ia, attr| {
if attr.check_name(sym::unwind) {
if let Some(meta) = attr.meta() {
if let MetaItemKind::List(items) = meta.node {
if let MetaItemKind::List(items) = meta.kind {
if items.len() == 1 {
if items[0].check_name(sym::allowed) {
return Some(UnwindAttr::Allowed);
@@ -239,7 +239,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
allow_const_fn_ptr = true;
}
// attributes with data
else if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta {
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
let meta = meta.as_ref().unwrap();
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
@@ -534,7 +534,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
if cfg.path.segments.len() != 1 {
return error(cfg.path.span, "`cfg` predicate key must be an identifier");
}
match &cfg.node {
match &cfg.kind {
MetaItemKind::List(..) => {
error(cfg.span, "unexpected parentheses after `cfg` predicate key")
}
@@ -563,7 +563,7 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
-> bool
where F: FnMut(&ast::MetaItem) -> bool
{
match cfg.node {
match cfg.kind {
ast::MetaItemKind::List(ref mis) => {
for mi in mis.iter() {
if !mi.is_meta_item() {
@@ -642,7 +642,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
}

let meta = attr.meta().unwrap();
depr = match &meta.node {
depr = match &meta.kind {
MetaItemKind::Word => Some(Deprecation { since: None, note: None }),
MetaItemKind::NameValue(..) => {
meta.value_str().map(|note| {
@@ -830,7 +830,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
} else {
if let Some(meta_item) = item.meta_item() {
if meta_item.check_name(sym::align) {
if let MetaItemKind::NameValue(ref value) = meta_item.node {
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
recognised = true;
let mut err = struct_span_err!(diagnostic, item.span(), E0693,
"incorrect `repr(align)` attribute format");
@@ -941,7 +941,7 @@ crate fn check_builtin_attribute(
name == sym::test || name == sym::bench;

match attr.parse_meta(sess) {
Ok(meta) => if !should_skip(name) && !template.compatible(&meta.node) {
Ok(meta) => if !should_skip(name) && !template.compatible(&meta.kind) {
let error_msg = format!("malformed `{}` attribute input", name);
let mut msg = "attribute must be of the form ".to_owned();
let mut suggestions = vec![];
@@ -174,7 +174,7 @@ impl Attribute {

pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
match self.meta() {
Some(MetaItem { node: MetaItemKind::List(list), .. }) => Some(list),
Some(MetaItem { kind: MetaItemKind::List(list), .. }) => Some(list),
_ => None
}
}
@@ -210,14 +210,14 @@ impl MetaItem {
// #[attribute(name = "value")]
// ^^^^^^^^^^^^^^
pub fn name_value_literal(&self) -> Option<&Lit> {
match &self.node {
match &self.kind {
MetaItemKind::NameValue(v) => Some(v),
_ => None,
}
}

pub fn value_str(&self) -> Option<Symbol> {
match self.node {
match self.kind {
MetaItemKind::NameValue(ref v) => {
match v.kind {
LitKind::Str(ref s, _) => Some(*s),
@@ -229,14 +229,14 @@ impl MetaItem {
}

pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
match self.node {
match self.kind {
MetaItemKind::List(ref l) => Some(&l[..]),
_ => None
}
}

pub fn is_word(&self) -> bool {
match self.node {
match self.kind {
MetaItemKind::Word => true,
_ => false,
}
@@ -261,11 +261,11 @@ impl Attribute {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
path: self.path.clone(),
node: if let Some(node) = MetaItemKind::from_tokens(&mut tokens) {
kind: if let Some(kind) = MetaItemKind::from_tokens(&mut tokens) {
if tokens.peek().is_some() {
return None;
}
node
kind
} else {
return None;
},
@@ -314,7 +314,7 @@ impl Attribute {
pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
Ok(MetaItem {
path: self.path.clone(),
node: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
kind: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
span: self.span,
})
}
@@ -336,7 +336,7 @@ impl Attribute {
id: self.id,
style: self.style,
path: meta.path,
tokens: meta.node.tokens(meta.span),
tokens: meta.kind.tokens(meta.span),
is_sugared_doc: true,
span: self.span,
})
@@ -356,15 +356,15 @@ pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> Meta
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
let lit = Lit::from_lit_kind(lit_kind, lit_span);
let span = ident.span.to(lit_span);
MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(lit) }
MetaItem { path: Path::from_ident(ident), span, kind: MetaItemKind::NameValue(lit) }
}

pub fn mk_list_item(ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::List(items) }
MetaItem { path: Path::from_ident(ident), span: ident.span, kind: MetaItemKind::List(items) }
}

pub fn mk_word_item(ident: Ident) -> MetaItem {
MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::Word }
MetaItem { path: Path::from_ident(ident), span: ident.span, kind: MetaItemKind::Word }
}

pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
@@ -395,12 +395,12 @@ pub fn mk_attr(style: AttrStyle, path: Path, tokens: TokenStream, span: Span) ->

/// Returns an inner attribute with the given value and span.
pub fn mk_attr_inner(item: MetaItem) -> Attribute {
mk_attr(AttrStyle::Inner, item.path, item.node.tokens(item.span), item.span)
mk_attr(AttrStyle::Inner, item.path, item.kind.tokens(item.span), item.span)
}

/// Returns an outer attribute with the given value and span.
pub fn mk_attr_outer(item: MetaItem) -> Attribute {
mk_attr(AttrStyle::Outer, item.path, item.node.tokens(item.span), item.span)
mk_attr(AttrStyle::Outer, item.path, item.kind.tokens(item.span), item.span)
}

pub fn mk_sugared_doc_attr(text: Symbol, span: Span) -> Attribute {
@@ -483,7 +483,7 @@ impl MetaItem {
idents.push(TokenTree::Token(Token::from_ast_ident(segment.ident)).into());
last_pos = segment.ident.span.hi();
}
self.node.tokens(self.span).append_to_tree_and_joint_vec(&mut idents);
self.kind.tokens(self.span).append_to_tree_and_joint_vec(&mut idents);
TokenStream::new(idents)
}

@@ -531,14 +531,14 @@ impl MetaItem {
_ => return None,
};
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());
let node = MetaItemKind::from_tokens(tokens)?;
let hi = match node {
let kind = MetaItemKind::from_tokens(tokens)?;
let hi = match kind {
MetaItemKind::NameValue(ref lit) => lit.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),
_ => path.span.hi(),
};
let span = path.span.with_hi(hi);
Some(MetaItem { path, node, span })
Some(MetaItem { path, kind, span })
}
}

@@ -659,7 +659,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
if !item.derive_allowed() {
return fragment_kind.dummy(span);
}
let meta = ast::MetaItem { node: ast::MetaItemKind::Word, span, path };
let meta = ast::MetaItem { kind: ast::MetaItemKind::Word, span, path };
let items = expander.expand(self.cx, span, &meta, item);
fragment_kind.expect_from_annotatables(items)
}
@@ -1534,7 +1534,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
id: at.id,
style: at.style,
path: meta.path,
tokens: meta.node.tokens(meta.span),
tokens: meta.kind.tokens(meta.span),
is_sugared_doc: false,
};
} else {
@@ -576,8 +576,8 @@ pub fn noop_visit_meta_list_item<T: MutVisitor>(li: &mut NestedMetaItem, vis: &m
}

pub fn noop_visit_meta_item<T: MutVisitor>(mi: &mut MetaItem, vis: &mut T) {
let MetaItem { path: _, node, span } = mi;
match node {
let MetaItem { path: _, kind, span } = mi;
match kind {
MetaItemKind::Word => {}
MetaItemKind::List(mis) => visit_vec(mis, |mi| vis.visit_meta_list_item(mi)),
MetaItemKind::NameValue(_s) => {}
@@ -179,7 +179,7 @@ impl<'a> Parser<'a> {
};
Ok(if let Some(meta) = meta {
self.bump();
(meta.path, meta.node.tokens(meta.span))
(meta.path, meta.kind.tokens(meta.span))
} else {
let path = self.parse_path(PathStyle::Mod)?;
let tokens = if self.check(&token::OpenDelim(DelimToken::Paren)) ||
@@ -281,9 +281,9 @@ impl<'a> Parser<'a> {

let lo = self.token.span;
let path = self.parse_path(PathStyle::Mod)?;
let node = self.parse_meta_item_kind()?;
let kind = self.parse_meta_item_kind()?;
let span = lo.to(self.prev_span);
Ok(ast::MetaItem { path, node, span })
Ok(ast::MetaItem { path, kind, span })
}

crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
@@ -114,7 +114,7 @@ impl<'a> Parser<'a> {
pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, Path> {
let meta_ident = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
token::NtMeta(ref meta) => match meta.node {
token::NtMeta(ref meta) => match meta.kind {
ast::MetaItemKind::Word => Some(meta.path.clone()),
_ => None,
},

0 comments on commit 3812117

Please sign in to comment.
You can’t perform that action at this time.