Refactor `MetaItemKind` to use `Name`s instead of `InternedString`s.

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,
};
let (message, label) = match &*name {
let (message, label) = match &*name.as_str() {
"C" => {
conflicting_reprs += 1;
if target != Target::Struct &&
@ -120,7 +120,7 @@ impl<'a> CheckAttrVisitor<'a> {
}
fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
let name: &str = &attr.name();
let name: &str = &attr.name().as_str();
match name {
"inline" => self.check_inline(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::fmt;
use syntax::attr;
use syntax::parse::token::InternedString;
use syntax::ast;
use syntax_pos::{MultiSpan, Span};
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
/// attributes. Writing this as an iterator is an enormous mess.
// See also the hir version just below.
pub fn gather_attrs(attrs: &[ast::Attribute])
-> Vec<Result<(InternedString, Level, Span), Span>> {
pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec<Result<(ast::Name, Level, Span), Span>> {
let mut out = vec![];
for attr in attrs {
let r = gather_attr(attr);
@ -394,11 +392,10 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
out
}
pub fn gather_attr(attr: &ast::Attribute)
-> Vec<Result<(InternedString, Level, Span), Span>> {
pub fn gather_attr(attr: &ast::Attribute) -> Vec<Result<(ast::Name, Level, Span), Span>> {
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,
Some(lvl) => lvl,
};
@ -414,9 +411,7 @@ pub fn gather_attr(attr: &ast::Attribute)
};
for li in metas {
out.push(li.word().map_or(Err(li.span), |word| {
Ok((word.name().clone(), level, word.span))
}));
out.push(li.word().map_or(Err(li.span), |word| Ok((word.name(), level, word.span))));
}
out
@ -629,10 +624,10 @@ pub trait LintContext: Sized {
continue;
}
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)],
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()
.map(|lint_id: &LintId|
(*lint_id, level, span))
@ -1193,8 +1188,7 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
continue;
}
Ok((lint_name, _, span)) => {
match check_lint_name(&cx.lints,
&lint_name[..]) {
match check_lint_name(&cx.lints, &lint_name.as_str()) {
CheckLintNameResult::Ok => (),
CheckLintNameResult::Warning(ref msg) => {
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();
for attr in lint::gather_attrs(attrs) {
match attr {
Ok((ref name, lint::Allow, _))
if &name[..] == dead_code => return true,
Ok((name, lint::Allow, _)) if name == &*dead_code => return true,
_ => (),
}
}

View File

@ -26,7 +26,7 @@ use middle::cstore;
use syntax::ast::{self, IntTy, UintTy};
use syntax::attr;
use syntax::parse;
use syntax::parse::{self, token};
use syntax::parse::token::InternedString;
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 mut ret = vec![ // Target bindings.
mk(InternedString::new("target_os"), intern(os)),
mk(InternedString::new("target_family"), fam.clone()),
mk(InternedString::new("target_arch"), intern(arch)),
mk(InternedString::new("target_endian"), intern(end)),
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
mk(InternedString::new("target_env"), intern(env)),
mk(InternedString::new("target_vendor"), intern(vendor)),
mk(token::intern("target_os"), intern(os)),
mk(token::intern("target_family"), fam.clone()),
mk(token::intern("target_arch"), intern(arch)),
mk(token::intern("target_endian"), intern(end)),
mk(token::intern("target_pointer_width"), intern(wordsz)),
mk(token::intern("target_env"), intern(env)),
mk(token::intern("target_vendor"), intern(vendor)),
];
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 {
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] {
if i <= max_atomic_width {
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 {
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 {
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) {
ret.push(attr::mk_word_item(InternedString::new("proc_macro")));
ret.push(attr::mk_word_item(token::intern("proc_macro")));
}
return ret;
}
pub fn append_configuration(cfg: &mut ast::CrateConfig,
name: InternedString) {
pub fn append_configuration(cfg: &mut ast::CrateConfig, name: ast::Name) {
if !cfg.iter().any(|mi| mi.name() == name) {
cfg.push(attr::mk_word_item(name))
}
@ -995,7 +994,7 @@ pub fn build_configuration(sess: &Session,
let default_cfg = default_configuration(sess);
// If the user wants a test runner, then add the test cfg
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<_>>();
v.extend_from_slice(&default_cfg[..]);

View File

@ -13,8 +13,7 @@ use llvm::LLVMRustHasFeature;
use rustc::session::Session;
use rustc_trans::back::write::create_target_machine;
use syntax::feature_gate::UnstableFeatures;
use syntax::parse::token::InternedString;
use syntax::parse::token::intern_and_get_ident as intern;
use syntax::parse::token::{self, intern_and_get_ident as intern};
use libc::c_char;
// 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 {
assert_eq!(feat.chars().last(), Some('\0'));
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::io::Write;
use syntax::ast;
use syntax::parse::token::InternedString;
use syntax_pos::Span;
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 Targets = Vec<(Span, InternedString, ast::NodeId, DepNode<DefId>)>;
type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode<DefId>)>;
struct IfThisChanged<'a, 'tcx:'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@ -106,7 +105,7 @@ struct IfThisChanged<'a, 'tcx:'a> {
}
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;
for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() {
@ -127,8 +126,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
None => DepNode::Hir(def_id),
Some(ref n) => {
match DepNode::from_label_string(&n[..], def_id) {
Some(n) => {
match DepNode::from_label_string(&n.as_str(), def_id) {
Ok(n) => n,
Err(()) => {
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) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
Some(ref n) => {
match DepNode::from_label_string(&n[..], def_id) {
Some(n) => {
match DepNode::from_label_string(&n.as_str(), def_id) {
Ok(n) => n,
Err(()) => {
self.tcx.sess.span_fatal(
@ -159,7 +158,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
}
};
self.then_this_would_need.push((attr.span,
dep_node_interned.clone().unwrap(),
dep_node_interned.unwrap(),
node_id,
dep_node));
}

View File

@ -875,16 +875,19 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
// ignoring span information, it doesn't matter here
self.hash_discriminant(&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.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.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.hash(self.st);
// 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 {
let attr = &attributes[i];
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);
self.hash_meta_item(&*attr.value);
}

View File

@ -772,9 +772,9 @@ impl LintPass for DeprecatedAttr {
impl EarlyLintPass for DeprecatedAttr {
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 {
if n == name {
if name == n {
if let &AttributeGate::Gated(Stability::Deprecated(link),
ref name,
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
// the crate level?
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();
if known_crate || plugin_crate {
let msg = match attr.style {

View File

@ -37,7 +37,7 @@ use syntax::abi::Abi;
use syntax::attr;
use syntax::ext::base::SyntaxExtension;
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 log;
@ -582,11 +582,11 @@ impl<'a> CrateLoader<'a> {
trait_name: &str,
expand: fn(TokenStream) -> TokenStream,
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(
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 {
// plugins must have a name and can't be key = value
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);
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),
}

View File

@ -31,7 +31,6 @@ use std::rc::Rc;
use syntax::ast::Name;
use syntax::attr;
use syntax::parse::token;
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
@ -632,7 +631,7 @@ impl<'b> Resolver<'b> {
match attr.meta_item_list() {
Some(names) => for attr in names {
if let Some(word) = attr.word() {
imports.imports.push((token::intern(&word.name()), attr.span()));
imports.imports.push((word.name(), attr.span()));
} else {
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() {
for attr in names {
if let Some(word) = attr.word() {
imports.reexports.push((token::intern(&word.name()), attr.span()));
imports.reexports.push((word.name(), attr.span()));
} else {
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::tt::macro_rules;
use syntax::fold::Folder;
use syntax::parse::token::intern;
use syntax::ptr::P;
use syntax::util::lev_distance::find_best_match_for_name;
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> {
for i in 0..attrs.len() {
let name = intern(&attrs[i].name());
match self.builtin_macros.get(&name).cloned() {
match self.builtin_macros.get(&attrs[i].name()).cloned() {
Some(binding) => match *self.get_macro(binding) {
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
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::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::print::pprust::{ty_to_string, arg_to_string};
use syntax::codemap::MacroAttribute;
@ -728,7 +728,7 @@ impl Visitor for PathCollector {
}
fn docs_for_attrs(attrs: &[Attribute]) -> String {
let doc = InternedString::new("doc");
let doc = token::intern("doc");
let mut result = String::new();
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 {
pub const fn with_empty_ctxt(name: Name) -> Ident {
Ident { name: name, ctxt: SyntaxContext::empty() }
@ -518,15 +524,15 @@ pub enum MetaItemKind {
/// Word meta item.
///
/// E.g. `test` as in `#[test]`
Word(InternedString),
Word(Name),
/// List meta item.
///
/// E.g. `derive(..)` as in `#[derive(..)]`
List(InternedString, Vec<NestedMetaItem>),
List(Name, Vec<NestedMetaItem>),
/// Name value meta item.
///
/// 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

View File

@ -15,7 +15,7 @@ pub use self::ReprAttr::*;
pub use self::IntType::*;
use ast;
use ast::{AttrId, Attribute};
use ast::{AttrId, Attribute, Name};
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use ast::{Lit, Expr, Item, Local, Stmt, StmtKind};
use codemap::{respan, spanned, dummy_spanned, mk_sp};
@ -37,8 +37,8 @@ thread_local! {
}
enum AttrError {
MultipleItem(InternedString),
UnknownMetaItem(InternedString),
MultipleItem(Name),
UnknownMetaItem(Name),
MissingSince,
MissingFeature,
MultipleStabilityLevels,
@ -134,7 +134,7 @@ impl NestedMetaItem {
/// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
/// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem
pub fn name(&self) -> Option<InternedString> {
pub fn name(&self) -> Option<Name> {
self.meta_item().and_then(|meta_item| Some(meta_item.name()))
}
@ -186,14 +186,14 @@ impl NestedMetaItem {
impl Attribute {
pub fn check_name(&self, name: &str) -> bool {
let matches = name == &self.name()[..];
let matches = self.name() == name;
if matches {
mark_used(self);
}
matches
}
pub fn name(&self) -> InternedString { self.meta().name() }
pub fn name(&self) -> Name { self.meta().name() }
pub fn value_str(&self) -> Option<InternedString> {
self.meta().value_str()
@ -218,11 +218,11 @@ impl Attribute {
}
impl MetaItem {
pub fn name(&self) -> InternedString {
pub fn name(&self) -> Name {
match self.node {
MetaItemKind::Word(ref n) => (*n).clone(),
MetaItemKind::NameValue(ref n, _) => (*n).clone(),
MetaItemKind::List(ref n, _) => (*n).clone(),
MetaItemKind::Word(n) => n,
MetaItemKind::NameValue(n, _) => n,
MetaItemKind::List(n, _) => n,
}
}
@ -255,7 +255,7 @@ impl MetaItem {
pub fn span(&self) -> Span { self.span }
pub fn check_name(&self, name: &str) -> bool {
name == &self.name()[..]
self.name() == name
}
pub fn is_value_str(&self) -> bool {
@ -282,7 +282,7 @@ impl Attribute {
if self.is_sugared_doc {
let comment = self.value_str().unwrap();
let meta = mk_name_value_item_str(
InternedString::new("doc"),
token::intern("doc"),
token::intern_and_get_ident(&strip_doc_comment_decoration(
&comment)));
if self.style == ast::AttrStyle::Outer {
@ -298,40 +298,36 @@ impl Attribute {
/* Constructors */
pub fn mk_name_value_item_str(name: InternedString, value: InternedString)
-> P<MetaItem> {
pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P<MetaItem> {
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
}
pub fn mk_name_value_item(name: InternedString, value: ast::Lit)
-> P<MetaItem> {
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P<MetaItem> {
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)
}
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)))
}
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)
}
pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit)
-> P<MetaItem> {
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
P(respan(sp, MetaItemKind::NameValue(name, value)))
}
pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec<NestedMetaItem>)
-> P<MetaItem> {
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
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)))
}
@ -398,7 +394,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
Attribute {
id: id,
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,
span: mk_sp(lo, hi),
}
@ -490,11 +486,11 @@ pub enum InlineAttr {
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
attrs.iter().fold(InlineAttr::None, |ia,attr| {
match attr.value.node {
MetaItemKind::Word(ref n) if n == "inline" => {
MetaItemKind::Word(n) if n == "inline" => {
mark_used(attr);
InlineAttr::Hint
}
MetaItemKind::List(ref n, ref items) if n == "inline" => {
MetaItemKind::List(n, ref items) if n == "inline" => {
mark_used(attr);
if items.len() != 1 {
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
// that they won't fail with the loop above.
match &pred[..] {
match &*pred.as_str() {
"any" => mis.iter().any(|mi| {
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 {
let tag = attr.name();
let tag = &*tag;
if tag != "rustc_deprecated" && tag != "unstable" && tag != "stable" {
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" => {
if rustc_depr.is_some() {
span_err!(diagnostic, item_sp, E0540,
@ -645,7 +640,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let mut reason = None;
for meta in metas {
if let Some(mi) = meta.meta_item() {
match &*mi.name() {
match &*mi.name().as_str() {
"since" => if !get(mi, &mut since) { 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;
for meta in metas {
if let Some(mi) = meta.meta_item() {
match &*mi.name() {
match &*mi.name().as_str() {
"feature" => if !get(mi, &mut feature) { continue 'outer },
"reason" => if !get(mi, &mut reason) { continue 'outer },
"issue" => if !get(mi, &mut issue) { continue 'outer },
@ -743,7 +738,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
let mut since = None;
for meta in metas {
if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
match &*mi.name() {
match &*mi.name().as_str() {
"feature" => if !get(mi, &mut feature) { 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;
for meta in metas {
if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
match &*mi.name() {
match &*mi.name().as_str() {
"since" => if !get(mi, &mut since) { 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> {
let mut acc = Vec::new();
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);
for item in items {
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() {
let word = &*mi.name();
let word = &*mi.name().as_str();
let hint = match word {
// Can't use "extern" because it's not a lexical identifier.
"C" => Some(ReprExtern),

View File

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

View File

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

View File

@ -757,7 +757,7 @@ pub struct GatedCfg {
impl GatedCfg {
pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
let name = cfg.name();
let name = &*cfg.name().as_str();
GATED_CFGS.iter()
.position(|info| info.0 == name)
.map(|idx| {
@ -804,7 +804,7 @@ macro_rules! gate_feature {
impl<'a> Context<'a> {
fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
debug!("check_attribute(attr = {:?})", attr);
let name = &*attr.name();
let name = &*attr.name().as_str();
for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES {
if n == name {
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) => {
for mi in list {
let name = if let Some(word) = mi.word() {
word.name()
word.name().as_str()
} else {
span_err!(span_handler, mi.span, E0556,
"malformed feature, expected just one word");

View File

@ -227,22 +227,21 @@ impl<'a> Parser<'a> {
let lo = self.span.lo;
let ident = self.parse_ident()?;
let name = self.id_to_interned_str(ident);
match self.token {
token::Eq => {
self.bump();
let lit = self.parse_unsuffixed_lit()?;
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) => {
let inner_items = self.parse_meta_seq()?;
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;
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 syntax_pos::{self, BytePos};
use errors;
use parse::token::{self, keywords, BinOpToken, Token, InternedString};
use parse::token::{self, keywords, BinOpToken, Token};
use parse::lexer::comments;
use parse;
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.
// #![feature(prelude_import)]
let prelude_import_meta = attr::mk_list_word_item(InternedString::new("prelude_import"));
let list = attr::mk_list_item(InternedString::new("feature"),
vec![prelude_import_meta]);
let prelude_import_meta = attr::mk_list_word_item(token::intern("prelude_import"));
let list = attr::mk_list_item(token::intern("feature"), vec![prelude_import_meta]);
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list);
try!(s.print_attribute(&fake_attr));
// #![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);
try!(s.print_attribute(&fake_attr));
}
@ -779,15 +778,15 @@ pub trait PrintState<'a> {
try!(self.ibox(INDENT_UNIT));
match item.node {
ast::MetaItemKind::Word(ref name) => {
try!(word(self.writer(), &name));
try!(word(self.writer(), &name.as_str()));
}
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.print_literal(value));
}
ast::MetaItemKind::List(ref name, ref items) => {
try!(word(self.writer(), &name));
try!(word(self.writer(), &name.as_str()));
try!(self.popen());
try!(self.commasep(Consistent,
&items[..],

View File

@ -12,7 +12,7 @@ use ast;
use attr;
use syntax_pos::{DUMMY_SP, Span};
use codemap::{self, ExpnInfo, NameAndSpan, MacroAttribute};
use parse::token::{intern, InternedString, keywords};
use parse::token::{intern, keywords};
use parse::{token, ParseSess};
use ptr::P;
@ -57,7 +57,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
krate.module.items.insert(0, P(ast::Item {
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,
node: ast::ItemKind::ExternCrate(Some(crate_name)),
ident: token::str_to_ident(name),
@ -70,7 +70,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
attrs: vec![ast::Attribute {
style: ast::AttrStyle::Outer,
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,
}),
id: attr::mk_attr_id(),

View File

@ -191,8 +191,8 @@ impl fold::Folder for EntryPointCleaner {
EntryPointType::MainAttr |
EntryPointType::Start =>
folded.map(|ast::Item {id, ident, attrs, node, vis, span}| {
let allow_str = InternedString::new("allow");
let dead_code_str = InternedString::new("dead_code");
let allow_str = token::intern("allow");
let dead_code_str = token::intern("dead_code");
let word_vec = vec![attr::mk_list_word_item(dead_code_str)];
let allow_dead_code_item = attr::mk_list_item(allow_str, word_vec);
let allow_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.
let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list(
DUMMY_SP,
InternedString::new("allow"),
vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, InternedString::new("private_in_public"))],
token::intern("allow"),
vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, token::intern("private_in_public"))],
));
let items = tests.into_iter().map(|r| {
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]);
let call_test_main = ecx.stmt_expr(call_test_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);
// pub fn main() { ... }
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::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::{keywords, InternedString};
use syntax::parse::token::{self, keywords};
use syntax::ptr::P;
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"),
}
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 trait_def = TraitDef {
span: span,

View File

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

View File

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::ptr::P;
use syntax_pos::Span;
@ -23,7 +23,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
mitem: &MetaItem,
item: &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 trait_def = TraitDef {
span: span,

View File

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::ptr::P;
use syntax_pos::Span;
@ -64,7 +64,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
macro_rules! md {
($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)];
MethodDef {
name: $name,

View File

@ -16,7 +16,7 @@ use deriving::generic::ty::*;
use syntax::ast::{self, BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::ptr::P;
use syntax_pos::Span;
@ -27,7 +27,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
push: &mut FnMut(Annotatable)) {
macro_rules! md {
($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)];
MethodDef {
name: $name,
@ -51,7 +51,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
vec![Box::new(ordering_ty)],
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 partial_cmp_def = MethodDef {

View File

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

View File

@ -14,7 +14,7 @@ use deriving::generic::ty::*;
use syntax::ast::{Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::ptr::P;
use syntax_pos::Span;
@ -23,7 +23,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
mitem: &MetaItem,
item: &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 trait_def = TraitDef {
span: span,

View File

@ -198,7 +198,7 @@ use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::codemap::{self, dummy_spanned, respan};
use syntax::util::move_map::MoveMap;
use syntax::parse::token::{InternedString, keywords};
use syntax::parse::token::{self, keywords};
use syntax::ptr::P;
use syntax_pos::{DUMMY_SP, Span};
use errors::Handler;
@ -442,7 +442,7 @@ impl<'a> TraitDef<'a> {
attrs.extend(item.attrs
.iter()
.filter(|a| {
match &a.name()[..] {
match &*a.name().as_str() {
"allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
_ => false,
}
@ -639,15 +639,15 @@ impl<'a> TraitDef<'a> {
let attr = cx.attribute(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
attr::mark_used(&attr);
let opt_trait_ref = Some(trait_ref);
let unused_qual = cx.attribute(self.span,
cx.meta_list(self.span,
InternedString::new("allow"),
vec![cx.meta_list_item_word(self.span,
InternedString::new("unused_qualifications"))]));
let unused_qual = {
let word = cx.meta_list_item_word(self.span, token::intern("unused_qualifications"));
cx.attribute(self.span, cx.meta_list(self.span, token::intern("allow"), vec![word]))
};
let mut a = vec![attr, unused_qual];
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::build::AstBuilder;
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_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 {
call_site: span,
callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern(attr_name)),
format: codemap::MacroAttribute(token::intern(attr_name)),
span: Some(span),
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();
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;
partition.1
});
@ -158,9 +159,8 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let tword = titem.word().unwrap();
let tname = tword.name();
if is_builtin_trait(&tname) || {
let derive_mode =
ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(intern(&tname)));
if is_builtin_trait(tname) || {
let derive_mode = ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(tname));
cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| {
if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false }
}).unwrap_or(false)
@ -176,7 +176,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
feature_gate::EXPLAIN_CUSTOM_DERIVE);
} else {
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);
new_attributes.push(cx.attribute(mitem.span, mitem));
}
@ -186,9 +186,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
item = item.map(|mut i| {
i.attrs.extend(new_attributes);
if traits.len() > 0 {
let list = cx.meta_list(mitem.span,
intern_and_get_ident("derive"),
traits);
let list = cx.meta_list(mitem.span, derive, traits);
i.attrs.push(cx.attribute(mitem.span, list));
}
i
@ -217,7 +215,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let macros_11_derive = traits.iter()
.cloned()
.enumerate()
.filter(|&(_, ref name)| !is_builtin_trait(&name.name().unwrap()))
.filter(|&(_, ref name)| !is_builtin_trait(name.name().unwrap()))
.next();
if let Some((i, titem)) = macros_11_derive {
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);
}
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 ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap();
traits.remove(i);
if traits.len() > 0 {
item = item.map(|mut i| {
let list = cx.meta_list(mitem.span,
intern_and_get_ident("derive"),
traits);
let list = cx.meta_list(mitem.span, derive, traits);
i.attrs.push(cx.attribute(mitem.span, list));
i
});
}
let titem = cx.meta_list_item_word(titem.span, titem.name().unwrap());
let mitem = cx.meta_list(titem.span,
intern_and_get_ident("derive"),
vec![titem]);
let mitem = cx.meta_list(titem.span, derive, vec![titem]);
let item = Annotatable::Item(item);
if let SyntaxExtension::CustomDerive(ref ext) = *ext {
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)
// `#[structural_match]` attribute.
if traits.iter().filter_map(|t| t.name()).any(|t| t == "PartialEq") &&
traits.iter().filter_map(|t| t.name()).any(|t| t == "Eq") {
let structural_match = intern_and_get_ident("structural_match");
let (partial_eq, eq) = (token::intern("PartialEq"), token::intern("Eq"));
if traits.iter().any(|t| t.name() == Some(partial_eq)) &&
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 meta = cx.meta_word(span, structural_match);
item = item.map(|mut i| {
@ -272,9 +267,10 @@ pub fn expand_derive(cx: &mut ExtCtxt,
// the same as the copy implementation.
//
// Add a marker attribute here picked up during #[derive(Clone)]
if traits.iter().filter_map(|t| t.name()).any(|t| t == "Clone") &&
traits.iter().filter_map(|t| t.name()).any(|t| t == "Copy") {
let marker = intern_and_get_ident("rustc_copy_clone_marker");
let (copy, clone) = (token::intern("Copy"), token::intern("Clone"));
if traits.iter().any(|t| t.name() == Some(clone)) &&
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 meta = cx.meta_word(span, marker);
item = item.map(|mut i| {
@ -286,14 +282,14 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let mut items = Vec::new();
for titem in traits.iter() {
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 span = Span {
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: titem.span,
callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern(&format!("derive({})", tname))),
format: codemap::MacroAttribute(token::intern(&format!("derive({})", tname))),
span: Some(titem.span),
allow_internal_unstable: true,
},
@ -302,7 +298,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
};
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);
});
item = my_item.expect_item();
@ -314,8 +310,8 @@ pub fn expand_derive(cx: &mut ExtCtxt,
macro_rules! derive_traits {
($( $name:expr => $func:path, )+) => {
pub fn is_builtin_trait(name: &str) -> bool {
match name {
pub fn is_builtin_trait(name: ast::Name) -> bool {
match &*name.as_str() {
$( $name )|+ => true,
_ => false,
}
@ -412,7 +408,7 @@ fn call_intrinsic(cx: &ExtCtxt,
span.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: span,
callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(intern("derive")),
format: codemap::MacroAttribute(token::intern("derive")),
span: Some(span),
allow_internal_unstable: true,
},

View File

@ -17,7 +17,7 @@ use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig;
use syntax::parse::ParseSess;
use syntax::parse::token::{self, InternedString};
use syntax::parse::token;
use syntax::feature_gate::Features;
use syntax::fold::Folder;
use syntax::ptr::P;
@ -27,10 +27,10 @@ use syntax::visit::{self, Visitor};
use deriving;
struct CustomDerive {
trait_name: InternedString,
trait_name: ast::Name,
function_name: Ident,
span: Span,
attrs: Vec<InternedString>,
attrs: Vec<ast::Name>,
}
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");
}
if deriving::is_builtin_trait(&trait_name) {
if deriving::is_builtin_trait(trait_name) {
self.handler.span_err(trait_attr.span(),
"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 stmts = custom_derives.iter().map(|cd| {
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(
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)
}).map(|(path, trait_name, attrs)| {
@ -316,8 +316,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
cx.ty(span, ast::TyKind::Tup(Vec::new())),
cx.block(span, stmts));
let derive_registrar = token::intern_and_get_ident("rustc_derive_registrar");
let derive_registrar = cx.meta_word(span, derive_registrar);
let derive_registrar = cx.meta_word(span, token::intern("rustc_derive_registrar"));
let derive_registrar = cx.attribute(span, derive_registrar);
let func = func.map(|mut i| {
i.attrs.push(derive_registrar);