Skip to content
Permalink
Browse files

Rename `MetaItem::ident` to `MetaItem::path`

  • Loading branch information...
petrochenkov committed Mar 2, 2019
1 parent 6ad55b3 commit 63116d313dbc1e8f7f0fa4a729aea8e4f824b370
@@ -368,7 +368,7 @@ impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItemKind {
});

impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
ident,
path,
node,
span
});
@@ -221,7 +221,7 @@ impl<'a> LintLevelsBuilder<'a> {
match item.node {
ast::MetaItemKind::Word => {} // actual lint names handled later
ast::MetaItemKind::NameValue(ref name_value) => {
if item.ident == "reason" {
if item.path == "reason" {
// found reason, reslice meta list to exclude it
metas = &metas[0..metas.len()-1];
// FIXME (#55112): issue unused-attributes lint if we thereby
@@ -261,7 +261,7 @@ impl<'a> LintLevelsBuilder<'a> {
let mut err = bad_attr(li.span);
if let Some(item) = li.meta_item() {
if let ast::MetaItemKind::NameValue(_) = item.node {
if item.ident == "reason" {
if item.path == "reason" {
err.help("reason in lint attribute must come last");
}
}
@@ -270,15 +270,15 @@ impl<'a> LintLevelsBuilder<'a> {
continue;
}
};
let tool_name = if meta_item.ident.segments.len() > 1 {
let tool_ident = meta_item.ident.segments[0].ident;
let tool_name = if meta_item.path.segments.len() > 1 {
let tool_ident = meta_item.path.segments[0].ident;
if !attr::is_known_lint_tool(tool_ident) {
span_err!(
sess,
tool_ident.span,
E0710,
"an unknown tool name found in scoped lint: `{}`",
meta_item.ident
meta_item.path
);
continue;
}
@@ -287,7 +287,7 @@ impl<'a> LintLevelsBuilder<'a> {
} else {
None
};
let name = meta_item.ident.segments.last().expect("empty lint name").ident.name;
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
match store.check_lint_name(&name.as_str(), tool_name) {
CheckLintNameResult::Ok(ids) => {
let src = LintSource::Node(name, li.span, reason);
@@ -1839,7 +1839,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String

match &mut parser.parse_meta_item() {
Ok(meta_item) if parser.token == token::Eof => {
if meta_item.ident.segments.len() != 1 {
if meta_item.path.segments.len() != 1 {
error!("argument key must be an identifier");
}
match &meta_item.node {
@@ -683,7 +683,7 @@ impl RustcDefaultCalls {

let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| {
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
ident: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)),
path: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)),
node: ast::MetaItemKind::Word,
span: DUMMY_SP,
});
@@ -146,7 +146,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitD
} else {
sess.span_err(
item.span,
&format!("{} attribute requires a path", item.ident));
&format!("{} attribute requires a path", item.path));
return None;
}
}
@@ -430,7 +430,7 @@ mod test {

fn dummy_meta_item_word(name: &str) -> MetaItem {
MetaItem {
ident: Path::from_ident(Ident::from_str(name)),
path: Path::from_ident(Ident::from_str(name)),
node: MetaItemKind::Word,
span: DUMMY_SP,
}
@@ -439,7 +439,7 @@ mod test {
macro_rules! dummy_meta_item_list {
($name:ident, [$($list:ident),* $(,)?]) => {
MetaItem {
ident: Path::from_ident(Ident::from_str(stringify!($name))),
path: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
$(
dummy_spanned(NestedMetaItemKind::MetaItem(
@@ -453,7 +453,7 @@ mod test {

($name:ident, [$($list:expr),* $(,)?]) => {
MetaItem {
ident: Path::from_ident(Ident::from_str(stringify!($name))),
path: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
$(
dummy_spanned(NestedMetaItemKind::MetaItem($list)),
@@ -593,7 +593,7 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));

let mi = MetaItem {
ident: Path::from_ident(Ident::from_str("all")),
path: Path::from_ident(Ident::from_str("all")),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Str(
Symbol::intern("done"),
StrStyle::Cooked,
@@ -628,7 +628,7 @@ mod test {
fn test_parse_err() {
with_globals(|| {
let mi = MetaItem {
ident: Path::from_ident(Ident::from_str("foo")),
path: Path::from_ident(Ident::from_str("foo")),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Bool(false))),
span: DUMMY_SP,
};
@@ -3713,7 +3713,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
}

fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
let path = attr.ident.to_string();
let path = attr.path.to_string();

if attr.is_word() {
Some(path)
@@ -464,7 +464,7 @@ pub enum NestedMetaItemKind {
/// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct MetaItem {
pub ident: Path,
pub path: Path,
pub node: MetaItemKind,
pub span: Span,
}
@@ -203,7 +203,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
let meta = meta.as_ref().unwrap();
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(sess, meta.span, AttrError::MultipleItem(meta.ident.to_string()));
handle_errors(sess, meta.span, AttrError::MultipleItem(meta.path.to_string()));
return false
}
if let Some(v) = meta.value_str() {
@@ -232,7 +232,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
handle_errors(
sess,
mi.span,
AttrError::UnknownMetaItem(mi.ident.to_string(), expected),
AttrError::UnknownMetaItem(mi.path.to_string(), expected),
);
continue 'outer
}
@@ -315,7 +315,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
sess,
meta.span,
AttrError::UnknownMetaItem(
mi.ident.to_string(),
mi.path.to_string(),
&["feature", "reason", "issue"]
),
);
@@ -387,7 +387,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
sess,
meta.span,
AttrError::UnknownMetaItem(
mi.ident.to_string(), &["since", "note"],
mi.path.to_string(), &["since", "note"],
),
);
continue 'outer
@@ -482,8 +482,8 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
gated_cfg.check_and_emit(sess, feats);
}
let error = |span, msg| { sess.span_diagnostic.span_err(span, msg); true };
if cfg.ident.segments.len() != 1 {
return error(cfg.ident.span, "`cfg` predicate key must be an identifier");
if cfg.path.segments.len() != 1 {
return error(cfg.path.span, "`cfg` predicate key must be an identifier");
}
match &cfg.node {
MetaItemKind::List(..) => {
@@ -549,7 +549,7 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
},
_ => {
span_err!(sess.span_diagnostic, cfg.span, E0537,
"invalid predicate `{}`", cfg.ident);
"invalid predicate `{}`", cfg.path);
false
}
}
@@ -604,7 +604,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(
sess, meta.span, AttrError::MultipleItem(meta.ident.to_string())
sess, meta.span, AttrError::MultipleItem(meta.path.to_string())
);
return false
}
@@ -642,7 +642,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
handle_errors(
sess,
meta.span(),
AttrError::UnknownMetaItem(mi.ident.to_string(),
AttrError::UnknownMetaItem(mi.path.to_string(),
&["since", "note"]),
);
continue 'outer
@@ -208,8 +208,8 @@ impl Attribute {
impl MetaItem {
/// For a single-segment meta-item returns its name, otherwise returns `None`.
pub fn ident(&self) -> Option<Ident> {
if self.ident.segments.len() == 1 {
Some(self.ident.segments[0].ident)
if self.path.segments.len() == 1 {
Some(self.path.segments[0].ident)
} else {
None
}
@@ -256,7 +256,7 @@ impl MetaItem {
pub fn span(&self) -> Span { self.span }

pub fn check_name(&self, name: &str) -> bool {
self.ident == name
self.path == name
}

pub fn is_value_str(&self) -> bool {
@@ -273,7 +273,7 @@ impl Attribute {
pub fn meta(&self) -> Option<MetaItem> {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
ident: self.path.clone(),
path: self.path.clone(),
node: if let Some(node) = MetaItemKind::from_tokens(&mut tokens) {
if tokens.peek().is_some() {
return None;
@@ -319,7 +319,7 @@ impl Attribute {

pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
Ok(MetaItem {
ident: self.path.clone(),
path: self.path.clone(),
node: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
span: self.span,
})
@@ -357,15 +357,15 @@ pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem
}

pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem {
MetaItem { ident: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) }
MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) }
}

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

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

pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
@@ -393,7 +393,7 @@ pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute
Attribute {
id,
style: ast::AttrStyle::Inner,
path: item.ident,
path: item.path,
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
@@ -410,7 +410,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute
Attribute {
id,
style: ast::AttrStyle::Outer,
path: item.ident,
path: item.path,
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
@@ -461,7 +461,7 @@ impl MetaItem {
fn tokens(&self) -> TokenStream {
let mut idents = vec![];
let mut last_pos = BytePos(0 as u32);
for (i, segment) in self.ident.segments.iter().enumerate() {
for (i, segment) in self.path.segments.iter().enumerate() {
let is_first = i == 0;
if !is_first {
let mod_sep_span = Span::new(last_pos,
@@ -481,7 +481,7 @@ impl MetaItem {
where I: Iterator<Item = TokenTree>,
{
// FIXME: Share code with `parse_path`.
let ident = match tokens.next() {
let path = match tokens.next() {
Some(TokenTree::Token(span, token @ Token::Ident(..))) |
Some(TokenTree::Token(span, token @ Token::ModSep)) => 'arm: {
let mut segments = if let Token::Ident(ident, _) = token {
@@ -522,11 +522,11 @@ impl MetaItem {
let node = MetaItemKind::from_tokens(tokens)?;
let hi = match node {
MetaItemKind::NameValue(ref lit) => lit.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(ident.span.hi()),
_ => ident.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),
_ => path.span.hi(),
};
let span = ident.span.with_hi(hi);
Some(MetaItem { ident, node, span })
let span = path.span.with_hi(hi);
Some(MetaItem { path, node, span })
}
}

@@ -929,7 +929,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
invoc.expansion_data.mark.set_expn_info(expn_info);
let span = span.with_ctxt(self.cx.backtrace());
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
ident: Path::from_ident(keywords::Invalid.ident()),
path: Path::from_ident(keywords::Invalid.ident()),
span: DUMMY_SP,
node: ast::MetaItemKind::Word,
};
@@ -548,7 +548,7 @@ 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 { ident: _, node, span } = mi;
let MetaItem { path: _, node, span } = mi;
match node {
MetaItemKind::Word => {}
MetaItemKind::List(mis) => visit_vec(mis, |mi| vis.visit_meta_list_item(mi)),
@@ -1340,4 +1340,3 @@ mod tests {
})
}
}

@@ -149,7 +149,7 @@ impl<'a> Parser<'a> {
};
Ok(if let Some(meta) = meta {
self.bump();
(meta.ident, meta.node.tokens(meta.span))
(meta.path, meta.node.tokens(meta.span))
} else {
let path = self.parse_path(PathStyle::Mod)?;
let tokens = if self.check(&token::OpenDelim(DelimToken::Paren)) ||
@@ -250,10 +250,10 @@ impl<'a> Parser<'a> {
}

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

crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
@@ -2333,7 +2333,7 @@ impl<'a> Parser<'a> {
let meta_ident = match self.token {
token::Interpolated(ref nt) => match **nt {
token::NtMeta(ref meta) => match meta.node {
ast::MetaItemKind::Word => Some(meta.ident.clone()),
ast::MetaItemKind::Word => Some(meta.path.clone()),
_ => None,
},
_ => None,
Oops, something went wrong.

0 comments on commit 63116d3

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