Skip to content

Commit

Permalink
Rename MetaItem::ident to MetaItem::path
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Mar 3, 2019
1 parent 37e7ae1 commit 0dd5ff1
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItemKind {
});

impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
ident,
path,
node,
span
});
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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
Expand Down Expand Up @@ -260,7 +260,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");
}
}
Expand All @@ -269,15 +269,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;
}
Expand All @@ -286,7 +286,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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {

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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,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,
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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(
Expand All @@ -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)),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,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)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
18 changes: 9 additions & 9 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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() {
Expand Down Expand Up @@ -246,7 +246,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
}
Expand Down Expand Up @@ -329,7 +329,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"]
),
);
Expand Down Expand Up @@ -401,7 +401,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
Expand Down Expand Up @@ -496,8 +496,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(..) => {
Expand Down Expand Up @@ -563,7 +563,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
}
}
Expand Down Expand Up @@ -618,7 +618,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
}
Expand Down Expand Up @@ -656,7 +656,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
Expand Down
32 changes: 16 additions & 16 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 })
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -1340,4 +1340,3 @@ mod tests {
})
}
}

6 changes: 3 additions & 3 deletions src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ||
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,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,
Expand Down
Loading

0 comments on commit 0dd5ff1

Please sign in to comment.