1
Fork 0

Refactor MetaItemKind to use Names instead of InternedStrings.

This commit is contained in:
Jeffrey Seyfried 2016-11-15 04:34:52 +00:00
parent ff4994235a
commit a2626410d7
33 changed files with 187 additions and 206 deletions

View file

@ -64,7 +64,7 @@ impl<'a> CheckAttrVisitor<'a> {
None => continue, None => continue,
}; };
let (message, label) = match &*name { let (message, label) = match &*name.as_str() {
"C" => { "C" => {
conflicting_reprs += 1; conflicting_reprs += 1;
if target != Target::Struct && if target != Target::Struct &&
@ -120,7 +120,7 @@ impl<'a> CheckAttrVisitor<'a> {
} }
fn check_attribute(&self, attr: &ast::Attribute, target: Target) { fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
let name: &str = &attr.name(); let name: &str = &attr.name().as_str();
match name { match name {
"inline" => self.check_inline(attr, target), "inline" => self.check_inline(attr, target),
"repr" => self.check_repr(attr, target), "repr" => self.check_repr(attr, target),

View file

@ -40,7 +40,6 @@ use std::default::Default as StdDefault;
use std::mem; use std::mem;
use std::fmt; use std::fmt;
use syntax::attr; use syntax::attr;
use syntax::parse::token::InternedString;
use syntax::ast; use syntax::ast;
use syntax_pos::{MultiSpan, Span}; use syntax_pos::{MultiSpan, Span};
use errors::{self, Diagnostic, DiagnosticBuilder}; use errors::{self, Diagnostic, DiagnosticBuilder};
@ -384,8 +383,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $ps:ident, $($args:expr),*) => ({
/// Parse the lint attributes into a vector, with `Err`s for malformed lint /// Parse the lint attributes into a vector, with `Err`s for malformed lint
/// attributes. Writing this as an iterator is an enormous mess. /// attributes. Writing this as an iterator is an enormous mess.
// See also the hir version just below. // See also the hir version just below.
pub fn gather_attrs(attrs: &[ast::Attribute]) pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec<Result<(ast::Name, Level, Span), Span>> {
-> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec![]; let mut out = vec![];
for attr in attrs { for attr in attrs {
let r = gather_attr(attr); let r = gather_attr(attr);
@ -394,11 +392,10 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
out out
} }
pub fn gather_attr(attr: &ast::Attribute) pub fn gather_attr(attr: &ast::Attribute) -> Vec<Result<(ast::Name, Level, Span), Span>> {
-> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec![]; let mut out = vec![];
let level = match Level::from_str(&attr.name()) { let level = match Level::from_str(&attr.name().as_str()) {
None => return out, None => return out,
Some(lvl) => lvl, Some(lvl) => lvl,
}; };
@ -414,9 +411,7 @@ pub fn gather_attr(attr: &ast::Attribute)
}; };
for li in metas { for li in metas {
out.push(li.word().map_or(Err(li.span), |word| { out.push(li.word().map_or(Err(li.span), |word| Ok((word.name(), level, word.span))));
Ok((word.name().clone(), level, word.span))
}));
} }
out out
@ -629,10 +624,10 @@ pub trait LintContext: Sized {
continue; continue;
} }
Ok((lint_name, level, span)) => { Ok((lint_name, level, span)) => {
match self.lints().find_lint(&lint_name, &self.sess(), Some(span)) { match self.lints().find_lint(&lint_name.as_str(), &self.sess(), Some(span)) {
Ok(lint_id) => vec![(lint_id, level, span)], Ok(lint_id) => vec![(lint_id, level, span)],
Err(FindLintError::NotFound) => { Err(FindLintError::NotFound) => {
match self.lints().lint_groups.get(&lint_name[..]) { match self.lints().lint_groups.get(&*lint_name.as_str()) {
Some(&(ref v, _)) => v.iter() Some(&(ref v, _)) => v.iter()
.map(|lint_id: &LintId| .map(|lint_id: &LintId|
(*lint_id, level, span)) (*lint_id, level, span))
@ -1193,8 +1188,7 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
continue; continue;
} }
Ok((lint_name, _, span)) => { Ok((lint_name, _, span)) => {
match check_lint_name(&cx.lints, match check_lint_name(&cx.lints, &lint_name.as_str()) {
&lint_name[..]) {
CheckLintNameResult::Ok => (), CheckLintNameResult::Ok => (),
CheckLintNameResult::Warning(ref msg) => { CheckLintNameResult::Warning(ref msg) => {
cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS, cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,

View file

@ -309,8 +309,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
let dead_code = lint::builtin::DEAD_CODE.name_lower(); let dead_code = lint::builtin::DEAD_CODE.name_lower();
for attr in lint::gather_attrs(attrs) { for attr in lint::gather_attrs(attrs) {
match attr { match attr {
Ok((ref name, lint::Allow, _)) Ok((name, lint::Allow, _)) if name == &*dead_code => return true,
if &name[..] == dead_code => return true,
_ => (), _ => (),
} }
} }

View file

@ -26,7 +26,7 @@ use middle::cstore;
use syntax::ast::{self, IntTy, UintTy}; use syntax::ast::{self, IntTy, UintTy};
use syntax::attr; use syntax::attr;
use syntax::parse; use syntax::parse::{self, token};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
@ -947,41 +947,40 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
let mk = attr::mk_name_value_item_str; let mk = attr::mk_name_value_item_str;
let mut ret = vec![ // Target bindings. let mut ret = vec![ // Target bindings.
mk(InternedString::new("target_os"), intern(os)), mk(token::intern("target_os"), intern(os)),
mk(InternedString::new("target_family"), fam.clone()), mk(token::intern("target_family"), fam.clone()),
mk(InternedString::new("target_arch"), intern(arch)), mk(token::intern("target_arch"), intern(arch)),
mk(InternedString::new("target_endian"), intern(end)), mk(token::intern("target_endian"), intern(end)),
mk(InternedString::new("target_pointer_width"), intern(wordsz)), mk(token::intern("target_pointer_width"), intern(wordsz)),
mk(InternedString::new("target_env"), intern(env)), mk(token::intern("target_env"), intern(env)),
mk(InternedString::new("target_vendor"), intern(vendor)), mk(token::intern("target_vendor"), intern(vendor)),
]; ];
match &fam[..] { match &fam[..] {
"windows" | "unix" => ret.push(attr::mk_word_item(fam)), "windows" | "unix" => ret.push(attr::mk_word_item(token::intern(&fam))),
_ => (), _ => (),
} }
if sess.target.target.options.has_elf_tls { if sess.target.target.options.has_elf_tls {
ret.push(attr::mk_word_item(InternedString::new("target_thread_local"))); ret.push(attr::mk_word_item(token::intern("target_thread_local")));
} }
for &i in &[8, 16, 32, 64, 128] { for &i in &[8, 16, 32, 64, 128] {
if i <= max_atomic_width { if i <= max_atomic_width {
let s = i.to_string(); let s = i.to_string();
ret.push(mk(InternedString::new("target_has_atomic"), intern(&s))); ret.push(mk(token::intern("target_has_atomic"), intern(&s)));
if &s == wordsz { if &s == wordsz {
ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr"))); ret.push(mk(token::intern("target_has_atomic"), intern("ptr")));
} }
} }
} }
if sess.opts.debug_assertions { if sess.opts.debug_assertions {
ret.push(attr::mk_word_item(InternedString::new("debug_assertions"))); ret.push(attr::mk_word_item(token::intern("debug_assertions")));
} }
if sess.opts.crate_types.contains(&CrateTypeProcMacro) { if sess.opts.crate_types.contains(&CrateTypeProcMacro) {
ret.push(attr::mk_word_item(InternedString::new("proc_macro"))); ret.push(attr::mk_word_item(token::intern("proc_macro")));
} }
return ret; return ret;
} }
pub fn append_configuration(cfg: &mut ast::CrateConfig, pub fn append_configuration(cfg: &mut ast::CrateConfig, name: ast::Name) {
name: InternedString) {
if !cfg.iter().any(|mi| mi.name() == name) { if !cfg.iter().any(|mi| mi.name() == name) {
cfg.push(attr::mk_word_item(name)) cfg.push(attr::mk_word_item(name))
} }
@ -995,7 +994,7 @@ pub fn build_configuration(sess: &Session,
let default_cfg = default_configuration(sess); let default_cfg = default_configuration(sess);
// If the user wants a test runner, then add the test cfg // If the user wants a test runner, then add the test cfg
if sess.opts.test { if sess.opts.test {
append_configuration(&mut user_cfg, InternedString::new("test")) append_configuration(&mut user_cfg, token::intern("test"))
} }
let mut v = user_cfg.into_iter().collect::<Vec<_>>(); let mut v = user_cfg.into_iter().collect::<Vec<_>>();
v.extend_from_slice(&default_cfg[..]); v.extend_from_slice(&default_cfg[..]);

View file

@ -13,8 +13,7 @@ use llvm::LLVMRustHasFeature;
use rustc::session::Session; use rustc::session::Session;
use rustc_trans::back::write::create_target_machine; use rustc_trans::back::write::create_target_machine;
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
use syntax::parse::token::InternedString; use syntax::parse::token::{self, intern_and_get_ident as intern};
use syntax::parse::token::intern_and_get_ident as intern;
use libc::c_char; use libc::c_char;
// WARNING: the features must be known to LLVM or the feature // WARNING: the features must be known to LLVM or the feature
@ -41,11 +40,11 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
_ => &[], _ => &[],
}; };
let tf = InternedString::new("target_feature"); let tf = token::intern("target_feature");
for feat in whitelist { for feat in whitelist {
assert_eq!(feat.chars().last(), Some('\0')); assert_eq!(feat.chars().last(), Some('\0'));
if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } { if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1]))) cfg.push(attr::mk_name_value_item_str(tf, intern(&feat[..feat.len() - 1])))
} }
} }

View file

@ -57,7 +57,6 @@ use std::env;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use syntax::ast; use syntax::ast;
use syntax::parse::token::InternedString;
use syntax_pos::Span; use syntax_pos::Span;
use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED}; use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
@ -97,7 +96,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
} }
type Sources = Vec<(Span, DefId, DepNode<DefId>)>; type Sources = Vec<(Span, DefId, DepNode<DefId>)>;
type Targets = Vec<(Span, InternedString, ast::NodeId, DepNode<DefId>)>; type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode<DefId>)>;
struct IfThisChanged<'a, 'tcx:'a> { struct IfThisChanged<'a, 'tcx:'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
@ -106,7 +105,7 @@ struct IfThisChanged<'a, 'tcx:'a> {
} }
impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
fn argument(&self, attr: &ast::Attribute) -> Option<InternedString> { fn argument(&self, attr: &ast::Attribute) -> Option<ast::Name> {
let mut value = None; let mut value = None;
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() {
@ -127,8 +126,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
let dep_node_interned = self.argument(attr); let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned { let dep_node = match dep_node_interned {
None => DepNode::Hir(def_id), None => DepNode::Hir(def_id),
Some(ref n) => { Some(n) => {
match DepNode::from_label_string(&n[..], def_id) { match DepNode::from_label_string(&n.as_str(), def_id) {
Ok(n) => n, Ok(n) => n,
Err(()) => { Err(()) => {
self.tcx.sess.span_fatal( self.tcx.sess.span_fatal(
@ -142,8 +141,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) { } else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
let dep_node_interned = self.argument(attr); let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned { let dep_node = match dep_node_interned {
Some(ref n) => { Some(n) => {
match DepNode::from_label_string(&n[..], def_id) { match DepNode::from_label_string(&n.as_str(), def_id) {
Ok(n) => n, Ok(n) => n,
Err(()) => { Err(()) => {
self.tcx.sess.span_fatal( self.tcx.sess.span_fatal(
@ -159,7 +158,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
} }
}; };
self.then_this_would_need.push((attr.span, self.then_this_would_need.push((attr.span,
dep_node_interned.clone().unwrap(), dep_node_interned.unwrap(),
node_id, node_id,
dep_node)); dep_node));
} }

View file

@ -875,16 +875,19 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
// ignoring span information, it doesn't matter here // ignoring span information, it doesn't matter here
self.hash_discriminant(&meta_item.node); self.hash_discriminant(&meta_item.node);
match meta_item.node { match meta_item.node {
ast::MetaItemKind::Word(ref s) => { ast::MetaItemKind::Word(s) => {
let s = &*s.as_str();
s.len().hash(self.st); s.len().hash(self.st);
s.hash(self.st); s.hash(self.st);
} }
ast::MetaItemKind::NameValue(ref s, ref lit) => { ast::MetaItemKind::NameValue(s, ref lit) => {
let s = &*s.as_str();
s.len().hash(self.st); s.len().hash(self.st);
s.hash(self.st); s.hash(self.st);
lit.node.hash(self.st); lit.node.hash(self.st);
} }
ast::MetaItemKind::List(ref s, ref items) => { ast::MetaItemKind::List(s, ref items) => {
let s = &*s.as_str();
s.len().hash(self.st); s.len().hash(self.st);
s.hash(self.st); s.hash(self.st);
// Sort subitems so the hash does not depend on their order // Sort subitems so the hash does not depend on their order
@ -916,7 +919,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
for i in indices { for i in indices {
let attr = &attributes[i]; let attr = &attributes[i];
if !attr.is_sugared_doc && if !attr.is_sugared_doc &&
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) { !IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
SawAttribute(attr.style).hash(self.st); SawAttribute(attr.style).hash(self.st);
self.hash_meta_item(&*attr.value); self.hash_meta_item(&*attr.value);
} }

View file

@ -772,9 +772,9 @@ impl LintPass for DeprecatedAttr {
impl EarlyLintPass for DeprecatedAttr { impl EarlyLintPass for DeprecatedAttr {
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) { fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
let name = &*attr.name(); let name = attr.name();
for &&(n, _, ref g) in &self.depr_attrs { for &&(n, _, ref g) in &self.depr_attrs {
if n == name { if name == n {
if let &AttributeGate::Gated(Stability::Deprecated(link), if let &AttributeGate::Gated(Stability::Deprecated(link),
ref name, ref name,
ref reason, ref reason,

View file

@ -274,7 +274,7 @@ impl LateLintPass for UnusedAttributes {
// Has a plugin registered this attribute as one which must be used at // Has a plugin registered this attribute as one which must be used at
// the crate level? // the crate level?
let plugin_crate = plugin_attributes.iter() let plugin_crate = plugin_attributes.iter()
.find(|&&(ref x, t)| &*attr.name() == x && AttributeType::CrateLevel == t) .find(|&&(ref x, t)| attr.name() == &**x && AttributeType::CrateLevel == t)
.is_some(); .is_some();
if known_crate || plugin_crate { if known_crate || plugin_crate {
let msg = match attr.style { let msg = match attr.style {

View file

@ -37,7 +37,7 @@ use syntax::abi::Abi;
use syntax::attr; use syntax::attr;
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax::feature_gate::{self, GateIssue}; use syntax::feature_gate::{self, GateIssue};
use syntax::parse::token::{InternedString, intern}; use syntax::parse::token::{self, InternedString};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
use log; use log;
@ -582,11 +582,11 @@ impl<'a> CrateLoader<'a> {
trait_name: &str, trait_name: &str,
expand: fn(TokenStream) -> TokenStream, expand: fn(TokenStream) -> TokenStream,
attributes: &[&'static str]) { attributes: &[&'static str]) {
let attrs = attributes.iter().map(|s| InternedString::new(s)).collect(); let attrs = attributes.iter().cloned().map(token::intern).collect();
let derive = SyntaxExtension::CustomDerive( let derive = SyntaxExtension::CustomDerive(
Box::new(CustomDerive::new(expand, attrs)) Box::new(CustomDerive::new(expand, attrs))
); );
self.0.push((intern(trait_name), Rc::new(derive))); self.0.push((token::intern(trait_name), Rc::new(derive)));
} }
} }

View file

@ -69,9 +69,9 @@ pub fn load_plugins(sess: &Session,
for plugin in plugins { for plugin in plugins {
// plugins must have a name and can't be key = value // plugins must have a name and can't be key = value
match plugin.name() { match plugin.name() {
Some(ref name) if !plugin.is_value_str() => { Some(name) if !plugin.is_value_str() => {
let args = plugin.meta_item_list().map(ToOwned::to_owned); let args = plugin.meta_item_list().map(ToOwned::to_owned);
loader.load_plugin(plugin.span, name, args.unwrap_or_default()); loader.load_plugin(plugin.span, &name.as_str(), args.unwrap_or_default());
}, },
_ => call_malformed_plugin_attribute(sess, attr.span), _ => call_malformed_plugin_attribute(sess, attr.span),
} }

View file

@ -31,7 +31,6 @@ use std::rc::Rc;
use syntax::ast::Name; use syntax::ast::Name;
use syntax::attr; use syntax::attr;
use syntax::parse::token;
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind}; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind}; use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
@ -632,7 +631,7 @@ impl<'b> Resolver<'b> {
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((token::intern(&word.name()), attr.span())); imports.imports.push((word.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");
} }
@ -646,7 +645,7 @@ impl<'b> Resolver<'b> {
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((token::intern(&word.name()), attr.span())); imports.reexports.push((word.name(), attr.span()));
} else { } else {
bad_macro_reexport(self, attr.span()); bad_macro_reexport(self, attr.span());
} }

View file

@ -27,7 +27,6 @@ use syntax::ext::expand::Expansion;
use syntax::ext::hygiene::Mark; use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules; use syntax::ext::tt::macro_rules;
use syntax::fold::Folder; use syntax::fold::Folder;
use syntax::parse::token::intern;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::util::lev_distance::find_best_match_for_name; use syntax::util::lev_distance::find_best_match_for_name;
use syntax::visit::Visitor; use syntax::visit::Visitor;
@ -207,8 +206,7 @@ impl<'a> base::Resolver for Resolver<'a> {
fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> { fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
for i in 0..attrs.len() { for i in 0..attrs.len() {
let name = intern(&attrs[i].name()); match self.builtin_macros.get(&attrs[i].name()).cloned() {
match self.builtin_macros.get(&name).cloned() {
Some(binding) => match *self.get_macro(binding) { Some(binding) => match *self.get_macro(binding) {
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => { MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
return Some(attrs.remove(i)) return Some(attrs.remove(i))

View file

@ -54,7 +54,7 @@ use std::path::{Path, PathBuf};
use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID}; use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID};
use syntax::parse::lexer::comments::strip_doc_comment_decoration; use syntax::parse::lexer::comments::strip_doc_comment_decoration;
use syntax::parse::token::{self, keywords, InternedString}; use syntax::parse::token::{self, keywords};
use syntax::visit::{self, Visitor}; use syntax::visit::{self, Visitor};
use syntax::print::pprust::{ty_to_string, arg_to_string}; use syntax::print::pprust::{ty_to_string, arg_to_string};
use syntax::codemap::MacroAttribute; use syntax::codemap::MacroAttribute;
@ -728,7 +728,7 @@ impl Visitor for PathCollector {
} }
fn docs_for_attrs(attrs: &[Attribute]) -> String { fn docs_for_attrs(attrs: &[Attribute]) -> String {
let doc = InternedString::new("doc"); let doc = token::intern("doc");
let mut result = String::new(); let mut result = String::new();
for attr in attrs { for attr in attrs {

View file

@ -75,6 +75,12 @@ impl Decodable for Name {
} }
} }
impl<'a> ::std::cmp::PartialEq<&'a str> for Name {
fn eq(&self, other: &&str) -> bool {
*self.as_str() == **other
}
}
impl Ident { impl Ident {
pub const fn with_empty_ctxt(name: Name) -> Ident { pub const fn with_empty_ctxt(name: Name) -> Ident {
Ident { name: name, ctxt: SyntaxContext::empty() } Ident { name: name, ctxt: SyntaxContext::empty() }
@ -518,15 +524,15 @@ pub enum MetaItemKind {
/// Word meta item. /// Word meta item.
/// ///
/// E.g. `test` as in `#[test]` /// E.g. `test` as in `#[test]`
Word(InternedString), Word(Name),
/// List meta item. /// List meta item.
/// ///
/// E.g. `derive(..)` as in `#[derive(..)]` /// E.g. `derive(..)` as in `#[derive(..)]`
List(InternedString, Vec<NestedMetaItem>), List(Name, Vec<NestedMetaItem>),
/// Name value meta item. /// Name value meta item.
/// ///
/// E.g. `feature = "foo"` as in `#[feature = "foo"]` /// E.g. `feature = "foo"` as in `#[feature = "foo"]`
NameValue(InternedString, Lit), NameValue(Name, Lit),
} }
// can't be derived because the MetaItemKind::List requires an unordered comparison // can't be derived because the MetaItemKind::List requires an unordered comparison

View file

@ -15,7 +15,7 @@ pub use self::ReprAttr::*;
pub use self::IntType::*; pub use self::IntType::*;
use ast; use ast;
use ast::{AttrId, Attribute}; use ast::{AttrId, Attribute, Name};
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use ast::{Lit, Expr, Item, Local, Stmt, StmtKind}; use ast::{Lit, Expr, Item, Local, Stmt, StmtKind};
use codemap::{respan, spanned, dummy_spanned, mk_sp}; use codemap::{respan, spanned, dummy_spanned, mk_sp};
@ -37,8 +37,8 @@ thread_local! {
} }
enum AttrError { enum AttrError {
MultipleItem(InternedString), MultipleItem(Name),
UnknownMetaItem(InternedString), UnknownMetaItem(Name),
MissingSince, MissingSince,
MissingFeature, MissingFeature,
MultipleStabilityLevels, MultipleStabilityLevels,
@ -134,7 +134,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<InternedString> { 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.name()))
} }
@ -186,14 +186,14 @@ impl NestedMetaItem {
impl Attribute { impl Attribute {
pub fn check_name(&self, name: &str) -> bool { pub fn check_name(&self, name: &str) -> bool {
let matches = name == &self.name()[..]; let matches = self.name() == name;
if matches { if matches {
mark_used(self); mark_used(self);
} }
matches matches
} }
pub fn name(&self) -> InternedString { self.meta().name() } pub fn name(&self) -> Name { self.meta().name() }
pub fn value_str(&self) -> Option<InternedString> { pub fn value_str(&self) -> Option<InternedString> {
self.meta().value_str() self.meta().value_str()
@ -218,11 +218,11 @@ impl Attribute {
} }
impl MetaItem { impl MetaItem {
pub fn name(&self) -> InternedString { pub fn name(&self) -> Name {
match self.node { match self.node {
MetaItemKind::Word(ref n) => (*n).clone(), MetaItemKind::Word(n) => n,
MetaItemKind::NameValue(ref n, _) => (*n).clone(), MetaItemKind::NameValue(n, _) => n,
MetaItemKind::List(ref n, _) => (*n).clone(), MetaItemKind::List(n, _) => n,
} }
} }
@ -255,7 +255,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 {
name == &self.name()[..] self.name() == name
} }
pub fn is_value_str(&self) -> bool { pub fn is_value_str(&self) -> bool {
@ -282,7 +282,7 @@ 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(
InternedString::new("doc"), token::intern("doc"),
token::intern_and_get_ident(&strip_doc_comment_decoration( token::intern_and_get_ident(&strip_doc_comment_decoration(
&comment))); &comment)));
if self.style == ast::AttrStyle::Outer { if self.style == ast::AttrStyle::Outer {
@ -298,40 +298,36 @@ impl Attribute {
/* Constructors */ /* Constructors */
pub fn mk_name_value_item_str(name: InternedString, value: InternedString) pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P<MetaItem> {
-> P<MetaItem> {
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked)); let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
mk_spanned_name_value_item(DUMMY_SP, name, value_lit) mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
} }
pub fn mk_name_value_item(name: InternedString, value: ast::Lit) pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P<MetaItem> {
-> P<MetaItem> {
mk_spanned_name_value_item(DUMMY_SP, name, value) mk_spanned_name_value_item(DUMMY_SP, name, value)
} }
pub fn mk_list_item(name: InternedString, items: Vec<NestedMetaItem>) -> P<MetaItem> { pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
mk_spanned_list_item(DUMMY_SP, name, items) mk_spanned_list_item(DUMMY_SP, name, items)
} }
pub fn mk_list_word_item(name: InternedString) -> ast::NestedMetaItem { pub fn mk_list_word_item(name: Name) -> ast::NestedMetaItem {
dummy_spanned(NestedMetaItemKind::MetaItem(mk_spanned_word_item(DUMMY_SP, name))) dummy_spanned(NestedMetaItemKind::MetaItem(mk_spanned_word_item(DUMMY_SP, name)))
} }
pub fn mk_word_item(name: InternedString) -> P<MetaItem> { pub fn mk_word_item(name: Name) -> P<MetaItem> {
mk_spanned_word_item(DUMMY_SP, name) mk_spanned_word_item(DUMMY_SP, name)
} }
pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit) pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
-> P<MetaItem> {
P(respan(sp, MetaItemKind::NameValue(name, value))) P(respan(sp, MetaItemKind::NameValue(name, value)))
} }
pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec<NestedMetaItem>) pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
-> P<MetaItem> {
P(respan(sp, MetaItemKind::List(name, items))) P(respan(sp, MetaItemKind::List(name, items)))
} }
pub fn mk_spanned_word_item(sp: Span, name: InternedString) -> P<MetaItem> { pub fn mk_spanned_word_item(sp: Span, name: Name) -> P<MetaItem> {
P(respan(sp, MetaItemKind::Word(name))) P(respan(sp, MetaItemKind::Word(name)))
} }
@ -398,7 +394,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
Attribute { Attribute {
id: id, id: id,
style: style, style: style,
value: P(spanned(lo, hi, MetaItemKind::NameValue(InternedString::new("doc"), lit))), value: P(spanned(lo, hi, MetaItemKind::NameValue(token::intern("doc"), lit))),
is_sugared_doc: true, is_sugared_doc: true,
span: mk_sp(lo, hi), span: mk_sp(lo, hi),
} }
@ -490,11 +486,11 @@ pub enum InlineAttr {
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr { pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
attrs.iter().fold(InlineAttr::None, |ia,attr| { attrs.iter().fold(InlineAttr::None, |ia,attr| {
match attr.value.node { match attr.value.node {
MetaItemKind::Word(ref n) if n == "inline" => { MetaItemKind::Word(n) if n == "inline" => {
mark_used(attr); mark_used(attr);
InlineAttr::Hint InlineAttr::Hint
} }
MetaItemKind::List(ref n, ref items) if n == "inline" => { MetaItemKind::List(n, ref items) if n == "inline" => {
mark_used(attr); mark_used(attr);
if items.len() != 1 { if items.len() != 1 {
diagnostic.map(|d|{ span_err!(d, attr.span, E0534, "expected one argument"); }); diagnostic.map(|d|{ span_err!(d, attr.span, E0534, "expected one argument"); });
@ -537,7 +533,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
// 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 &pred[..] { match &*pred.as_str() {
"any" => mis.iter().any(|mi| { "any" => mis.iter().any(|mi| {
cfg_matches(mi.meta_item().unwrap(), sess, features) cfg_matches(mi.meta_item().unwrap(), sess, features)
}), }),
@ -611,7 +607,6 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
'outer: for attr in attrs_iter { 'outer: for attr in attrs_iter {
let tag = attr.name(); let tag = attr.name();
let tag = &*tag;
if tag != "rustc_deprecated" && tag != "unstable" && tag != "stable" { if tag != "rustc_deprecated" && tag != "unstable" && tag != "stable" {
continue // not a stability level continue // not a stability level
} }
@ -633,7 +628,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
} }
}; };
match tag { match &*tag.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,
@ -645,7 +640,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let mut reason = None; let mut reason = 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() { match &*mi.name().as_str() {
"since" => if !get(mi, &mut since) { continue 'outer }, "since" => if !get(mi, &mut since) { continue 'outer },
"reason" => if !get(mi, &mut reason) { continue 'outer }, "reason" => if !get(mi, &mut reason) { continue 'outer },
_ => { _ => {
@ -688,7 +683,7 @@ 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() { match &*mi.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 },
@ -743,7 +738,7 @@ 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() { match &*mi.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 },
_ => { _ => {
@ -839,7 +834,7 @@ 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() { match &*mi.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 },
_ => { _ => {
@ -897,7 +892,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> { pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
let mut acc = Vec::new(); let mut acc = Vec::new();
match attr.value.node { match attr.value.node {
ast::MetaItemKind::List(ref s, ref items) if s == "repr" => { ast::MetaItemKind::List(s, ref items) if s == "repr" => {
mark_used(attr); mark_used(attr);
for item in items { for item in items {
if !item.is_meta_item() { if !item.is_meta_item() {
@ -906,7 +901,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
} }
if let Some(mi) = item.word() { if let Some(mi) = item.word() {
let word = &*mi.name(); let word = &*mi.name().as_str();
let hint = match word { let hint = match word {
// Can't use "extern" because it's not a lexical identifier. // Can't use "extern" because it's not a lexical identifier.
"C" => Some(ReprExtern), "C" => Some(ReprExtern),

View file

@ -277,18 +277,18 @@ pub trait AstBuilder {
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute; fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem>; fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem>;
fn meta_list_item_word(&self, sp: Span, w: InternedString) -> ast::NestedMetaItem; fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem;
fn meta_list(&self, fn meta_list(&self,
sp: Span, sp: Span,
name: InternedString, name: ast::Name,
mis: Vec<ast::NestedMetaItem> ) mis: Vec<ast::NestedMetaItem> )
-> P<ast::MetaItem>; -> P<ast::MetaItem>;
fn meta_name_value(&self, fn meta_name_value(&self,
sp: Span, sp: Span,
name: InternedString, name: ast::Name,
value: ast::LitKind) value: ast::LitKind)
-> P<ast::MetaItem>; -> P<ast::MetaItem>;
@ -1150,20 +1150,20 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi) attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi)
} }
fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem> { fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem> {
attr::mk_spanned_word_item(sp, w) attr::mk_spanned_word_item(sp, w)
} }
fn meta_list_item_word(&self, sp: Span, w: InternedString) -> 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))) respan(sp, ast::NestedMetaItemKind::MetaItem(attr::mk_spanned_word_item(sp, w)))
} }
fn meta_list(&self, sp: Span, name: InternedString, mis: Vec<ast::NestedMetaItem>) fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
-> P<ast::MetaItem> { -> P<ast::MetaItem> {
attr::mk_spanned_list_item(sp, name, mis) attr::mk_spanned_list_item(sp, name, mis)
} }
fn meta_name_value(&self, sp: Span, name: InternedString, value: ast::LitKind) fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
-> P<ast::MetaItem> { -> P<ast::MetaItem> {
attr::mk_spanned_name_value_item(sp, name, respan(sp, value)) attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
} }

View file

@ -23,7 +23,7 @@ use fold;
use fold::*; use fold::*;
use parse::{ParseSess, PResult, lexer}; use parse::{ParseSess, PResult, lexer};
use parse::parser::Parser; use parse::parser::Parser;
use parse::token::{self, intern, keywords}; use parse::token::{self, keywords};
use print::pprust; use print::pprust;
use ptr::P; use ptr::P;
use std_inject; use std_inject;
@ -246,7 +246,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.cx.resolver.resolve_macro(scope, &mac.node.path, force) self.cx.resolver.resolve_macro(scope, &mac.node.path, force)
} }
InvocationKind::Attr { ref attr, .. } => { InvocationKind::Attr { ref attr, .. } => {
let ident = ast::Ident::with_empty_ctxt(intern(&*attr.name())); let ident = ast::Ident::with_empty_ctxt(attr.name());
let path = ast::Path::from_ident(attr.span, ident); let path = ast::Path::from_ident(attr.span, ident);
self.cx.resolver.resolve_macro(scope, &path, force) self.cx.resolver.resolve_macro(scope, &path, force)
} }
@ -341,7 +341,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}; };
attr::mark_used(&attr); attr::mark_used(&attr);
let name = intern(&attr.name()); let name = attr.name();
self.cx.bt_push(ExpnInfo { self.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {

View file

@ -757,7 +757,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(); let name = &*cfg.name().as_str();
GATED_CFGS.iter() GATED_CFGS.iter()
.position(|info| info.0 == name) .position(|info| info.0 == name)
.map(|idx| { .map(|idx| {
@ -804,7 +804,7 @@ macro_rules! gate_feature {
impl<'a> Context<'a> { impl<'a> Context<'a> {
fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) { fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
debug!("check_attribute(attr = {:?})", attr); debug!("check_attribute(attr = {:?})", attr);
let name = &*attr.name(); let name = &*attr.name().as_str();
for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES { for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES {
if n == name { if n == name {
if let &Gated(_, ref name, ref desc, ref has_feature) = gateage { if let &Gated(_, ref name, ref desc, ref has_feature) = gateage {
@ -1351,7 +1351,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> F
Some(list) => { Some(list) => {
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.name().as_str()
} 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

@ -227,22 +227,21 @@ impl<'a> Parser<'a> {
let lo = self.span.lo; let lo = self.span.lo;
let ident = self.parse_ident()?; let ident = self.parse_ident()?;
let name = self.id_to_interned_str(ident);
match self.token { match self.token {
token::Eq => { token::Eq => {
self.bump(); self.bump();
let lit = self.parse_unsuffixed_lit()?; let lit = self.parse_unsuffixed_lit()?;
let hi = self.prev_span.hi; let hi = self.prev_span.hi;
Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(name, lit)))) Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(ident.name, lit))))
} }
token::OpenDelim(token::Paren) => { token::OpenDelim(token::Paren) => {
let inner_items = self.parse_meta_seq()?; let inner_items = self.parse_meta_seq()?;
let hi = self.prev_span.hi; let hi = self.prev_span.hi;
Ok(P(spanned(lo, hi, ast::MetaItemKind::List(name, inner_items)))) Ok(P(spanned(lo, hi, ast::MetaItemKind::List(ident.name, inner_items))))
} }
_ => { _ => {
let hi = self.prev_span.hi; let hi = self.prev_span.hi;
Ok(P(spanned(lo, hi, ast::MetaItemKind::Word(name)))) Ok(P(spanned(lo, hi, ast::MetaItemKind::Word(ident.name))))
} }
} }
} }

View file

@ -19,7 +19,7 @@ use attr;
use codemap::{self, CodeMap}; use codemap::{self, CodeMap};
use syntax_pos::{self, BytePos}; use syntax_pos::{self, BytePos};
use errors; use errors;
use parse::token::{self, keywords, BinOpToken, Token, InternedString}; use parse::token::{self, keywords, BinOpToken, Token};
use parse::lexer::comments; use parse::lexer::comments;
use parse; use parse;
use print::pp::{self, break_offset, word, space, zerobreak, hardbreak}; use print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
@ -119,14 +119,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(InternedString::new("prelude_import")); let prelude_import_meta = attr::mk_list_word_item(token::intern("prelude_import"));
let list = attr::mk_list_item(InternedString::new("feature"), let list = attr::mk_list_item(token::intern("feature"), vec![prelude_import_meta]);
vec![prelude_import_meta]);
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list); let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list);
try!(s.print_attribute(&fake_attr)); try!(s.print_attribute(&fake_attr));
// #![no_std] // #![no_std]
let no_std_meta = attr::mk_word_item(InternedString::new("no_std")); let no_std_meta = attr::mk_word_item(token::intern("no_std"));
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), no_std_meta); let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), no_std_meta);
try!(s.print_attribute(&fake_attr)); try!(s.print_attribute(&fake_attr));
} }
@ -779,15 +778,15 @@ pub trait PrintState<'a> {
try!(self.ibox(INDENT_UNIT)); try!(self.ibox(INDENT_UNIT));
match item.node { match item.node {
ast::MetaItemKind::Word(ref name) => { ast::MetaItemKind::Word(ref name) => {
try!(word(self.writer(), &name)); try!(word(self.writer(), &name.as_str()));
} }
ast::MetaItemKind::NameValue(ref name, ref value) => { ast::MetaItemKind::NameValue(ref name, ref value) => {
try!(self.word_space(&name[..])); try!(self.word_space(&name.as_str()));
try!(self.word_space("=")); try!(self.word_space("="));
try!(self.print_literal(value)); try!(self.print_literal(value));
} }
ast::MetaItemKind::List(ref name, ref items) => { ast::MetaItemKind::List(ref name, ref items) => {
try!(word(self.writer(), &name)); try!(word(self.writer(), &name.as_str()));
try!(self.popen()); try!(self.popen());
try!(self.commasep(Consistent, try!(self.commasep(Consistent,
&items[..], &items[..],

View file

@ -12,7 +12,7 @@ use ast;
use attr; use attr;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
use codemap::{self, ExpnInfo, NameAndSpan, MacroAttribute}; use codemap::{self, ExpnInfo, NameAndSpan, MacroAttribute};
use parse::token::{intern, InternedString, keywords}; use parse::token::{intern, keywords};
use parse::{token, ParseSess}; use parse::{token, ParseSess};
use ptr::P; use ptr::P;
@ -57,7 +57,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
krate.module.items.insert(0, P(ast::Item { krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(attr::mk_attr_id(), attrs: vec![attr::mk_attr_outer(attr::mk_attr_id(),
attr::mk_word_item(InternedString::new("macro_use")))], attr::mk_word_item(token::intern("macro_use")))],
vis: ast::Visibility::Inherited, vis: ast::Visibility::Inherited,
node: ast::ItemKind::ExternCrate(Some(crate_name)), node: ast::ItemKind::ExternCrate(Some(crate_name)),
ident: token::str_to_ident(name), ident: token::str_to_ident(name),
@ -70,7 +70,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
attrs: vec![ast::Attribute { attrs: vec![ast::Attribute {
style: ast::AttrStyle::Outer, style: ast::AttrStyle::Outer,
value: P(ast::MetaItem { value: P(ast::MetaItem {
node: ast::MetaItemKind::Word(token::intern_and_get_ident("prelude_import")), node: ast::MetaItemKind::Word(token::intern("prelude_import")),
span: span, span: span,
}), }),
id: attr::mk_attr_id(), id: attr::mk_attr_id(),

View file

@ -191,8 +191,8 @@ impl fold::Folder for EntryPointCleaner {
EntryPointType::MainAttr | EntryPointType::MainAttr |
EntryPointType::Start => EntryPointType::Start =>
folded.map(|ast::Item {id, ident, attrs, node, vis, span}| { folded.map(|ast::Item {id, ident, attrs, node, vis, span}| {
let allow_str = InternedString::new("allow"); let allow_str = token::intern("allow");
let dead_code_str = InternedString::new("dead_code"); let dead_code_str = token::intern("dead_code");
let word_vec = vec![attr::mk_list_word_item(dead_code_str)]; 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_dead_code_item = attr::mk_list_item(allow_str, word_vec);
let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(), let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(),
@ -229,8 +229,8 @@ fn mk_reexport_mod(cx: &mut TestCtxt, parent: ast::NodeId, tests: Vec<ast::Ident
// Generate imports with `#[allow(private_in_public)]` to work around issue #36768. // Generate imports with `#[allow(private_in_public)]` to work around issue #36768.
let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list( let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list(
DUMMY_SP, DUMMY_SP,
InternedString::new("allow"), token::intern("allow"),
vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, InternedString::new("private_in_public"))], vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, token::intern("private_in_public"))],
)); ));
let items = tests.into_iter().map(|r| { let items = tests.into_iter().map(|r| {
cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public, cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public,
@ -496,7 +496,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
vec![tests_ident_expr]); vec![tests_ident_expr]);
let call_test_main = ecx.stmt_expr(call_test_main); let call_test_main = ecx.stmt_expr(call_test_main);
// #![main] // #![main]
let main_meta = ecx.meta_word(sp, token::intern_and_get_ident("main")); let main_meta = ecx.meta_word(sp, token::intern("main"));
let main_attr = ecx.attribute(sp, main_meta); let main_attr = ecx.attribute(sp, main_meta);
// pub fn main() { ... } // pub fn main() { ... }
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![])); let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));

View file

@ -15,7 +15,7 @@ use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData};
use syntax::attr; use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::{keywords, InternedString}; use syntax::parse::token::{self, keywords};
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -74,7 +74,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
_ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"), _ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"),
} }
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span: span, span: span,

View file

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem}; use syntax::ast::{self, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -23,9 +23,9 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut FnMut(Annotatable)) { push: &mut FnMut(Annotatable)) {
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let hidden = cx.meta_list_item_word(span, InternedString::new("hidden")); let hidden = cx.meta_list_item_word(span, token::intern("hidden"));
let doc = cx.meta_list(span, InternedString::new("doc"), vec![hidden]); let doc = cx.meta_list(span, token::intern("doc"), vec![hidden]);
let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)]; let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)];
let trait_def = TraitDef { let trait_def = TraitDef {
span: span, span: span,

View file

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem}; use syntax::ast::{self, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -23,7 +23,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut FnMut(Annotatable)) { push: &mut FnMut(Annotatable)) {
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span: span, span: span,

View file

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{BinOpKind, Expr, MetaItem}; use syntax::ast::{BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -64,7 +64,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
macro_rules! md { macro_rules! md {
($name:expr, $f:ident) => { { ($name:expr, $f:ident) => { {
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
MethodDef { MethodDef {
name: $name, name: $name,

View file

@ -16,7 +16,7 @@ use deriving::generic::ty::*;
use syntax::ast::{self, BinOpKind, Expr, MetaItem}; use syntax::ast::{self, BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -27,7 +27,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
push: &mut FnMut(Annotatable)) { push: &mut FnMut(Annotatable)) {
macro_rules! md { macro_rules! md {
($name:expr, $op:expr, $equal:expr) => { { ($name:expr, $op:expr, $equal:expr) => { {
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
MethodDef { MethodDef {
name: $name, name: $name,
@ -51,7 +51,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
vec![Box::new(ordering_ty)], vec![Box::new(ordering_ty)],
true)); true));
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let partial_cmp_def = MethodDef { let partial_cmp_def = MethodDef {

View file

@ -17,10 +17,9 @@ use syntax::attr::{mark_used, mark_known};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::fold::Folder; use syntax::fold::Folder;
use syntax::parse::token::InternedString;
use syntax::visit::Visitor; use syntax::visit::Visitor;
struct MarkAttrs<'a>(&'a [InternedString]); struct MarkAttrs<'a>(&'a [ast::Name]);
impl<'a> Visitor for MarkAttrs<'a> { impl<'a> Visitor for MarkAttrs<'a> {
fn visit_attribute(&mut self, attr: &Attribute) { fn visit_attribute(&mut self, attr: &Attribute) {
@ -33,13 +32,11 @@ impl<'a> Visitor for MarkAttrs<'a> {
pub struct CustomDerive { pub struct CustomDerive {
inner: fn(TokenStream) -> TokenStream, inner: fn(TokenStream) -> TokenStream,
attrs: Vec<InternedString>, attrs: Vec<ast::Name>,
} }
impl CustomDerive { impl CustomDerive {
pub fn new(inner: fn(TokenStream) -> TokenStream, pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> CustomDerive {
attrs: Vec<InternedString>)
-> CustomDerive {
CustomDerive { inner: inner, attrs: attrs } CustomDerive { inner: inner, attrs: attrs }
} }
} }

View file

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{Expr, MetaItem}; use syntax::ast::{Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -23,7 +23,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut FnMut(Annotatable)) { push: &mut FnMut(Annotatable)) {
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, token::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span: span, span: span,

View file

@ -198,7 +198,7 @@ use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::codemap::{self, dummy_spanned, respan}; use syntax::codemap::{self, dummy_spanned, respan};
use syntax::util::move_map::MoveMap; use syntax::util::move_map::MoveMap;
use syntax::parse::token::{InternedString, keywords}; use syntax::parse::token::{self, keywords};
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
use errors::Handler; use errors::Handler;
@ -442,7 +442,7 @@ impl<'a> TraitDef<'a> {
attrs.extend(item.attrs attrs.extend(item.attrs
.iter() .iter()
.filter(|a| { .filter(|a| {
match &a.name()[..] { match &*a.name().as_str() {
"allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true, "allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
_ => false, _ => false,
} }
@ -639,15 +639,15 @@ impl<'a> TraitDef<'a> {
let attr = cx.attribute(self.span, let attr = cx.attribute(self.span,
cx.meta_word(self.span, cx.meta_word(self.span,
InternedString::new("automatically_derived"))); token::intern("automatically_derived")));
// Just mark it now since we know that it'll end up used downstream // Just mark it now since we know that it'll end up used downstream
attr::mark_used(&attr); attr::mark_used(&attr);
let opt_trait_ref = Some(trait_ref); let opt_trait_ref = Some(trait_ref);
let unused_qual = cx.attribute(self.span, let unused_qual = {
cx.meta_list(self.span, let word = cx.meta_list_item_word(self.span, token::intern("unused_qualifications"));
InternedString::new("allow"), cx.attribute(self.span, cx.meta_list(self.span, token::intern("allow"), vec![word]))
vec![cx.meta_list_item_word(self.span, };
InternedString::new("unused_qualifications"))]));
let mut a = vec![attr, unused_qual]; let mut a = vec![attr, unused_qual];
a.extend(self.attributes.iter().cloned()); a.extend(self.attributes.iter().cloned());

View file

@ -16,7 +16,7 @@ use syntax::codemap;
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension}; use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::feature_gate::{self, emit_feature_err}; use syntax::feature_gate::{self, emit_feature_err};
use syntax::parse::token::{intern, intern_and_get_ident}; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -80,7 +80,7 @@ fn allow_unstable(cx: &mut ExtCtxt, span: Span, attr_name: &str) -> Span {
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo { expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: span, call_site: span,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern(attr_name)), format: codemap::MacroAttribute(token::intern(attr_name)),
span: Some(span), span: Some(span),
allow_internal_unstable: true, allow_internal_unstable: true,
}, },
@ -105,9 +105,10 @@ pub fn expand_derive(cx: &mut ExtCtxt,
} }
}; };
let derive = token::intern("derive");
let mut derive_attrs = Vec::new(); let mut derive_attrs = Vec::new();
item = item.map_attrs(|attrs| { item = item.map_attrs(|attrs| {
let partition = attrs.into_iter().partition(|attr| &attr.name() == "derive"); let partition = attrs.into_iter().partition(|attr| attr.name() == derive);
derive_attrs = partition.0; derive_attrs = partition.0;
partition.1 partition.1
}); });
@ -158,9 +159,8 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let tword = titem.word().unwrap(); let tword = titem.word().unwrap();
let tname = tword.name(); let tname = tword.name();
if is_builtin_trait(&tname) || { if is_builtin_trait(tname) || {
let derive_mode = let derive_mode = ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(tname));
ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(intern(&tname)));
cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| { cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| {
if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false } if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false }
}).unwrap_or(false) }).unwrap_or(false)
@ -176,7 +176,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
feature_gate::EXPLAIN_CUSTOM_DERIVE); feature_gate::EXPLAIN_CUSTOM_DERIVE);
} else { } else {
cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE); cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
let name = intern_and_get_ident(&format!("derive_{}", tname)); let name = token::intern(&format!("derive_{}", tname));
let mitem = cx.meta_word(titem.span, name); let mitem = cx.meta_word(titem.span, name);
new_attributes.push(cx.attribute(mitem.span, mitem)); new_attributes.push(cx.attribute(mitem.span, mitem));
} }
@ -186,9 +186,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
item = item.map(|mut i| { item = item.map(|mut i| {
i.attrs.extend(new_attributes); i.attrs.extend(new_attributes);
if traits.len() > 0 { if traits.len() > 0 {
let list = cx.meta_list(mitem.span, let list = cx.meta_list(mitem.span, derive, traits);
intern_and_get_ident("derive"),
traits);
i.attrs.push(cx.attribute(mitem.span, list)); i.attrs.push(cx.attribute(mitem.span, list));
} }
i i
@ -217,7 +215,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let macros_11_derive = traits.iter() let macros_11_derive = traits.iter()
.cloned() .cloned()
.enumerate() .enumerate()
.filter(|&(_, ref name)| !is_builtin_trait(&name.name().unwrap())) .filter(|&(_, ref name)| !is_builtin_trait(name.name().unwrap()))
.next(); .next();
if let Some((i, titem)) = macros_11_derive { if let Some((i, titem)) = macros_11_derive {
if !cx.ecfg.features.unwrap().proc_macro { if !cx.ecfg.features.unwrap().proc_macro {
@ -226,24 +224,20 @@ pub fn expand_derive(cx: &mut ExtCtxt,
emit_feature_err(cx.parse_sess, "proc_macro", titem.span, issue, msg); emit_feature_err(cx.parse_sess, "proc_macro", titem.span, issue, msg);
} }
let tname = ast::Ident::with_empty_ctxt(intern(&titem.name().unwrap())); let tname = ast::Ident::with_empty_ctxt(titem.name().unwrap());
let path = ast::Path::from_ident(titem.span, tname); let path = ast::Path::from_ident(titem.span, tname);
let ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap(); let ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap();
traits.remove(i); traits.remove(i);
if traits.len() > 0 { if traits.len() > 0 {
item = item.map(|mut i| { item = item.map(|mut i| {
let list = cx.meta_list(mitem.span, let list = cx.meta_list(mitem.span, derive, traits);
intern_and_get_ident("derive"),
traits);
i.attrs.push(cx.attribute(mitem.span, list)); i.attrs.push(cx.attribute(mitem.span, list));
i i
}); });
} }
let titem = cx.meta_list_item_word(titem.span, titem.name().unwrap()); let titem = cx.meta_list_item_word(titem.span, titem.name().unwrap());
let mitem = cx.meta_list(titem.span, let mitem = cx.meta_list(titem.span, derive, vec![titem]);
intern_and_get_ident("derive"),
vec![titem]);
let item = Annotatable::Item(item); let item = Annotatable::Item(item);
if let SyntaxExtension::CustomDerive(ref ext) = *ext { if let SyntaxExtension::CustomDerive(ref ext) = *ext {
return ext.expand(cx, mitem.span, &mitem, item); return ext.expand(cx, mitem.span, &mitem, item);
@ -257,9 +251,10 @@ pub fn expand_derive(cx: &mut ExtCtxt,
// RFC #1445. `#[derive(PartialEq, Eq)]` adds a (trusted) // RFC #1445. `#[derive(PartialEq, Eq)]` adds a (trusted)
// `#[structural_match]` attribute. // `#[structural_match]` attribute.
if traits.iter().filter_map(|t| t.name()).any(|t| t == "PartialEq") && let (partial_eq, eq) = (token::intern("PartialEq"), token::intern("Eq"));
traits.iter().filter_map(|t| t.name()).any(|t| t == "Eq") { if traits.iter().any(|t| t.name() == Some(partial_eq)) &&
let structural_match = intern_and_get_ident("structural_match"); traits.iter().any(|t| t.name() == Some(eq)) {
let structural_match = token::intern("structural_match");
let span = allow_unstable(cx, span, "derive(PartialEq, Eq)"); let span = allow_unstable(cx, span, "derive(PartialEq, Eq)");
let meta = cx.meta_word(span, structural_match); let meta = cx.meta_word(span, structural_match);
item = item.map(|mut i| { item = item.map(|mut i| {
@ -272,9 +267,10 @@ pub fn expand_derive(cx: &mut ExtCtxt,
// the same as the copy implementation. // the same as the copy implementation.
// //
// Add a marker attribute here picked up during #[derive(Clone)] // Add a marker attribute here picked up during #[derive(Clone)]
if traits.iter().filter_map(|t| t.name()).any(|t| t == "Clone") && let (copy, clone) = (token::intern("Copy"), token::intern("Clone"));
traits.iter().filter_map(|t| t.name()).any(|t| t == "Copy") { if traits.iter().any(|t| t.name() == Some(clone)) &&
let marker = intern_and_get_ident("rustc_copy_clone_marker"); traits.iter().any(|t| t.name() == Some(copy)) {
let marker = token::intern("rustc_copy_clone_marker");
let span = allow_unstable(cx, span, "derive(Copy, Clone)"); let span = allow_unstable(cx, span, "derive(Copy, Clone)");
let meta = cx.meta_word(span, marker); let meta = cx.meta_word(span, marker);
item = item.map(|mut i| { item = item.map(|mut i| {
@ -286,14 +282,14 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let mut items = Vec::new(); let mut items = Vec::new();
for titem in traits.iter() { for titem in traits.iter() {
let tname = titem.word().unwrap().name(); let tname = titem.word().unwrap().name();
let name = intern_and_get_ident(&format!("derive({})", tname)); let name = token::intern(&format!("derive({})", tname));
let mitem = cx.meta_word(titem.span, name); let mitem = cx.meta_word(titem.span, name);
let span = Span { let span = Span {
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo { expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: titem.span, call_site: titem.span,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern(&format!("derive({})", tname))), format: codemap::MacroAttribute(token::intern(&format!("derive({})", tname))),
span: Some(titem.span), span: Some(titem.span),
allow_internal_unstable: true, allow_internal_unstable: true,
}, },
@ -302,7 +298,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
}; };
let my_item = Annotatable::Item(item); let my_item = Annotatable::Item(item);
expand_builtin(&tname, cx, span, &mitem, &my_item, &mut |a| { expand_builtin(&tname.as_str(), cx, span, &mitem, &my_item, &mut |a| {
items.push(a); items.push(a);
}); });
item = my_item.expect_item(); item = my_item.expect_item();
@ -314,8 +310,8 @@ pub fn expand_derive(cx: &mut ExtCtxt,
macro_rules! derive_traits { macro_rules! derive_traits {
($( $name:expr => $func:path, )+) => { ($( $name:expr => $func:path, )+) => {
pub fn is_builtin_trait(name: &str) -> bool { pub fn is_builtin_trait(name: ast::Name) -> bool {
match name { match &*name.as_str() {
$( $name )|+ => true, $( $name )|+ => true,
_ => false, _ => false,
} }
@ -412,7 +408,7 @@ fn call_intrinsic(cx: &ExtCtxt,
span.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo { span.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: span, call_site: span,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern("derive")), format: codemap::MacroAttribute(token::intern("derive")),
span: Some(span), span: Some(span),
allow_internal_unstable: true, allow_internal_unstable: true,
}, },

View file

@ -17,7 +17,7 @@ use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig; use syntax::ext::expand::ExpansionConfig;
use syntax::parse::ParseSess; use syntax::parse::ParseSess;
use syntax::parse::token::{self, InternedString}; use syntax::parse::token;
use syntax::feature_gate::Features; use syntax::feature_gate::Features;
use syntax::fold::Folder; use syntax::fold::Folder;
use syntax::ptr::P; use syntax::ptr::P;
@ -27,10 +27,10 @@ use syntax::visit::{self, Visitor};
use deriving; use deriving;
struct CustomDerive { struct CustomDerive {
trait_name: InternedString, trait_name: ast::Name,
function_name: Ident, function_name: Ident,
span: Span, span: Span,
attrs: Vec<InternedString>, attrs: Vec<ast::Name>,
} }
struct CollectCustomDerives<'a> { struct CollectCustomDerives<'a> {
@ -183,7 +183,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
self.handler.span_err(trait_attr.span(), "must only be one word"); self.handler.span_err(trait_attr.span(), "must only be one word");
} }
if deriving::is_builtin_trait(&trait_name) { if deriving::is_builtin_trait(trait_name) {
self.handler.span_err(trait_attr.span(), self.handler.span_err(trait_attr.span(),
"cannot override a built-in #[derive] mode"); "cannot override a built-in #[derive] mode");
} }
@ -290,10 +290,10 @@ fn mk_registrar(cx: &mut ExtCtxt,
let register_custom_derive = token::str_to_ident("register_custom_derive"); let register_custom_derive = token::str_to_ident("register_custom_derive");
let stmts = custom_derives.iter().map(|cd| { let stmts = custom_derives.iter().map(|cd| {
let path = cx.path_global(cd.span, vec![cd.function_name]); let path = cx.path_global(cd.span, vec![cd.function_name]);
let trait_name = cx.expr_str(cd.span, cd.trait_name.clone()); let trait_name = cx.expr_str(cd.span, cd.trait_name.as_str());
let attrs = cx.expr_vec_slice( let attrs = cx.expr_vec_slice(
span, span,
cd.attrs.iter().map(|s| cx.expr_str(cd.span, s.clone())).collect::<Vec<_>>() cd.attrs.iter().map(|s| cx.expr_str(cd.span, s.as_str())).collect::<Vec<_>>()
); );
(path, trait_name, attrs) (path, trait_name, attrs)
}).map(|(path, trait_name, attrs)| { }).map(|(path, trait_name, attrs)| {
@ -316,8 +316,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
cx.ty(span, ast::TyKind::Tup(Vec::new())), cx.ty(span, ast::TyKind::Tup(Vec::new())),
cx.block(span, stmts)); cx.block(span, stmts));
let derive_registrar = token::intern_and_get_ident("rustc_derive_registrar"); let derive_registrar = cx.meta_word(span, token::intern("rustc_derive_registrar"));
let derive_registrar = cx.meta_word(span, derive_registrar);
let derive_registrar = cx.attribute(span, derive_registrar); let derive_registrar = cx.attribute(span, derive_registrar);
let func = func.map(|mut i| { let func = func.map(|mut i| {
i.attrs.push(derive_registrar); i.attrs.push(derive_registrar);