1
Fork 0

Use Ident instead of Name in MetaItem

This commit is contained in:
Vadim Petrochenkov 2018-03-24 21:17:27 +03:00
parent 303298b1d5
commit 3a30bad6de
27 changed files with 138 additions and 164 deletions

View file

@ -3503,12 +3503,10 @@ impl<'a> LoweringContext<'a> {
let attr = {
// allow(unreachable_code)
let allow = {
let allow_ident = self.str_to_ident("allow");
let uc_ident = self.str_to_ident("unreachable_code");
let uc_meta_item = attr::mk_spanned_word_item(e.span, uc_ident);
let uc_nested = NestedMetaItemKind::MetaItem(uc_meta_item);
let uc_spanned = respan(e.span, uc_nested);
attr::mk_spanned_list_item(e.span, allow_ident, vec![uc_spanned])
let allow_ident = Ident::from_str("allow").with_span_pos(e.span);
let uc_ident = Ident::from_str("unreachable_code").with_span_pos(e.span);
let uc_nested = attr::mk_nested_word_item(uc_ident);
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
};
attr::mk_spanned_attr_outer(e.span, attr::mk_attr_id(), allow)
};

View file

@ -341,7 +341,7 @@ impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItemKind {
});
impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
name,
ident,
node,
span
});

View file

@ -221,7 +221,7 @@ impl<'a> LintLevelsBuilder<'a> {
continue
}
};
let name = word.name();
let name = word.ident.name;
match store.check_lint_name(&name.as_str()) {
CheckLintNameResult::Ok(ids) => {
let src = LintSource::Node(name, li.span);

View file

@ -1683,12 +1683,12 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
} else if meta_item.is_meta_item_list() {
let msg = format!(
"invalid predicate in --cfg command line argument: `{}`",
meta_item.name()
meta_item.ident
);
early_error(ErrorOutputType::default(), &msg)
}
(meta_item.name(), meta_item.value_str())
(meta_item.ident.name, meta_item.value_str())
})
.collect::<ast::CrateConfig>()
}

View file

