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 = { let attr = {
// allow(unreachable_code) // allow(unreachable_code)
let allow = { let allow = {
let allow_ident = self.str_to_ident("allow"); let allow_ident = Ident::from_str("allow").with_span_pos(e.span);
let uc_ident = self.str_to_ident("unreachable_code"); let uc_ident = Ident::from_str("unreachable_code").with_span_pos(e.span);
let uc_meta_item = attr::mk_spanned_word_item(e.span, uc_ident); let uc_nested = attr::mk_nested_word_item(uc_ident);
let uc_nested = NestedMetaItemKind::MetaItem(uc_meta_item); attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
let uc_spanned = respan(e.span, uc_nested);
attr::mk_spanned_list_item(e.span, allow_ident, vec![uc_spanned])
}; };
attr::mk_spanned_attr_outer(e.span, attr::mk_attr_id(), allow) 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 { impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
name, ident,
node, node,
span span
}); });

View file

@ -221,7 +221,7 @@ impl<'a> LintLevelsBuilder<'a> {
continue continue
} }
}; };
let name = word.name(); let name = word.ident.name;
match store.check_lint_name(&name.as_str()) { match store.check_lint_name(&name.as_str()) {
CheckLintNameResult::Ok(ids) => { CheckLintNameResult::Ok(ids) => {
let src = LintSource::Node(name, li.span); 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() { } else if meta_item.is_meta_item_list() {
let msg = format!( let msg = format!(
"invalid predicate in --cfg command line argument: `{}`", "invalid predicate in --cfg command line argument: `{}`",
meta_item.name() meta_item.ident
); );
early_error(ErrorOutputType::default(), &msg) early_error(ErrorOutputType::default(), &msg)
} }
(meta_item.name(), meta_item.value_str()) (meta_item.ident.name, meta_item.value_str())
}) })
.collect::<ast::CrateConfig>() .collect::<ast::CrateConfig>()
} }

View file

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

View file