@ -190,7 +190,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
for command in self.subcommands.iter().chain(Some(self)).rev() {
if let Some(ref condition) = command.condition {
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
options.contains(&(c.name().as_str().to_string(),
options.contains(&(c.ident.name.as_str().to_string(),
match c.value_str().map(|s| s.as_str().to_string()) {
Some(s) => Some(s),
None => None

View file

@ -1045,7 +1045,7 @@ impl RustcDefaultCalls {
let mut cfgs = Vec::new();
for &(name, ref value) in sess.parse_sess.config.iter() {
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
name,
ident: ast::Ident::with_empty_ctxt(name),
node: ast::MetaItemKind::Word,
span: DUMMY_SP,
});

View file

@ -110,7 +110,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() {
Some(word) if value.is_none() =>
value = Some(word.name().clone()),
value = Some(word.ident.name),
_ =>
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.node),

View file

@ -152,7 +152,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.name()));
&format!("{} attribute requires a path", item.ident));
return None;
}
}

View file

@ -717,7 +717,7 @@ impl<'a> Resolver<'a> {
match attr.meta_item_list() {
Some(names) => for attr in names {
if let Some(word) = attr.word() {
imports.imports.push((word.name(), attr.span()));
imports.imports.push((word.ident.name, attr.span()));
} else {
span_err!(self.session, attr.span(), E0466, "bad macro import");
}
@ -731,7 +731,7 @@ impl<'a> Resolver<'a> {
if let Some(names) = attr.meta_item_list() {
for attr in names {
if let Some(word) = attr.word() {
imports.reexports.push((word.name(), attr.span()));
imports.reexports.push((word.ident.name, attr.span()));
} else {
bad_macro_reexport(self, attr.span());
}

View file

@ -171,7 +171,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
let mut segments = path.segments.into_vec();
let last = segments.pop().unwrap();
let real_name = name.as_ref().map(|n| Symbol::from(n.as_str()));
let real_name = name.map(|name| Symbol::intern(&name));
segments.push(hir::PathSegment::new(
real_name.unwrap_or(last.name),

View file

@ -67,7 +67,7 @@ impl Cfg {
/// If the content is not properly formatted, it will return an error indicating what and where
/// the error is.
pub fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
let name = cfg.name();
let name = cfg.ident.name;
match cfg.node {
MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
MetaItemKind::NameValue(ref lit) => match lit.node {
@ -562,14 +562,14 @@ mod test {
fn test_parse_ok() {
with_globals(|| {
let mi = MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::Word,
span: DUMMY_SP,
};
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
let mi = MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Str(
Symbol::intern("done"),
StrStyle::Cooked,
@ -579,15 +579,15 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
let mi = MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -597,15 +597,15 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b")));
let mi = MetaItem {
name: Symbol::intern("any"),
ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -615,10 +615,10 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") | word_cfg("b")));
let mi = MetaItem {
name: Symbol::intern("not"),
ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -628,26 +628,26 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(!word_cfg("a")));
let mi = MetaItem {
name: Symbol::intern("not"),
ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("any"),
ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("c"),
ident: Ident::from_str("c"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -663,20 +663,20 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(!(word_cfg("a") | (word_cfg("b") & word_cfg("c")))));
let mi = MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("c"),
ident: Ident::from_str("c"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -691,22 +691,22 @@ mod test {
fn test_parse_err() {
with_globals(|| {
let mi = MetaItem {
name: Symbol::intern("foo"),
ident: Ident::from_str("foo"),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Bool(false))),
span: DUMMY_SP,
};
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("not"),
ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -716,17 +716,17 @@ mod test {
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("not"),
ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![]),
span: DUMMY_SP,
};
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("foo"),
ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -736,15 +736,15 @@ mod test {
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("all"),
ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"),
ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]),
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"),
ident: Ident::from_str("b"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
@ -754,15 +754,15 @@ mod test {
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("any"),
ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"),
ident: Ident::from_str("a"),
node: MetaItemKind::Word,
span: DUMMY_SP,
})),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"),
ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]),
span: DUMMY_SP,
})),
@ -772,10 +772,10 @@ mod test {
assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem {
name: Symbol::intern("not"),
ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"),
ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]),
span: DUMMY_SP,
})),

View file

@ -21,9 +21,9 @@ pub use self::Visibility::*;
use syntax;
use syntax::abi::Abi;
use syntax::ast::{self, AttrStyle};
use syntax::ast::{self, AttrStyle, Ident};
use syntax::attr;
use syntax::codemap::Spanned;
use syntax::codemap::{dummy_spanned, Spanned};
use syntax::feature_gate::UnstableFeatures;
use syntax::ptr::P;
use syntax::symbol::keywords;
@ -840,7 +840,8 @@ impl Attributes {
for attr in attrs.lists("target_feature") {
if attr.check_name("enable") {
if let Some(feat) = attr.value_str() {
let meta = attr::mk_name_value_item_str("target_feature".into(), feat);
let meta = attr::mk_name_value_item_str(Ident::from_str("target_feature"),
dummy_spanned(feat));
if let Ok(feat_cfg) = Cfg::parse(&meta) {
cfg &= feat_cfg;
}
@ -1146,7 +1147,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::hygiene::Mark;
let segment = ast::PathSegment::from_ident(ast::Ident::from_str(path_str));
let segment = ast::PathSegment::from_ident(Ident::from_str(path_str));
let path = ast::Path { segments: vec![segment], span: DUMMY_SP };
let mut resolver = cx.resolver.borrow_mut();
let mark = Mark::root();
@ -1158,7 +1159,7 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
} else {
None
}
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
} else if let Some(def) = resolver.all_macros.get(&Symbol::intern(path_str)) {
Some(*def)
} else {
None

View file

@ -2966,7 +2966,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
let name = attr.name();
let name = attr.ident.name;
if attr.is_word() {
Some(format!("{}", name))

View file

@ -477,7 +477,7 @@ pub enum NestedMetaItemKind {
/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct MetaItem {
pub name: Name,
pub ident: Ident,
pub node: MetaItemKind,
pub span: Span,
}

View file

@ -19,7 +19,7 @@ use ast::{AttrId, Attribute, Name, Ident};
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind};
use codemap::{Spanned, respan, dummy_spanned};
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::Span;
use errors::Handler;
use feature_gate::{Features, GatedCfg};
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
@ -137,7 +137,7 @@ impl NestedMetaItem {
/// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
/// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem
pub fn name(&self) -> Option<Name> {
self.meta_item().and_then(|meta_item| Some(meta_item.name()))
self.meta_item().and_then(|meta_item| Some(meta_item.ident.name))
}
/// Gets the string value if self is a MetaItem and the MetaItem is a
@ -154,7 +154,7 @@ impl NestedMetaItem {
if meta_item_list.len() == 1 {
let nested_item = &meta_item_list[0];
if nested_item.is_literal() {
Some((meta_item.name(), nested_item.literal().unwrap()))
Some((meta_item.ident.name, nested_item.literal().unwrap()))
} else {
None
}
@ -250,10 +250,6 @@ impl Attribute {
}
impl MetaItem {
pub fn name(&self) -> Name {
self.name
}
pub fn value_str(&self) -> Option<Symbol> {
match self.node {
MetaItemKind::NameValue(ref v) => {
@ -283,7 +279,7 @@ impl MetaItem {
pub fn span(&self) -> Span { self.span }
pub fn check_name(&self, name: &str) -> bool {
self.name() == name
self.ident.name == name
}
pub fn is_value_str(&self) -> bool {
@ -300,8 +296,8 @@ impl Attribute {
pub fn meta(&self) -> Option<MetaItem> {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
name: match self.path.segments.len() {
1 => self.path.segments[0].ident.name,
ident: match self.path.segments.len() {
1 => self.path.segments[0].ident,
_ => return None,
},
node: if let Some(node) = MetaItemKind::from_tokens(&mut tokens) {
@ -353,7 +349,7 @@ impl Attribute {
}
Ok(MetaItem {
name: self.path.segments.last().unwrap().ident.name,
ident: self.path.segments.last().unwrap().ident,
node: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
span: self.span,
})
@ -368,8 +364,8 @@ impl Attribute {
if self.is_sugared_doc {
let comment = self.value_str().unwrap();
let meta = mk_name_value_item_str(
Symbol::intern("doc"),
Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())));
Ident::from_str("doc"),
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
let mut attr = if self.style == ast::AttrStyle::Outer {
mk_attr_outer(self.span, self.id, meta)
} else {
@ -385,37 +381,24 @@ impl Attribute {
/* Constructors */
pub fn mk_name_value_item_str(name: Name, value: Symbol) -> MetaItem {
let value_lit = dummy_spanned(LitKind::Str(value, ast::StrStyle::Cooked));
mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
let value = respan(value.span, LitKind::Str(value.node, ast::StrStyle::Cooked));
mk_name_value_item(ident.span.to(value.span), ident, value)
}
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> MetaItem {
mk_spanned_name_value_item(DUMMY_SP, name, value)
pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem {
MetaItem { ident, span, node: MetaItemKind::NameValue(value) }
}
pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
mk_spanned_list_item(DUMMY_SP, name, items)
pub fn mk_list_item(span: Span, ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { ident, span, node: MetaItemKind::List(items) }
}
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(ident: Ident) -> MetaItem {
MetaItem { ident, span: ident.span, node: MetaItemKind::Word }
}
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) -> MetaItem {
MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) }
}
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) -> MetaItem {
MetaItem { span: sp, name: name, node: MetaItemKind::Word }
pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
respan(ident.span, NestedMetaItemKind::MetaItem(mk_word_item(ident)))
}
pub fn mk_attr_id() -> AttrId {
@ -436,11 +419,10 @@ pub fn mk_attr_inner(span: Span, id: AttrId, item: MetaItem) -> Attribute {
/// Returns an inner attribute with the given value and span.
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
let ident = ast::Ident::with_empty_ctxt(item.name).with_span_pos(item.span);
Attribute {
id,
style: ast::AttrStyle::Inner,
path: ast::Path::from_ident(ident),
path: ast::Path::from_ident(item.ident),
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
@ -455,11 +437,10 @@ pub fn mk_attr_outer(span: Span, id: AttrId, item: MetaItem) -> Attribute {
/// Returns an outer attribute with the given value and span.
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
let ident = ast::Ident::with_empty_ctxt(item.name).with_span_pos(item.span);
Attribute {
id,
style: ast::AttrStyle::Outer,
path: ast::Path::from_ident(ident),
path: ast::Path::from_ident(item.ident),
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
@ -472,7 +453,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
Attribute {
id,
style,
path: ast::Path::from_ident(ast::Ident::from_str("doc").with_span_pos(span)),
path: ast::Path::from_ident(Ident::from_str("doc").with_span_pos(span)),
tokens: MetaItemKind::NameValue(lit).tokens(span),
is_sugared_doc: true,
span,
@ -508,7 +489,7 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool {
item.check_name("feature") &&
item.meta_item_list().map(|list| {
list.iter().any(|mi| {
mi.word().map(|w| w.name() == feature_name)
mi.word().map(|w| w.ident.name == feature_name)
.unwrap_or(false)
})
}).unwrap_or(false)
@ -581,7 +562,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
if let (Some(feats), Some(gated_cfg)) = (features, GatedCfg::gate(cfg)) {
gated_cfg.check_and_emit(sess, feats);
}
sess.config.contains(&(cfg.name(), cfg.value_str()))
sess.config.contains(&(cfg.ident.name, cfg.value_str()))
})
}
@ -602,7 +583,7 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
// The unwraps below may look dangerous, but we've already asserted
// that they won't fail with the loop above.
match &*cfg.name.as_str() {
match &*cfg.ident.name.as_str() {
"any" => mis.iter().any(|mi| {
eval_condition(mi.meta_item().unwrap(), sess, eval)
}),
@ -695,7 +676,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let meta = meta.as_ref().unwrap();
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()));
handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.ident.name));
return false
}
if let Some(v) = meta.value_str() {
@ -714,14 +695,14 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
)+
for meta in metas {
if let Some(mi) = meta.meta_item() {
match &*mi.name().as_str() {
match &*mi.ident.name.as_str() {
$(
stringify!($name)
=> if !get(mi, &mut $name) { continue 'outer },
)+
_ => {
handle_errors(diagnostic, mi.span,
AttrError::UnknownMetaItem(mi.name()));
AttrError::UnknownMetaItem(mi.ident.name));
continue 'outer
}
}
@ -733,7 +714,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
}
}
match &*meta.name.as_str() {
match &*meta.ident.name.as_str() {
"rustc_deprecated" => {
if rustc_depr.is_some() {
span_err!(diagnostic, item_sp, E0540,
@ -788,13 +769,13 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let mut issue = None;
for meta in metas {
if let Some(mi) = meta.meta_item() {
match &*mi.name().as_str() {
match &*mi.ident.name.as_str() {
"feature" => if !get(mi, &mut feature) { continue 'outer },
"reason" => if !get(mi, &mut reason) { continue 'outer },
"issue" => if !get(mi, &mut issue) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
AttrError::UnknownMetaItem(mi.ident.name));
continue 'outer
}
}
@ -844,12 +825,12 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let mut since = None;
for meta in metas {
if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
match &*mi.name().as_str() {
match &*mi.ident.name.as_str() {
"feature" => if !get(mi, &mut feature) { continue 'outer },
"since" => if !get(mi, &mut since) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
AttrError::UnknownMetaItem(mi.ident.name));
continue 'outer
}
}
@ -936,7 +917,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
depr = if let Some(metas) = attr.meta_item_list() {
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() {
handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()));
handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.ident.name));
return false
}
if let Some(v) = meta.value_str() {
@ -952,12 +933,12 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
let mut note = None;
for meta in metas {
if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
match &*mi.name().as_str() {
match &*mi.ident.name.as_str() {
"since" => if !get(mi, &mut since) { continue 'outer },
"note" => if !get(mi, &mut note) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
AttrError::UnknownMetaItem(mi.ident.name));
continue 'outer
}
}
@ -1009,7 +990,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
let mut recognised = false;
if let Some(mi) = item.word() {
let word = &*mi.name().as_str();
let word = &*mi.ident.name.as_str();
let hint = match word {
"C" => Some(ReprC),
"packed" => Some(ReprPacked),
@ -1108,18 +1089,17 @@ impl IntType {
impl MetaItem {
fn tokens(&self) -> TokenStream {
let ident = TokenTree::Token(self.span,
Token::from_ast_ident(Ident::with_empty_ctxt(self.name)));
let ident = TokenTree::Token(self.span, Token::from_ast_ident(self.ident));
TokenStream::concat(vec![ident.into(), self.node.tokens(self.span)])
}
fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem>
where I: Iterator<Item = TokenTree>,
{
let (span, name) = match tokens.next() {
Some(TokenTree::Token(span, Token::Ident(ident, _))) => (span, ident.name),
let (span, ident) = match tokens.next() {
Some(TokenTree::Token(span, Token::Ident(ident, _))) => (span, ident),
Some(TokenTree::Token(_, Token::Interpolated(ref nt))) => match nt.0 {
token::Nonterminal::NtIdent(ident, _) => (ident.span, ident.name),
token::Nonterminal::NtIdent(ident, _) => (ident.span, ident),
token::Nonterminal::NtMeta(ref meta) => return Some(meta.clone()),
_ => return None,
},
@ -1132,7 +1112,7 @@ impl MetaItem {
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(span.hi()),
_ => span.hi(),
};
Some(MetaItem { name, node, span: span.with_hi(hi) })
Some(MetaItem { ident, node, span: span.with_hi(hi) })
}
}

View file

@ -1129,21 +1129,22 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem {
attr::mk_spanned_word_item(sp, w)
attr::mk_word_item(Ident::with_empty_ctxt(w).with_span_pos(sp))
}
fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem {
respan(sp, ast::NestedMetaItemKind::MetaItem(attr::mk_spanned_word_item(sp, w)))
attr::mk_nested_word_item(Ident::with_empty_ctxt(w).with_span_pos(sp))
}
fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
-> ast::MetaItem {
attr::mk_spanned_list_item(sp, name, mis)
attr::mk_list_item(sp, Ident::with_empty_ctxt(name).with_span_pos(sp), mis)
}
fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
-> ast::MetaItem {
attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
attr::mk_name_value_item(sp, Ident::with_empty_ctxt(name).with_span_pos(sp),
respan(sp, value))
}
fn item_use(&self, sp: Span,

View file

@ -733,7 +733,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
name: keywords::Invalid.name(),
ident: keywords::Invalid.ident(),
span: DUMMY_SP,
node: ast::MetaItemKind::Word,
};
@ -1279,15 +1279,16 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
let include_info = vec![
dummy_spanned(ast::NestedMetaItemKind::MetaItem(
attr::mk_name_value_item_str("file".into(),
file))),
attr::mk_name_value_item_str(Ident::from_str("file"),
dummy_spanned(file)))),
dummy_spanned(ast::NestedMetaItemKind::MetaItem(
attr::mk_name_value_item_str("contents".into(),
(&*src).into()))),
attr::mk_name_value_item_str(Ident::from_str("contents"),
dummy_spanned(Symbol::intern(&src))))),
];
items.push(dummy_spanned(ast::NestedMetaItemKind::MetaItem(
attr::mk_list_item("include".into(), include_info))));
let include_ident = Ident::from_str("include");
let item = attr::mk_list_item(DUMMY_SP, include_ident, include_info);
items.push(dummy_spanned(ast::NestedMetaItemKind::MetaItem(item)));
}
Err(_) => {
self.cx.span_err(at.span,
@ -1300,7 +1301,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}
}
let meta = attr::mk_list_item("doc".into(), items);
let meta = attr::mk_list_item(DUMMY_SP, Ident::from_str("doc"), items);
match at.style {
ast::AttrStyle::Inner =>
Some(attr::mk_spanned_attr_inner(at.span, at.id, meta)),

View file

@ -1054,7 +1054,7 @@ pub struct GatedCfg {
impl GatedCfg {
pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
let name = cfg.name().as_str();
let name = cfg.ident.name.as_str();
GATED_CFGS.iter()
.position(|info| info.0 == name)
.map(|idx| {
@ -1811,7 +1811,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
for mi in list {
let name = if let Some(word) = mi.word() {
word.name()
word.ident.name
} else {
span_err!(span_handler, mi.span, E0556,
"malformed feature, expected just one word");

View file

@ -543,7 +543,7 @@ pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
pub fn noop_fold_meta_item<T: Folder>(mi: MetaItem, fld: &mut T) -> MetaItem {
MetaItem {
name: mi.name,
ident: mi.ident,
node: match mi.node {
MetaItemKind::Word => MetaItemKind::Word,
MetaItemKind::List(mis) => {

View file

@ -149,8 +149,7 @@ impl<'a> Parser<'a> {
};
Ok(if let Some(meta) = meta {
self.bump();
(ast::Path::from_ident(ast::Ident::with_empty_ctxt(meta.name).with_span_pos(meta.span)),
meta.node.tokens(meta.span))
(ast::Path::from_ident(meta.ident), meta.node.tokens(meta.span))
} else {
(self.parse_path(PathStyle::Mod)?, self.parse_tokens())
})
@ -228,7 +227,7 @@ impl<'a> Parser<'a> {
let lo = self.span;
let ident = self.parse_ident()?;
let node = self.parse_meta_item_kind()?;
Ok(ast::MetaItem { name: ident.name, node: node, span: lo.to(self.prev_span) })
Ok(ast::MetaItem { ident, node: node, span: lo.to(self.prev_span) })
}
pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {

View file

@ -1957,7 +1957,7 @@ impl<'a> Parser<'a> {
let meta_ident = match self.token {
token::Interpolated(ref nt) => match nt.0 {
token::NtMeta(ref meta) => match meta.node {
ast::MetaItemKind::Word => Some(ast::Ident::with_empty_ctxt(meta.name)),
ast::MetaItemKind::Word => Some(meta.ident),
_ => None,
},
_ => None,
@ -1966,7 +1966,7 @@ impl<'a> Parser<'a> {
};
if let Some(ident) = meta_ident {
self.bump();
return Ok(ast::Path::from_ident(ident.with_span_pos(self.prev_span)));
return Ok(ast::Path::from_ident(ident));
}
self.parse_path(style)
}

View file

@ -26,7 +26,7 @@ use print::pp::{self, Breaks};
use print::pp::Breaks::{Consistent, Inconsistent};
use ptr::P;
use std_inject;
use symbol::{Symbol, keywords};
use symbol::keywords;
use syntax_pos::{DUMMY_SP, FileName};
use tokenstream::{self, TokenStream, TokenTree};
@ -101,13 +101,13 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
// of the feature gate, so we fake them up here.
// #![feature(prelude_import)]
let prelude_import_meta = attr::mk_list_word_item(Symbol::intern("prelude_import"));
let list = attr::mk_list_item(Symbol::intern("feature"), vec![prelude_import_meta]);
let pi_nested = attr::mk_nested_word_item(ast::Ident::from_str("prelude_import"));
let list = attr::mk_list_item(DUMMY_SP, ast::Ident::from_str("feature"), vec![pi_nested]);
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
s.print_attribute(&fake_attr)?;
// #![no_std]
let no_std_meta = attr::mk_word_item(Symbol::intern("no_std"));
let no_std_meta = attr::mk_word_item(ast::Ident::from_str("no_std"));
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
s.print_attribute(&fake_attr)?;
}
@ -768,15 +768,15 @@ pub trait PrintState<'a> {
self.ibox(INDENT_UNIT)?;
match item.node {
ast::MetaItemKind::Word => {
self.writer().word(&item.name.as_str())?;
self.writer().word(&item.ident.name.as_str())?;
}
ast::MetaItemKind::NameValue(ref value) => {
self.word_space(&item.name.as_str())?;
self.word_space(&item.ident.name.as_str())?;
self.word_space("=")?;
self.print_literal(value)?;
}
ast::MetaItemKind::List(ref items) => {
self.writer().word(&item.name.as_str())?;
self.writer().word(&item.ident.name.as_str())?;
self.popen()?;
self.commasep(Consistent,
&items[..],

View file

@ -57,7 +57,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>
krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(),
attr::mk_word_item(Symbol::intern("macro_use")))],
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
ident: ast::Ident::from_str(name),

View file

@ -195,10 +195,10 @@ impl fold::Folder for EntryPointCleaner {
EntryPointType::MainAttr |
EntryPointType::Start =>
folded.map(|ast::Item {id, ident, attrs, node, vis, span, tokens}| {
let allow_str = Symbol::intern("allow");
let dead_code_str = Symbol::intern("dead_code");
let word_vec = vec![attr::mk_list_word_item(dead_code_str)];
let allow_dead_code_item = attr::mk_list_item(allow_str, word_vec);
let allow_ident = Ident::from_str("allow");
let dc_nested = attr::mk_nested_word_item(Ident::from_str("dead_code"));
let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
vec![dc_nested]);
let allow_dead_code = attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(),
allow_dead_code_item);

View file

@ -47,7 +47,7 @@ impl Ident {
}
pub fn without_first_quote(self) -> Ident {
Ident::new(Symbol::from(self.name.as_str().trim_left_matches('\'')), self.span)
Ident::new(Symbol::intern(self.name.as_str().trim_left_matches('\'')), self.span)
}
pub fn modern(self) -> Ident {
@ -147,12 +147,6 @@ impl Symbol {
}
}
impl<'a> From<&'a str> for Symbol {
fn from(string: &'a str) -> Symbol {
Symbol::intern(string)
}
}
impl fmt::Debug for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));

View file

@ -117,7 +117,7 @@ fn expand_duplicate(cx: &mut ExtCtxt,
let copy_name = match mi.node {
ast::MetaItemKind::List(ref xs) => {
if let Some(word) = xs[0].word() {
ast::Ident::with_empty_ctxt(word.name())
word.ident
} else {
cx.span_err(mi.span, "Expected word");
return;

View file

@ -112,7 +112,7 @@ fn expand_duplicate(cx: &mut ExtCtxt,
let copy_name = match mi.node {
ast::MetaItemKind::List(ref xs) => {
if let Some(word) = xs[0].word() {
ast::Ident::with_empty_ctxt(word.name())
word.ident
} else {
cx.span_err(mi.span, "Expected word");
return;