@ -1045,7 +1045,7 @@ impl RustcDefaultCalls {
let mut cfgs = Vec::new(); let mut cfgs = Vec::new();
for &(name, ref value) in sess.parse_sess.config.iter() { for &(name, ref value) in sess.parse_sess.config.iter() {
let gated_cfg = GatedCfg::gate(&ast::MetaItem { let gated_cfg = GatedCfg::gate(&ast::MetaItem {
name, ident: ast::Ident::with_empty_ctxt(name),
node: ast::MetaItemKind::Word, node: ast::MetaItemKind::Word,
span: DUMMY_SP, 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() { for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() { match list_item.word() {
Some(word) if value.is_none() => 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`) // FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.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 { } else {
sess.span_err( sess.span_err(
item.span, item.span,
&format!("{} attribute requires a path", item.name())); &format!("{} attribute requires a path", item.ident));
return None; return None;
} }
} }

View file

@ -717,7 +717,7 @@ impl<'a> Resolver<'a> {
match attr.meta_item_list() { match attr.meta_item_list() {
Some(names) => for attr in names { Some(names) => for attr in names {
if let Some(word) = attr.word() { if let Some(word) = attr.word() {
imports.imports.push((word.name(), attr.span())); imports.imports.push((word.ident.name, attr.span()));
} else { } else {
span_err!(self.session, attr.span(), E0466, "bad macro import"); 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() { if let Some(names) = attr.meta_item_list() {
for attr in names { for attr in names {
if let Some(word) = attr.word() { if let Some(word) = attr.word() {
imports.reexports.push((word.name(), attr.span())); imports.reexports.push((word.ident.name, attr.span()));
} else { } else {
bad_macro_reexport(self, attr.span()); 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 mut segments = path.segments.into_vec();
let last = segments.pop().unwrap(); 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( segments.push(hir::PathSegment::new(
real_name.unwrap_or(last.name), 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 /// If the content is not properly formatted, it will return an error indicating what and where
/// the error is. /// the error is.
pub fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> { pub fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> {
let name = cfg.name(); let name = cfg.ident.name;
match cfg.node { match cfg.node {
MetaItemKind::Word => Ok(Cfg::Cfg(name, None)), MetaItemKind::Word => Ok(Cfg::Cfg(name, None)),
MetaItemKind::NameValue(ref lit) => match lit.node { MetaItemKind::NameValue(ref lit) => match lit.node {
@ -562,14 +562,14 @@ mod test {
fn test_parse_ok() { fn test_parse_ok() {
with_globals(|| { with_globals(|| {
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
}; };
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all"))); assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Str( node: MetaItemKind::NameValue(dummy_spanned(LitKind::Str(
Symbol::intern("done"), Symbol::intern("done"),
StrStyle::Cooked, StrStyle::Cooked,
@ -579,15 +579,15 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done"))); assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -597,15 +597,15 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b"))); assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") & word_cfg("b")));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("any"), ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -615,10 +615,10 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") | word_cfg("b"))); assert_eq!(Cfg::parse(&mi), Ok(word_cfg("a") | word_cfg("b")));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("not"), ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -628,26 +628,26 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(!word_cfg("a"))); assert_eq!(Cfg::parse(&mi), Ok(!word_cfg("a")));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("not"), ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("any"), ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("c"), ident: Ident::from_str("c"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -663,20 +663,20 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(!(word_cfg("a") | (word_cfg("b") & word_cfg("c"))))); assert_eq!(Cfg::parse(&mi), Ok(!(word_cfg("a") | (word_cfg("b") & word_cfg("c")))));
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("c"), ident: Ident::from_str("c"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -691,22 +691,22 @@ mod test {
fn test_parse_err() { fn test_parse_err() {
with_globals(|| { with_globals(|| {
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("foo"), ident: Ident::from_str("foo"),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Bool(false))), node: MetaItemKind::NameValue(dummy_spanned(LitKind::Bool(false))),
span: DUMMY_SP, span: DUMMY_SP,
}; };
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("not"), ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -716,17 +716,17 @@ mod test {
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("not"), ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![]), node: MetaItemKind::List(vec![]),
span: DUMMY_SP, span: DUMMY_SP,
}; };
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("foo"), ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -736,15 +736,15 @@ mod test {
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("all"), ident: Ident::from_str("all"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"), ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]), node: MetaItemKind::List(vec![]),
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("b"), ident: Ident::from_str("b"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -754,15 +754,15 @@ mod test {
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("any"), ident: Ident::from_str("any"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("a"), ident: Ident::from_str("a"),
node: MetaItemKind::Word, node: MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
})), })),
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"), ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]), node: MetaItemKind::List(vec![]),
span: DUMMY_SP, span: DUMMY_SP,
})), })),
@ -772,10 +772,10 @@ mod test {
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
let mi = MetaItem { let mi = MetaItem {
name: Symbol::intern("not"), ident: Ident::from_str("not"),
node: MetaItemKind::List(vec![ node: MetaItemKind::List(vec![
dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem { dummy_spanned(NestedMetaItemKind::MetaItem(MetaItem {
name: Symbol::intern("foo"), ident: Ident::from_str("foo"),
node: MetaItemKind::List(vec![]), node: MetaItemKind::List(vec![]),
span: DUMMY_SP, span: DUMMY_SP,
})), })),

View file

@ -21,9 +21,9 @@ pub use self::Visibility::*;
use syntax; use syntax;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast::{self, AttrStyle}; use syntax::ast::{self, AttrStyle, Ident};
use syntax::attr; use syntax::attr;
use syntax::codemap::Spanned; use syntax::codemap::{dummy_spanned, Spanned};
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::keywords; use syntax::symbol::keywords;
@ -840,7 +840,8 @@ impl Attributes {
for attr in attrs.lists("target_feature") { for attr in attrs.lists("target_feature") {
if attr.check_name("enable") { if attr.check_name("enable") {
if let Some(feat) = attr.value_str() { 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) { if let Ok(feat_cfg) = Cfg::parse(&meta) {
cfg &= feat_cfg; 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> { fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::hygiene::Mark; 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 path = ast::Path { segments: vec![segment], span: DUMMY_SP };
let mut resolver = cx.resolver.borrow_mut(); let mut resolver = cx.resolver.borrow_mut();
let mark = Mark::root(); let mark = Mark::root();
@ -1158,7 +1159,7 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
} else { } else {
None 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) Some(*def)
} else { } else {
None 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> { fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
let name = attr.name(); let name = attr.ident.name;
if attr.is_word() { if attr.is_word() {
Some(format!("{}", name)) Some(format!("{}", name))

View file

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

View file

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

View file

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

View file

@ -149,8 +149,7 @@ impl<'a> Parser<'a> {
}; };
Ok(if let Some(meta) = meta { Ok(if let Some(meta) = meta {
self.bump(); self.bump();
(ast::Path::from_ident(ast::Ident::with_empty_ctxt(meta.name).with_span_pos(meta.span)), (ast::Path::from_ident(meta.ident), meta.node.tokens(meta.span))
meta.node.tokens(meta.span))
} else { } else {
(self.parse_path(PathStyle::Mod)?, self.parse_tokens()) (self.parse_path(PathStyle::Mod)?, self.parse_tokens())
}) })
@ -228,7 +227,7 @@ impl<'a> Parser<'a> {
let lo = self.span; let lo = self.span;
let ident = self.parse_ident()?; let ident = self.parse_ident()?;
let node = self.parse_meta_item_kind()?; 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> { 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 { let meta_ident = match self.token {
token::Interpolated(ref nt) => match nt.0 { token::Interpolated(ref nt) => match nt.0 {
token::NtMeta(ref meta) => match meta.node { 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,
}, },
_ => None, _ => None,
@ -1966,7 +1966,7 @@ impl<'a> Parser<'a> {
}; };
if let Some(ident) = meta_ident { if let Some(ident) = meta_ident {
self.bump(); 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) self.parse_path(style)
} }

View file

@ -26,7 +26,7 @@ use print::pp::{self, Breaks};
use print::pp::Breaks::{Consistent, Inconsistent}; use print::pp::Breaks::{Consistent, Inconsistent};
use ptr::P; use ptr::P;
use std_inject; use std_inject;
use symbol::{Symbol, keywords}; use symbol::keywords;
use syntax_pos::{DUMMY_SP, FileName}; use syntax_pos::{DUMMY_SP, FileName};
use tokenstream::{self, TokenStream, TokenTree}; 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. // of the feature gate, so we fake them up here.
// #![feature(prelude_import)] // #![feature(prelude_import)]
let prelude_import_meta = attr::mk_list_word_item(Symbol::intern("prelude_import")); let pi_nested = attr::mk_nested_word_item(ast::Ident::from_str("prelude_import"));
let list = attr::mk_list_item(Symbol::intern("feature"), vec![prelude_import_meta]); 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); let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
s.print_attribute(&fake_attr)?; s.print_attribute(&fake_attr)?;
// #![no_std] // #![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); let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
s.print_attribute(&fake_attr)?; s.print_attribute(&fake_attr)?;
} }
@ -768,15 +768,15 @@ pub trait PrintState<'a> {
self.ibox(INDENT_UNIT)?; self.ibox(INDENT_UNIT)?;
match item.node { match item.node {
ast::MetaItemKind::Word => { ast::MetaItemKind::Word => {
self.writer().word(&item.name.as_str())?; self.writer().word(&item.ident.name.as_str())?;
} }
ast::MetaItemKind::NameValue(ref value) => { ast::MetaItemKind::NameValue(ref value) => {
self.word_space(&item.name.as_str())?; self.word_space(&item.ident.name.as_str())?;
self.word_space("=")?; self.word_space("=")?;
self.print_literal(value)?; self.print_literal(value)?;
} }
ast::MetaItemKind::List(ref items) => { ast::MetaItemKind::List(ref items) => {
self.writer().word(&item.name.as_str())?; self.writer().word(&item.ident.name.as_str())?;
self.popen()?; self.popen()?;
self.commasep(Consistent, self.commasep(Consistent,
&items[..], &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 { krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(DUMMY_SP, attrs: vec![attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(), 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), vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)), node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
ident: ast::Ident::from_str(name), ident: ast::Ident::from_str(name),

View file

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

View file

@ -47,7 +47,7 @@ impl Ident {
} }
pub fn without_first_quote(self) -> 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 { 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 { impl fmt::Debug for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let is_gensymed = with_interner(|interner| interner.is_gensymed(*self)); 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 { let copy_name = match mi.node {
ast::MetaItemKind::List(ref xs) => { ast::MetaItemKind::List(ref xs) => {
if let Some(word) = xs[0].word() { if let Some(word) = xs[0].word() {
ast::Ident::with_empty_ctxt(word.name()) word.ident
} else { } else {
cx.span_err(mi.span, "Expected word"); cx.span_err(mi.span, "Expected word");
return; return;

View file

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